c_cpp openFrameworks - 使用ofFmodSoundPlayer从audioPlayer获取原始音频帧

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了c_cpp openFrameworks - 使用ofFmodSoundPlayer从audioPlayer获取原始音频帧相关的知识,希望对你有一定的参考价值。


#ifndef ofxFmodSoundPlayer_h
#define ofxFmodSoundPlayer_h

#include "ofFmodSoundPlayer.h"

class ofxFmodSoundPlayer : public ofFmodSoundPlayer
{
    public:
    ofxFmodSoundPlayer();
    
    void play();
    
    private:
    FMOD_DSP       *analyzer;
};

#endif
#include "ofxFmodSoundPlayer.h"

FMOD_RESULT F_CALLBACK analyzerCallback(FMOD_DSP_STATE *dsp_state,
                                        float *inbuffer, float *outbuffer,
                                        unsigned int length, int inchannels,
                                        int outchannels)

{
     // pass the data along
    memcpy(outbuffer, inbuffer, sizeof(float)* length * outchannels);
    
    ////////// Here you have acess the raw audio data from the sound file
    //////////
  
    void *userdata = NULL;
    FMOD_DSP_GetUserData(dsp_state->instance, &userdata);
    ofxFmodSoundPlayer *player = (ofxFmodSoundPlayer *)userdata;
    
    // now you can access your instnce of your ofxFmodSondPlayer instance
  
    return FMOD_OK;
}

ofxFmodSoundPlayer::ofxFmodSoundPlayer(){
  // FIXME: I'd love to setup the analyer callback here, but somehow FMOD doesnt allow me to do so... :-(
}

void ofxFmodSoundPlayer::play(){
    ofFmodSoundPlayer::play();

    // Setup - insert our own callback into FMOD graph
    FMOD_SYSTEM  *system;
    FMOD_RESULT result  = FMOD_Sound_GetSystemObject(sound, &system);
    ERRCHECK(result);
    
    FMOD_DSP_DESCRIPTION dsp_description;
    memset(&dsp_description, 0, sizeof(FMOD_DSP_DESCRIPTION));
    strcpy(dsp_description.name, "Audio Analyzer DSP");
    dsp_description.channels     = 0;
    dsp_description.read         = analyzerCallback;
    dsp_description.userdata     = this;
    result = FMOD_System_CreateDSP(system, &dsp_description, &analyzer);
    ERRCHECK(result);
    
    // Create DSP
    result = FMOD_Channel_AddDSP(channel, analyzer, 0);
    ERRCHECK(result);
}

void ERRCHECK(FMOD_RESULT result){
    if (result != FMOD_OK){
        fprintf(stderr, "FMOD error! (%d) %s\n", result, FMOD_ErrorString(result));
        exit(-1);
    }
}


以上是关于c_cpp openFrameworks - 使用ofFmodSoundPlayer从audioPlayer获取原始音频帧的主要内容,如果未能解决你的问题,请参考以下文章

c_cpp 在openFrameworks中找到单应性

c_cpp openFrameworks - 使用ofFmodSoundPlayer从audioPlayer获取原始音频帧

c_cpp openFrameworks内联着色器模板(仅限vert和frag)

c_cpp openFrameworks现代main.cpp(Open GL 4.1)

c_cpp 矢量函数(openFrameworks的Vec2f / 3f / 4f端口)

使 iPad 屏幕关闭,但通过触摸唤醒(无锁定) - - iOS 6.0 / openFrameworks