Skip to content

Commit

Permalink
fixes for Julia 1.11 (#172)
Browse files Browse the repository at this point in the history
* ignore versioned manifest

* fix serialization on 1.11

* use set values instead of calling random

* add FLAC_jll to examples project

* add missing qualification

* slightly more efficient serialization

* fix `read` on 1.11

* patch bump

* straight to vec, thanks @ararslan
  • Loading branch information
palday authored Oct 9, 2024
1 parent 4153b50 commit a24a92a
Show file tree
Hide file tree
Showing 6 changed files with 21 additions and 12 deletions.
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

# 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
12 changes: 6 additions & 6 deletions src/serialization.jl
Original file line number Diff line number Diff line change
Expand Up @@ -282,16 +282,16 @@ 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

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(samples))
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

2 comments on commit a24a92a

@palday
Copy link
Member Author

@palday palday commented on a24a92a Oct 9, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@JuliaRegistrator
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Registration pull request created: JuliaRegistries/General/116915

Tip: Release Notes

Did you know you can add release notes too? Just add markdown formatted text underneath the comment after the text
"Release notes:" and it will be added to the registry PR, and if TagBot is installed it will also be added to the
release that TagBot creates. i.e.

@JuliaRegistrator register

Release notes:

## Breaking changes

- blah

To add them here just re-invoke and the PR will be updated.

Tagging

After the above pull request is merged, it is recommended that a tag is created on this repository for the registered package version.

This will be done automatically if the Julia TagBot GitHub Action is installed, or can be done manually through the github interface, or via:

git tag -a v0.15.10 -m "<description of version>" a24a92a2d943c8a17a1594bfe912fb19e6b91a5e
git push origin v0.15.10

Please sign in to comment.