abstract class RemiAudio::Drivers::AudioDevice

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:

remiaudio/drivers.cr

Instance Method Summary

Instance Method Detail

def <<(buf : Array(Float32) | Slice(Float32)) : Nil #

:ditto::


[View source]
def bitDepth : UInt8 #

Returns the bit depth that this device will request from the underlying backend when started.


[View source]
def bufferSize : UInt32 #

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.


[View source]
def bufferSize=(value : Int) : Nil #

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.


[View source]
def channels : UInt8 #

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.


[View source]
def expectedBufferSize : UInt32 #

The expected size of the audio buffers that you send to #writeBuffer. This value changes depending on what you set for #bufferSize.


[View source]
def sampleRate : UInt32 #

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.


[View source]
abstract def start : Nil #

Opens the audio stream. This must be called before #writeBuffer is called.


[View source]
def started? : Bool #

Returns true if the device has been started, or false otherwise.


[View source]
abstract def stop : Nil #

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.


[View source]
abstract def writeBuffer(buf : Array(Float32) | Slice(Float32)) : Nil #

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.


[View source]