We are developing various audio data processes such as this one: first, through processing to the current way, such as adding MOD to PCM by collecting PCM data, after processing, input the processed data into virtual sound. The problem I am currently encountering is how to make the FMOD engine work without playing. I have seen a lot of examples, all of them are called, and the playback code is like this:
result = system->playSound(sound, 0, 0, &channel);
You only need to call System::playSound
if you want to play the sound back, and you do not need to play the Sound
in order to modify its audio data. To get a pointer to the Sound
’s audio data call Sound::lock
. With that you can manipulate the audio data as required, and when you are finished call Sound::unlock
to give control back to FMOD before playing it back with System::playSound
.
Thanks for your reply. throught calling Sound::lock and Sound::unlock, I can modify pcm with my own algorithm. But I want to adjust pcm using FMOD not calling playSound. The below is my demo:
- Read PCM from a vector cache:
FMOD_RESULT F_CALLBACK FmodService::pcmreadcallback(FMOD_SOUND* /sound/, void* data, unsigned int datalen)
{
signed short* stereo16bitbuffer = (signed short*)data;
do {
mtx.lock();
if (pcmVector->size() <= 0) {
mtx.unlock();
Common_Sleep(10);
std::cout << “read pcm failed.” << std::endl;
continue;
}
std::cout << “read pcm” << std::endl;
* stereo16bitbuffer++ = *pcmVector->begin();
pcmVector->erase(pcmVector->begin());
mtx.unlock();
datalen -= 2;
} while (running && datalen > 0);
std::cout << “read pcm ok!!!” << std::endl;
return FMOD_OK;
}
exinfo.pcmreadcallback = pcmreadcallback;
result = system->createSound(0, mode, &exinfo, &sound);
// Is there a way to do dsp tuning without calling playSound?
result = system->playSound(sound, 0, 0, &channel);
- Add Fmod Dsp effect the reason I used Fmod:
result = system->createDSPByType(FMOD_DSP_TYPE_ECHO, &dspecho);
result = mastergroup->addDSP(0, dspecho);
- Get the pcm atfer DSP effect:
result = captureDSP->getParameterData(0, (void**)&captureData, &length, valuestr, 0);
ERRCHECK(result);
outf.write((char*)captureData->buffer, captureData->length_samples * sizeof(float));
I see- you cannot add a DSP
to a Sound
, you add a DSP
to a Channel
, and the Channel
only exists after calling System::playSound
. So you must call System::playSound
to apply an effect.
Why is it you don’t want to call System::playSound
? If you don’t want to hear the sound then you can set the system’s output type to FMOD_OUTPUTTYPE_NOSOUND_NRT, though that will disable all sound for that system object. If you don’t want to hear just that sound, you can add a FMOD_DSP_TYPE_FADER to the end of the signal chain and set its volume to 0 so that no audio reaches the mixer.
Thanks, I solve this problem by accustoming my own DSP.