abstract class RemiSound::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:

remisound/audiodevice.cr

Constructors

Instance Method Summary

Constructor Detail

def self.new(newSampleRate : Int, newBitDepth : Int, newChannels : Int) #

Creates a new device instance with the requested parameters.


[View source]

Instance Method Detail

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 : UInt32) : Nil #

[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.


[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]