About Store Forum Documentation Contact



Post Reply 
How to Stop the SoundCallback
Author Message
take_de_x Offline
Member

Post: #1
How to Stop the SoundCallback
Hi.grin
Now, I have the audio playback using the SoundCallback.
After playing with the SoundPlay(), please tell me how to stop this.


--------------------------------------------
class MySound : public SoundCallback
{
}

MySound* mySound = new MySound();

SoundPlay(*mySound);

// ** I want to Stop mySound. SoundStop(*mySound)???

delete mySound;


// ** Assertion
// !!! SoundCallback::set() is called from the sound thread.
--------------------------------------------

thank you.
05-31-2014 05:47 PM
Find all posts by this user Quote this message in a reply
Rofar Offline
Member

Post: #2
RE: How to Stop the SoundCallback
I think you just call SoundPlay again with a null parameter.
SoundPlay (NULL)
05-31-2014 07:36 PM
Find all posts by this user Quote this message in a reply
Esenthel Online
Administrator

Post: #3
RE: How to Stop the SoundCallback
Code:
const_mem_addr struct SoundCallback // Sound Callback used to dynamically create sound data !! must be stored in constant memory address !! this object is passed on to functions which store pointer to it, therefore it must be stored in a constant memory address
{
   virtual Bool create(Byte &bits, Byte &channels, Int &frequency, Int &raw_length, Int &bit_rate)=NULL; // 'create' will be called upon creation of the sound, you should override this method and inside it fill all of the parameters, 'bits'=number of bits per sample (valid values are 8 and 16), 'channels'=number of channels (valid values are '1'=mono, '2'=stereo), 'frequency'=number of samples per second (valid values are 1..192000, recommended value is 44100), 'raw_length'=total size of the uncompressed sound data in bytes (use -1 if the size is unknown), 'bit_rate'=this parameter is optional, it specifies the average number of compressed data bytes needed to fill a 1 second of uncompressed data (use -1 if unknown), return false on fail, warning: this may get called on secondary thread
   virtual Bool raw   (Int   raw           ) {return true;} // 'raw' will be called when the sound is being requested to jump to specified position, the position is specified in raw bytes of uncompressed data, return false on fail, warning: this may get called on secondary thread
   virtual Int  set   (Ptr   data, Int size)=NULL;          // 'set' will be called when the sound is being requested to fill the 'data' buffer with raw uncompressed sound data of 'size' length, you should not write more data than requested 'size', return the number of bytes written or -1 on fail, warning: this may get called on secondary thread
I think you can try returning -1 in 'set'.

SoundPlay(NULL) won't work as SoundPlay always creates a new sound that plays it until it ends.

Alternatively you can do
Sound sound; sound.play(..); sound.del(); // instead of SoundPlay
05-31-2014 10:28 PM
Find all posts by this user Quote this message in a reply
take_de_x Offline
Member

Post: #4
RE: How to Stop the SoundCallback
Hi. Rofar, Hi. Esenthelsmile

Thank you for your reply.

I had overlooked the "Sound::play()".
I'm sorry.

I was looking for this.
> Sound sound; sound.play(..); sound.del(); // instead of SoundPlay

I was confirmed in the code below.
thank you.


-- Test of minimum ---------------------------------------------
Code:
class MySound : public SoundCallback
{
public:
  MySound(){}
  virtual bool create(byte &bits, byte &channels, int &frequency, int &raw_length, int &bit_rate) // this will be called upon first usage of the callback, Warning: this may get called on a secondary thread
  {
     bits=16;
     channels=2;
     frequency=44100;
     return true;
  }
  virtual int set(ptr data, int size) // this will be called when 'data' needs to be filled with uncompressed sound data, Warning: this may get called on a secondary thread
  {
     memset(data, 0, size);
     return size;
  }
}

class MySoundController
{
public:
  MySoundController(){}
  void Play()
  {
     // !!! exception SoundPlay(m_mySound);
     m_player.play(m_mySound, true);
  }
private:
  MySound m_mySound;
  Sound m_player;
}
Code:
{
  MySoundController controller;
  controller.Play();
} // end of scope, exception has occurred.
06-01-2014 12:18 AM
Find all posts by this user Quote this message in a reply
Rofar Offline
Member

Post: #5
RE: How to Stop the SoundCallback
Now that I have the code in front of me, I see that my guess was not correct. I was thinking about the MusicManager play function. I'm glad Greg corrected me smile
06-01-2014 01:54 PM
Find all posts by this user Quote this message in a reply
Post Reply