android save sound to a .wav file


(Xingsheng) #1

hi,I have done the change of source voice, but I can’t find the suitable method in your SDK to save the voice after changed. My code is :

system->createDSPByType(FMOD_DSP_TYPE_PITCHSHIFT, &dsp);
dsp->setParameterFloat(FMOD_DSP_PITCHSHIFT_PITCH, 1.7);
system->playSound(sound, 0, false, &channel);
channel->addDSP(0, dsp);

after changing the sound could play normaly ,but how can I save the sound after changed to a .wav file. could you offer me some help?


(リチャード清水) #2

Hi Xingsheng,

I replied to your email but I will put the response here as well for other people’s benefit.

If you wish to save the altered voice to a .wav file then you will need to use FMOD_OUTPUTTYPE_WAVWRITER.

https://www.fmod.org/documentation/#content/generated/FMOD_OUTPUTTYPE.html

Please keep in mind that if you require to output to both speakers and the .wav file at the same time you will need to create a custom DSP for this.

I hope this helped.

Thanks,
Richard


(Xingsheng) #3

Thank you for your reply!I will try it


(庄绪安) #4

hi,Xingsheng:
I have the same question to you.
below is my code,but save the sound is very slowly than normal sound.
Could you help me ?

//start -------------------------------------------------------
System *system;
Sound *sound;
DSP *dsp;
bool playing = true;
// void *buff = 0;
unsigned int dataRead;
Channel *channel;
float frequency = 0;
System_Create(&system);
system->init(32, FMOD_INIT_NORMAL, NULL);
const char *path_cstr = env->GetStringUTFChars(path_jstr, NULL);
//创建声音
system->createSound(path_cstr, FMOD_DEFAULT, NULL, &sound);
system->createDSPByType(FMOD_DSP_TYPE_NORMALIZE, &dsp);
system->playSound(sound, 0, false, &channel);
channel->getFrequency(&frequency);
frequency = frequency * 1.6;
channel->setFrequency(frequency);
FMOD_RESULT result;
FMOD_SOUND_FORMAT irSoundFormat;
FMOD_SOUND_TYPE irSoundType;
int irSoundBits, irSoundChannels;
result = sound->getFormat(&irSoundType, &irSoundFormat, &irSoundChannels, &irSoundBits);
unsigned int irSoundLength;
result = sound->getLength(&irSoundLength, FMOD_TIMEUNIT_PCM);

    if (irSoundFormat != FMOD_SOUND_FORMAT_PCM16)
    {
        /*
            For simplicity of the example, if the impulse response is the wrong format just display an error
        */
        LOGI("%s", "not pcm");
    }

    /*
        The reverb unit expects a block of data containing a single 16 bit int containing
        the number of channels in the impulse response, followed by PCM 16 data
    */
    unsigned int irDataLength = sizeof(short) * (irSoundLength * irSoundChannels + 1);
    short* irData = (short*)malloc(irDataLength);
    irData[0] = (short)irSoundChannels;
    unsigned int irDataRead;
    result = sound->readData(&irData[1], irDataLength - sizeof(short), &irDataRead);
    FILE *fpw = fopen("sdcard/voice_changed.pcm","wb+");
    fwrite(&irData[1], irDataLength, sizeof(short), fpw);
    fclose(fpw);
    free(irData);

} catch (...) {
    LOGE("%s", "发生异常");
    goto end;
}
system->update();
while (playing) {
    channel->isPlaying(&playing);
    usleep(1000 * 1000);
}
goto end;
end:
env->ReleaseStringUTFChars(path_jstr, path_cstr);
sound->release();
system->close();
system->release();

(yourks) #5

Hello, I have the same problem, but the custom DSP is not quite clear. Is there a good example to learn?