audio::ostream
October 18, 2017 · View on GitHub
The base class for all audio output streams.
unformatted output operations
Inherited from std::ostream
- write(): inserts blocks of characters
⚠️ Using these operations should be avoided. They are provided for maximum flexibility if clients need to operate on the raw pcm data. In most use cases, formatted output operations can and should be used as they provide type safety and are optimized for best performance.
positioning operations
Inherited from std::ostream.
tellp(): returns the output position indicatorseekp(): ⚠️ is not implemented yet. It is unclear at this point if this fucntionality can be / will be added later on, as it seems not all codecs support seeking while encoding.
⚠️ Using these operations should be avoided. They are provided for maximum flexibility if clients need to operate on the raw pcm data. It is the clients reponsibility to ensure that the position is aligned withing a sample or frame. Therefore it is recommended to use sample based positioning operations instead.
state functions
Inherited from std::basic_ios.
good(): checks if no error has occurred i.e. I/O operations are availableeof(): checks if end-of-file has been reachedfail(): checks if an error has occurredbad(): checks if a non-recoverable error has occurredoperator!(): checks if an error has occurred (synonym of fail())operator bool(): checks if no error has occurred (synonym of !fail())rdstate(): returns state flagssetstate(): sets state flagsclear(): modifies state flags
formatted output operations
These operations inserts one or more samples into the stream, by converting the sequence of samples
to a pcm data sequence which is then insterted into the stream. The sample format can be any floating
point type (i.e. float, double) or integral type (e.g int8_t, int16_t, int32_t, int64_t,
uint8_t, uint16_t, uint32_t, uint64_t).
operator<<: inserts samples into the stream.- The value-based operator inserts a single sample into the stream, in analogy to
std::ostreamoperator<<. - The range-based operator inserts a range of samples into the stream.
- The value-based operator inserts a single sample into the stream, in analogy to
⚠️ It is highly recommended to use the range-based version instead of the value-based version, as this will result in a better performance (during pcm conversion).
I.e. clients should stream block wise:
void fill(audio::ostream& stream, const std::vector<float>& samples)
{
stream << samples;
}
rather than sample wise:
void fill(audio::istream& stream, const std::vector<float>& samples)
{
for (auto sample : samples)
{
stream << sample;
}
}
sample based positioning operations
sample_tellp(): returns the output position indicator of the current sample.frame_tellp(): returns the output position indicator of the current frame.
audio specific operations
info(): returns the stream infoaudio::ostream_infowhich contains audio specific information like:num_channels: the number of channelsnum_frames: the number of sample frames (one frame consist ofnum_channelssamples)sample_rate: the sample rateformat: the pcm format the audio data is stored in- …