主要内容

write

Pre-buffer (queue) audio to play

Since R2026a

    Description

    write(as,x) writes the audio data x to the playback queue of the audiostreamer object, as.

    If the audiostreamer object is open and playback is not paused, the samples start playing immediately. Otherwise, the samples are added to the queue and playback remains paused. This behavior differs from play, which starts or resumes play automatically.

    example

    write(as,x,"non-blocking") queues the audio data without blocking MATLAB® execution and always returns immediately.

    Examples

    collapse all

    Create a dspFileAudioReader System object™ that reads data from the audio file SpeechDFT-16-8-mono-5secs.wav. The sample rate is 8 kHz.

    reader = dsp.AudioFileReader('SpeechDFT-16-8-mono-5secs.wav');

    Create an audiostreamer object appropriate for the audio file. By default, the mode is "player".

    as = audiostreamer(SampleRate=8e3);

    Pre-buffer the data in the audiostreamer. Inspect the number of samples in the buffer.

    while ~reader.isDone
        write(as,reader())
    end
    as.NumPlayerSamples
    ans = 
    39936
    

    Play the data.

    start(as)

    Release the device and reader.

    release(as)
    release(reader)

    Input Arguments

    collapse all

    The audiostreamer object to pre-buffer data.

    Audio data to pre-buffer on the device, specified as a column vector or matrix where the columns correspond to independent audio channels.

    Data Types: single | double

    Version History

    Introduced in R2026a

    See Also

    Objects

    Functions