0
0

Hallo again,

is this part of the fmodex record example the right place to fill the lame’s beEncodeChunk() function:

/*
Lock the sound to get access to the raw data.
/
soundx->lock(lastrecordpos * 4, blocklength * 4, &ptr1, &ptr2, &len1, &len2); /
*4 = stereo 16bit. 1 sample = 4 bytes. */

        /*
        Write it to disk.
        */
        if (ptr1 && len1)
        {
            datalength += fwrite(ptr1, 1, len1, fp);
        }

        if (ptr2 && len2)
        {
            datalength += fwrite(ptr2, 1, len2, fp);
        }
        /*
        Unlock the sound to allow FMOD to use it again.
        */
        soundx->unlock(ptr1, ptr2, len1, len2);

???

Please tell me how can I encode the data between lock and unlock to
mp3.
Is there no one with an example in fmod ex???

  • You must to post comments
0
0

Hallo brett,

I stud the output-mp3 example an I have now a piece of code that encode
to mp3 and write it to disc while a sound is playing:

void CRipper::OnTimer(UINT nIDEvent)
{
if(nIDEvent == 8)
{
CMainFrame* pMain1 = (CMainFrame*)AfxGetMainWnd();
static unsigned int lastrecordpos = 0;
unsigned int recordpos = 0;
DWORD dwRead=0;
DWORD dwWrite=0;

    pMain1->system->getRecordPosition(&recordpos);
    if (recordpos != lastrecordpos)        
    {
        void *ptr1, *ptr2;
        int blocklength;
        unsigned int len1, len2;

        blocklength = (int)recordpos - (int)lastrecordpos;
        if (blocklength < 0)
        {
            blocklength += soundlength;
        }
        /*
        Lock the sound to get access to the raw data.
        */
        soundx->lock(lastrecordpos * 4, blocklength * 4, &ptr1, &ptr2, &len1, &len2);   /* *4 = stereo 16bit.  1 sample = 4 bytes. */
        /*
        Write it to disk.
        */
        if (ptr1 && len1)
        {
            (size_t)datalength += fwrite(ptr1, 1, len1, fp);

            memcpy( pWAVBuffer, ptr1, dwSamples );
            dwRead = dwSamples / 2;
            err = beEncodeChunk(hbeStream, dwRead, pWAVBuffer, pMP3Buffer, &dwWrite);
            fwrite(pMP3Buffer,1,dwWrite,pFileOut);
        }


        if (ptr2 && len2)
        {
            (size_t)datalength += fwrite(ptr2, 1, len2, fp);

            memcpy( pWAVBuffer, ptr2, dwSamples );
            dwRead = dwSamples / 2;
            err = beEncodeChunk(hbeStream, dwRead , pWAVBuffer, pMP3Buffer, &dwWrite);
            fwrite(pMP3Buffer,1,dwWrite,pFileOut);
        }
        soundx->unlock(ptr1, ptr2, len1, len2);
    }
}

}

So I can avoid the masses of callback functions the mp3-output example give. (I hope so:)
But there is a problem with my recorded mp3-output.
The sound stutters very hard. But I can hear that it is the song I want to decode :)
I think I use the wrong length or the wrong data sizes probably. Im not very trusted with dword, pshorts etc.
But I think when I can encode and record at all that the problem is to find here.
Please take a look at my code. Where is the wrong piece that makes my recorded mp3-output stuttering.
The timer I use is set by SetTimer(8,50,NULL); That sould be the shortest intervall that is possible in VC++, system->update() is called for each timer call. All the other settings and vars I took from the fmodex’s dev-plugin example.

Thanks a lot

greetings
Daniel

  • You must to post comments
0
0

ohhh pleeeeease …

  • You must to post comments
Showing 2 results
Your Answer

Please first to submit.