0
0

Hi all,

i got a problem with FSOUND_Sample_Lock.
I want to record sound and use FSOUND_Sample_Lock to access tha data.
(win xp)

[code:3k0qsxuy]
m_pSample = FSOUND_Sample_Alloc( 0, 1024, FSOUND_16BITS | FSOUND_SIGNED | FSOUND_STEREO, 44100, 50, 0, 0)
FSOUND_Record_StartSample (m_pSample, true)
[...]
int lastRecPos = FSOUND_Record_GetPosition() – 512;
if (lastRecPos < 0) lastRecPos += 1024;
FSOUND_Sample_Lock (m_pSample, lastRecPos, 512, (void) &pData1, (void)&pData2, &length1, &length2);
std::cout << "length1: " << length1 << " , length2: " << length2 << std::endl;
memcpy (m_pSoundData, pData1, length14);
memcpy (&m_pSoundData[length1], pData2, length2
4);
FSOUND_Sample_Unlock (m_pSample, pData1, pData2, length1, length2);[/code:3k0qsxuy]

length1 is always 512 although 1024-lastRecPos < 512.
Why is that? Shouldn’t FSOUND_Sample_Lock fill pData2 if the buffer has been wrapped?

thx in advance

  • You must to post comments
0
0

thx, fixed this, but is there anything wrong with this code, cause after a while of running the prog it crashes (callstack: fmod.dll -> msvcrt.dll):
(using .net 2003)

[code:38zxad3c]void CSoundManager::update(void)
{
static long lastTime=GetTickCount();
if (m_pSample)
{

    long now = GetTickCount();
    int lastRecPos = (FSOUND_Record_GetPosition() - 512);
    if (lastRecPos &lt; 0) lastRecPos += 1024;

    m_lTime += (now - lastTime);
    lastTime = now; 
    short *pData1=0;
    short *pData2=0;
    unsigned int length1, length2;

    FSOUND_Sample_Lock (m_pSample, lastRecPos&lt;&lt;2, 2048,  (void**) &amp;pData1, (void**)&amp;pData2, &amp;length1, &amp;length2);
    //std::cout &lt;&lt; &quot;length1: &quot; &lt;&lt; length1 &lt;&lt; &quot;, length2: &quot; &lt;&lt; length2 &lt;&lt; std::endl;
    //memcpy (m_pSoundData, pData1, length1);
    //if (length2 &gt; 0) memcpy (&amp;m_pSoundData[length1], pData2, length2);
    FSOUND_Sample_Unlock (m_pSample, pData1, pData2, length1, length2);

    int i;
    pData1 = (short*)m_pSoundData;
    for (i=0; i&lt;512; ++i)
    {
        m_Sound.pWaveL[i] = (float)pData1[i*2];
        m_Sound.pWaveR[i] = (float)pData1[i*2+1];
    }

}

}[/code:38zxad3c]

any ideas?

  • You must to post comments
Showing 1 result
Your Answer

Please first to submit.