FMOD変音処理後のデータをどのようにキャプチャして格納するか

4800 ワード

AVAudioEngineの機能と同様に、1つのEngineがN個のconnect接続(直列と並列)を一緒に接続することで、複数の入力源、多層処理効果の混合出力を実現することができる.この実現に必要な機能もこのようなスキームによって実現される.すなわち、使用する音響効果と目標出力との間に独自のカスタム音響処理を追加し、この音響処理を実現するにあたって、最終的なBUFFERデータを前の音響効果入力のBUFFERデータとして設定し、これらのデータをファイルに書き込む.
1.2つのDSPをバインドする
system->playSound(sound, 0, false, &channel);
FMOD::DSP          *mydsp = configuration(system);
 int result = system->getMasterChannelGroup(&mastergroup);
//mastergroup MixOutNode
//dsp 
//mydsp 
ERRCHECK(result);
//
mastergroup->addDSP(0, dsp);
result = mastergroup->addDSP(0, mydsp);
ERRCHECK(result);

2.カスタム音響効果処理関数では、データを切り取り、前の処理結果を出力に設定する
/*
dspdesc.read                = myDSPCallback;
system->createDSP(&dspdesc, &mydsp);
*/
FMOD_RESULT F_CALLBACK myDSPCallback(FMOD_DSP_STATE *dsp_state, float *inbuffer, float *outbuffer, unsigned int length, int inchannels, int *outchannels)
{
    printf("+++++++++");
    mydsp_data_t *data = (mydsp_data_t *)dsp_state->plugindata;
    
    /*
     This loop assumes inchannels = outchannels, which it will be if the DSP is created with '0'
     as the number of channels in FMOD_DSP_DESCRIPTION.
     Specifying an actual channel count will mean you have to take care of any number of channels coming in,
     but outputting the number of channels specified. Generally it is best to keep the channel
     count at 0 for maximum compatibility.
     */
    for (unsigned int samp = 0; samp < length; samp++)
    {
        /*
         Feel free to unroll this.
         */
        for (int chan = 0; chan < *outchannels; chan++)
        {
            /*
             This DSP filter just halves the volume!
             Input is modified, and sent to output.
              , ( PCM )
             */
            data->buffer[(samp * *outchannels) + chan] = outbuffer[(samp * inchannels) + chan] = inbuffer[(samp * inchannels) + chan] * data->volume_linear;
        }

    }
    printf("--->%u
",length); data->channels = inchannels; // , length, PCM fwrite(data->buffer, sizeof(float), length**outchannels, saveFile); return FMOD_OK; }

3.注意点(サンプリングレートと出力チャネル数)
に設定されている
system->setDSPBufferSize(44100, 2);
しかし、取得と測定された2つの指標は44100と1(他のデータが正常に取得できない設定、大きな雑音が発生するなど、熟練指導が必要)である.
3 ps:実際の効果は指標が22050と2かもしれないし、設定や出力は関係なく読み取りの要求だけかもしれない
end:以上がこの機能の実現に成功した最も主要な説明で、みんなが一緒に検討することを歓迎します
転載先:https://www.cnblogs.com/yuxiaoyiyou/p/9188601.html