SoundRecorder is an interface for capturing sound data.
Callback or processSamples override will be called by a different thread, take care of synchronization issues.
Examples:
Can be used directly :
bool callback(short[] data, void* userData)
{
//Process data
return true; //return true to continue capture, else return false
}
class MyClass
{
public bool myCallback(short[] data, void* userData)
{
//Process data
return true;
}
}
void main()
{
SoundRecorder record = new SoundRecorder(&callback);
// or ...
MyClass myClass = new MyClass();
SoundRecorder record = new SoundRecorder(&myClass.myCallback);
record.Start(); //Start recording with default sample rate.
}
or as base class
class MySoundRecorder : SoundRecorder
{
this()
{
}
//Override this method
protected bool processSamples(out short[])
{
// Process data here
return true; //return true to continue capture, else return false
}
}
- this(bool function(short[], void*) callback, void* userData = null);
- Construct the sound recorder with a callback function for processing captured samples
Params:
bool function(short[], void*) callback |
Callback for processing captured samples |
void* userData |
Data to pass to the callback function (null by default) |
- this(bool delegate(short[], void*) callback, void* userData = null);
- Construct the sound recorder with a delegate for processing captured samples
Params:
bool delegate(short[], void*) callback |
Callback for processing captured samples |
void* userData |
Data to pass to the callback function (null by default) |
- void start(uint sampleRate = cast(uint)44100);
- Start the capture.
Only one capture can happen at the same time
Params:
- void stop();
- Stop the capture
- uint getSampleRate();
- Get the sample rate
Returns:
Frequency, in samples per second
- static bool canCapture();
- Tell if the system supports sound capture.
If not, this class won't be usable
Returns:
True if audio capture is supported
- this();
- Protected constructor
- protected bool processSamples(short[] s);
- callback function