# NewGamePhysics.Utilities.SampleBuffer Class Reference

Object which represents a data buffer of audio samples. More...

List of all members.

## Public Member Functions
| SampleBuffer (IntPtr waveOutHandle, int bufferSize)
| Represents a sample buffer which can be played via the native interface.
void | Dispose ()
| Dispose of sample buffer.
bool | Play ()
| Start playing the sample buffer.
void | WaitForBuffer ()
| Waits for event indicating that a buffer has completed playing.
void | OnCompleted ()
| Set event that buffer has completed playing.
## Properties
int | Size`[get]`
| Gets the size of the sample buffer.
IntPtr | Data`[get]`
| Gets a pointer to the sample buffer.

## Detailed Description

Object which represents a data buffer of audio samples.

Definition at line 267 of file NativeAudio.cs.

## Constructor & Destructor Documentation

NewGamePhysics.Utilities.SampleBuffer.SampleBuffer | ( | IntPtr | waveOutHandle,
|  | int | bufferSize |
| ) |  |  |

Represents a sample buffer which can be played via the native interface.

Parameters:

  | waveOutHandle | Pointer to sample buffer.
  | bufferSize | Size of sample buffer.

Definition at line 343 of file NativeAudio.cs.

    00344                 {
    00345             // Sample buffer
    00346             waveData = waveOutHandle;
    00347
    00348             // Create header
    00349             headerHandle = GCHandle.Alloc(header, GCHandleType.Pinned);
    00350             header.dwUser = (IntPtr)GCHandle.Alloc(this);
    00351
    00352             // Create sample buffer
    00353             headerData = new byte[bufferSize];
    00354             headerDataHandle = GCHandle.Alloc(headerData, GCHandleType.Pinned);
    00355             header.lpData = headerDataHandle.AddrOfPinnedObject();
    00356             header.dwBufferLength = bufferSize;
    00357
    00358             // Prepare sample buffer
    00359             int error = NativeAudioInterface.waveOutPrepareHeader(
    00360                 waveData,
    00361                 ref header,
    00362                 Marshal.SizeOf(header));
    00363             if (error != NativeAudioInterface.MMSYSERR_NOERROR)
    00364             {
    00365                 throw new ApplicationException("Could not prepare sample buffer.");
    00366             }
    00367                 }

## Member Function Documentation

void NewGamePhysics.Utilities.SampleBuffer.Dispose | ( |  | ) |

Dispose of sample buffer.

Definition at line 380 of file NativeAudio.cs.

    00381         {
    00382             // Clean header
    00383             if (header.lpData != IntPtr.Zero)
    00384             {
    00385                 NativeAudioInterface.waveOutUnprepareHeader(waveData, ref header, Marshal.SizeOf(header));
    00386                 headerHandle.Free();
    00387                 header.lpData = IntPtr.Zero;
    00388             }
    00389
    00390             // Clean sample buffer
    00391             if (headerDataHandle.IsAllocated)
    00392             {
    00393                 headerDataHandle.Free();
    00394             }
    00395
    00396             // Clean event
    00397             bufferCompleted.Close();
    00398
    00399             GC.SuppressFinalize(this);
    00400         }

void NewGamePhysics.Utilities.SampleBuffer.OnCompleted | ( |  | ) |

Set event that buffer has completed playing.

Definition at line 451 of file NativeAudio.cs.

    00452         {
    00453             lock (this)
    00454             {
    00455                 this.bufferCompleted.Set();
    00456                 this.isPlaying = false;
    00457             }
    00458         }

bool NewGamePhysics.Utilities.SampleBuffer.Play | ( |  | ) |

Start playing the sample buffer.

Returns:
  True if playback was be started.

Definition at line 422 of file NativeAudio.cs.

    00423         {
    00424             lock(this)
    00425             {
    00426                 this.bufferCompleted.Reset();
    00427                 int result = NativeAudioInterface.waveOutWrite(
    00428                     waveData,
    00429                     ref header,
    00430                     Marshal.SizeOf(header));
    00431                 this.isPlaying = (result == NativeAudioInterface.MMSYSERR_NOERROR);
    00432             }
    00433
    00434             return this.isPlaying;
    00435         }

void NewGamePhysics.Utilities.SampleBuffer.WaitForBuffer | ( |  | ) |

Waits for event indicating that a buffer has completed playing.

Definition at line 440 of file NativeAudio.cs.

    00441         {
    00442             if (this.isPlaying)
    00443             {
    00444                 this.bufferCompleted.WaitOne(new TimeSpan(0, 0, BufferWaitTimeoutSeconds));
    00445             }
    00446         }

## Property Documentation

IntPtr NewGamePhysics.Utilities.SampleBuffer.Data`[get]`

Gets a pointer to the sample buffer.

Definition at line 414 of file NativeAudio.cs.

int NewGamePhysics.Utilities.SampleBuffer.Size`[get]`

Gets the size of the sample buffer.

Definition at line 406 of file NativeAudio.cs.

The documentation for this class was generated from the following file:

- C:/Users/Andreas Schiffler/Desktop/SVN/NewGamePhysics/NewGamePhysics/Utilities/NativeAudio.cs