now transposing the audio so columns are channels on a file read
This commit is contained in:
parent
d4b4b33361
commit
edf2f8fd04
2 changed files with 38 additions and 3 deletions
|
@ -97,7 +97,8 @@ end
|
||||||
# through an arbitrary render chain and returns the result as a vector
|
# through an arbitrary render chain and returns the result as a vector
|
||||||
function Base.read(file::AudioFile, nframes::Integer, dtype::Type)
|
function Base.read(file::AudioFile, nframes::Integer, dtype::Type)
|
||||||
@assert file.sfinfo.channels <= 2
|
@assert file.sfinfo.channels <= 2
|
||||||
arr = zeros(dtype, nframes, file.sfinfo.channels)
|
# the data comes in interleaved
|
||||||
|
arr = zeros(dtype, file.sfinfo.channels, nframes)
|
||||||
|
|
||||||
if dtype == Int16
|
if dtype == Int16
|
||||||
nread = ccall((:sf_readf_short, libsndfile), Int64,
|
nread = ccall((:sf_readf_short, libsndfile), Int64,
|
||||||
|
@ -117,7 +118,7 @@ function Base.read(file::AudioFile, nframes::Integer, dtype::Type)
|
||||||
file.filePtr, arr, nframes)
|
file.filePtr, arr, nframes)
|
||||||
end
|
end
|
||||||
|
|
||||||
return arr[1:nread, :]
|
return arr[:, 1:nread]'
|
||||||
end
|
end
|
||||||
|
|
||||||
Base.read(file::AudioFile, dtype::Type) = Base.read(file, file.sfinfo.frames, dtype)
|
Base.read(file::AudioFile, dtype::Type) = Base.read(file, file.sfinfo.frames, dtype)
|
||||||
|
|
|
@ -28,6 +28,8 @@ facts("WAV file write/read") do
|
||||||
@fact reference => actual[:, 1]
|
@fact reference => actual[:, 1]
|
||||||
end
|
end
|
||||||
|
|
||||||
|
# test seeking
|
||||||
|
|
||||||
# test rendering as an AudioNode
|
# test rendering as an AudioNode
|
||||||
AudioIO.open(fname) do f
|
AudioIO.open(fname) do f
|
||||||
# pretend we have a stream at the same rate as the file
|
# pretend we have a stream at the same rate as the file
|
||||||
|
@ -42,7 +44,39 @@ facts("WAV file write/read") do
|
||||||
buf = render(node, input, test_info)
|
buf = render(node, input, test_info)
|
||||||
@fact expected[bufsize+1:2*bufsize] => buf[1:bufsize]
|
@fact expected[bufsize+1:2*bufsize] => buf[1:bufsize]
|
||||||
end
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
||||||
|
facts("Stereo file reading") do
|
||||||
|
fname = Pkg.dir("AudioIO", "test", "440left_880right.wav")
|
||||||
|
samplerate = 44100
|
||||||
|
t = [0 : 2 * samplerate - 1] / samplerate
|
||||||
|
expected = int16((2^15-1) * hcat(sin(2pi*t*440), sin(2pi*t*880)))
|
||||||
|
|
||||||
|
AudioIO.open(fname) do f
|
||||||
|
buf = read(f)
|
||||||
|
@fact buf => mse(expected, 5)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
# note - currently AudioIO just mixes down to Mono. soon we'll support this
|
||||||
|
# new-fangled stereo sound stuff
|
||||||
|
#facts("Stereo file rendering") do
|
||||||
|
# fname = Pkg.dir("AudioIO", "test", "440left_880right.wav")
|
||||||
|
# samplerate = 44100
|
||||||
|
# bufsize = 1024
|
||||||
|
# input = zeros(AudioSample, bufsize)
|
||||||
|
# test_info = DeviceInfo(samplerate, bufsize)
|
||||||
|
# t = [0 : 2 * samplerate - 1] / samplerate
|
||||||
|
# expected = convert(AudioBuf, 0.5 * (sin(2pi*t*440) + sin(2pi*t*880)))
|
||||||
|
#
|
||||||
|
# AudioIO.open(fname) do f
|
||||||
|
# node = FilePlayer(f)
|
||||||
|
# buf = render(node, input, test_info)
|
||||||
|
# print(size(buf))
|
||||||
|
# @fact expected[1:bufsize] => buf[1:bufsize]
|
||||||
|
# buf = render(node, input, test_info)
|
||||||
|
# @fact expected[bufsize+1:2*bufsize] => buf[1:bufsize]
|
||||||
|
# end
|
||||||
|
#end
|
||||||
|
|
||||||
end # module TestSndfile
|
end # module TestSndfile
|
||||||
|
|
Loading…
Reference in a new issue