diff --git a/Project.toml b/Project.toml index 538f044..08fdb23 100644 --- a/Project.toml +++ b/Project.toml @@ -11,7 +11,7 @@ SampledSignals = "bd7594eb-a658-542f-9e75-4c4d8908c167" libsndfile_jll = "5bf562c0-5a39-5b4f-b979-f64ac885830c" [compat] -FileIO = "1.10" +FileIO = "1.18" SampledSignals = "2.1.0" julia = "1.3" libsndfile_jll = "1.0.28" diff --git a/src/LibSndFile.jl b/src/LibSndFile.jl index c5ca292..c8efa6d 100644 --- a/src/LibSndFile.jl +++ b/src/LibSndFile.jl @@ -10,7 +10,7 @@ using Printf: @printf using LinearAlgebra: transpose! using libsndfile_jll: libsndfile -const supported_formats = (format"WAV", format"FLAC", format"OGG") +const supported_formats = (format"WAV", format"FLAC", format"OGG", format"AIFF") include("libsndfile_h.jl") include("lengthIO.jl") diff --git a/src/libsndfile_h.jl b/src/libsndfile_h.jl index 722c7a6..8b1babd 100644 --- a/src/libsndfile_h.jl +++ b/src/libsndfile_h.jl @@ -81,6 +81,7 @@ const SF_SEEK_END = Int32(2) formatcode(::Type{format"WAV"}) = SF_FORMAT_WAV formatcode(::Type{format"FLAC"}) = SF_FORMAT_FLAC formatcode(::Type{format"OGG"}) = SF_FORMAT_OGG +formatcode(::Type{format"AIFF"}) = SF_FORMAT_AIFF subformatcode(::Type{PCM16Sample}) = SF_FORMAT_PCM_16 subformatcode(::Type{PCM32Sample}) = SF_FORMAT_PCM_32 diff --git a/test/440left_880right_0.5amp.aiff b/test/440left_880right_0.5amp.aiff new file mode 100644 index 0000000..c2b3450 Binary files /dev/null and b/test/440left_880right_0.5amp.aiff differ diff --git a/test/runtests.jl b/test/runtests.jl index 1e38d18..fdec05f 100755 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -24,7 +24,7 @@ include("testhelpers.jl") for f in (:load, :save, :loadstreaming, :savestreaming) for io in ((String, File), (IO, Stream)) - for fmt in (("_wav", format"WAV"), ("_ogg", format"OGG"), ("_flac", format"FLAC")) + for fmt in (("_wav", format"WAV"), ("_ogg", format"OGG"), ("_flac", format"FLAC"), ("_aiff", format"AIFF")) @eval $(Symbol(f, fmt[1]))(io::$(io[1]), args...) = LibSndFile.$f($(io[2]){$(fmt[2])}( io), args...) if f in (:loadstreaming, :savestreaming) @@ -58,6 +58,7 @@ reference_wav_double = joinpath(dirname(@__FILE__), "440left_880right_0.5amp_dou reference_wav_pcm24 = joinpath(dirname(@__FILE__), "440left_880right_0.5amp_pcm24.wav") reference_ogg = joinpath(dirname(@__FILE__), "440left_880right_0.5amp.ogg") reference_flac = joinpath(dirname(@__FILE__), "440left_880right_0.5amp.flac") +reference_aiff = joinpath(dirname(@__FILE__), "440left_880right_0.5amp.aiff") reference_buf = gen_reference(srate) # don't indent the individual testsets so we can more easily run them from @@ -108,6 +109,15 @@ end @test mse(buf, reference_buf) < 1e-10 end +@testset "AIFF file reading" begin + buf = load_aiff(reference_aiff) + @test samplerate(buf) == srate + @test nchannels(buf) == 2 + @test nframes(buf) == 100 + @test isapprox(domain(buf), collect(0:99)/srate) + @test mse(buf, reference_buf) < 1e-10 +end + @testset "OGG file reading" begin buf = load_ogg(reference_ogg) @test samplerate(buf) == srate @@ -244,6 +254,19 @@ end @test mse(buf, testbuf) < 1e-10 end +@testset "AIFF file writing" begin + fname = string(tempname(), ".aiff") + arr = map(PCM16Sample, rand(100, 2) .- 0.5) + testbuf = SampleBuf(arr, srate) + save_aiff(fname, testbuf) + buf = load_aiff(fname) + @test samplerate(buf) == srate + @test nchannels(buf) == 2 + @test nframes(buf) == 100 + @test isapprox(domain(buf), collect(0:99)/srate) + @test mse(buf, testbuf) < 1e-10 +end + @testset "Writing $T data" for T in [PCM16Sample, PCM32Sample, Float32, Float64] fname = string(tempname(), ".wav") arr = map(T, rand(100, 2) .- 0.5) @@ -288,7 +311,7 @@ end @testset "FileIO Integration" begin arr = map(PCM16Sample, rand(100, 2) .- 0.5) testbuf = SampleBuf(arr, srate) - for ext in (".wav", ".ogg", ".flac") + for ext in (".wav", ".ogg", ".flac", ".aiff") fname = string(tempname(), ext) FileIO.save(fname, testbuf) buf = FileIO.load(fname)