deprecates af_open in favor of AudioIO.open

This commit is contained in:
Spencer Russell 2014-08-11 17:34:21 -04:00
parent 18f0cee2e5
commit 89043b80c9
3 changed files with 21 additions and 14 deletions

View file

@ -55,13 +55,13 @@ IOStream API
Separate Open Function API
--------------------------
* users use an explicit `af_open` function to open sound files
* `af_open` takes mode arguments just like the regular julia `open` function
* `af_open` returns a AudioFile instance.
* users use an explicit `AudioIO.open` function to open sound files
* `AudioIO.open` takes mode arguments just like the regular julia `open` function
* `AudioIO.open` returns a AudioFile instance.
### Play a file through the speakers
sndfile = af_open("myfile.wav")
sndfile = AudioIO.open("myfile.wav")
play(sndfile)
close(sndfile)
@ -71,7 +71,7 @@ or
### Use a file as input to an AudioNode for processing
sndfile = af_open("myfile.wav")
sndfile = AudioIO.open("myfile.wav")
# FilePlayer also can take a string filename for convenience
node = FilePlayer(sndfile)
mixer = AudioMixer([node])
@ -79,20 +79,20 @@ or
### Read a file into an array
sndfile = af_open("myfile.wav")
sndfile = AudioIO.open("myfile.wav")
vec = read(sndfile) # takes an optional arg for number of frames to read
close(sndfile)
### Write an array into a file
sndfile = af_open("myfile.wav", "w") #TODO: need to specify format
sndfile = AudioIO.open("myfile.wav", "w") #TODO: need to specify format
vec = rand(Float32, 441000) # 10 seconds of noise
write(sndfile, vec)
close(sndfile)
### Write the output of an AudioNode to a file
sndfile = af_open("myfile.wav", "w") #TODO: need to specify format
sndfile = AudioIO.open("myfile.wav", "w") #TODO: need to specify format
node = SinOsc(440)
write(sndfile, node, 44100) # record 1 second, optional block_size
# note that write() can handle sample depth conversions, and render() is

View file

@ -37,7 +37,9 @@ type AudioFile
sfinfo::SF_INFO
end
function af_open(path::String, mode::String = "r",
# AudioIO.open is part of the public API, but is not exported so that it
# doesn't conflict with Base.open
function open(path::String, mode::String = "r",
sampleRate::Integer = 44100, channels::Integer = 1,
format::Integer = 0)
@assert channels <= 2
@ -76,12 +78,17 @@ function Base.close(file::AudioFile)
end
end
function af_open(f::Function, args...)
file = af_open(args...)
function open(f::Function, args...)
file = AudioIO.open(args...)
f(file)
close(file)
end
function af_open(args...)
warn("af_open is deprecated, please use AudioIO.open instead")
AudioIO.open(args...)
end
# TODO: we should implement a general read(node::AudioNode) that pulls data
# through an arbitrary render chain and returns the result as a vector
function Base.read(file::AudioFile, nframes::Integer, dtype::Type)
@ -152,7 +159,7 @@ end
typealias FilePlayer AudioNode{FileRenderer}
FilePlayer(file::AudioFile) = FilePlayer(FileRenderer(file))
FilePlayer(path::String) = FilePlayer(af_open(path))
FilePlayer(path::String) = FilePlayer(AudioIO.open(path))
function render(node::FileRenderer, device_input::AudioBuf, info::DeviceInfo)
@assert node.file.sfinfo.samplerate == info.sample_rate

View file

@ -108,11 +108,11 @@ facts("WAV file write/read") do
phase = 2 * pi * freq * t
reference = int16((2 ^ 15 - 1) * sin(phase))
af_open(fname, "w") do f
AudioIO.open(fname, "w") do f
write(f, reference)
end
af_open(fname) do f
AudioIO.open(fname) do f
@fact f.sfinfo.channels => 1
@fact f.sfinfo.frames => 2 * samplerate
actual = read(f, 2 * samplerate)