[vorbis-dev] Streaming buffers/ov_read question

Akshay Dhalwala akdjr at softhome.net
Thu Jul 5 11:36:16 PDT 2001



Has anyone had experience using ov_read in a thread with streaming
directsound buffers?  i have tried the following, but it just produces a
repeating garbage noise.  i would appreciate some help.

notes:
 test.ogg in my code was a song that i converted to the vorbis format
(Gorillaz - Cling Eastwood)
pcmData is defined like this:  char pcmData[4096];
the ogg file and the directsound buffer (lpdsBuffer and vorbisFile) have
already been set up properly.

// code start
void PlaybackThread(void *param)
{
 UCHAR *ptr1, *ptr2;
 DWORD len1, len2;
 long retVal;
 int bytes_to_read = 4096;
 int writeCursor = 0;
 int bufferReadCursor = 0;
 bool begPlay = true;
 int len1_copy, len2_copy;
 HWND hDlg = (HWND)param;

 while (!eof)
 {
  if (bufferReadCursor > 4096)
  {
   // fill more data into the buffer;
   bytes_to_read = 4096;
   while (bytes_to_read > 0)
   {
    retVal = ov_read(&vorbisFile, pcmData, bytes_to_read, 0, 2, 1,
&currentSection);
    if (retVal == 0)
    {
     eof = true;
     break;
    }
    else if (retVal < 0)
    {
     // Hole in data
     // do nothing right now
    }
    else
    {
     bytes_to_read = bytes_to_read - retVal;
    }
   }
   bufferReadCursor = 0;
  }

  if (eof)
   break;

  lpdsBuffer->Lock(0, 4096, (void **)&ptr1, &len1, (void **)&ptr2, &len2,
DSBLOCK_FROMWRITECURSOR);

  if (len1 > (4096 - bufferReadCursor))
   len1_copy = 4096 - bufferReadCursor;
  else
   len1_copy = len1;
  memcpy(ptr1, pcmData + bufferReadCursor, len1_copy);
  bufferReadCursor += len1_copy;
  if (ptr2 != NULL)
  {
   if (len2 > (4096 - bufferReadCursor))
    len2_copy = 4096 - bufferReadCursor;
   else
    len2_copy = len2;
   memcpy(ptr2, pcmData + bufferReadCursor, len2_copy);
   bufferReadCursor += len2_copy;
  }

  lpdsBuffer->Unlock((void **)&ptr1, len1, (void **)&ptr2, len2);

  if (begPlay)
  {
   lpdsBuffer->Play(0, 0, DSBPLAY_LOOPING);
   begPlay = false;
  }
 }

 lpdsBuffer->Release();

 _endthread();
}

// end code

--- >8 ----
List archives:  http://www.xiph.org/archives/
Ogg project homepage: http://www.xiph.org/ogg/
To unsubscribe from this list, send a message to 'vorbis-dev-request at xiph.org'
containing only the word 'unsubscribe' in the body.  No subject is needed.
Unsubscribe messages sent to the list will be ignored/filtered.



More information about the Vorbis-dev mailing list