Plays audio via the waveOut device. More...
Public Member Functions | |
| WaveOutPlayer (WaveFormat format, BufferFillCallback bufferFillCallback) | |
| Plays audio via waveOut device. | |
| void | Dispose () |
| Dispose of waveOut player. | |
Plays audio via the waveOut device.
Definition at line 464 of file NativeAudio.cs.
| NewGamePhysics.Utilities.WaveOutPlayer.WaveOutPlayer | ( | WaveFormat | format, | |
| BufferFillCallback | bufferFillCallback | |||
| ) |
Plays audio via waveOut device.
| format | Playback format to use. | |
| bufferFillCallback | The callback delegate which provides sample data. |
Definition at line 522 of file NativeAudio.cs.
00525 { 00526 // Determine quiet sample value 00527 this.zeroSampleValue = format.bitsPerSample == 8 ? (byte)128 : (byte)0; 00528 00529 // Remember callback 00530 this.bufferFillCallback = bufferFillCallback; 00531 00532 // Open wave out device. 00533 int result = NativeAudioInterface.waveOutOpen( 00534 out waveOutHandle, 00535 -1, 00536 format, 00537 waveOutProc, 00538 0, 00539 NativeAudioInterface.CALLBACK_FUNCTION); 00540 if (result != NativeAudioInterface.MMSYSERR_NOERROR) 00541 { 00542 throw new ApplicationException("Could not open wave out device. Error: " + result); 00543 } 00544 00545 // Allocate sample buffers. 00546 AllocateBuffers(); 00547 00548 // Start thread which provides sample data. 00549 fillBufferThread = new Thread(new ThreadStart(WaveOutPlayerThread)); 00550 fillBufferThread.Start(); 00551 }
| void NewGamePhysics.Utilities.WaveOutPlayer.Dispose | ( | ) |
Dispose of waveOut player.
Definition at line 564 of file NativeAudio.cs.
00565 { 00566 if (fillBufferThread != null) 00567 { 00568 try 00569 { 00570 finished = true; 00571 if (waveOutHandle != IntPtr.Zero) 00572 { 00573 NativeAudioInterface.waveOutReset(waveOutHandle); 00574 } 00575 00576 fillBufferThread.Join(); 00577 bufferFillCallback = null; 00578 FreeBuffers(); 00579 if (waveOutHandle != IntPtr.Zero) 00580 { 00581 NativeAudioInterface.waveOutClose(waveOutHandle); 00582 } 00583 } 00584 finally 00585 { 00586 fillBufferThread = null; 00587 waveOutHandle = IntPtr.Zero; 00588 } 00589 } 00590 00591 GC.SuppressFinalize(this); 00592 }
1.6.2