Provides methods to instantiate, use and destroy an audio device for recording. Static methods are provided to list available devices known by the driver. More...
Public Member Functions | |
| AudioCapture () | |
| Opens the default device for audio recording. Implicitly set parameters are: 22050Hz, 16Bit Mono, 4096 samples ringbuffer. | |
| AudioCapture (string deviceName, int frequency, ALFormat sampleFormat, int bufferSize) | |
| Opens a device for audio recording. | |
| void | CheckErrors () |
| Checks for ALC error conditions. | |
| void | Start () |
| Start recording samples. The number of available samples can be obtained through the AvailableSamples property. The data can be queried with any ReadSamples(IntPtr, int) method. | |
| void | Stop () |
| Stop recording samples. This will not clear previously recorded samples. | |
| void | ReadSamples (IntPtr buffer, int sampleCount) |
| Fills the specified buffer with samples from the internal capture ring-buffer. This method does not block: it is an error to specify a sampleCount larger than AvailableSamples. | |
| void | ReadSamples< TBuffer > (TBuffer[] buffer, int sampleCount) |
| Fills the specified buffer with samples from the internal capture ring-buffer. This method does not block: it is an error to specify a sampleCount larger than AvailableSamples. | |
| void | Dispose () |
| Closes the device and disposes the instance. | |
Properties | |
| string | CurrentDevice [get] |
| The name of the device associated with this instance. | |
| static IList< string > | AvailableDevices [get] |
| Returns a list of strings containing all known recording devices. | |
| static string | DefaultDevice [get] |
| Returns the name of the device that will be used as recording default. | |
| AlcError | CurrentError [get] |
| Returns the ALC error code for this device. | |
| int | AvailableSamples [get] |
| Returns the number of available samples for capture. | |
| ALFormat | SampleFormat [get, set] |
| Gets the OpenTK.Audio.ALFormat for this instance. | |
| int | SampleFrequency [get, set] |
| Gets the sampling rate for this instance. | |
| bool | IsRunning [get] |
| Gets a value indicating whether this instance is currently capturing samples. | |
Provides methods to instantiate, use and destroy an audio device for recording. Static methods are provided to list available devices known by the driver.
Definition at line 42 of file AudioCapture.cs.
| OpenTK.Audio.AudioCapture.AudioCapture | ( | ) |
Opens the default device for audio recording. Implicitly set parameters are: 22050Hz, 16Bit Mono, 4096 samples ringbuffer.
Definition at line 70 of file AudioCapture.cs.
| OpenTK.Audio.AudioCapture.AudioCapture | ( | string | deviceName, | |
| int | frequency, | |||
| ALFormat | sampleFormat, | |||
| int | bufferSize | |||
| ) |
Opens a device for audio recording.
| deviceName | The device name. | |
| frequency | The frequency that the data should be captured at. | |
| sampleFormat | The requested capture buffer format. | |
| bufferSize | The size of OpenAL's capture internal ring-buffer. This value expects number of samples, not bytes. |
Definition at line 80 of file AudioCapture.cs.
00081 { 00082 if (!AudioDeviceEnumerator.IsOpenALSupported) 00083 throw new DllNotFoundException("openal32.dll"); 00084 if (frequency <= 0) 00085 throw new ArgumentOutOfRangeException("frequency"); 00086 if (bufferSize <= 0) 00087 throw new ArgumentOutOfRangeException("bufferSize"); 00088 00089 // Try to open specified device. If it fails, try to open default device. 00090 device_name = deviceName; 00091 Handle = Alc.CaptureOpenDevice(deviceName, frequency, sampleFormat, bufferSize); 00092 00093 if (Handle == IntPtr.Zero) 00094 { 00095 Debug.WriteLine(ErrorMessage(deviceName, frequency, sampleFormat, bufferSize)); 00096 device_name = "IntPtr.Zero"; 00097 Handle = Alc.CaptureOpenDevice(null, frequency, sampleFormat, bufferSize); 00098 } 00099 00100 if (Handle == IntPtr.Zero) 00101 { 00102 Debug.WriteLine(ErrorMessage("IntPtr.Zero", frequency, sampleFormat, bufferSize)); 00103 device_name = AudioDeviceEnumerator.DefaultRecordingDevice; 00104 Handle = Alc.CaptureOpenDevice(AudioDeviceEnumerator.DefaultRecordingDevice, frequency, sampleFormat, bufferSize); 00105 } 00106 00107 if (Handle == IntPtr.Zero) 00108 { 00109 // Everything we tried failed. Capture may not be supported, bail out. 00110 Debug.WriteLine(ErrorMessage(AudioDeviceEnumerator.DefaultRecordingDevice, frequency, sampleFormat, bufferSize)); 00111 device_name = "None"; 00112 00113 throw new AudioDeviceException("All attempts to open capture devices returned IntPtr.Zero. See debug log for verbose list."); 00114 } 00115 00116 // handle is not null, check for some Alc Error 00117 CheckErrors(); 00118 00119 SampleFormat = sampleFormat; 00120 SampleFrequency = frequency; 00121 }
| void OpenTK.Audio.AudioCapture.CheckErrors | ( | ) |
Checks for ALC error conditions.
| OutOfMemoryException | Raised when an out of memory error is detected. | |
| AudioValueException | Raised when an invalid value is detected. | |
| AudioDeviceException | Raised when an invalid device is detected. | |
| AudioContextException | Raised when an invalid context is detected. |
Definition at line 183 of file AudioCapture.cs.
| void OpenTK.Audio.AudioCapture.Dispose | ( | ) |
Closes the device and disposes the instance.
Definition at line 392 of file AudioCapture.cs.
00393 { 00394 this.Dispose(true); 00395 GC.SuppressFinalize(this); 00396 }
| void OpenTK.Audio.AudioCapture.ReadSamples | ( | IntPtr | buffer, | |
| int | sampleCount | |||
| ) |
Fills the specified buffer with samples from the internal capture ring-buffer. This method does not block: it is an error to specify a sampleCount larger than AvailableSamples.
| buffer | A pointer to a previously initialized and pinned array. | |
| sampleCount | The number of samples to be written to the buffer. |
Definition at line 247 of file AudioCapture.cs.
| void OpenTK.Audio.AudioCapture.ReadSamples< TBuffer > | ( | TBuffer[] | buffer, | |
| int | sampleCount | |||
| ) |
Fills the specified buffer with samples from the internal capture ring-buffer. This method does not block: it is an error to specify a sampleCount larger than AvailableSamples.
| buffer | The buffer to fill. | |
| sampleCount | The number of samples to be written to the buffer. |
| System.ArgumentNullException | Raised when buffer is null. | |
| System.ArgumentOutOfRangeException | Raised when sampleCount is larger than the buffer. |
| TBuffer | : | struct |
| void OpenTK.Audio.AudioCapture.Start | ( | ) |
Start recording samples. The number of available samples can be obtained through the AvailableSamples property. The data can be queried with any ReadSamples(IntPtr, int) method.
Definition at line 210 of file AudioCapture.cs.
| void OpenTK.Audio.AudioCapture.Stop | ( | ) |
Stop recording samples. This will not clear previously recorded samples.
Definition at line 217 of file AudioCapture.cs.
IList<string> OpenTK.Audio.AudioCapture.AvailableDevices [static, get] |
Returns a list of strings containing all known recording devices.
Definition at line 150 of file AudioCapture.cs.
int OpenTK.Audio.AudioCapture.AvailableSamples [get] |
Returns the number of available samples for capture.
Definition at line 229 of file AudioCapture.cs.
string OpenTK.Audio.AudioCapture.CurrentDevice [get] |
The name of the device associated with this instance.
Definition at line 135 of file AudioCapture.cs.
AlcError OpenTK.Audio.AudioCapture.CurrentError [get] |
Returns the ALC error code for this device.
Definition at line 194 of file AudioCapture.cs.
string OpenTK.Audio.AudioCapture.DefaultDevice [static, get] |
Returns the name of the device that will be used as recording default.
Definition at line 165 of file AudioCapture.cs.
bool OpenTK.Audio.AudioCapture.IsRunning [get] |
Gets a value indicating whether this instance is currently capturing samples.
Definition at line 307 of file AudioCapture.cs.
ALFormat OpenTK.Audio.AudioCapture.SampleFormat [get, set] |
Gets the OpenTK.Audio.ALFormat for this instance.
Definition at line 285 of file AudioCapture.cs.
int OpenTK.Audio.AudioCapture.SampleFrequency [get, set] |
Gets the sampling rate for this instance.
Definition at line 294 of file AudioCapture.cs.
1.6.1