Updated to use latest Audio api.

This commit is contained in:
the_fiddler 2009-07-17 23:00:50 +00:00
parent 1fff5cc885
commit 3222b976b3

View file

@ -121,8 +121,8 @@ namespace Examples
AllPlaybackDevices = AudioContext.AvailableDevices; AllPlaybackDevices = AudioContext.AvailableDevices;
AllRecordingDevices = AudioCapture.AvailableDevices; AllRecordingDevices = AudioCapture.AvailableDevices;
DefaultPlaybackDevice = AudioContext.Default; DefaultPlaybackDevice = AudioContext.DefaultDevice;
DefaultRecordingDevice = AudioCapture.Default; DefaultRecordingDevice = AudioCapture.DefaultDevice;
} }
public void Print() public void Print()
@ -513,7 +513,7 @@ namespace Examples
private void CheckRecorderError(string location) private void CheckRecorderError(string location)
{ {
AlcError err = r.CurrentAlcError; AlcError err = r.CurrentError;
if (err != AlcError.NoError) if (err != AlcError.NoError)
Errorlist.Add(location, err); Errorlist.Add(location, err);
} }
@ -525,7 +525,7 @@ namespace Examples
try try
{ {
r = new AudioCapture(AudioCapture.Default, (uint)16000, ALFormat.Mono16, 4096); r = new AudioCapture(AudioCapture.DefaultDevice, 16000, ALFormat.Mono16, 4096);
} }
catch (AudioDeviceException ade) catch (AudioDeviceException ade)
{ {
@ -543,14 +543,13 @@ namespace Examples
CheckRecorderError("Alc.CaptureStop"); CheckRecorderError("Alc.CaptureStop");
byte[] Buffer = new byte[8192]; byte[] Buffer = new byte[8192];
GCHandle BufferHandle = GCHandle.Alloc(Buffer, GCHandleType.Pinned);
IntPtr BufferPtr = BufferHandle.AddrOfPinnedObject();
Thread.Sleep(10); // Wait for a few samples to become available.
int SamplesBefore = r.AvailableSamples; int SamplesBefore = r.AvailableSamples;
CheckRecorderError("Alc.GetInteger(...CaptureSamples...)"); CheckRecorderError("Alc.GetInteger(...CaptureSamples...)");
r.GetSamples(BufferPtr, (SamplesBefore > 4096 ? 4096 : SamplesBefore)); r.ReadSamples(Buffer, (SamplesBefore > 4096 ? 4096 : SamplesBefore));
CheckRecorderError("Alc.CaptureSamples"); CheckRecorderError("Alc.CaptureSamples");
Thread.Sleep(50); // getsamples doesn't block
int SamplesCaptured = SamplesBefore - r.AvailableSamples; int SamplesCaptured = SamplesBefore - r.AvailableSamples;
@ -597,8 +596,6 @@ namespace Examples
AL.DeleteSource(ref src); AL.DeleteSource(ref src);
AL.DeleteBuffer(ref buf); AL.DeleteBuffer(ref buf);
*/ */
BufferHandle.Free();
} }
public void Print() public void Print()