Skip to content

Commit 531a0d0

Browse files
committed
feat: add AIFF format tests and some fix
1 parent bf4beff commit 531a0d0

3 files changed

Lines changed: 26 additions & 2 deletions

File tree

src/libsndfile_h.jl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,7 @@ const SF_SEEK_END = Int32(2)
8181
formatcode(::Type{format"WAV"}) = SF_FORMAT_WAV
8282
formatcode(::Type{format"FLAC"}) = SF_FORMAT_FLAC
8383
formatcode(::Type{format"OGG"}) = SF_FORMAT_OGG
84+
formatcode(::Type{format"AIFF"}) = SF_FORMAT_AIFF
8485

8586
subformatcode(::Type{PCM16Sample}) = SF_FORMAT_PCM_16
8687
subformatcode(::Type{PCM32Sample}) = SF_FORMAT_PCM_32

test/440left_880right_0.5amp.aiff

454 Bytes
Binary file not shown.

test/runtests.jl

Lines changed: 25 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ include("testhelpers.jl")
2424

2525
for f in (:load, :save, :loadstreaming, :savestreaming)
2626
for io in ((String, File), (IO, Stream))
27-
for fmt in (("_wav", format"WAV"), ("_ogg", format"OGG"), ("_flac", format"FLAC"))
27+
for fmt in (("_wav", format"WAV"), ("_ogg", format"OGG"), ("_flac", format"FLAC"), ("_aiff", format"AIFF"))
2828
@eval $(Symbol(f, fmt[1]))(io::$(io[1]), args...) =
2929
LibSndFile.$f($(io[2]){$(fmt[2])}( io), args...)
3030
if f in (:loadstreaming, :savestreaming)
@@ -58,6 +58,7 @@ reference_wav_double = joinpath(dirname(@__FILE__), "440left_880right_0.5amp_dou
5858
reference_wav_pcm24 = joinpath(dirname(@__FILE__), "440left_880right_0.5amp_pcm24.wav")
5959
reference_ogg = joinpath(dirname(@__FILE__), "440left_880right_0.5amp.ogg")
6060
reference_flac = joinpath(dirname(@__FILE__), "440left_880right_0.5amp.flac")
61+
reference_aiff = joinpath(dirname(@__FILE__), "440left_880right_0.5amp.aiff")
6162
reference_buf = gen_reference(srate)
6263

6364
# don't indent the individual testsets so we can more easily run them from
@@ -108,6 +109,15 @@ end
108109
@test mse(buf, reference_buf) < 1e-10
109110
end
110111

112+
@testset "AIFF file reading" begin
113+
buf = load_aiff(reference_aiff)
114+
@test samplerate(buf) == srate
115+
@test nchannels(buf) == 2
116+
@test nframes(buf) == 100
117+
@test isapprox(domain(buf), collect(0:99)/srate)
118+
@test mse(buf, reference_buf) < 1e-10
119+
end
120+
111121
@testset "OGG file reading" begin
112122
buf = load_ogg(reference_ogg)
113123
@test samplerate(buf) == srate
@@ -244,6 +254,19 @@ end
244254
@test mse(buf, testbuf) < 1e-10
245255
end
246256

257+
@testset "AIFF file writing" begin
258+
fname = string(tempname(), ".aiff")
259+
arr = map(PCM16Sample, rand(100, 2) .- 0.5)
260+
testbuf = SampleBuf(arr, srate)
261+
save_aiff(fname, testbuf)
262+
buf = load_aiff(fname)
263+
@test samplerate(buf) == srate
264+
@test nchannels(buf) == 2
265+
@test nframes(buf) == 100
266+
@test isapprox(domain(buf), collect(0:99)/srate)
267+
@test mse(buf, testbuf) < 1e-10
268+
end
269+
247270
@testset "Writing $T data" for T in [PCM16Sample, PCM32Sample, Float32, Float64]
248271
fname = string(tempname(), ".wav")
249272
arr = map(T, rand(100, 2) .- 0.5)
@@ -288,7 +311,7 @@ end
288311
@testset "FileIO Integration" begin
289312
arr = map(PCM16Sample, rand(100, 2) .- 0.5)
290313
testbuf = SampleBuf(arr, srate)
291-
for ext in (".wav", ".ogg", ".flac")
314+
for ext in (".wav", ".ogg", ".flac", ".aiff")
292315
fname = string(tempname(), ext)
293316
FileIO.save(fname, testbuf)
294317
buf = FileIO.load(fname)

0 commit comments

Comments
 (0)