SFML community forums

Help => Audio => Topic started by: Groogy on November 25, 2010, 04:41:14 pm

Title: sf::SoundStream::OnGetData
Post by: Groogy on November 25, 2010, 04:41:14 pm
Hi! Just wondering here in this example:

Code: [Select]
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.
Title: sf::SoundStream::OnGetData
Post by: Laurent on November 25, 2010, 04:53:44 pm
sf::SoundStream copies the chunk data as soon as OnGetData returns, so you're responsible for freeing the data you put in the chunk.