Welcome, Guest. Please login or register. Did you miss your activation email?

Author Topic: sf::SoundStream::OnGetData  (Read 2529 times)

0 Members and 1 Guest are viewing this topic.

Groogy

  • Hero Member
  • *****
  • Posts: 1469
    • MSN Messenger - groogy@groogy.se
    • View Profile
    • http://www.groogy.se
    • Email
sf::SoundStream::OnGetData
« 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.
Developer and Maker of rbSFML and Programmer at Paradox Development Studio

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
sf::SoundStream::OnGetData
« Reply #1 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.
Laurent Gomila - SFML developer

 

anything