zoukankan      html  css  js  c++  java
  • FMOD变声如何捕获并存储处理音效之后的数据

    类似AVAudioEngine的功能,一个Engine可以将N个connect连接(串联和并联)在一起,这样来实现多个输入源,多层处理效果的混合输出。实现这个所需功能也是通过这样的方案来实现的。也就是说,在使用的音效和目标输出之间增加一个自己的自定义音效处理,在实现这个音效处理时,将最终BUFFER数据设置成为上一音效处理效果输入的BUFFER数据,并且存储这些数据写入文件。

    1.绑定两个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);

    但是测定为获取下来的两项指标为:44100和1(设定其它数据无法正常获取,出现很大的杂音等,急需熟手指导)

    3ps:实际效果是指标可能为22050和2,也可能设定和输出并没有关系只是读取的要求

    end:以上就是成功实现该项功能的最主要说明,欢迎大家一起探讨

  • 相关阅读:
    asp.net后台导出excel的方法:使用response导出excel
    asp.net后台导出excel的方法一:使用response导出excel
    infragistics--web网站升级注意点
    infragistics--网站部署时webtab的tab前出现textbox
    Jewels and Stones
    To Lower Case
    Unique Email Addresses
    unique-morse-code-words
    很久没来博客园了。。。。
    Centos7 基础知识---------root文件夹下没有.ssh文件
  • 原文地址:https://www.cnblogs.com/yuxiaoyiyou/p/9188601.html
Copyright © 2011-2022 走看看