Parasol Framework
  • Gallery
  • API
  • Wiki
  • GitHub
    •  Overview
    • MixContinue()
    • MixEndSequence()
    • MixFrequency()
    • MixMute()
    • MixPan()
    • MixPlay()
    • MixRate()
    • MixSample()
    • MixStartSequence()
    • MixStop()
    • MixStopLoop()
    • MixVolume()
    • 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
      • NetClient
      • NetSocket
      • Proxy
      • Vector
      • VectorClip
      • VectorColour
      • VectorEllipse
      • VectorFilter
      • VectorGradient
      • VectorGroup
      • VectorImage
      • VectorPath
      • VectorPattern
      • VectorPolygon
      • VectorRectangle
      • VectorScene
      • VectorShape
      • VectorSpiral
      • VectorText
      • VectorTransition
      • VectorViewport
      • VectorWave
      • Linux Builds
      • Windows Builds
      • Customising Your Build
      • Parasol Objects
      • Parasol In Depth
      • Fluid Reference Manual
      • Common API
      • FileSearch API
      • GUI API
      • JSON API
      • VFX API
      • Widgets
      • RIPL Reference Manual
      • Parasol Cmd Tool
      • Flute / Unit Testing
      • Embedded Document Format
      • FDL Reference Manual
      • FDL Tools
      • Action Reference Manual
      • System Error Codes

Audio Module

Comprehensive audio processing and playback system with professional-grade mixing capabilities.

The Audio module provides a robust, cross-platform audio infrastructure that manages the complete audio pipeline from sample loading through to hardware output. The module's architecture supports both high-level convenience interfaces and low-level professional audio control, making it suitable for applications ranging from simple media playback to sophisticated audio production environments.

The module implements a client-server design pattern with two complementary class interfaces:

  • Audio: Low-level hardware interface providing precise control over audio mixing, buffering, and output configuration. Designed for applications requiring professional audio capabilities including real-time processing, multi-channel mixing, and advanced streaming architectures
  • Sound: High-level sample playback interface optimised for simplicity and performance. Automatically manages resource allocation, format conversion, and hardware abstraction whilst providing intelligent streaming decisions

The internal mixer is a floating-point engine that processes all audio internally at 32-bit precision regardless of output bit depth. The mixer supports features that include:

  • Oversampling with interpolation for enhanced quality and reduced aliasing
  • Real-time volume ramping to eliminate audio artefacts during playback transitions
  • Multi-stage filtering with configurable low-pass and high-pass characteristics
  • Sample-accurate playback positioning with sub-sample interpolation
  • Bidirectional and unidirectional looping with precision loop point handling

Platform-Specific Optimisations

Audio implementation is optimised for each supported platform to maximise performance and minimise latency:

  • Linux (ALSA Integration): Utilises ALSA's period-based buffering with configurable period counts and sizes. All samples are processed through the unified mixer with support for system-wide volume control and hardware mixer integration
  • Windows (DirectSound Integration): Implements dual-path audio where simple playback can bypass the internal mixer for reduced latency, whilst complex operations utilise the full mixing pipeline. Automatic fallback ensures compatibility across Windows audio driver variations
  • Cross-Platform Consistency: API behaviour remains consistent across platforms, with platform-specific optimisations operating transparently to applications

Streaming and Memory Management

The module implements streaming technology that automatically adapts to sample characteristics and system resources:

  • Smart streaming decisions based on sample size, available memory, and playback requirements
  • Configurable streaming thresholds with support for forced streaming or memory-resident operation
  • Rolling buffer architecture for large samples with automatic buffer management
  • Loop-aware streaming that maintains loop points during streaming operations

Usage Guidelines

For optimal results, choose the appropriate interface based on application requirements:

  • Sound Class (Recommended for Most Applications): Provides immediate audio playback with automatic resource management, format detection, and intelligent streaming. Ideal for media players, games, and general-purpose audio applications
  • Audio Class (Advanced Applications): Offers complete control over the audio pipeline including custom mixer configurations, real-time effects processing, and professional-grade timing control. Required for audio workstations, synthesisers, and applications with demanding audio requirements

Technical Specifications

  • Internal processing: 32-bit floating-point precision
  • Output formats: 8, 16, 24, and 32-bit with automatic conversion
  • Sample rates: Up to 44.1 kHz (hardware dependent)
  • Channel configurations: Mono and stereo with automatic format adaptation
  • Latency: Platform-optimised with configurable buffering for real-time applications

Functions

MixContinue | MixEndSequence | MixFrequency | MixMute | MixPan | MixPlay | MixRate | MixSample | MixStartSequence | MixStop | MixStopLoop | MixVolume

Structures

AudioLoop

Classes

Audio | Sound

Constants

ADF | CHF | CHS | LOOP | LTYPE | NOTE | SDF | SFM | STREAM | SVF | VCF

MixContinue()

Continue playing a stopped channel.

ERR snd::MixContinue(objAudio * Audio, INT Handle)
ParameterDescription
AudioThe target Audio object.
HandleThe target channel.

This function will continue playback on a channel that has previously been stopped.

Error Codes

OkayOperation successful.
NullArgsFunction call missing argument value(s)
Audio module documentation © Paul Manias © 2002-2025

MixEndSequence()

Ends the buffering of mix commands.

ERR snd::MixEndSequence(objAudio * Audio, INT Handle)
ParameterDescription
AudioThe target Audio object.
HandleThe target channel.

Use this function to end a buffered command sequence that was started by MixStartSequence().

Error Codes

OkayOperation successful.
NullArgsFunction call missing argument value(s)
Audio module documentation © Paul Manias © 2002-2025

MixFrequency()

Sets a channel's playback rate.

ERR snd::MixFrequency(objAudio * Audio, INT Handle, INT Frequency)
ParameterDescription
AudioThe target Audio object.
HandleThe target channel.
FrequencyThe desired frequency.

Use this function to set the playback rate of a mixer channel.

Error Codes

OkayOperation successful.
NullArgsFunction call missing argument value(s)
Audio module documentation © Paul Manias © 2002-2025

MixMute()

Mutes the audio of a channel.

ERR snd::MixMute(objAudio * Audio, INT Handle, INT Mute)
ParameterDescription
AudioThe target Audio object.
HandleThe target channel.
MuteSet to true to mute the channel. A value of 0 will undo the mute setting.

Use this function to mute the audio of a mixer channel.

Error Codes

OkayOperation successful.
NullArgsFunction call missing argument value(s)
Audio module documentation © Paul Manias © 2002-2025

MixPan()

Sets a channel's panning value.

ERR snd::MixPan(objAudio * Audio, INT Handle, DOUBLE Pan)
ParameterDescription
AudioThe target Audio object.
HandleThe target channel.
PanThe desired pan value between -1.0 and 1.0.

Use this function to set a mixer channel's panning value. Accepted values are between -1.0 (left) and 1.0 (right).

Error Codes

OkayOperation successful.
NullArgsFunction call missing argument value(s)
Audio module documentation © Paul Manias © 2002-2025

MixPlay()

Commences channel playback at a set frequency.

ERR snd::MixPlay(objAudio * Audio, INT Handle, INT Position)
ParameterDescription
AudioThe target Audio object.
HandleThe target channel.
PositionThe new playing position, measured in bytes.

This function will start playback of the sound sample associated with the target mixer channel. If the channel is already in playback mode, it will be stopped to facilitate the new playback request.

Error Codes

OkayPlayback successfully initiated.
FailedChannel not associated with a valid sample.
OutOfRangePosition exceeds sample boundaries.
NullArgsRequired parameters are null or missing.
Audio module documentation © Paul Manias © 2002-2025

MixRate()

Sets a new update rate for a channel.

ERR snd::MixRate(objAudio * Audio, INT Handle, INT Rate)
ParameterDescription
AudioThe target Audio object.
HandleThe channel set allocated from OpenChannels().
RateThe new update rate in milliseconds.

This function will set a new update rate for all channels, measured in milliseconds. The default update rate is 125, which is equivalent to 5000Hz.

Error Codes

OkayOperation successful.
NullArgsFunction call missing argument value(s)
Audio module documentation © Paul Manias © 2002-2025

MixSample()

Associate a sound sample with a mixer channel.

ERR snd::MixSample(objAudio * Audio, INT Handle, INT Sample)
ParameterDescription
AudioThe target Audio object.
HandleThe target channel.
SampleA sample handle allocated from Audio⇒AddSample() or Audio⇒AddStream().

This function will associate a sound sample with the channel identified by Handle. The client should follow this by setting configuration details (e.g. volume and pan values).

The referenced Sample must have been added to the audio server via the Audio⇒AddSample() or Audio⇒AddStream() methods.

Error Codes

OkayOperation successful.
NullArgsFunction call missing argument value(s)
Audio module documentation © Paul Manias © 2002-2025

MixStartSequence()

Initiates buffering of mix commands.

ERR snd::MixStartSequence(objAudio * Audio, INT Handle)
ParameterDescription
AudioThe target Audio object.
HandleThe target channel.

Use this function to initiate the buffering of mix commands, up until a call to MixEndSequence() is made. The buffering of mix commands makes it possible to create batches of commands that are executed at timed intervals as determined by MixRate().

Command Buffering Architecture

When command buffering is activated, the mixer transitions to a batch processing mode with several key characteristics:

  • Deferred Execution: All mixer operations (MixPlay(), MixVolume(), MixPan(), MixFrequency(), etc.) are queued rather than executed immediately
  • Atomic Batch Processing: Queued commands are processed synchronously during the next mixer update cycle, ensuring sample-accurate timing coordination
  • Thread-Safe Queueing: Commands can be safely queued from multiple threads without explicit synchronisation requirements
  • Overflow Protection: Command buffers include overflow detection to prevent memory exhaustion during extended buffering periods

This feature can be used to implement complex sound mixes and digital music players.

Advanced Usage Patterns

  1. Sequence Initiation: Call MixStartSequence() to begin command buffering for the target channel or channel set
  2. Command Queuing: Issue multiple mixer commands (volume, pan, play, frequency adjustments, etc.) which are automatically queued
  3. Sequence Completion: Call MixEndSequence() to mark the end of the command batch and schedule execution
  4. Automatic Execution: Commands execute atomically at the next mixer update interval determined by MixRate()

Error Codes

OkayCommand buffering successfully initiated.
NullArgsRequired parameters are null or missing.
Audio module documentation © Paul Manias © 2002-2025

MixStop()

Stops all playback on a channel.

ERR snd::MixStop(objAudio * Audio, INT Handle)
ParameterDescription
AudioThe target Audio object.
HandleThe target channel.

This function will stop a channel that is currently playing.

Error Codes

OkayOperation successful.
NullArgsFunction call missing argument value(s)
Audio module documentation © Paul Manias © 2002-2025

MixStopLoop()

Cancels any playback loop configured for a channel.

ERR snd::MixStopLoop(objAudio * Audio, INT Handle)
ParameterDescription
AudioThe target Audio object.
HandleThe target channel.

This function will cancel the loop that is associated with the channel identified by Handle if in playback mode. The existing loop configuration will remain intact if playback is restarted.

Error Codes

OkayOperation successful.
NullArgsFunction call missing argument value(s)
Audio module documentation © Paul Manias © 2002-2025

MixVolume()

Changes the volume of a channel.

ERR snd::MixVolume(objAudio * Audio, INT Handle, DOUBLE Volume)
ParameterDescription
AudioThe target Audio object.
HandleThe target channel.
VolumeThe new volume for the channel.

This function will change the volume of the mixer channel identified by Handle. Valid values are from 0 (silent) to 1.0 (maximum).

Error Codes

OkayOperation successful.
NullArgsFunction call missing argument value(s)
Audio module 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

CHF Type

Optional flags for the AudioChannel structure.

NameDescription
CHF::BACKWARDPlay channel backwards.
CHF::CHANGEDSample change
CHF::MUTEChannel is muted.
CHF::VOL_RAMPVolume ramping is enabled.
Audio module documentation © Paul Manias © 2002-2025

CHS Type

Channel status types for the AudioChannel structure.

NameDescription
CHS::FADE_OUTPlayback is fading out.
CHS::FINISHEDPlayback concluded by reaching the sample end.
CHS::PLAYINGSample playing and not released.
CHS::RELEASEDSample playing and note has been released.
CHS::STOPPEDPlaying was stopped by the client.
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

NOTE Type

Definitions for the Note field. An 'S' indicates a sharp note.

NameDescription
NOTE::A
NOTE::AS
NOTE::B
NOTE::C
NOTE::CS
NOTE::D
NOTE::DS
NOTE::E
NOTE::F
NOTE::FS
NOTE::G
NOTE::GS
NOTE::OCTAVE
Audio module documentation © Paul Manias © 2002-2025

SDF Type

Sound flags

NameDescription
SDF::LOOPEnables sample looping. The LoopStart and LoopEnd fields determine where the looping area lies within the sample data.
SDF::NEWCreate the sample from scratch (e.g. for audio recording purposes).
SDF::RESTRICT_PLAYRestricts playback so that the sound can never play on more than one channel at any given time.
SDF::STEREOIndicates that the sound has multiple audio channels.
SDF::STREAMRead-Only. Indicates that streaming is enabled.
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

STREAM Type

Streaming options

NameDescription
STREAM::ALWAYSStream if the sample length exceeds 64k.
STREAM::NEVERNo streaming - load all data into memory.
STREAM::SMARTSmart streaming is the default. If the sample appears to be relatively small with respect to available system RAM, it will be loaded into memory. Otherwise it will be streamed.
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

VCF Type

Volume control flags

NameDescription
VCF::CAPTUREThe mixer supports audio input.
VCF::JOINEDThe mixer channels are joined (e.g. left and right speakers cannot be adjusted separately).
VCF::MONOThe mixer is restricted to mono input/output.
VCF::MUTEThe mixer is muted.
VCF::PLAYBACKThe mixer supports audio output.
VCF::SYNCThe mixer is synchronised.
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 module documentation © Paul Manias © 2002-2025