API reference
API reference
Select your platform
No SDKs available
No versions available

BufferedAudioStream Class

BufferedAudioStream provides a way to stream audio data from an AudioSource object. It maintains an internal buffer and offers methods for updating and adding new data. Update() updates playback based on remaining buffer time, while AddData() adds new data to the buffer, wrapping around if necessary. This class is useful for real-time audio streaming, such as playing back audio from a network connection or generating audio dynamically.

Member Functions

The constructor of BufferedAudioStream takes an AudioSource object as a parameter and initializes the audio buffer with a specified size. It also sets the loop property of the AudioSource object to true and creates an AudioClip object with the specified buffer size, sample rate, and number of channels.
This method updates the audio playback based on the remaining buffer time. If there is still buffer time remaining, it checks if the audio should start playing and updates the playback delay timer. If the audio is currently playing, it decrements the remaining buffer time. If the buffer is empty, it stops the audio playback and logs a message.
This method adds new audio data to the buffer. It takes an array of float samples as input and writes them to the internal audio buffer. If there is not enough space in the buffer, it will wrap around to the beginning of the buffer. If the write position exceeds the buffer length, an exception is thrown. The method returns the number of samples written to the buffer.
Did you find this page helpful?
Thumbs up icon
Thumbs down icon