Currently, I have perfect realtime playback of the microphone input in realtime. However, when I play back the sound from a saved wav file, it is horrendously scratchy. Am I missing something fundamental about the lock/unlock? I am including the code for my WinMain loop which is pretty much the chunk of it. Most code is referenced from examples (thanks brett!)

EDIT: Here is what the code is supposed to be doing: It is buffering 5 seconds of raw audio data in a buffer, to save it to a .wav file. Notice the redundant of rewriting data on the (else of the (pos < lastpos) check), this is just to get it working at first.

If the recordPosition has wrapped, then it takes the last chunk of the sound since the last loop iteration and appends it to the buffer and writes the file. Right now, very incorrectly. The header seems to be quite valid but the length of the sound in iTunes is only listed as 0:02 instead of the correct 0:05. What am I missing?!

buffer is a char array of SOUND_LENGTH * 44100;
SOUND_LENGTH is #define of the number of seconds to record (5 in this test case)

audio is a weak wrapper right now for FMOD. I initialize it before the loop with

result = FMOD::System_Create(&system);
result = system->getVersion(&version);
result = system->setOutput(FMOD_OUTPUTTYPE_DSOUND);
result = system->getNumDrivers(&numdrivers);
result = system->setDriver(0);
result = system->setRecordDriver(0);
result = system->init(32, FMOD_INIT_NORMAL, 0);

now on to the main loop of my broken program:

while (TRUE)
if (PeekMessage(&msg,NULL,0,0,PM_REMOVE))
// Test if this is a quit
if (msg.message == WM_QUIT)

        //  Translate any accelerator keys

        //  Send the message to the window proc

    bool isRec = false;

    UINT pos = 0;

    if (isRec)
        if (!bPlay)
        audio.GetSystem()-&gt;playSound(FMOD_CHANNEL_REUSE, sound, false, &amp;channel);
        bPlay = true;

        if (pos &lt; lastpos)
            void *ptr1, *ptr2;
            unsigned int len1, len2;

            sound-&gt;lock(lastpos, (int(44100 * SOUND_LENGTH) - lastpos), &amp;ptr1, &amp;ptr2, &amp;len1, &amp;len2);   /* * exinfo.numchannels * 2 = stereo 16bit.  1 sample = 4 bytes. */
            sound-&gt;unlock(ptr1, ptr2, len1, len2);

         theFile = fopen(&quot;please.wav&quot;,&quot;w+&quot;);

         int channels;
         float rates;
         int bitss;
         sound-&gt;getFormat  (0, 0, &amp;channels, &amp;bitss);
         sound-&gt;getDefaults(&amp;rates, 0, 0, 0);

         sound-&gt;getLength(&amp;soundlength, FMOD_TIMEUNIT_PCM);

            // copy data into a buffer
            void *ptr1, *ptr2;
            unsigned int len1, len2;

            sound-&gt;lock(0, pos, &amp;ptr1, &amp;ptr2, &amp;len1, &amp;len2);  


            sound-&gt;unlock(ptr1, ptr2, len1, len2);


    lastpos = pos;


Any and all help will be graciously accepted!


  • You must to post comments
Showing 0 results
Your Answer

Please first to submit.