Beispiel #1
0
BOOL DirectSoundManager::CreateSound(TCHAR *FileName,DirectSoundBuffer &Buffer)
{    
    DSBUFFERDESC BufferDesc;
    WAVEFORMATEX WaveFormat;
    CWaveFile     InputWave;

    if(DirectSound == NULL)
        return FALSE;

    // Load the specified wave file:

   if ( !InputWave.Load ( FileName ) )
      return FALSE;

   // Make the format of the sound buffer to be created match the
   // format of the wave file just loaded:

   InputWave.GetWaveFormat ( WaveFormat );

   // Specify the options of the sound buffer to be created:

   BufferDesc.dwSize  = sizeof ( DSBUFFERDESC );

   // Require that the buffer have pan, volume, frequency, and
   // position notification capability (if just basic playback is
   // desired, specifiy DSBCAPS_STATIC and nothing else):

   BufferDesc.dwFlags         = DSBCAPS_CTRLPAN
                                | DSBCAPS_CTRLVOLUME
                                | DSBCAPS_CTRLFREQUENCY
                                | DSBCAPS_STATIC
                                | DSBCAPS_CTRLPOSITIONNOTIFY;
   
   BufferDesc.dwBufferBytes   = InputWave.GetDataSize ();
   BufferDesc.dwReserved      = 0;
   BufferDesc.lpwfxFormat     = &WaveFormat;

   // Create the sound buffer:

   if ( DirectSound->CreateSoundBuffer ( &BufferDesc, &Buffer.Buffer, NULL ) != DS_OK )
      return FALSE;


   // Close the input wave file so the sound buffer can access the
   // file to load the wave data:

   InputWave.Close ();

   // Have the sound buffer load its wave data:

   Buffer.Load ( FileName );

   return TRUE;

}
Beispiel #2
0
BOOL DirectSoundBuffer::Load(TCHAR *File) 
{
   CWaveFile    InputWave;
   LPVOID      BufferPointer;
   DWORD       Bytes1;

   if ( Buffer == NULL )
      return false;

   // Save the file name of the wave for restoration of the sound
   // buffer when it is lost:
   if ( File != FileName )
      lstrcpy ( FileName, File );

   // Load the specified wave file:
   if ( !InputWave.Load ( FileName ) )
      return false;

   // Store the wave format in case it's needed later:
   InputWave.GetWaveFormat ( WaveFormat );

   // Lock the sound buffer to obtain a pointer to the memory where
   // its wave data is stored:
   if ( Buffer->Lock ( 0, 0, &BufferPointer, &Bytes1, NULL, NULL,
                       DSBLOCK_ENTIREBUFFER ) != DS_OK )
      return false;

   DataSize = InputWave.GetDataSize ();

   // Store the wave data in the sound buffer:
   if ( !InputWave.GetData ( BufferPointer, DataSize ) )
      return false;

   // Unlock the sound buffer:
   if ( Buffer->Unlock ( BufferPointer, DataSize, NULL, NULL )
        != DS_OK )
      return false;

   return true;
}