0
0

Hello,

I’m trying to write my own ‘jukebox’ with two players so I can cross-fade from song to song. FMOD looks really nice, but I seem to be doing something wrong. I’ve looked at the examples and they’ve helped but still it’s not working.

First some code, I’ve included only the relevant functions. As you can see most of the code is coming from the stream example.

[code:wupwg934]
FSOUND_STREAM *stream[3];
int channel[3];

signed char F_CALLBACKAPI endcallback(FSOUND_STREAM *lstream, void *buff, int len, void *param)
{
int num;
// end of stream callback doesnt have a ‘buff’ value, if it doesnt it could be a synch point.
if (buff)
{
printf("\nSYNCHPOINT : \"%s\"\n", buff);
}
else
{
num = (int)param;
FSOUND_Stream_Stop(stream[num]);
FSOUND_Stream_Close(stream[num]);
//stream[num] = NULL;
printf("\nSTREAM %d ENDED!!\n", num);
FmodPlaySong ( "mp3/file3.mp3", num );
}
return TRUE;
}

int InitFmodSound()
{

FSOUND_SetOutput(FSOUND_OUTPUT_ALSA);
FSOUND_SetDriver(0);                    // Select sound card (0 = default)

if (!FSOUND_Init(44100, 32, 0))
{
    printf("Error!\n");
    printf("%s\n", FMOD_ErrorString(FSOUND_GetError()));
    FSOUND_Close();
    return 1;
}

FSOUND_Stream_SetBufferSize(500);
return 0;

}

int FmodPlaySong (char *file, int num)
{
stream[num] = FSOUND_Stream_Open( file, FSOUND_NORMAL | FSOUND_MPEGACCURATE, 0, 0);
if (!stream[num])
{
printf("Error!\n");
printf("%s\n", FMOD_ErrorString(FSOUND_GetError()));
FSOUND_Close();

    //return 1;
}

FSOUND_Stream_SetEndCallback( stream[num], endcallback, (void*)num);
FSOUND_Stream_SetSyncCallback( stream[num], endcallback, (void*)num);

channel[num] = FSOUND_Stream_PlayEx(FSOUND_FREE, stream[num], NULL, TRUE);
FSOUND_SetPaused(channel[num], FALSE);

printf ( "Channel %d -> Started playing : %s\n", channel[num], file );
printf ( "Currently : %d channels playing\n", FSOUND_GetChannelsPlaying());
printf ( "With : %d max channels\n", FSOUND_GetMaxChannels());

return channel[num];

}

int main(int argc, char *argv[])
{
int done=0;
channel[1] = -1;
channel[2] = -1;

InitFmodSound();
FmodPlaySong ( "mp3/file1.mp3", 1 );
FmodPlaySong ( "mp3/file2.mp3", 2 );

while(done == 0)
{
// SDL loop which handles graphics and mous i/o.
}

FSOUND_Stream_Close(stream[1]);
FSOUND_Stream_Close(stream[2]);
FSOUND_Close();
}[/code:wupwg934]

Basically this is what happens, two songs are started, once one of them is finished the endcallback function starts playing the third song on whatever channel is finished first. This should be possible, shouldn’t it ?

As soon as the endcallback function is called by a finished stream the sound output stops entirely, both channels. Even though there’s no sound, FSOUND_Stream_GetTime() is still returning values.

My questions are :
* Is this possible to reuse these variables ?
* If it is possible can you spot the error I’m making ?

Thanks,
Bart.

  • You must to post comments
0
0

what do all of your print fucntions ouput, that should help see whats happening

  • You must to post comments
0
0

[code:301nvm2a]dj casumm # ./casumm
Channel 4096 -> Started playing : /usr/local/src/examples/casumm/mp3/file1.mp3
Currently : 1 channels playing
With : 32 max channels
Channel 4097 -> Started playing : /usr/local/src/examples/casumm/mp3/file2.mp3
Currently : 2 channels playing
With : 32 max channels

[b]STREAM 2 ENDED!![/b]
Channel 4098 -> Started playing : /usr/local/src/examples/casumm/mp3/file3.mp3
Currently : 2 channels playing
With : 32 max channels

STREAM 2 ENDED!!
Channel 4099 -> Started playing : /usr/local/src/examples/casumm/mp3/file3.mp3
Currently : 2 channels playing
With : 32 max channels

STREAM 1 ENDED!!
Channel 4100 -> Started playing : /usr/local/src/examples/casumm/mp3/file3.mp3
Currently : 2 channels playing
With : 32 max channels

STREAM 2 ENDED!!
Channel 4101 -> Started playing : /usr/local/src/examples/casumm/mp3/file3.mp3
Currently : 2 channels playing
With : 32 max channels
[/code:301nvm2a]

This basicly goes on till I kill the process. As far as I can tell this is what it’s supposed to be. Not sure about the increasing channel number. If you’re willing to take a look at it, I can upload the entire code to my website.

Thanks,
Bart.

  • You must to post comments
0
0

Now I’m confused. I’ve been testing things by removing the stream cleanup and starting the new song from the endcallback function. I have placed that in the main loop. This did not help, as you probably expected.

Why I’m confused; the streams only stop playing when I load a specific mp3 file. I’m trying to figure out why that one fails, because the stream example does play the same file. Let you know if I find out why that file stops audio output. Any hints are always appreciated.

  • You must to post comments
Showing 3 results
Your Answer

Please first to submit.