Hi again, thanks for all the help I’ve been getting so far.
I kinda thought I could handle the recording part easily, but just faced another problem.
What I’m trying to do is:

  1. start recording
  2. lock the sample being recorded and copy the data to another buffer (recBuf), using the methods according to all the info I’ve gathered
  3. since I want to (have to, maybe…) send the data of fixed length(2000 bytes) to a remote pc, check the recBuf length and send 2000 bytes of recBuf if its length exceeds 2000.

And here’s my code:

char temp[RECBUFFER+20]; //RECBUFFER = 2000
void *ptr1, *ptr2;
unsigned int len1, len2;
int recordpos, oldrecpos=0;
int buflength, x; //buffer length to send
int offset=0; //offset for fmodBuf

log.WriteString("In OnStartrecording\n");

if (!FSOUND_Record_StartSample(recSample, TRUE))    /* start recording and make it loop also */
    log.WriteString("Error in Record_StartSample!\n");
    //printf("%s\n", FMOD_ErrorString(FSOUND_GetError()));

    return FALSE;
recording = TRUE;
log.WriteString("Recording started.\n");

do {

    recordpos = FSOUND_Record_GetPosition();
    sprintf(temp,"\n recordpos = %d , oldrecpos = %d",recordpos, oldrecpos);
    if(recordpos > oldrecpos)                    //sample hasn't wrapped yet / offset hasn't reached 2000 yet
        buflength = recordpos-oldrecpos;
        FSOUND_Sample_Lock(recSample, oldrecpos, buflength, &ptr1, &ptr2, &len1, &len2);
        memcpy(&fmodBuf[offset], ptr1, len1);       //accumulate the locked data into fmodBuf
        offset = offset + len1;                 //increase offset until it exceeds the end(2000)
        FSOUND_Sample_Unlock(recSample, ptr1, ptr2, len1, len2);

    else                                                //the sample has wrapped 
        buflength = RECBUFFER-oldrecpos + recordpos;    
                                                //first copy the rest of the data previously recorded before wrapping
        FSOUND_Sample_Lock(recSample, oldrecpos, RECBUFFER-oldrecpos, &ptr1, &ptr2, &len1, &len2);
        memcpy(&fmodBuf[offset], ptr1, len1);       
        offset = offset + len1;             //increase offset (should be hitting 2000 here)
        FSOUND_Sample_Unlock(recSample, ptr1, ptr2, len1, len2);

        ((Display*)dlg)->sendMessage(&fmodBuf[0],RECBUFFER); //send the copied 2000 data to the net
        offset = 0;                                     
                                                    //and copy the data from position 0 to recordpos
        FSOUND_Sample_Lock(recSample, 0, recordpos, &ptr1, &ptr2, &len1, &len2);
        memcpy(&fmodBuf[offset], ptr1, len1);
        offset = offset + len1;
        FSOUND_Sample_Unlock(recSample, ptr1, ptr2, len1, len2);


    oldrecpos = recordpos;
} while(!terminateRec);

return TRUE;


What happens is :
1. not recorded
2. access violation when terminating.

Can anybody help me out fix this…? Any help will be really appreciated.

  • You must to post comments

I sent you a private message, did you receive it?

  • You must to post comments
Showing 1 result
Your Answer

Please first to submit.