0
0

I want to use FMOD’s DSP to implement following:
Input a sample buffer and get the result sample buffer after DSP’s processing?
Is it doable and how can I do it? :roll:

  • You must to post comments
0
0

I find the reason: Under the FMOD_OUTPUTTYPE_NOSOUND_NRT mode, the sound’s frequency must fit the frequency of the the frequency of System’s softwareformat.

  • You must to post comments
0
0

I know how the DSP unit works by document.
But now I want write a function to process input buffer by using DSP as following:
int ProcDataByDSP_HighPass(void pSampleIn, int nInDataLen, void *pSampleOut) {
/

Process Code
*/
return nOutDataLen;
}
I know that I should Create a sound by input data and using HighPass DSP, then use FMOD_OUTPUTTYPE_NOSOUND_NRT flag and System::update.But not sure how to do it step by step.
Thanks!

  • You must to post comments
0
0

Dear brett:
Thanks for your help.
I have done the work, but have a problem as following:
I give the 16bit data as signed short type, and get the result data as float type from custom dsp. Then I translate the float type to signed short type with code: if(pfSrc >= 1.0f) {
*pnDst = 32767;
}
else if(
pfSrc < -1.0f) {
pnDst = -32768;
}
else {
*pnDst = signed short(
pfSrc * 32768.0f);
}
As a result it produce noise because of misrepresentation.
How can I do to avoid this effect?

  • You must to post comments
0
0

No, I use the 16bit data to write file.
When it is played back, the noise will be produced.

  • You must to post comments
0
0

I use the DirectShow play the 16bit data processed by FMOD.

  • You must to post comments
0
0

I write test code to do as following:
1,Add my custom DSP that only transforms inbuffer(32bit) to 16bit data to System;
2,Push my 16bit audio data to Sound and record the data to 1.txt file;
3,Update the System and record the result data to 2.txt file;
4,I find the two types of 16bit data’s discrepancy is about 10.
Pls help, Thanks

  • You must to post comments
0
0

Dear Brett:
I think this problem is complex.
I first set the system’s out by FMOD_OUTPUTTYPE_NOSOUND_NRT for none-realtime process.
Then create a sound by use flag FMOD_OPENRAW and put my 16bit data in it.
Finnally I use System::update() to drive the process.
Now I do createsoundexinfo.defaultfrequency = 44100, noise produce. But when I do createsoundexinfo.defaultfrequency = 48000, noise disappear although the data’s frequency is 44100 in fact.
Pls tell me why?
Best Regards.

  • You must to post comments
0
0

Dear Brett:
I write a audio transform filter by using directshow and use FMODEx to process audio data.
I play a mp3 file to test it’s effect.
I have sent the source code to your mailbox.
The CDsp class encapsulates the function of FMODEx.
I use CDsp::Initial before i use it and CDsp::Uninitial fininally.The CDsp::DoAudioData does the real work.
Pls help, Thanks.

  • You must to post comments
0
0

[code:1jp30deu]
BOOL CDsp::Initial(FMOD_DSP_TYPE typeDSP,
int nChannels,
int nFrequency,
FMOD_SOUND_FORMAT format /* = FMOD_SOUND_FORMAT_PCM16 /,
int nMaxChannels /
= 2 */) {
FMOD_RESULT fr = FMOD_OK;
fr = System_Create(&m_pSystem);
ReturnIfFail(fr);

UINT uVersion;
fr = m_pSystem-&gt;getVersion(&amp;uVersion);
ReturnIfFail(fr);
if(uVersion &lt; FMOD_VERSION) {
    m_pSystem-&gt;release();
    return FALSE;
}

fr = m_pSystem-&gt;setOutput(FMOD_OUTPUTTYPE_NOSOUND_NRT);
ReturnIfFail(fr);

fr = m_pSystem-&gt;init(nMaxChannels, FMOD_INIT_NORMAL, NULL);
ReturnIfFail(fr);

fr = m_pSystem-&gt;setUserData(this);
ReturnIfFail(fr);

m_nChannels = nChannels;
m_nFrequency = nFrequency;
m_soundFormat = format;

fr = m_pSystem-&gt;createDSPByType(typeDSP, &amp;m_pDSP);
ReturnIfFail(fr);

FMOD_DSP_DESCRIPTION  dspdesc;
memset(&amp;dspdesc, 0, sizeof(FMOD_DSP_DESCRIPTION));
strcpy(dspdesc.name, &quot;Get Result DSP unit&quot;);
dspdesc.channels = 0;
dspdesc.read = DSPGetResultCallback;
fr = m_pSystem-&gt;createDSP(&amp;dspdesc, &amp;m_pDSPGetResult);
ReturnIfFail(fr);

fr = m_pSystem-&gt;addDSP(m_pDSP);
ReturnIfFail(fr);

fr = m_pSystem-&gt;addDSP(m_pDSPGetResult);
ReturnIfFail(fr);

return TRUE;

}

void CDsp::Uninitial() {
if(NULL != m_pDSP) {
m_pDSP->release();
m_pDSP = NULL;
}

if(NULL != m_pDSPGetResult) {
    m_pDSPGetResult-&gt;release();
    m_pDSPGetResult = NULL;
}

if(NULL != m_pSystem) {
    m_pSystem-&gt;close();
    m_pSystem-&gt;release();
    m_pSystem = NULL;
}

}

FMOD_RESULT F_CALLBACK CDsp::DSPGetResultCallback(FMOD_DSP_STATE *pDspState,
float *pInBuf,
float *pOutBuf,
unsigned int nSamples,
int nInChannels,
int nOutChannels) {
FMOD_RESULT fr = FMOD_OK;
DSP *pDSP = (DSP *)pDspState->instance;
System *pSystem;
fr = pDSP->getSystemObject(&pSystem);
ReturnIfFail2(fr);

CDsp *pThis;
fr = pSystem-&gt;getUserData((void **)&amp;pThis);
ReturnIfFail2(fr);

float *pfSrc = (float *)pInBuf;
for(unsigned int i = 0; i &lt; nSamples; i++) {
    for(int j = 0; j &lt; nInChannels; j++) {
            if(*pfSrc &gt;= 1.0f) {
                *pThis-&gt;m_pOutData = 32767;
            }
            else if(*pfSrc &lt; -1.0f) {
                *pThis-&gt;m_pOutData = -32768;
            }
            else {
                *pThis-&gt;m_pOutData = signed short(*pfSrc * 32768.0f);
            }

            pThis-&gt;m_pOutData++;
            pThis-&gt;m_nOutLength--;
        pfSrc++;
    }
}

return FMOD_OK;

}

BOOL CDsp::DoAudioData(void *pData, unsigned int nBuffers) {
if(NULL == m_pSystem) {
return FALSE;
}

int nOldBuffers = nBuffers;
if(nBuffers % 4096 != 0) {
    nBuffers += (4096 - nBuffers % 4096);
}

FMOD_CREATESOUNDEXINFO csei;
memset(&amp;csei, 0, sizeof(FMOD_CREATESOUNDEXINFO));
csei.cbsize = sizeof(FMOD_CREATESOUNDEXINFO);
csei.length = nBuffers;
csei.numchannels       = m_nChannels;
csei.defaultfrequency  = 48000;//m_nFrequency;
csei.format            = m_soundFormat;

FMOD_RESULT fr = FMOD_OK;
Sound *pSound;
char *pBuf = new char[nBuffers];
memcpy(pBuf, pData, nOldBuffers);
fr = m_pSystem-&gt;createSound((const char *)pBuf, FMOD_OPENMEMORY | FMOD_OPENRAW, &amp;csei, &amp;pSound);
delete [] pBuf;
ReturnIfFail3(fr);

fr = m_pSystem-&gt;playSound(FMOD_CHANNEL_REUSE, pSound, false, &amp;m_pChannel);
ReturnIfFail3(fr);

m_pOutData = (signed short *)pData;
m_nOutLength = nOldBuffers / sizeof(signed short);

for(unsigned int i = 0; i &lt; (nBuffers / m_nChannels)&gt;&gt;11; i++) {
    m_pSystem-&gt;update();
}

pSound-&gt;release();

return TRUE;

}[/code:1jp30deu]

  • You must to post comments
Showing 9 results
Your Answer

Please first to submit.