Method: WaveFile::Buffer#convert
- Defined in:
- lib/wavefile/buffer.rb
#convert(new_format) ⇒ Object
Public: Creates a new Buffer containing the sample data of this Buffer, but converted to a different format.
new_format - The format that the sample data should be converted to. If the new format
has a different number of channels than the original buffer format, the sample data
will be converted in the following way:
1 -> n: Each mono sample will be duplicated into the new number of channels.
n -> 1: Each sample in each sample frame will be averaged into a single sample.
(n > 2) -> 2: The first two channels will be kept, all other channels discarded.
other: Unsupported, will cause BufferConversionError to be raised.
Examples
new_format = Format.new(:mono, :pcm_16, 44100)
new_buffer = old_buffer.convert(new_format)
Returns a new Buffer; the existing Buffer is unmodified.
Raises BufferConversionError if the Buffer can’t be converted to the given format
82 83 84 85 |
# File 'lib/wavefile/buffer.rb', line 82 def convert(new_format) new_samples = convert_buffer(@samples.dup, @format, new_format) Buffer.new(new_samples, new_format) end |