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(&system);
ERRCHECK(result);
result = system->init(32, FMOD_INIT_NORMAL, 0);
ERRCHECK(result);
result = system->createSound("../wavesource/v40_20ms.wav", modeTyre, 0, &sound1);
ERRCHECK(result);
result = system->createSound("../wavesource/v80_20ms.wav", modeTyre, 0, &sound2);
ERRCHECK(result);
hSoundOverEvent = CreateEvent( NULL, FALSE, FALSE, NULL);
int i= 1;
do
{
if(_kbhit())
{
key = getch();
}
if((i & 1) == 0)
result = system->playSound(FMOD_CHANNEL_FREE, sound2, false, &channel);
else
result = system->playSound(FMOD_CHANNEL_FREE, sound1, false, &channel);
i +=1;
channel->setCallback(callbackChannel);
system->update();
WaitForSingleObject(hSoundOverEvent, INFINITE);
} while (key != 27);
/*
Shut down
*/
CloseHandle(hSoundOverEvent);
result = sound1->release();
ERRCHECK(result);
result = sound2->release();
ERRCHECK(result);
result = system->close();
ERRCHECK(result);
result = system->release();
return 0;
}[/code:1e7wf2zy]
- brian_zhao asked 7 years ago
- You must login to post comments
Please login first to submit.