Note
located in sound.jl
This module contains functions intended to process acoustic samples.
These functions are used for loading and saving RIFF/WAVE (wav) functions. The API is very similar to the one found in MATLAB.
Here is a quick example that copies an existing file:
julia> require("sound")
julia> using Sound
julia> in_filename = ARGS[1]
julia> y, Fs, nbits, extra = wavread(in_filename)
julia> wavwrite(y, Fs, nbits, strcat("out-", in_filename))
Note
This implementation only supports little endian machines right now.
Reads and returns the samples from a RIFF/WAVE file. The samples are converted to floating point values in the range from -1.0 to 1.0 by default. The io argument accepts either an IO object or a filename (String). The options are passed via an Options object (see the OptionsMod module).
The available options, and the default values, are:
The returned values are:
The following functions are also defined to make this function compatible with MATLAB:
wavread(filename::String) = wavread(filename, @options)
wavread(filename::String, fmt::String) = wavread(filename, @options format=fmt)
wavread(filename::String, N::Int) = wavread(filename, @options subrange=N)
wavread(filename::String, N::Range1{Int}) = wavread(filename, @options subrange=N)
wavread(filename::String, N::Int, fmt::String) = wavread(filename, @options subrange=N format=fmt)
wavread(filename::String, N::Range1{Int}, fmt::String) = wavread(filename, @options subrange=N format=fmt)
Writes samples to a RIFF/WAVE file io object. The io argument accepts either an IO object or a filename (String). The function assumes that the sample rate is 8 kHz and uses 16 bits to encode each sample. Both of these values can be changed with the options parameter. Each column of the data represents a different channel. Stereo files should contain two columns. The options are passed via an Options object (see the OptionsMod module).
The available options, and the default values, are:
The type of the input array, samples, also affects the generated file. “Native” WAVE files are written when integers are passed into wavwrite. This means that the literal values are written into the file. The input ranges are as follows for integer samples.
N Bits | y Data Type | y Data Range | Output Format |
---|---|---|---|
8 | uint8 | 0 <= y <= 255 | uint8 |
16 | int16 | –32768 <= y <= +32767 | int16 |
24 | int32 | –2^23 <= y <= 2^23 – 1 | int32 |
If samples contains floating point values, the input data ranges are the following.
N Bits | y Data Type | y Data Range | Output Format |
---|---|---|---|
8 | single or double | –1.0 <= y < +1.0 | uint8 |
16 | single or double | –1.0 <= y < +1.0 | int16 |
24 | single or double | –1.0 <= y < +1.0 | int32 |
32 | single or double | –1.0 <= y <= +1.0 | single |
The following functions are also defined to make this function compatible with MATLAB:
wavwrite(y::Array) = wavwrite(y, @options)
wavwrite(y::Array, Fs::Real, filename::String) = wavwrite(y, filename, @options sample_rate=Fs)
wavwrite(y::Array, Fs::Real, N::Real, filename::String) = wavwrite(y, filename, @options sample_rate=Fs nbits=N)