class RemiAudio::Drivers::Ao::AoDevice

Overview

The AoDevice class is used to playback audio using libao.

As libao does not support output to Float32 directly, this class will convert the audio to the requested bit rate on-the-fly. It does this without any dithering. Additionally, only 8-bit, 16-bit, and 24-bit output is supported by this device.

Defined in:

remiaudio/drivers/ao.cr

Constructors

Class Method Summary

Instance Method Summary

Instance methods inherited from class RemiAudio::Drivers::AudioDevice

<<(buf : Array(Float32) | Slice(Float32)) : Nil <<, bitDepth : UInt8 bitDepth, bufferSize : UInt32 bufferSize, bufferSize=(value : Int) : Nil bufferSize=, channels : UInt8 channels, expectedBufferSize : UInt32 expectedBufferSize, sampleRate : UInt32 sampleRate, start : Nil start, started? : Bool started?, stop : Nil stop, writeBuffer(buf : Array(Float32) | Slice(Float32)) : Nil writeBuffer

Constructor Detail

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

Creates a new AoDevice instance.

Note that only 8-bit, 16-bit, and 24-bit samples are supported, so newBitDepth must be one of these values.


[View source]

Class Method Detail

def self.getDriverID(name : String) : Int32 | Nil #

Attempts to lookup the numeric driver ID for a given driver. name should be the driver's short name. If the driver is not known, this returns nil.

You can read more about libao drivers here.


[View source]

Instance Method Detail

def author : String #

The author of the driver. This is populated after calling #start.


[View source]
def availableOptions : Array(String) #

The possible options for thsi driver. This isn't used directly by RemiAudio at the moment, and is purely informational. This is populated after calling #start.


[View source]
def comment : String #

A comment about the driver. This is populated after calling #start.


[View source]
def driverID : Int32 #

The driver ID that will be requested when #start is called. This cannot be changed once #start has been called. You can use AoDevice.getDriverId to get the numeric ID for a driver.

You can read more about libao drivers

here.


[View source]
def driverID=(id : Int32) : Nil #

Sets the numeric driver ID that will be used when #start is called. This cannot be changed after #start is called.

You can read more about libao drivers

here.


[View source]
def matrix : String #

The layout of the channels. This cannot be changed once #start has been called.


[View source]
def matrix=(value : String) : Nil #

Sets the channel layout. This cannot be changed once #start has been called.

Some common examples of channel orderings:

  • "L,R": Stereo ordering in virtually all file formats
  • "L,R,BL,BR": Quadraphonic ordering for most file formats
  • "L,R,C,LFE,BR,BL": channel order of a 5.1 WAV or FLAC file
  • "L,R,C,LFE,BR,BL,SL,SR": channel order of a 7.1 WAV or FLAC file
  • "L,C,R,BR,BL,LFE": channel order of a six channel (5.1) Vorbis I file
  • "L,C,R,BR,BL,SL,SR,LFE": channel order of an eight channel (7.1) Vorbis file
  • "L,CL,C,R,RC,BC": channel order of a six channel AIFF[-C] file

See also: https://www.xiph.org/ao/doc/ao_sample_format.html


[View source]
def name : String #

The short name of the driver. This is populated after calling #start.


[View source]
def preferredByteFormat : Format #

The preferred byte ordering (endianness) for samples. Ideally, samples sent to #writeBuffer will be in the same format, but they don't have to be. Using samples of a different endianness may result in slightly higher CPU and memory usage by libao. This is populated after calling #start.


[View source]
def priority : Int32 #

A positive integer ranking how likely it is for this driver to be the default.


[View source]
def shortName : String #

The short name of the driver. This is populated after calling #start.


[View source]
def start : Nil #

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


[View source]
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]
def type : DriverType #

The output type of the underlying libao driver.


[View source]
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.

Note: if -Dremiaudio_wd40 is used at compile time, then the size of buf is not checked for a valid size, and it is not checked if the device has been started.


[View source]