Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fixes for Julia 1.11 #172

Merged
merged 12 commits into from
Oct 9, 2024
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,7 @@ dmypy.json
docs/build/
docs/site/
Manifest.toml
Manifest-v*.toml
ararslan marked this conversation as resolved.
Show resolved Hide resolved

# misc
*.DS_Store
2 changes: 1 addition & 1 deletion Project.toml
Original file line number Diff line number Diff line change
@@ -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"
Expand Down
4 changes: 4 additions & 0 deletions examples/Project.toml
Original file line number Diff line number Diff line change
@@ -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"
9 changes: 5 additions & 4 deletions examples/flac.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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)",
Expand All @@ -56,15 +56,16 @@ 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

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
Expand All @@ -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

#####
Expand Down
15 changes: 9 additions & 6 deletions src/serialization.jl
Original file line number Diff line number Diff line change
Expand Up @@ -282,16 +282,19 @@ 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
_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 resize!(io.data, io.size)
return reinterpret(UInt8, vec(_matrix(samples)))
palday marked this conversation as resolved.
Show resolved Hide resolved
end

function serialize_lpcm(stream::LPCMStream, samples::AbstractMatrix)
Expand Down
5 changes: 4 additions & 1 deletion test/samples.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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) == """
Expand Down
Loading