Parasol Framework
  • Gallery
  • API
  • Wiki
  • GitHub
    • Audio
    • Core
    • Display
    • Fluid
    • Font
    • Network
    • Vector
    • Audio
    • Sound
    • File
    • MetaClass
    • Module
    • StorageDevice
    • Task
    • Thread
    • Time
    • Compression
    • Config
    • Script
    • XML
    • Controller
    • BlurFX
    • ColourFX
    • CompositeFX
    • ConvolveFX
    • DisplacementFX
    • FilterEffect
    • FloodFX
    • ImageFX
    • LightingFX
    • MergeFX
    • MorphologyFX
    • OffsetFX
    • RemapFX
    • SourceFX
    • TurbulenceFX
    • WaveFunctionFX
    • Scintilla
    • ScintillaSearch
    • Bitmap
    • Clipboard
    • Display
    • Document
    • Font
    • Picture
    • Pointer
    • Surface
    • SVG
    • ClientSocket
    • HTTP
    • NetSocket
    • Proxy
    • Vector
    • VectorClip
    • VectorColour
    • VectorEllipse
    • VectorFilter
    • VectorGradient
    • VectorGroup
    • VectorImage
    • VectorPath
    • VectorPattern
    • VectorPolygon
    • VectorRectangle
    • VectorScene
    • VectorShape
    • VectorSpiral
    • VectorText
    • VectorTransition
    • VectorViewport
    • VectorWave

Audio Class

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.

Structure

The Audio class consists of the following fields:

Access
NameTypeComment
  BitDepthINTThe 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 8, 16 and 24, with 16 being the recommended value for CD quality playback.

  DeviceSTRINGThe 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 Device field to a valid alternative.

The default device can always be referenced with a name of default.

  FlagsADFSpecial 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:

NameDescription
ADF::AUTO_SAVESave configuration information on exit.
ADF::FILTER_HIGHEnable a high level of output filtering to minimise distortion.
ADF::FILTER_LOWEnable a low level of output filtering to minimise distortion.
ADF::OVER_SAMPLINGEnables oversampling for higher quality audio at the cost of slower mixing.
ADF::STEREOEnable stereo output (set by default if the platform supports stereo). If not set, output is in mono.
ADF::SYSTEM_WIDEMixer changes should be applied system-wide.
ADF::VOL_RAMPINGEnable volume ramping for softer playback when a sample is played multiple times (enabled by default).
  InputRateINTDetermines 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 44100 for CD quality audio.

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.

  MasterVolumeDOUBLEThe 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 0 and 1.0.

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

  MuteINTMutes all audio output.

Audio output can be muted at any time by setting this value to true. To restart audio output after muting, set the field to false. Muting does not disable the audio system, which is achieved by calling Deactivate().

  OutputRateINTDetermines 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 44100 for CD quality audio.

The OutputRate can only be set prior to initialisation, further attempts to set the field will be ignored.

  PeriodSizeINTDefines the byte size of each period allocated to the internal audio buffer.

Refer to the Periods field for further information.

  PeriodsINTDefines 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 2 and the maximum is 16. This field is supplemented with the PeriodSize, which indicates the byte size of each period. The total size of the audio buffer is calculated as the number of Periods multiplied by the PeriodSize value.

The minimum period size is 1K and maximum 16K.

  QualityINTDetermines 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: ADF::FILTER_LOW, ADF::FILTER_HIGH and ADF::OVER_SAMPLING.

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.

  StereoINTSet to true for stereo output and false for mono output.

Actions

The following actions are currently supported:

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

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

SaveSettingsSaves the current audio settings.
SaveToObjectSaves the current audio settings to another object.
ERR acSaveToObject(*Object, OBJECTID Dest, CLASSID ClassID)
ParameterDescription
DestRefers to an object that will receive the encoded data.
ClassIDCan refer to a sub-class that should be used when encoding the data.

Methods

The following methods are currently supported:

AddSampleAdds a new sample to an audio object for channel-based playback.
ERR snd::AddSample(OBJECTPTR Object, FUNCTION OnStop, SFM SampleFormat, APTR Data, INT DataSize, struct AudioLoop * Loop, INT LoopSize, INT * Result)
ParameterDescription
OnStopThis optional callback function will be called when the stream stops playing.
SampleFormatIndicates the format of the sample data that you are adding.
DataPoints to the address of the sample data.
DataSizeSize of the sample data, in bytes.
LoopOptional sample loop information.
LoopSizeMust be set to sizeof(AudioLoop) if Loop is defined.
ResultThe resulting sample handle will be returned in this parameter.

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:

NameDescription
SFM::F_BIG_ENDIANCombine this flag with any audio format to declare it as big endian.
SFM::S16_BIT_MONO16-bit mono signed sample.
SFM::S16_BIT_STEREO16-bit stereo signed sample.
SFM::U8_BIT_MONO8-bit mono unsigned sample.
SFM::U8_BIT_STEREO8-bit stereo unsigned sample.

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 SFM::F_BIG_ENDIAN.

It is also possible to supply loop information with the sample data. This is achieved by configuring the AudioLoop structure:

FieldTypeDescription
LoopModeLOOPLoop mode (single, double)
Loop1TypeLTYPEFirst loop type (unidirectional, bidirectional)
Loop2TypeLTYPESecond loop type (unidirectional, bidirectional)
Loop1StartINTStart of the first loop
Loop1EndINTEnd of the first loop
Loop2StartINTStart of the second loop
Loop2EndINTEnd of the second loop

The types that can be specified in the LoopMode field are:

NameDescription
LOOP::AMIGASingle loop: Amiga style.
LOOP::AMIGA_NONEAmiga loop: Do nothing.
LOOP::DOUBLEDouble loop: When the note is released, playing shifts to the second loop.
LOOP::SINGLESingle loop: Releasing will end the note.
LOOP::SINGLE_RELEASESingle loop: Sample data after the loop will be played when the note is released.

The Loop1Type and Loop2Type fields alter the style of the loop. These can be set to the following:

NameDescription
LTYPE::BIDIRECTIONALThe sample will play in reverse whenever it hits the end marker, then forwards when it hits the start marker.
LTYPE::UNIDIRECTIONALThe sample playback position returns to the byte position specified in the Loop1Start field.
Error Codes
OkayOperation successful.
ArgsInvalid arguments passed to function.
AllocMemoryFailed to allocate enough memory to hold the sample data.
NullArgsFunction call missing argument value(s)
AddStreamAdds a new sample-stream to an Audio object for channel-based playback.
ERR snd::AddStream(OBJECTPTR Object, FUNCTION Callback, FUNCTION OnStop, SFM SampleFormat, INT SampleLength, INT PlayOffset, struct AudioLoop * Loop, INT LoopSize, INT * Result)
ParameterDescription
CallbackThis callback function must be able to return raw audio data for streaming.
OnStopThis optional callback function will be called when the stream stops playing.
SampleFormatIndicates the format of the sample data that you are adding.
SampleLengthTotal byte-length of the sample data that is being streamed. May be set to zero if the length is infinite or unknown.
PlayOffsetOffset the playing position by this byte index.
LoopRefers to sample loop information, or NULL if no loop is required.
LoopSizeMust be set to sizeof(AudioLoop).
ResultThe resulting sample handle will be returned in this parameter.

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 Callback function. The prototype is LONG callback(LONG SampleHandle, LONG Offset, UBYTE *Buffer, LONG BufferSize).

The Offset reflects the retrieval point of the decoded data and is measured in bytes. The Buffer and BufferSize reflect the target for the decoded data. The function must return the total number of bytes that were written to the Buffer. If an error occurs, return zero.

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:

NameDescription
SFM::F_BIG_ENDIANCombine this flag with any audio format to declare it as big endian.
SFM::S16_BIT_MONO16-bit mono signed sample.
SFM::S16_BIT_STEREO16-bit stereo signed sample.
SFM::U8_BIT_MONO8-bit mono unsigned sample.
SFM::U8_BIT_STEREO8-bit stereo unsigned sample.

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 the flag SFM::F_BIG_ENDIAN.

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:

FieldTypeDescription
LoopModeLOOPLoop mode (single, double)
Loop1TypeLTYPEFirst loop type (unidirectional, bidirectional)
Loop2TypeLTYPESecond loop type (unidirectional, bidirectional)
Loop1StartINTStart of the first loop
Loop1EndINTEnd of the first loop
Loop2StartINTStart of the second loop
Loop2EndINTEnd of the second loop

There are three types of loop modes that can be specified in the LoopMode field:

NameDescription
LOOP::AMIGASingle loop: Amiga style.
LOOP::AMIGA_NONEAmiga loop: Do nothing.
LOOP::DOUBLEDouble loop: When the note is released, playing shifts to the second loop.
LOOP::SINGLESingle loop: Releasing will end the note.
LOOP::SINGLE_RELEASESingle loop: Sample data after the loop will be played when the note is released.

The Loop1Type and Loop2Type fields normally determine the style of the loop, however only unidirectional looping is currently supported for streams. For that reason, set the type variables to either LTYPE::NIL or LTYPE::UNIDIRECTIONAL.

Error Codes
OkayOperation successful.
ArgsInvalid arguments passed to function.
AllocMemoryFailed to allocate the stream buffer.
NullArgsFunction call missing argument value(s)
BeepBeeps the PC audio speaker.
ERR snd::Beep(OBJECTPTR Object, INT Pitch, INT Duration, INT Volume)
ParameterDescription
PitchThe pitch of the beep in HZ.
DurationThe duration of the beep in milliseconds.
VolumeThe volume of the beep, from 0 to 100.

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
OkayOperation successful.
NoSupportPC speaker support is not available.
NullArgsFunction call missing argument value(s)
CloseChannelsFrees audio channels that have been allocated for sample playback.
ERR snd::CloseChannels(OBJECTPTR Object, INT Handle)
ParameterDescription
HandleMust refer to a channel handle returned from the OpenChannels() method.

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
OkayOperation successful.
ArgsInvalid arguments passed to function.
NullArgsFunction call missing argument value(s)
OpenChannelsAllocates audio channels that can be used for sample playback.
ERR snd::OpenChannels(OBJECTPTR Object, INT Total, INT * Result)
ParameterDescription
TotalTotal of channels to allocate.
ResultThe resulting channel handle is returned in this parameter.

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 Channel = Handle | ChannelNo.

To destroy allocated channels, use the CloseChannels() method.

Error Codes
OkayOperation successful.
OutOfRangeThe amount of requested channels or commands is outside of acceptable range.
AllocMemoryMemory for the audio channels could not be allocated.
NullArgsFunction call missing argument value(s)
RemoveSampleRemoves a sample from the global sample list and deallocates its resources.
ERR snd::RemoveSample(OBJECTPTR Object, INT Handle)
ParameterDescription
HandleThe handle of the sample that requires removal.

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 Handle value.

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
OkayOperation successful.
OutOfRangeThe provided sample handle is not within the valid range.
NullArgsFunction call missing argument value(s)
SetSampleLengthSets the byte length of a streaming sample.
ERR snd::SetSampleLength(OBJECTPTR Object, INT Sample, INT64 Length)
ParameterDescription
SampleA sample handle from AddStream().
LengthByte length of the sample stream.

This function will update the byte length of a streaming Sample. Although it is possible to manually stop a stream at any point, setting the length is a preferable means to stop playback as it ensures complete accuracy when a sample's output is buffered.

Setting a Length of -1 indicates that the stream should be played indefinitely.

Error Codes
OkayOperation successful.
FailedSample is not a stream.
ArgsInvalid arguments passed to function.
NullArgsFunction call missing argument value(s)
SetVolumeSets the volume for input and output mixers.
ERR snd::SetVolume(OBJECTPTR Object, INT Index, CSTRING Name, SVF Flags, INT Channel, DOUBLE Volume)
ParameterDescription
IndexThe index of the mixer that you want to set.
NameIf the correct index number is unknown, the name of the mixer may be set here.
FlagsOptional flags.
ChannelA specific channel to modify (e.g. 0 for left, 1 for right). If -1, all channels are affected.
VolumeThe volume to set for the mixer, from 0 to 1.0. If -1, the current volume values are retained.

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 Master).

A target Channel such as the left 0 or right 1 speaker can be specified. Set the Channel to -1 if all channels should be the same value.

The new mixer value is set in the Volume field.

Optional flags may be set as follows:

NameDescription
SVF::CAPTURESet input, not output.
SVF::MUTEMute the audio for this channel.
SVF::UNMUTEUnmute the audio for this channel.
Error Codes
OkayThe new volume was applied successfully.
ArgsInvalid arguments passed to function.
OutOfRangeThe Volume or Index is out of the acceptable range.
NullArgsFunction call missing argument value(s)
Audio class documentation © Paul Manias © 2002-2025

ADF Type

Optional flags for the Audio object.

NameDescription
ADF::AUTO_SAVESave configuration information on exit.
ADF::FILTER_HIGHEnable a high level of output filtering to minimise distortion.
ADF::FILTER_LOWEnable a low level of output filtering to minimise distortion.
ADF::OVER_SAMPLINGEnables oversampling for higher quality audio at the cost of slower mixing.
ADF::STEREOEnable stereo output (set by default if the platform supports stereo). If not set, output is in mono.
ADF::SYSTEM_WIDEMixer changes should be applied system-wide.
ADF::VOL_RAMPINGEnable volume ramping for softer playback when a sample is played multiple times (enabled by default).
Audio module documentation © Paul Manias © 2002-2025

LOOP Type

Loop modes for the AudioLoop structure.

NameDescription
LOOP::AMIGASingle loop: Amiga style.
LOOP::AMIGA_NONEAmiga loop: Do nothing.
LOOP::DOUBLEDouble loop: When the note is released, playing shifts to the second loop.
LOOP::SINGLESingle loop: Releasing will end the note.
LOOP::SINGLE_RELEASESingle loop: Sample data after the loop will be played when the note is released.
Audio module documentation © Paul Manias © 2002-2025

LTYPE Type

Loop types for the AudioLoop structure.

NameDescription
LTYPE::BIDIRECTIONALThe sample will play in reverse whenever it hits the end marker, then forwards when it hits the start marker.
LTYPE::UNIDIRECTIONALThe sample playback position returns to the byte position specified in the Loop1Start field.
Audio module documentation © Paul Manias © 2002-2025

SFM Type

These audio bit formats are supported by AddSample and AddStream.

NameDescription
SFM::F_BIG_ENDIANCombine this flag with any audio format to declare it as big endian.
SFM::S16_BIT_MONO16-bit mono signed sample.
SFM::S16_BIT_STEREO16-bit stereo signed sample.
SFM::U8_BIT_MONO8-bit mono unsigned sample.
SFM::U8_BIT_STEREO8-bit stereo unsigned sample.
Audio module documentation © Paul Manias © 2002-2025

SVF Type

Flags for the SetVolume() method.

NameDescription
SVF::CAPTURESet input, not output.
SVF::MUTEMute the audio for this channel.
SVF::UNMUTEUnmute the audio for this channel.
Audio module documentation © Paul Manias © 2002-2025

AudioLoop Structure

Loop settings for the AddSample() method.

FieldTypeDescription
LoopModeLOOPLoop mode (single, double)
Loop1TypeLTYPEFirst loop type (unidirectional, bidirectional)
Loop2TypeLTYPESecond loop type (unidirectional, bidirectional)
Loop1StartINTStart of the first loop
Loop1EndINTEnd of the first loop
Loop2StartINTStart of the second loop
Loop2EndINTEnd of the second loop
Audio class documentation © Paul Manias © 2002-2025