Object which represents a data buffer of audio samples. More...
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. | |
Object which represents a data buffer of audio samples.
Definition at line 267 of file NativeAudio.cs.
| NewGamePhysics.Utilities.SampleBuffer.SampleBuffer | ( | IntPtr | waveOutHandle, | |
| int | bufferSize | |||
| ) |
Represents a sample buffer which can be played via the native interface.
| 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 }
| 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.
| bool NewGamePhysics.Utilities.SampleBuffer.Play | ( | ) |
Start playing the sample buffer.
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.
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.
1.6.2