Author Topic: Looking for implementation help  (Read 2683 times)

Mr24Play

  • Posts: 2
Looking for implementation help
« on: 13 Jun '03 - 20:30 »
I've been reading the board and am amazed at how helpful everyone is, so I thought I'd ask for a lil' too.

My goal is to Record from the Line In,
simple enough, but, I have hit a mental brick wall on choosing the best method to pursue a tivo like buffer
recording. in essence I thought I'd continuously record to memory buffer say 15 seconds worth and if the record button is pushed start recording and when the stop button is pushed combine the buffered 15 seconds with what was recorded between button presses. think of listening to the radio and realizing you favorite song is on, and by the time you hit record the first few seconds have passed by.
I realize you may think this is nuts but actually its part of my future car player front end for my XMPCR radio and the button presses are really analogies to the songname and artist information display latency, the song may start but the display can be a few seconds later, later at home I can clean up the "cut points". thanks guys

Ian @ un4seen

  • Administrator
  • Posts: 24940
Re: Looking for implementation help
« Reply #1 on: 16 Jun '03 - 22:48 »
Here's a basic example...
Code: [Select]
#define recbuflen (15*176400) // 15 seconds (44100hz stereo 16-bit)
char *recbuf;
BOOL writing;

BOOL CALLBACK RecordingCallback(void *buffer, DWORD length, DWORD user)
{
     if (!writing) { // not writing to disk, so buffer it...
           // make room in the buffer
           memmove(recbuf,recbuf+length,recbuflen-length);
           // put the new data in the buffer
           memcpy(recbuf+recbuflen-length,buffer,length);
     } else {
           // write the contents of "buffer" to disk here
     }
     return TRUE; // continue recording
}

...

recbuf=malloc(recbuflen); // allocate buffer
memset(recbuf,0,recbuflen); // fill it with silence initially
writing=FALSE; // not writing to disk yet
// start recording @ 44100hz stereo 16-bit
BASS_RecordStart(44100,0,&RecordingCallback,0);

When you want to start writing to disk... create the file, write the "recbuf" contents to it first, and then set "writing" to TRUE. You could also leave space for a WAV header at the front, and fill that after you finish recording, if you wish :)
« Last Edit: 16 Jun '03 - 22:52 by Ian @ un4seen »

Mr24Play

  • Posts: 2
Re: Looking for implementation help
« Reply #2 on: 17 Jun '03 - 03:37 »
Thanks much that gave me inspiration, I really appreciate the code.