From 9321418df61db6ba0451def53e4ffcd37d492a02 Mon Sep 17 00:00:00 2001 From: Phillip Alday Date: Tue, 8 Oct 2024 13:16:15 -0500 Subject: [PATCH 01/11] ignore versioned manifest --- .gitignore | 1 + 1 file changed, 1 insertion(+) diff --git a/.gitignore b/.gitignore index e796c3e8..047fafea 100644 --- a/.gitignore +++ b/.gitignore @@ -129,6 +129,7 @@ dmypy.json docs/build/ docs/site/ Manifest.toml +Manifest-v*.toml # misc *.DS_Store From 42a4700bf07da4c29380dc6c8fa550fec649266c Mon Sep 17 00:00:00 2001 From: Phillip Alday Date: Tue, 8 Oct 2024 13:36:37 -0500 Subject: [PATCH 02/11] fix serialization on 1.11 --- src/serialization.jl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/serialization.jl b/src/serialization.jl index e450f614..831b6d9f 100644 --- a/src/serialization.jl +++ b/src/serialization.jl @@ -291,7 +291,7 @@ function serialize_lpcm(format::LPCMFormat, samples::AbstractMatrix) samples isa Matrix && return reinterpret(UInt8, vec(samples)) io = IOBuffer() write(io, samples) - return resize!(io.data, io.size) + return take!(seekstart(io)) end function serialize_lpcm(stream::LPCMStream, samples::AbstractMatrix) From 9b618ae64b1066edad070c16b28490fc58c92724 Mon Sep 17 00:00:00 2001 From: Phillip Alday Date: Tue, 8 Oct 2024 13:37:08 -0500 Subject: [PATCH 03/11] use set values instead of calling random --- test/samples.jl | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/test/samples.jl b/test/samples.jl index 81911b1a..3d044b40 100644 --- a/test/samples.jl +++ b/test/samples.jl @@ -142,7 +142,10 @@ end sample_offset_in_unit=-0.5, sample_type=Int16, sample_rate=50.2) - samples = Samples(rand(Random.MersenneTwister(0), sample_type(info), 3, 5), info, true) + data = Int16[20032 4760 27427 -20758 24287 + 14240 5037 5598 -5888 21784 + 16885 600 20880 -32493 -19305] + samples = Samples(data, info, true) M = VERSION >= v"1.6" ? "Matrix{Int16}" : "Array{Int16,2}" @test sprint(show, samples, context=(:compact => true)) == "Samples(3×5 $M)" @test sprint(show, samples) == """ From 78322d844fc96a778aec53e03e14b98bcc9eb20a Mon Sep 17 00:00:00 2001 From: Phillip Alday Date: Wed, 9 Oct 2024 09:50:19 -0500 Subject: [PATCH 04/11] add FLAC_jll to examples project --- examples/Project.toml | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/examples/Project.toml b/examples/Project.toml index d6b2dac2..14608961 100644 --- a/examples/Project.toml +++ b/examples/Project.toml @@ -1,6 +1,10 @@ [deps] Arrow = "69666777-d1a9-59fb-9406-91d4454c9d45" DataFrames = "a93c6f00-e57d-5684-b7b6-d8193f3e46c0" +FLAC_jll = "1d38b3a6-207b-531b-80e8-c83f48dafa73" Legolas = "741b9549-f6ed-4911-9fbf-4a1c0c97f0cd" Onda = "e853f5be-6863-11e9-128d-476edb89bfb5" TimeSpans = "bb34ddd2-327f-4c4a-bfb0-c98fc494ece1" + +[compat] +FLAC_jll = "1.3.3" From c48317e7f04a6fa7e5e65d21b89937b021f48710 Mon Sep 17 00:00:00 2001 From: Phillip Alday Date: Wed, 9 Oct 2024 09:50:38 -0500 Subject: [PATCH 05/11] add missing qualification --- examples/flac.jl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/examples/flac.jl b/examples/flac.jl index 3fb54ee4..05038023 100644 --- a/examples/flac.jl +++ b/examples/flac.jl @@ -38,7 +38,7 @@ FLACFormat(info; kwargs...) = FLACFormat(LPCMFormat(info); sample_rate=info.samp Onda.register_lpcm_format!(file_format -> file_format == "flac" ? FLACFormat : nothing) -file_format_string(::FLACFormat) = "flac" +Onda.file_format_string(::FLACFormat) = "flac" function flac_raw_specification_flags(format::FLACFormat{S}) where {S} return (level="--compression-level-$(format.level)", From c5437cfc259ef154813d55435b9997af39df10b2 Mon Sep 17 00:00:00 2001 From: Phillip Alday Date: Wed, 9 Oct 2024 10:06:37 -0500 Subject: [PATCH 06/11] whitespace Co-authored-by: Eric Davies --- test/samples.jl | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/test/samples.jl b/test/samples.jl index 3d044b40..412e8d81 100644 --- a/test/samples.jl +++ b/test/samples.jl @@ -142,9 +142,9 @@ end sample_offset_in_unit=-0.5, sample_type=Int16, sample_rate=50.2) - data = Int16[20032 4760 27427 -20758 24287 - 14240 5037 5598 -5888 21784 - 16885 600 20880 -32493 -19305] + data = Int16[20032 4760 27427 -20758 24287 + 14240 5037 5598 -5888 21784 + 16885 600 20880 -32493 -19305] samples = Samples(data, info, true) M = VERSION >= v"1.6" ? "Matrix{Int16}" : "Array{Int16,2}" @test sprint(show, samples, context=(:compact => true)) == "Samples(3×5 $M)" From 9d2859126bfc5a5e0d69d4fd7a574735e7ba2d9a Mon Sep 17 00:00:00 2001 From: Phillip Alday Date: Wed, 9 Oct 2024 10:11:31 -0500 Subject: [PATCH 07/11] slightly more efficient serialization --- src/serialization.jl | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/serialization.jl b/src/serialization.jl index 831b6d9f..990f4eab 100644 --- a/src/serialization.jl +++ b/src/serialization.jl @@ -286,12 +286,12 @@ function deserialize_lpcm(stream::LPCMStream, sample_offset::Integer=0, return deserialize_lpcm(stream.format, read(stream.io, byte_count)) end +_matrix(samples::Matrix) = samples +_matrix(samples::AbstractMatrix) = Matrix(samples) + function serialize_lpcm(format::LPCMFormat, samples::AbstractMatrix) _validate_lpcm_samples(format, samples) - samples isa Matrix && return reinterpret(UInt8, vec(samples)) - io = IOBuffer() - write(io, samples) - return take!(seekstart(io)) + return reinterpret(UInt8, vec(_matrix(samples))) end function serialize_lpcm(stream::LPCMStream, samples::AbstractMatrix) From 05fe086b3093573975c0ae12537d233f62844037 Mon Sep 17 00:00:00 2001 From: Phillip Alday Date: Wed, 9 Oct 2024 11:05:15 -0500 Subject: [PATCH 08/11] edits --- examples/flac.jl | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/examples/flac.jl b/examples/flac.jl index 05038023..a57975d6 100644 --- a/examples/flac.jl +++ b/examples/flac.jl @@ -56,7 +56,8 @@ end function Onda.deserializing_lpcm_stream(format::FLACFormat, io) flags = flac_raw_specification_flags(format) cmd = flac() do flac_path - return open(`$flac_path - --totally-silent -d --force-raw-format $(flags.endian) $(flags.is_signed)`, io) + return open(`$flac_path --decode --totally-silent --force-raw-format $(flags.level) $(flags.endian) $(flags.is_signed) -`, + io; read=true) end return FLACStream(Onda.LPCMStream(format.lpcm, cmd)) end @@ -64,7 +65,7 @@ end function Onda.serializing_lpcm_stream(format::FLACFormat, io) flags = flac_raw_specification_flags(format) cmd = flac() do flac_path - return open(`$flac_path --totally-silent $(flags) -`, io; write=true) + return open(`$flac_path --totally-silent --force-raw-format $(flags) -`, io; write=true) end return FLACStream(Onda.LPCMStream(format.lpcm, cmd)) end @@ -91,7 +92,7 @@ function Onda.serialize_lpcm(format::FLACFormat, samples::AbstractMatrix) stream = serializing_lpcm_stream(format, io) serialize_lpcm(stream, samples) finalize_lpcm_stream(stream) - return take!(io) + return take!(seekstart(io)) end ##### From 838129b7629fd7b04c86d98b826788d0ed131e8d Mon Sep 17 00:00:00 2001 From: Phillip Alday Date: Wed, 9 Oct 2024 11:05:23 -0500 Subject: [PATCH 09/11] fix on 1.11 --- src/serialization.jl | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/serialization.jl b/src/serialization.jl index 990f4eab..30223732 100644 --- a/src/serialization.jl +++ b/src/serialization.jl @@ -282,8 +282,11 @@ function deserialize_lpcm(stream::LPCMStream, sample_offset::Integer=0, bytes_per_sample = _bytes_per_sample(stream.format) jump(stream.io, bytes_per_sample * sample_offset) byte_count = bytes_per_sample * sample_count - byte_count = byte_count >= 0 ? byte_count : typemax(Int) # handle overflow - return deserialize_lpcm(stream.format, read(stream.io, byte_count)) + # XXX on Julia 1.11.0, setting byte_count to the sentinal value typemax(Int) + # doesn't work: the correct number of bytes is returned from `read`, but the + # values change every time. By using a different method, we avoid that problem + bytes = byte_count >= 0 ? read(stream.io, byte_count) : read(stream.io) # handle overflow + return deserialize_lpcm(stream.format, bytes) end _matrix(samples::Matrix) = samples From 17759b50b3d8d6ac3a5a7570ca904e4bc2891b9a Mon Sep 17 00:00:00 2001 From: Phillip Alday Date: Wed, 9 Oct 2024 11:08:43 -0500 Subject: [PATCH 10/11] patch bump --- Project.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Project.toml b/Project.toml index 34a2eecb..1d0f44b9 100644 --- a/Project.toml +++ b/Project.toml @@ -1,7 +1,7 @@ name = "Onda" uuid = "e853f5be-6863-11e9-128d-476edb89bfb5" authors = ["Beacon Biosignals, Inc."] -version = "0.15.9" +version = "0.15.10" [deps] Arrow = "69666777-d1a9-59fb-9406-91d4454c9d45" From 0f7bfaac676799a95c9224992b86f40b51ddd60e Mon Sep 17 00:00:00 2001 From: Phillip Alday Date: Wed, 9 Oct 2024 12:16:01 -0500 Subject: [PATCH 11/11] straight to vec, thanks @ararslan --- src/serialization.jl | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/src/serialization.jl b/src/serialization.jl index 30223732..a2a5a1f7 100644 --- a/src/serialization.jl +++ b/src/serialization.jl @@ -289,12 +289,9 @@ function deserialize_lpcm(stream::LPCMStream, sample_offset::Integer=0, return deserialize_lpcm(stream.format, bytes) end -_matrix(samples::Matrix) = samples -_matrix(samples::AbstractMatrix) = Matrix(samples) - function serialize_lpcm(format::LPCMFormat, samples::AbstractMatrix) _validate_lpcm_samples(format, samples) - return reinterpret(UInt8, vec(_matrix(samples))) + return reinterpret(UInt8, vec(samples)) end function serialize_lpcm(stream::LPCMStream, samples::AbstractMatrix)