0
0

I have found that FSOUND_SetReserved does not work if the channel handle you use is no longer valid. Is this a bug?

This is the situation. I have started a sound playing on a channel, then I have called SetReserved( channelHandle, true ) to ensure the channel is safe.

Later on I discover the sound has stopped playing (by calling FSOUND_IsPlaying(channelHandle) so i decide to un-reserve the reserved channel. I call SetReserved( channelHandle, false ), which does not work. The channel remains reserved.

The only way I can work around this is to bitmask the channel handle to get the channel index (ie mask out the ref count bits), then call SetReserved( channelIndex, false ). This works ok.

Shouldn’t FSOUND_SetReserved still work on channel handles that aren’t valid, by extracting teh channel index and operating on that?

  • You must to post comments
0
0

So you are saying that we shouldn’t unreserve channels after they are stopped? Do they remain reserved or not if we do not call SetReserved(id, false)?

I get the following trace in my code:

FSOUND_Stream_PlayEx(FSOUND_FREE, m_Stream, NULL, true)
FSOUND_SetReserved(4132, true)
FSOUND_Stream_GetLength(m_Stream)
FSOUND_Stream_GetLengthMs(m_Stream)
FSOUND_GetFrequency(4132)
FSOUND_SetPan(4132, 128)
FSOUND_SetVolume(4132, 255)
FSOUND_SetFrequency(4132, 44100)
FSOUND_SetPaused(4132, false)
FSOUND_Stream_GetTime(m_Stream)
FSOUND_IsPlaying(4132)
FSOUND_Stream_GetTime(m_Stream)
FSOUND_IsPlaying(4132)
FSOUND_Stream_GetTime(m_Stream)
FSOUND_Stream_Close(m_Stream)
FSOUND_IsPlaying(4132)
FSOUND_SetReserved(4128, false)

and the last call fails….

Thanks!

  • You must to post comments
0
0

i am not hardcoding the numbers (that’s just my trace). the actual code looks like this:

[code:2roe4yvo]
bool
cSoundChannel::PlayStreamAndReserveNewChannel(void)
{
bool success = false;

m_Section.Lock();
{
m_GlobalPlayStreamSection.Lock();
{
m_channelId = FSOUND_FREE;

     if(!m_Stream)
     {
        // Stream should not be NULL.
        ASSERT(false);
     }
     else
     {
        // Open it paused.
        {
           try
           {
              FMOD_TRACE(_T("FSOUND_Stream_PlayEx(FSOUND_FREE, m_Stream, NULL, true)\n"));

              m_channelId = FSOUND_Stream_PlayEx(FSOUND_FREE, m_Stream,
               NULL, true);
           }
           catch(...)
           {
              // Fmod dll crash.
              ASSERT(false);
           }
        }

        if(m_channelId == -1)
        {
           // No new channels.

           #if defined(_DEBUG)
           {
              ASSERT(false);
           }
           #endif
        }
        else
        {
           try
           {
              // Set it as reserved so no one else can steal it.

              FMOD_TRACE1(_T("FSOUND_SetReserved(%i, true)\n"),
               m_channelId);

              if(!FSOUND_SetReserved(m_channelId, true))
              {
                 // Couldn't reserve it (someone else got it).

                 #if defined(_DEBUG)
                 {
                    ASSERT(false);
                 }
                 #endif
              }
              else
              {
                 // Success.
                 success = true;
              }
           }
           catch(...)
           {
              // Fmod dll crash.
              ASSERT(false);
           }
        }
     }
  }
  m_GlobalPlayStreamSection.Unlock();

  if(!success)
  {
     const bool fadeout = false;
     StopPlaying(fadeout);
  }

}
m_Section.Unlock();

return success;
}
[/code:2roe4yvo]

i don’t want channels to be reserved all the time — i want to create a dynamic range of sound samples, where whenever i create a cSoundChannel, it opens a new channel, and then releases it when it’s done (or when the object is destroyed).

How do I release the channel automatically once the stream stops playing? I understand I can’t do this because the handle is no longer at that point?

try putting a sleep in your test code like so:

[code:2roe4yvo]

            int c = FSOUND_PlaySound(FSOUND_FREE, samp1); 

            FSOUND_SetReserved(c, TRUE); 
            while (FSOUND_IsPlaying(c)) 
            { 
                Sleep(100); 
            } 
            FSOUND_SetReserved(c, FALSE); 
            >> Sleep(1000);
            printf("\n\nreserved = %d\n\n", FSOUND_GetReserved(c));  

[/code:2roe4yvo]

thanks for your help… 8)

  • You must to post comments
0
0

To reproduce this, I constantly call my play function to keep playling random sounds one after another, and after about 10 minutes, i get an access violation, and the following debug output (including my trace):

[code:1pxokjie]
FSOUND_Stream_GetTime(m_Stream)
FSOUND_IsPlaying(1421354)
FSOUND_Stream_GetTime(m_Stream)
FSOUND_Stream_GetTime(m_Stream)
FSOUND_SetReserved(1896488, false)
FSOUND_Stream_Close(m_Stream)
First-chance exception in Photokeeper – Debug.exe (FMOD.DLL): 0xC0000005: Access Violation.
[/code:1pxokjie]

i can get the same result during normal operation, usually after like a half hour of testing with sounds on. might be a thread sync issue with fmod?[/code]

  • You must to post comments
0
0

stack at the crash is:

[code:2ekuykl3]
FMOD! 0035714e()
FMOD! 003572be()
KERNEL32! 77e7d33b()
[/code:2ekuykl3]

this doesn’t happen on the main thread, but some other thread — the only thread with priority 11.[/code]

  • You must to post comments
0
0

hey brett!

any ideas on this? i’m banging my head on the wall trying to figure out what is going on… your help would be much appreciated.

  1. how thread-safe is fmod?

  2. what is that fmod thread with priority 11 that seems to appear out of nowhere and then crash?

Thanks…

  • You must to post comments
0
0

:roll:

um ok i did some more experiementing… i found that if i don’t reserve/unreserve channels, the crash never occurs. so that’s it for me, but i still think you have a pesky little bug in there somewhere…

sorry about the overpostage.

  • You must to post comments
0
0

Geez well that explains a lot! I was assuming that FMOD was threadsafe because it is really made for games, which are inherently multithreaded.

Perhaps you need an intro topic in the help docs that spells this out ;).

  • You must to post comments
Showing 7 results
Your Answer

Please first to submit.