2015-05-16 29 views
1

我想代表在3D平面上的声音的频谱,但我也只能播放声音,不能让DSP进入结构FMOD_DSP_PARAMETER_FFT,numchannels和长度总是= 0C++ FMOD Studio无法为freq的FMOD_DSP_PARAMETER_FFT赋值。 analisys

我的代码是这样的:

FMOD::System  *system; 
FMOD::Sound  *sound1; 
FMOD::Channel *channel = 0; 
FMOD::ChannelGroup *mastergroup; 
FMOD::DSP   *mydsp, *dsphead, *dspchannelmixer; 
FMOD::DSPConnection *conection; 
FMOD_RESULT  result; 
unsigned int  version; 
result = FMOD::System_Create(&system); 
result = system->getVersion(&version); 

result = system->init(32, FMOD_INIT_NORMAL, NULL); 


result = system->createSound("mysong.mp3",FMOD_DEFAULT, 0, &sound1); 
result = sound1->setMode(FMOD_LOOP_NORMAL); 
result = system->playSound(sound1, 0, true, &channel); 

/* 
Create the DSP effect. 
*/ 

result = system->createDSPByType(FMOD_DSP_TYPE_FFT, &mydsp); 
result = mydsp->setParameterFloat(FMOD_DSP_FFT_SPECTRUMDATA, 300.0f); 

result = system->getMasterChannelGroup(&mastergroup); 
result = mastergroup->getDSP(FMOD_CHANNELCONTROL_DSP_HEAD, &dsphead); 
result = dsphead->getInput(0, &dspchannelmixer, 0); 

result = dsphead->disconnectFrom(dspchannelmixer); 
result = dsphead->addInput(mydsp, &conection); 
result = mydsp->addInput(dspchannelmixer); 

result = mydsp->setBypass(true); 
result = mydsp->setActive(true); 

char s[256]; 
unsigned int len; 
float freq[32]; 

float fft = 0; 
std::vector<float> fftheights; 

//program loop 
while (1) { 


    unsigned int ms = 0; 
    unsigned int lenms = 0; 
    bool   playing = 0; 
    bool   paused = 0; 
    int   channelsplaying = 0; 

    if (channel) 
    { 
    FMOD::Sound *currentsound = 0; 
    result = channel->setPaused(false); 
    result = channel->setMute(false); 
    result = channel->isPlaying(&playing); 
    result = channel->getPaused(&paused); 
    result = channel->setVolume(0.5); 
    result = channel->getPosition(&ms, FMOD_TIMEUNIT_MS); 
    channel->getCurrentSound(&currentsound); 
    if (currentsound) 
    { 
     result = currentsound->getLength(&lenms, FMOD_TIMEUNIT_MS); 
    } 
    } 
    system->getChannelsPlaying(&channelsplaying); 
    render_function(); 
    FMOD_DSP_PARAMETER_FFT *fftparameter; 
    result = mydsp->getParameterData(FMOD_DSP_FFT_SPECTRUMDATA, (void **)&fftparameter, 0, 0, 0); 
    result = mydsp->getOutput(FMOD_DSP_FFT_SPECTRUMDATA, &mydsp, 0); 

    for (int channelfft = 0; channelfft < fftparameter->numchannels; channelfft++) 
    { 
    for (int bin = 0; bin < fftparameter->length; bin++) 
    { 
     float val = fftparameter->spectrum[channelfft][bin]; 
     if (channelfft == 0){ 
     fftheights.push_back(val); 
     } 
     else{ 
     fftheights[bin] += val; 
     } 

    } 
    } 
    result = system->update(); 
} 

这个错误,我不能推回值到fftheights载体,总是空的0,如果你能帮助我,我会同意。

谢谢。

+0

我的代码已经改变了很多,但如果你能帮助我,我会同意,因为我的更改没有解决问题... – Custodius

+0

最后问题是我绕过dps,代码运行良好 – Custodius

回答

1

我认为你需要使用设置这些值:

mydsp->setParameterInt(...); // <-- put stuff there 

此外,检查是否功能是通过看“结果”

Here更多信息返回任何错误。

+0

我试着用这个:mydsp-> setParameterInt(FMOD_DSP_FFT_WINDOWSIZE,FFT_NUM_BINS); mydsp-> setParameterInt(FMOD_DSP_FFT_WINDOWTYPE,FMOD_DSP_FFT_WINDOW_HAMMING);现在我收到数字,但数值很低(* 10e-34),而且从未改变:( – Custodius

+0

Roddey,当你说“把工作人员放在这里”时,你的意思是什么?你能给我一个例子吗? – Custodius

+0

这就是我所得到的当我说“把东西放在这里”时,只需在函数中加入参数,FFT的窗口大小是多少?尝试输入确切的数字,并检查所有的“结果”变量。转到信号处理交换,他们可能比我更熟悉fmod –