hey, I am new in fmod.
I am quite confused how to use sound::lock to get the data from the sound after dsp processing. For my understanding, the dsp processing happens in the channel, so when I use sound::lock it just give the data for the original sound(before processing). So if there is any methods to put the processed sound in ‘channel’ back to the ‘sound’ parameter,so that I can use sound::lock to get the processed data and save them as a txt file.
here is my code:
result = system->createSound((const char*)buff, FMOD_OPENMEMORY | FMOD_OPENRAW, &exinfo, &sound);
ERRCHECK(result);
FMOD::DSP* dsp;
system->createDSPByType(FMOD_DSP_TYPE_PITCHSHIFT, &dsp);
dsp->setParameterFloat(FMOD_DSP_PITCHSHIFT_PITCH, 1.7); //luoli
result = system->playSound(sound, 0, false, &channel);
ERRCHECK(result);
channel->addDSP(0, dsp);
system->update();
bool isplaying = true;
while (isplaying) {
channel->isPlaying(&isplaying);
}
unsigned int numSamples = 0;
unsigned int mappedMemorySize = 0;
int bitsPerSample = 0;
sound->getFormat(NULL, NULL, NULL, &bitsPerSample);
sound->getLength(&numSamples, FMOD_TIMEUNIT_PCM);
sound->getLength(&mappedMemorySize, FMOD_TIMEUNIT_PCMBYTES);
assert(bitsPerSample == 16);
mappedMemorySize *= 2;
printf("Num samples: %i\tBits per sample: %i\n", numSamples, bitsPerSample);
int16_t* mappedMemory = new int16_t[mappedMemorySize];
unsigned int bytesRead = 0;
int16_t* mem = 0;
int16_t* output = mappedMemory;
FILE* fp;
ofstream outfile("test.txt", ios::trunc);
sound->lock(0, mappedMemorySize / 2, (void**)& mem, 0, &bytesRead, 0);
for (int i = 0; i < bytesRead; i++) {
int16_t sample = mem[i];
output[i] = ((int16_t)mem[i]);
//printf("%d\n", output[i]);
outfile << output[i] << "\n";
}
outfile.close();
sound->unlock(mem, 0, bytesRead, 0);
result = sound->release();