Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
2 changes: 1 addition & 1 deletion src/LibSndFile.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
1 change: 1 addition & 0 deletions src/libsndfile_h.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Binary file added test/440left_880right_0.5amp.aiff
Binary file not shown.
27 changes: 25 additions & 2 deletions test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down
Loading