SFML community forums
Help => Audio => Topic started by: Groogy on November 25, 2010, 04:41:14 pm
-
Hi! Just wondering here in this example:
class CustomStream : public sf::SoundStream
{
public :
bool Open(const std::string& location)
{
// Open the source and get audio settings
...
unsigned int channelsCount = ...;
unsigned int sampleRate = ...;
// Initialize the stream -- important!
Initialize(channelsCount, sampleRate);
}
private :
virtual bool OnGetData(Chunk& data)
{
// Fill the chunk with audio data from the stream source
data.Samples = ...;
data.NbSamples = ...;
// Return true to continue playing
return true;
}
virtual void OnSeek(float timeOffset)
{
// Change the current position in the stream source
...
}
}
// Usage
CustomStream stream;
stream.Open("path/to/stream");
stream.Play();
Will the stream free the allocated Samples data or will you have to do that yourself? Or does it maybe copy the data to an internal array?
What I'm referring to is the Chunk::Samples sf::Int16 pointer.
-
sf::SoundStream copies the chunk data as soon as OnGetData returns, so you're responsible for freeing the data you put in the chunk.