abstract class RemiAudio::Drivers::AudioDevice
- RemiAudio::Drivers::AudioDevice
- Reference
- Object
Overview
The AudioDevice
class is a virtual representation of an audio output
device. Subclasses exist for various "driver" backends, such as libao,
PortAudio, etc.
Whenever possible, the implementing class attempts to work entirely using
32-bit floating point audio, and the #writeBuffer
method only accepts
32-bit floating point. However, some backends (e.g. libao) do not support
floating point audio natively, so the corresponding subclass will convert
audio automatically on the fly. See the documentation for these subclasses
for more information.
Direct Known Subclasses
- RemiAudio::Drivers::Ao::AoDevice
- RemiAudio::Drivers::PortAudio::PortDevice
- RemiAudio::Drivers::PulseAudio::PulseDevice
- RemiAudio::Drivers::Tcp::TcpDevice
Defined in:
remiaudio/drivers.crInstance Method Summary
-
#<<(buf : Array(Float32) | Slice(Float32)) : Nil
:ditto::
-
#bitDepth : UInt8
Returns the bit depth that this device will request from the underlying backend when started.
-
#bufferSize : UInt32
The size of the audio buffers that will get written.
-
#bufferSize=(value : Int) : Nil
Sets the buffer size.
-
#channels : UInt8
Returns the number of output channels that this device will request from the underlying backend when started.
-
#expectedBufferSize : UInt32
The expected size of the audio buffers that you send to
#writeBuffer
. -
#sampleRate : UInt32
Returns the sample rate that this device will request from the underlying backend when started.
-
#start : Nil
Opens the audio stream.
-
#started? : Bool
Returns
true
if the device has been started, orfalse
otherwise. -
#stop : Nil
Closes the audio stream and frees resources.
-
#writeBuffer(buf : Array(Float32) | Slice(Float32)) : Nil
Plays back the audio in buf by sending it to the underlying backend.
Instance Method Detail
Returns the bit depth that this device will request from the underlying backend when started.
The size of the audio buffers that will get written. This is per-channel, so if this is 2048 and there are two channels, then you need an array of 4096 elements for a buffer.
This MUST NOT change after the driver has been started, and you MUST
ALWAYS pass the correct buffer size to #writeBuffer
.
Sets the buffer size. This dictates what size of array you must pass into
#writeBuffer
. This is per-channel, so if this is 2048 and there are two
channels, then you need an array of 4096 elements for a buffer.
This MUST NOT change after the driver has been started, and you MUST
ALWAYS pass the correct buffer size to #writeBuffer
. Any attempt to
change this after starting the device will raise an AudioDeviceError
.
Returns the number of output channels that this device will request from
the underlying backend when started. The audio data sent to
#writeBuffer
should match this.
The expected size of the audio buffers that you send to #writeBuffer
.
This value changes depending on what you set for #bufferSize
.
Returns the sample rate that this device will request from the underlying
backend when started. The audio data sent to #writeBuffer
should match
this sample rate.
Opens the audio stream. This must be called before #writeBuffer
is
called.
Closes the audio stream and frees resources. This must be called when you are finished using the instance to ensure that the resources are properly freed and the audio device is properly closed.
Plays back the audio in buf by sending it to the underlying backend.
You MUST ALWAYS pass the correct buffer size to #writeBuffer
, as defined
by the value of #bufferSize
multiplied by the number of #channels
.