Logo Search packages:      
Sourcecode: pwlib version File versions  Download package

BOOL PSoundChannelDirectSound::Write ( const void *  buf,
PINDEX  len 
) [virtual]

Low level write (or play) to the channel. This function will block until the requested number of characters are written or the write timeout is reached. The GetLastWriteCount() function returns the actual number of bytes written.

The GetErrorCode() function should be consulted after Write() returns FALSE to determine what caused the failure.

Returns:
TRUE if at least len bytes were written to the channel.

Reimplemented from PSoundChannel.

Definition at line 427 of file sound_directsound.cxx.

References HasPlayCompleted(), and PChannel::lastWriteCount.

Referenced by PlayFile(), and PlaySound().

{

  PINDEX to_write = len, written = 0;
  BYTE * input_buffer = (BYTE*) buf;

  if (!isInitialised)
    {
      PTRACE (4, "PSoundChannelDirectSound::Write Failed: Device not initialised :");
      return false;
    }

  //Wait for Mutex signal
  PWaitAndSignal mutex(bufferMutex);

  lastWriteCount = 0;

  while (to_write > mOutburst)
    {

      /*
      //Adjust to blockalign
      if (mOutburst != 0)
      write_in_cycle = (write_in_cycle / mOutburst ) * mOutburst;
      */

      /* Write data from buf to circular buffer */
      written = WriteToDXBuffer (input_buffer, 
                         MIN (GetDXBufferFreeSpace (), to_write));

      if (HasPlayCompleted ()) 
      {
        mAudioPlaybackBuffer->Play (0, 
                              0, 
                              mStreaming ? DSBPLAY_LOOPING : 0L);
      }

      //Move the cursor into the data buffer
      input_buffer += written;
      //Update the written buffer count for PWLIB usage
      lastWriteCount += written;
      //Set the count of buffers left to write
      to_write -= written;

      /* Wait as buffer is played */
      FlushBuffer ();
    }
  return true;

}

Here is the call graph for this function:

Here is the caller graph for this function:


Generated by  Doxygen 1.6.0   Back to index