abstract class RemiSound::AudioDevice
- RemiSound::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
Defined in:
remisound/audiodevice.crConstructors
-
.new(newSampleRate : Int, newBitDepth : Int, newChannels : Int)
Creates a new device instance with the requested parameters.
Instance Method Summary
-
#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 : UInt32) : Nil
-
#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.
Constructor Detail
Creates a new device instance with the requested parameters.
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
.
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.
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
.