The OpenD Programming Language

AudioStream

An AudioStream is a pointer to a dynamically allocated Stream. It can encode and decode to audio files or in memory.

AudioStream are subtyped like this:

AudioStream AudioStream can be: isError() or isValid(). / \ Image start their life as AudioStream.init in error state. isError() or isValid() Image that are isError can only call the open functions to reboot them.

TODO: specify how usable is an isError() stream, what is still available (if any)

Destructor

A destructor is present on this object, but not explicitly documented in the source.

Members

Functions

canSeek
bool canSeek()
countModulePatterns
int countModulePatterns()

Length. Returns the amount of patterns in the module Formats that support this: MOD, XM.

errorMessage
immutable(char)[] errorMessage()

The error message (null if no error currently held). This slice is followed by a '\0' zero terminal character, so it can be safely given to a print function. Tags: none.

finalizeAndGetEncodedResult
const(ubyte)[] finalizeAndGetEncodedResult()

Finalize encoding and get internal buffer. This can be called multiple times, in which cases the stream is finalized only the first time.

finalizeAndGetEncodedResultDisown
const(ubyte)[] finalizeAndGetEncodedResultDisown()

Finalize encoding and get internal buffer, which is disowned by the AudioStream. The caller has to call freeEncodedAudio manually. This can be called exactly one time, if a growable owned buffer was used.

finalizeEncoding
bool finalizeEncoding()

Finalize encoding. After finalization, further writes are not possible anymore however the stream is considered complete and valid for storage.

flush
void flush()

Call fflush() on written samples, if any. It is only useful for streamable output formats, that may want to flush things to disk.

framesRemainingInPattern
int framesRemainingInPattern()

Playback info. Returns the amount of multi-channel frames remaining in the current playing pattern. Formats that support this: MOD

getFormat
AudioFileFormat getFormat()
getLengthInFrames
long getLengthInFrames()
getModuleLength
int getModuleLength()

Length. Returns the amount of PLAYED patterns in the module Formats that support this: MOD, XM.

getNumChannels
int getNumChannels()
getSamplerate
float getSamplerate()
isError
bool isError()

FUTURE: will replace Exception. An AudioStream that is isError cannot be used except for initialization again.

isModule
bool isModule()
isOpenForReading
bool isOpenForReading()
isOpenForWriting
bool isOpenForWriting()
isValid
bool isValid()

AudioStream is valid, meaning it is not in error state. Always return !isError().

openFromFile
void openFromFile(const(char)[] path)

Opens an audio stream that decodes from a file. This stream will be opened for reading only.

openFromMemory
void openFromMemory(const(ubyte)[] inputData)

Opens an audio stream that decodes from memory. This stream will be opened for reading only. Note: throws a manually allocated exception in case of error. Free it with destroyAudioFormatsException.

openToBuffer
void openToBuffer(AudioFileFormat format, float sampleRate, int numChannels, EncodingOptions options)

Opens an audio stream that writes to a dynamically growable output buffer. This stream will be open for writing only. Access to the internal buffer after encoding with finalizeAndGetEncodedResult. Note: throws a manually allocated exception in case of error. Free it with destroyAudioFormatsException.

openToFile
void openToFile(const(char)[] path, AudioFileFormat format, float sampleRate, int numChannels, EncodingOptions options)

Opens an audio stream that writes to file. This stream will be open for writing only. Note: throws a manually allocated exception in case of error. Free it with destroyAudioFormatsException.

openToMemory
void openToMemory(ubyte* data, size_t maxLength, AudioFileFormat format, float sampleRate, int numChannels, EncodingOptions options)

Opens an audio stream that writes to a pre-defined area in memory of maxLength bytes. This stream will be open for writing only. Destroy this stream with closeAudioStream. Note: throws a manually allocated exception in case of error. Free it with destroyAudioFormatsException.

readSamplesDouble
int readSamplesDouble(double* outData, int frames)
int readSamplesDouble(double[] outData)

Read interleaved double samples in the given buffer outData.

readSamplesFloat
int readSamplesFloat(float* outData, int frames)
int readSamplesFloat(float[] outData)

Read interleaved float samples in the given buffer outData.

realtimeSafe
bool realtimeSafe()
rowsInPattern
int rowsInPattern(int pattern)

Tell. Returns amount of rows in a pattern. Formats that support this: MOD, XM.

seekPosition
bool seekPosition(int pattern, int row)

Seeking. Subsequent reads start from pattern + row, 0 index Only available for input streams. Formats that support seeking per pattern/row: MOD, XM

seekPosition
bool seekPosition(int frame)

Seeking. Subsequent reads start from multi-channel frame index frames. Only available for input streams, for streams whose canSeek() returns true. Warning: seekPosition(lengthInFrames) is Undefined Behaviour for now. (it works in MP3).

tellModulePattern
int tellModulePattern()

Tell. Returns the current playing pattern id Formats that support this: MOD, XM

tellModuleRow
int tellModuleRow()

Tell. Returns the current playing row id Formats that support this: MOD, XM

tellPosition
int tellPosition()

Tell. Returns the current position in multichannel frames. -1 on error.

writeSamplesDouble
int writeSamplesDouble(const(double)* inData, int frames)
int writeSamplesDouble(const(double)[] inData)

Write interleaved double samples to the stream, from the given buffer inData[0..frames].

writeSamplesFloat
int writeSamplesFloat(const(float)* inData, int frames)
int writeSamplesFloat(const(float)[] inData)

Write interleaved float samples to the stream, from the given buffer inData[0..frames].

Meta