0
0

Sounds are created by myself. i want to play two sounds end to end. i set the channelCallback, judge the status of " the FMOD_CHANNEL_CALLBACKTYPE_END". And in main.cpp, i used WaitForSingleObject (hSoundOverEvent, INFINITE) to wait the signal of channel end. But the process will stop at the WaitForSingleObject (hSoundOverEvent, INFINITE) . So i can’t reach my aim. i need a help: how to play two sounds circularly? (i can’t use the playlist, because sounds are generated in real time in actual use. )

[code:1e7wf2zy]#include <windows.h>

include <stdio.h>

include <conio.h>

include "../../api/inc/fmod.hpp"

include "../../api/inc/fmod_errors.h"

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

HANDLE hSoundOverEvent = NULL;

FMOD_RESULT F_CALLBACK callbackChannel(FMOD_CHANNEL * channel, FMOD_CHANNEL_CALLBACKTYPE type, void * commanddata1, void * commanddata2)
{
FMOD::Channel *cppchannel = (FMOD::Channel *)channel;

if(type == FMOD_CHANNEL_CALLBACKTYPE_END)
{
    SetEvent(hSoundOverEvent);
};

return FMOD_OK;

}

int main(int argc, char *argv[])
{

/************************************
      Create sound system
 ***********************************/

FMOD::System     *system;
FMOD::Sound      *sound1, *sound2;
FMOD::Channel    *channel;
FMOD_RESULT       result;
int               key;
FMOD_MODE         modeTyre = FMOD_LOOP_OFF | FMOD_SOFTWARE;

result = FMOD::System_Create(&amp;system);
ERRCHECK(result);

result = system-&gt;init(32, FMOD_INIT_NORMAL, 0);
ERRCHECK(result);

result = system-&gt;createSound(&quot;../wavesource/v40_20ms.wav&quot;, modeTyre, 0, &amp;sound1);
ERRCHECK(result);
result = system-&gt;createSound(&quot;../wavesource/v80_20ms.wav&quot;, modeTyre, 0, &amp;sound2);
ERRCHECK(result);

hSoundOverEvent = CreateEvent( NULL, FALSE, FALSE, NULL);

int i= 1;   


do
{
    if(_kbhit())
    {
        key = getch();
    }
    if((i &amp; 1) == 0)
        result = system-&gt;playSound(FMOD_CHANNEL_FREE, sound2, false, &amp;channel);
    else
        result = system-&gt;playSound(FMOD_CHANNEL_FREE, sound1, false, &amp;channel);
    i +=1;
    channel-&gt;setCallback(callbackChannel);
    system-&gt;update();
    WaitForSingleObject(hSoundOverEvent, INFINITE);
} while (key != 27);


/*
    Shut down
*/

CloseHandle(hSoundOverEvent);
result = sound1-&gt;release();
ERRCHECK(result);
result = sound2-&gt;release();
ERRCHECK(result);
result = system-&gt;close();
ERRCHECK(result);
result = system-&gt;release();

return 0;

}[/code:1e7wf2zy]

  • You must to post comments
Showing 0 results
Your Answer

Please first to submit.