0
0

Hi

Why when you activate FMOD_Sound_Release (sound)
everything is blocked?

A small example with a list (pls) radio … break the connection when I want to switch to another server.
[list:2x48q192]
//==============================================================================
// A partir de l’exemple NetStream (FMOD Ex)
//==============================================================================

include <windows.h>

include <stdio.h>

include <conio.h>

include <vcl\fmod.h>

include <vcl\fmod_errors.h>

FMOD_SYSTEM *rsystem;
FMOD_SOUND *sound;
FMOD_CHANNEL *channel = 0;
FMOD_RESULT result;
FMOD_MODE mode = FMOD_SOFTWARE | FMOD_LOOP_OFF | FMOD_2D | FMOD_CREATESTREAM | FMOD_NONBLOCKING;

FMOD_OPENSTATE openstate;
FMOD_TAG tag;

unsigned int version, percent = 0, lastpercent = 0;
int playing = FALSE, paused = FALSE, starving = FALSE;
int loop, key, restart, IdxRadio, MaxRadio;

char * SmoothWeb[] =
{
"http://64.15.67.14:80&quot;, // 0
"http://scfire-ntc-aa10.stream.aol.com/stream/1005&quot;, // 1
"http://scfire-dtc-aa01.stream.aol.com/stream/1005&quot;, // 2
"http://scfire-dtc-aa02.stream.aol.com/stream/1005&quot;, // 3
"http://scfire-dtc-aa03.stream.aol.com/stream/1005&quot;, // 4
"http://scfire-dtc-aa04.stream.aol.com/stream/1005&quot;, // 5
"http://scfire-dtc-aa04.stream.aol.com/stream/1005&quot;, // 6
"http://scfire-dtc-aa05.stream.aol.com/stream/1005&quot;, // 7
"http://scfire-dtc-aa06.stream.aol.com/stream/1005&quot;, // 8
"http://scfire-dtc-aa07.stream.aol.com/stream/1005&quot;, // 9
"http://scfire-dtc-aa08.stream.aol.com/stream/1005&quot;, // 10
"http://scfire-mtc-aa01.stream.aol.com/stream/1005&quot;, // 11
"http://scfire-mtc-aa02.stream.aol.com/stream/1005&quot;, // 12
"http://scfire-mtc-aa03.stream.aol.com/stream/1005&quot;, // 13
"http://scfire-mtc-aa04.stream.aol.com/stream/1005&quot;, // 14
"http://scfire-mtc-aa05.stream.aol.com/stream/1005&quot;, // 15
"http://scfire-mtc-aa06.stream.aol.com/stream/1005&quot;, // 16
"http://scfire-mtc-aa07.stream.aol.com/stream/1005&quot;, // 17
"http://scfire-mtc-aa07.stream.aol.com/stream/1005&quot;, // 18
"http://scfire-mtc-aa08.stream.aol.com/stream/1005&quot;, // 19
"http://scfire-ntc-aa01.stream.aol.com/stream/1005&quot;, // 20
"http://scfire-ntc-aa02.stream.aol.com/stream/1005&quot;, // 21
"http://scfire-ntc-aa03.stream.aol.com/stream/1005&quot;, // 22
"http://scfire-ntc-aa04.stream.aol.com/stream/1005&quot;, // 23
"http://scfire-ntc-aa05.stream.aol.com/stream/1005&quot;, // 24
"http://scfire-ntc-aa06.stream.aol.com/stream/1005&quot;, // 25
"http://scfire-ntc-aa07.stream.aol.com/stream/1005&quot;, // 26
"http://scfire-ntc-aa08.stream.aol.com/stream/1005&quot;, // 27
"http://scfire-ntc-aa09.stream.aol.com/stream/1005&quot;, // 28
"http://207.200.96.226:8052/stream/1005&quot; // 29
};
int maxsmooth = (sizeof(SmoothWeb) / sizeof(int)) -1;

char **RadioWeb;

void ErrCheck(FMOD_RESULT result)
{
if (result != FMOD_OK)
{
printf("FMOD error! (%d) %s\n", result, FMOD_ErrorString(result));
exit(-1);
}
}

int main(int argc, char *argv[])
{
printf("===================================================================\n");
printf(" SmoothJazz \n");
printf("===================================================================\n\n");

printf("Press space to pause, Esc to quit\n\n");

result = FMOD_System_Create(&rsystem);
ErrCheck(result);

result = FMOD_System_GetVersion(rsystem, &version);
ErrCheck(result);

if (version < FMOD_VERSION)
{
printf("Erreur! La version que vous devez utiliser FMOD %08x\n", FMOD_VERSION);
return 0;
}

RadioWeb = SmoothWeb; MaxRadio = maxsmooth;
IdxRadio = 0; loop = TRUE;

result = FMOD_System_Init(rsystem, 1, FMOD_INIT_NORMAL, 0);
ErrCheck(result);

result = FMOD_System_SetStreamBufferSize(rsystem, 64*1024, FMOD_TIMEUNIT_RAWBYTES);
ErrCheck(result);

result = FMOD_System_CreateSound(rsystem, RadioWeb[IdxRadio], mode, 0, &sound);
ErrCheck(result);

do
{
if (kbhit())
{
key = getch();

  switch (key)
  {
    case ' ' :
    {
      if (channel)
      {
        FMOD_Channel_GetPaused(channel, &amp;paused);
        FMOD_Channel_SetPaused(channel, !paused);
      }
      break;
    }
    case 27:
    {
      loop = FALSE;
      break;
    }
  }
}

FMOD_System_Update(rsystem);


if ((sound) &amp;&amp; (!channel))
{
  FMOD_System_PlaySound(rsystem, FMOD_CHANNEL_FREE, sound, 0, &amp;channel);
}

if (channel)
{
  for ( ; ; )
  {
    if (FMOD_Sound_GetTag(sound, 0, -1, &amp;tag) != FMOD_OK)
      break;
    if (tag.datatype == FMOD_TAGDATATYPE_STRING)
      printf(&quot;%s = %s                            \n&quot;,
                 tag.name, tag.data);
  }


  FMOD_Sound_GetOpenState(sound, &amp;openstate, &amp;percent, &amp;starving);
  printf(&quot;Buffer: (%3d%%)  Radio:  %d  \r&quot;, percent, IdxRadio);

  if ((percent &lt; lastpercent) &amp;&amp; (percent &lt; 50))
  {
    printf(&quot;\nRestart ...\n&quot;);
    FMOD_Channel_Stop(channel);

[color=yellow:2x48q192][b:2x48q192]// FMOD_Sound_Release(sound);[/b:2x48q192][/color:2x48q192]
Sleep(200);
sound = 0; channel = 0; percent = 0;
if (++IdxRadio > MaxRadio) IdxRadio = 0;
FMOD_System_CreateStream(rsystem, RadioWeb[IdxRadio], mode, 0,&sound);
}
lastpercent = percent;
}

Sleep(100);

} while (loop);

printf("\nShutting down.\n");

/*
Shut down
*/
result = FMOD_Channel_Stop(channel);
ErrCheck(result);
// result = FMOD_Sound_Release(sound);
// ErrCheck(result);
result = FMOD_System_Close(rsystem);
ErrCheck(result);
result = FMOD_System_Release(rsystem);
ErrCheck(result);

printf("By by …\n");
return 0;
}[/list:u:2x48q192]

  • You must to post comments
0
0

Im having exactly the same problem under Purebasic. If the connection goes down, the last 3 seconds of the stream loop continuously. When using FMOD_NONBLOCKING you can stop the sound in this situation but FMOD still blocks wnen you call FMOD_System_Release. Is there no way to stop the stream manually? It looks like its waiting for the stream to timeout. Maybe we can set this timeout?

  • You must to post comments
0
0

You are missig a few key elements from the net stream example… One of them is not to release while it’s not ready. It’s anoying I know. And it does not always work…

[code:9zogbbty]
do
{
FMOD_OPENSTATE openstate;

    result = FMOD_Sound_GetOpenState(sound, &amp;openstate, 0, 0);
    ERRCHECK(result);

    if (openstate == FMOD_OPENSTATE_READY)
    {
        break;
    }

    printf(&quot;Waiting for sound to finish opening before trying to release it....\r&quot;);

//note to fmod developers
//Shoud there not be a System_Update here???

    Sleep(10);
} while (1);

/*
    Shut down
*/
result = FMOD_Sound_Release(sound);
ERRCHECK(result);

[/code:9zogbbty]
And you are not checking the starving state and such things.

One thing I do in an example like yours, playing from a play list is have an array of sounds. like 10… I stop the channel and flag the sound to be freed and create another sound instance… The main loop checke the states for all the sounds that are ready to be released and only frees them when they are ready/safe to be freed. It’s not perfect… Some sounds never get ready to be freed…

When you quit the app, dont free the sounds that are stuck… Skip over them and let windows handle it (to hell with it I say LOL).

Be, when I quit the app, I check the states for a maximum of 10 seconds before giving up on the stuck sounds…

  • You must to post comments
Showing 2 results
Your Answer

Please first to submit.