Stream sound
4 posters
Stream sound
There is a problem with streaming sound (in a separate thread)? If the source is starved of audio data then it stops playing, and then it needs to be restarted.
FlagellumDei- Posts : 5
Join date : 2009-03-14
Re: Stream sound
Can you please be more specific or simply send me a template project by email that reproduce the bug.
Tks!
Tks!
Re: Stream sound
I want to play a background music in the game which is updated in a separate thread. So I created a thread like this:
_SIO2thread = sio2ThreadInit();
sio2ThreadCreate(_SIO2thread, MusicUpdateThread, ( void * )g_pGame, SIO2_THREAD_PRIORITY_NORMAL);
sio2ThreadPlay(_SIO2thread);
Here's the thread function:
void MusicUpdateThread( void *_ptr )
{
CGame* pGame = (CGame*)_ptr;
SIO2sound* pSound = NULL;
pSound = pGame->GetGameMusic();
if (pSound) sio2SoundUpdateStream(pSound);
}
_SIO2thread = sio2ThreadInit();
sio2ThreadCreate(_SIO2thread, MusicUpdateThread, ( void * )g_pGame, SIO2_THREAD_PRIORITY_NORMAL);
sio2ThreadPlay(_SIO2thread);
Here's the thread function:
void MusicUpdateThread( void *_ptr )
{
CGame* pGame = (CGame*)_ptr;
SIO2sound* pSound = NULL;
pSound = pGame->GetGameMusic();
if (pSound) sio2SoundUpdateStream(pSound);
}
FlagellumDei- Posts : 5
Join date : 2009-03-14
Re: Stream sound
And if I add this to the "void sio2SoundUpdateStream( SIO2sound *_SIO2sound )" function after the "if( !q )":
else
{
int iState;
// Check the status of the Source. If it is not playing, then playback was completed,
// or the Source was starved of audio data, and needs to be restarted.
alGetSourcei(_SIO2sound->sid, AL_SOURCE_STATE, &iState);
if (iState != AL_PLAYING && iState != AL_PAUSED)
{
// source was starved of audio data
sio2SoundPlay( _SIO2sound );
}
}
the state of the source will be AL_STOPPED. But now the last buffer is played again, before it continues.
else
{
int iState;
// Check the status of the Source. If it is not playing, then playback was completed,
// or the Source was starved of audio data, and needs to be restarted.
alGetSourcei(_SIO2sound->sid, AL_SOURCE_STATE, &iState);
if (iState != AL_PLAYING && iState != AL_PAUSED)
{
// source was starved of audio data
sio2SoundPlay( _SIO2sound );
}
}
the state of the source will be AL_STOPPED. But now the last buffer is played again, before it continues.
FlagellumDei- Posts : 5
Join date : 2009-03-14
Re: Stream sound
Hi,
I have simple problem when trying play backgrownd music. I use double buffering for sound, but hear only one....
I have simple problem when trying play backgrownd music. I use double buffering for sound, but hear only one....
- Code:
void LoadSound (void)
{
{
SIO2stream *streamSound = NULL;
streamSound = sio2StreamOpen("mozart_sym40_1.ogg", 1);
if (streamSound)
{
SIO2soundbuffer *soundBuffer = sio2SoundBufferInit("music");
sio2SoundBufferLoad(soundBuffer, streamSound);
sio2SoundBufferGenId(soundBuffer, 1);
music = sio2SoundInit("music");
sio2SoundGenId(music, soundBuffer, SIO2_SOUND_STREAM|SIO2_SOUND_LOOP);
sio2SoundBufferFree(soundBuffer);
}
sio2StreamClose(streamSound);
}
void templateRender( void )
{
...
static bool b = false;
if (!b)
{
sio2SoundPlay(music);
b = true;
}
sio2SoundUpdateState(music);
if (music->state != SIO2_SOUND_PLAY)
{
sio2SoundUpdateStream(music);
}
}
hazeleye- Posts : 34
Join date : 2008-09-24
Re: Stream sound
sio2ResourceRender( level,
sio2->_SIO2window,
sio2->_SIO2camera,
SIO2_RENDER_SOLID_OBJECT | SIO2_RENDER_ALPHA_OBJECT | SIO2_UPDATE_SOUND_STREAM );
sio2->_SIO2window,
sio2->_SIO2camera,
SIO2_RENDER_SOLID_OBJECT | SIO2_RENDER_ALPHA_OBJECT | SIO2_UPDATE_SOUND_STREAM );
Re: Stream sound
I change my LoadSound function and all working!
Thanks
Thanks
hazeleye- Posts : 34
Join date : 2008-09-24
Re: Stream sound
hazeleye wrote:I change my LoadSound function and all working!
Thanks
I'm using exactly the code you have above, but my sound just plays for a bit and then loops.
The same happens when I load the sound through Blender like on tutorial 15.
Can you or someone tell me what's happening please?
Thanks
andreassilva- Posts : 22
Join date : 2009-02-19
Similar topics
» Sound Example
» Trying to play a sound
» Error when using sound files
» Hook a sound to a physics collision
» Duplicating an object with sound attached
» Trying to play a sound
» Error when using sound files
» Hook a sound to a physics collision
» Duplicating an object with sound attached
Permissions in this forum:
You cannot reply to topics in this forum