ni-media

audio::istream

The base class for all audio input streams.

unformatted input operations

Inherited from std::istream.

⚠️ 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 input operations can and should be used as they provide type safety and are optimized for best performance.

positioning operations

Inherited from std::istream.

⚠️ 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 (#sample-based-positioning-operations) instead.

state functions

Inherited from std::basic_ios.

miscellaneous

Accessing the associated stream buffer might be usefull for i.e. wrapping an audio::stream into an std::istream (and interface with other std functions) :

std::string to_string(audio::istream& stream)
{
    std::istream ref_stream( stream.rdbuf() ); // a reference to the stream

    return { std::istreambuf_iterator<char>(ref_stream), std::istreambuf_iterator<char>() };

}

formatted input operations

These operations extracts one or more samples from the stream, by converting the underlying pcm data sequence into a sequence of samples. 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)

⚠️ 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 process(audio::istream& stream)
{
    std::vector<float> buffer(256);
    while (stream >> buffer)
    {
        // process whole buffer
    }
}

rather than sample wise:

void process(audio::istream& stream)
{
    float value;
    while (stream >> value)
    {
        // process sample
    }
}

sample based positioning operations:

audio specific operations

⚠️ The info may contain erroneous information in case the stream is corrupted. Clients have to check if the info is plausible in their own context (i.e. num_channels <= 2 when expecting stereo data).