Represents information about the data format for a Wave file, such as number of channels, bits per sample, sample rate, and so forth. A Format instance is used by Reader to indicate what format to read samples out as, and by Writer to indicate what format to write samples as.
This class is immutable - once a new Format is constructed, it can't be modified.
Constructs a new immutable Format.
The number of channels in the format. Can either be an Integer (e.g. 1, 2, 3) or the symbols :mono (equivalent to 1) or :stereo (equivalent to 2).
A symbol indicating the format of each sample. Consists of two parts: a format code, and the bits per sample. The valid values are :pcm_8, :pcm_16, :pcm_24, :pcm_32, :float_32, :float_64, and :float (equivalent to :float_32)
The number of samples per second, such as 44100
format = Format.new(1, :pcm_16, 44100) format = Format.new(:mono, :pcm_16, 44100) # Equivalent to above format = Format.new(:stereo, :float_32, 44100) format = Format.new(:stereo, :float, 44100) # Equivalent to above
# File lib/wavefile/format.rb, line 41 def initialize(channels, format_code, sample_rate) channels = normalize_channels(channels) sample_format, bits_per_sample = normalize_format_code(format_code) validate_channels(channels) validate_sample_format(sample_format) validate_bits_per_sample(sample_format, bits_per_sample) validate_sample_rate(sample_rate) @channels = channels @sample_format = sample_format @bits_per_sample = bits_per_sample @sample_rate = sample_rate @block_align = (@bits_per_sample / 8) * @channels @byte_rate = @block_align * @sample_rate end