Supports a machine's audio hardware and provides a client-server audio management service.
The Audio class provides a common audio service that works across multiple platforms and follows a client-server design model.
Supported features include 8/16/32 bit output in stereo or mono, oversampling, streaming, multiple audio channels and command sequencing. Audio functionality is simplified in the Sound class interface, which we recommend when straight-forward audio playback is sufficient.
Support for audio recording is not currently available.
The Audio class consists of the following fields:
Access | Name | Type | Comment | ||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
BitDepth | INT | The bit depth affects the overall quality of audio input and output. | |||||||||||||||||
This field manages the bit depth for audio mixing and output. Valid bit depths are | |||||||||||||||||||
Device | STRING | The name of the audio device used by this audio object. | |||||||||||||||||
A host platform may have multiple audio devices installed, but a given audio object can represent only one device at a time. A new audio object will always represent the default device initially. Choose a different device by setting the The default device can always be referenced with a name of | |||||||||||||||||||
Flags | ADF | Special audio flags can be set here. | |||||||||||||||||
The audio class supports a number of special flags that affect internal behaviour. The following table illustrates the publicly available flags:
| |||||||||||||||||||
InputRate | INT | Determines the frequency to use when recording audio data. | |||||||||||||||||
The InputRate determines the frequency to use when recording audio data from a Line-In connection or microphone. In most cases, this value should be set to The InputRate can only be set prior to initialisation, further attempts to set the field will be ignored. On some platforms, it may not be possible to set an InputRate that is different to the OutputRate. In such a case, the value of the InputRate shall be ignored. | |||||||||||||||||||
MasterVolume | DOUBLE | The master volume to use for audio playback. | |||||||||||||||||
The MasterVolume field controls the amount of volume applied to all of the audio channels. Volume is expressed as a value between | |||||||||||||||||||
MixerLag | DOUBLE | Returns the lag time of the internal mixer, measured in seconds. | |||||||||||||||||
This field will return the worst-case value for latency imposed by the internal audio mixer. The value is measured in seconds and will differ between platforms and user configurations. | |||||||||||||||||||
Mute | INT | Mutes all audio output. | |||||||||||||||||
Audio output can be muted at any time by setting this value to | |||||||||||||||||||
OutputRate | INT | Determines the frequency to use for the output of audio data. | |||||||||||||||||
The OutputRate determines the frequency of the audio data that will be output to the audio speakers. In most cases, this value should be set to The OutputRate can only be set prior to initialisation, further attempts to set the field will be ignored. | |||||||||||||||||||
PeriodSize | INT | Defines the byte size of each period allocated to the internal audio buffer. | |||||||||||||||||
Refer to the Periods field for further information. | |||||||||||||||||||
Periods | INT | Defines the number of periods that make up the internal audio buffer. | |||||||||||||||||
The internal audio buffer is split into periods with each period being a certain byte size. The minimum period is The minimum period size is 1K and maximum 16K. | |||||||||||||||||||
Quality | INT | Determines the quality of the audio mixing. | |||||||||||||||||
Alter the quality of internal audio mixing by adjusting the Quality field. The value range is from 0 (low quality) and 100 (high quality). A setting between 70 and 80 is recommended. Setting a Quality value results in the following flags being automatically adjusted in the audio object: In general, low quality mixing should only be used when the audio output needs to be raw, or if the audio speaker is of low quality and will not benefit from high quality output. | |||||||||||||||||||
Stereo | INT | Set to true for stereo output and false for mono output. |
The following actions are currently supported:
Name | Comment | |||||||
---|---|---|---|---|---|---|---|---|
Activate | Enables access to the audio hardware and initialises the mixer. | |||||||
ERR acActivate(*Object) An audio object will not play or record until it has been activated. Activating the object will result in an attempt to access the device hardware, which on some platforms may lead to failure if another process has permanently locked the audio device. The resources and any device locks obtained by this action can be released with a call to Deactivate(). An inactive audio object can operate in a limited fashion but is without access to the audio hardware. | ||||||||
Deactivate | Disables the audio mixer and returns device resources to the system. | |||||||
ERR acDeactivate(*Object) Deactivating an audio object will switch off the mixer, clear the output buffer and return any allocated device resources back to the host system. The audio object will remain in a suspended state until it is reactivated. | ||||||||
SaveSettings | Saves the current audio settings. | |||||||
SaveToObject | Saves the current audio settings to another object. | |||||||
ERR acSaveToObject(*Object, OBJECTID Dest, CLASSID ClassID)
|
The following methods are currently supported:
Name | Comment | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
AddSample | Adds a new sample to an audio object for channel-based playback. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
ERR snd::AddSample(OBJECTPTR Object, FUNCTION OnStop, SFM SampleFormat, APTR Data, LONG DataSize, struct AudioLoop * Loop, LONG LoopSize, LONG * Result)
Audio samples can be loaded into an Audio object for playback via the AddSample() or AddStream() methods. For small samples under 512k we recommend AddSample(), while anything larger should be supported through AddStream(). When adding a sample, it is essential to select the correct bit format for the sample data. While it is important to differentiate between simple attributes such as 8 or 16 bit data, mono or stereo format, you should also be aware of whether or not the data is little or big endian, and if the sample data consists of signed or unsigned values. Because of the possible variations there are a number of sample formats, as illustrated in the following table:
By default, all samples are assumed to be in little endian format, as supported by Intel CPU's. If the data is in big endian format, logical-or the SampleFormat value with It is also possible to supply loop information with the sample data. This is achieved by configuring the AudioLoop structure:
The types that can be specified in the
The
Error Codes
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
AddStream | Adds a new sample-stream to an Audio object for channel-based playback. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
ERR snd::AddStream(OBJECTPTR Object, FUNCTION Callback, FUNCTION OnStop, SFM SampleFormat, LONG SampleLength, LONG PlayOffset, struct AudioLoop * Loop, LONG LoopSize, LONG * Result)
Use AddStream to load large sound samples to an Audio object, allowing it to play those samples on the client machine without over-provisioning available resources. For small samples under 256k consider using AddSample() instead. The data source used for a stream will need to be provided by a client provided The When creating a new stream, pay attention to the audio format that is being used for the sample data. It is important to differentiate between 8-bit, 16-bit, mono and stereo, but also be aware of whether or not the data is little or big endian, and if the sample data consists of signed or unsigned values. Because of the possible variations there are a number of sample formats, as illustrated in the following table:
By default, all samples are assumed to be in little endian format, as supported by Intel CPU's. If the data is in big endian format, logical-or the It is also possible to supply loop information with the stream. The Audio class supports a number of different looping formats via the AudioLoop structure:
There are three types of loop modes that can be specified in the
The Error Codes
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Beep | Beeps the PC audio speaker. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
ERR snd::Beep(OBJECTPTR Object, LONG Pitch, LONG Duration, LONG Volume)
This method will beep the PC audio speaker, if available. It is possible to request the specific Pitch, Duration and Volume for the sound although not all platforms may support the parameters. In some cases the beep may be converted to a standard warning sound by the host. Error Codes
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
CloseChannels | Frees audio channels that have been allocated for sample playback. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
ERR snd::CloseChannels(OBJECTPTR Object, LONG Handle)
Use CloseChannels to destroy a group of channels that have previously been allocated through the OpenChannels() method. Any audio commands buffered against the channels will be cleared instantly. Any audio data that has already been mixed into the output buffer can continue to play for 1 - 2 seconds. If this is an issue then the volume should be muted at the same time. Error Codes
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
OpenChannels | Allocates audio channels that can be used for sample playback. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
ERR snd::OpenChannels(OBJECTPTR Object, LONG Total, LONG * Result)
Use the OpenChannels method to open audio channels for sample playback. Channels are allocated in sets with a size range between 1 and 64. Channel sets make it easier to segregate playback between users of the same audio object. The resulting handle returned from this method is an integer consisting of two parts. The upper word uniquely identifies the channel set that has been provided to you, while the lower word is used to refer to specific channel numbers. If referring to a specific channel is required for a function, use the formula To destroy allocated channels, use the CloseChannels() method. Error Codes
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
RemoveSample | Removes a sample from the global sample list and deallocates its resources. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
ERR snd::RemoveSample(OBJECTPTR Object, LONG Handle)
Remove an allocated sample by calling the RemoveSample method. Removed samples are permanently deleted from the audio server and it is not possible to reallocate the sample against the same Sample handles can be reused by the API after being removed. Clearing references to stale sample handles on the client side is recommended. Error Codes
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
SetSampleLength | Sets the byte length of a streaming sample. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
ERR snd::SetSampleLength(OBJECTPTR Object, LONG Sample, LARGE Length)
This function will update the byte length of a streaming Setting a Error Codes
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
SetVolume | Sets the volume for input and output mixers. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
ERR snd::SetVolume(OBJECTPTR Object, LONG Index, CSTRING Name, SVF Flags, LONG Channel, DOUBLE Volume)
To change volume and mixer levels, use the SetVolume method. It is possible to make adjustments to any of the available mixers and for different channels per mixer - for instance you may set different volumes for left and right speakers. Support is also provided for special options such as muting. To set the volume for a mixer, use its index or set its name (to change the master volume, use a name of A target The new mixer value is set in the Optional flags may be set as follows:
Error Codes
|
Optional flags for the Audio object.
Name | Description |
---|---|
ADF::AUTO_SAVE | Save configuration information on exit. |
ADF::FILTER_HIGH | Enable a high level of output filtering to minimise distortion. |
ADF::FILTER_LOW | Enable a low level of output filtering to minimise distortion. |
ADF::OVER_SAMPLING | Enables oversampling for higher quality audio at the cost of slower mixing. |
ADF::STEREO | Enable stereo output (set by default if the platform supports stereo). If not set, output is in mono. |
ADF::SYSTEM_WIDE | Mixer changes should be applied system-wide. |
ADF::VOL_RAMPING | Enable volume ramping for softer playback when a sample is played multiple times (enabled by default). |
Loop modes for the AudioLoop structure.
Name | Description |
---|---|
LOOP::AMIGA | Single loop: Amiga style. |
LOOP::AMIGA_NONE | Amiga loop: Do nothing. |
LOOP::DOUBLE | Double loop: When the note is released, playing shifts to the second loop. |
LOOP::SINGLE | Single loop: Releasing will end the note. |
LOOP::SINGLE_RELEASE | Single loop: Sample data after the loop will be played when the note is released. |
Loop types for the AudioLoop structure.
Name | Description |
---|---|
LTYPE::BIDIRECTIONAL | The sample will play in reverse whenever it hits the end marker, then forwards when it hits the start marker. |
LTYPE::UNIDIRECTIONAL | The sample playback position returns to the byte position specified in the Loop1Start field. |
These audio bit formats are supported by AddSample and AddStream.
Name | Description |
---|---|
SFM::F_BIG_ENDIAN | Combine this flag with any audio format to declare it as big endian. |
SFM::S16_BIT_MONO | 16-bit mono signed sample. |
SFM::S16_BIT_STEREO | 16-bit stereo signed sample. |
SFM::U8_BIT_MONO | 8-bit mono unsigned sample. |
SFM::U8_BIT_STEREO | 8-bit stereo unsigned sample. |
Flags for the SetVolume() method.
Name | Description |
---|---|
SVF::CAPTURE | Set input, not output. |
SVF::MUTE | Mute the audio for this channel. |
SVF::UNMUTE | Unmute the audio for this channel. |
Loop settings for the AddSample() method.
Field | Type | Description |
---|---|---|
LoopMode | LOOP | Loop mode (single, double) |
Loop1Type | LTYPE | First loop type (unidirectional, bidirectional) |
Loop2Type | LTYPE | Second loop type (unidirectional, bidirectional) |
Loop1Start | LONG | Start of the first loop |
Loop1End | LONG | End of the first loop |
Loop2Start | LONG | Start of the second loop |
Loop2End | LONG | End of the second loop |
Class Info | |
---|---|
ID | ID_AUDIO |
Category | Audio |
Include | modules/audio.h |
Version | 1 |