Skip to content

Commit

Permalink
missing qualification
Browse files Browse the repository at this point in the history
  • Loading branch information
palday committed Oct 9, 2024
1 parent 9b618ae commit 4f7ceb2
Showing 1 changed file with 13 additions and 5 deletions.
18 changes: 13 additions & 5 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 --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 --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 All @@ -111,11 +112,14 @@ if VERSION >= v"1.1.0"
sample_rate=50)
data = saws(info, Minute(3))
samples = encode(Samples(data, info, false))
fmt = FLACFormat(info)
fmt = FLACFormat(info; level=0)

bytes = serialize_lpcm(fmt, samples.data)
# fail
@test deserialize_lpcm(fmt, bytes) == samples.data
# fail
@test deserialize_lpcm(fmt, bytes, 99) == view(samples.data, :, 100:size(samples.data, 2))
# pass
@test deserialize_lpcm(fmt, bytes, 99, 201) == view(samples.data, :, 100:300)

io = IOBuffer()
Expand All @@ -124,13 +128,17 @@ if VERSION >= v"1.1.0"
@test finalize_lpcm_stream(stream)
seekstart(io)
stream = deserializing_lpcm_stream(fmt, io)
# fail
@test deserialize_lpcm(stream) == samples.data
finalize_lpcm_stream(stream) && close(io)

io = IOBuffer(bytes)
stream = deserializing_lpcm_stream(fmt, io)
# pass
@test deserialize_lpcm(stream, 49, 51) == view(samples.data, :, 50:100)
# pass
@test deserialize_lpcm(stream, 49, 51) == view(samples.data, :, 150:200)
# fail
@test deserialize_lpcm(stream, 9) == view(samples.data, :, 210:size(samples.data, 2))
finalize_lpcm_stream(stream) && close(io)
end
Expand Down

0 comments on commit 4f7ceb2

Please sign in to comment.