Skip to content

Commit

Permalink
AudioBuffer: docs
Browse files Browse the repository at this point in the history
Missing docs.
  • Loading branch information
dimensionscape authored Aug 22, 2024
1 parent 4f4f5df commit 0b93684
Showing 1 changed file with 78 additions and 0 deletions.
78 changes: 78 additions & 0 deletions src/lime/media/AudioBuffer.hx
Original file line number Diff line number Diff line change
Expand Up @@ -31,12 +31,41 @@ import flash.net.URLRequest;
@:fileXml('tags="haxe,release"')
@:noDebug
#end

/**
The `AudioBuffer` class represents a buffer of audio data that can be played back using an `AudioSource`.
It supports a variety of audio formats and platforms, providing a consistent API for loading and managing audio data.
Depending on the platform, the audio backend may differ, but the class provides a unified interface for accessing
audio data, whether it's stored in memory, loaded from a file, or streamed.
@see lime.media.AudioSource
**/
class AudioBuffer
{
/**
The number of bits per sample in the audio data.
**/
public var bitsPerSample:Int;

/**
The number of audio channels (e.g., 1 for mono, 2 for stereo).
**/
public var channels:Int;

/**
The raw audio data stored as a `UInt8Array`.
**/
public var data:UInt8Array;

/**
The sample rate of the audio data, in Hz.
**/
public var sampleRate:Int;

/**
The source of the audio data. This can be an `Audio`, `Sound`, `Howl`, or other platform-specific object.
**/
public var src(get, set):Dynamic;

@:noCompletion private var __srcAudio:#if (js && html5) Audio #else Dynamic #end;
Expand All @@ -57,15 +86,27 @@ class AudioBuffer
}
#end

/**
Creates a new, empty `AudioBuffer` instance.
**/
public function new() {}

/**
Disposes of the resources used by this `AudioBuffer`, such as unloading any associated audio data.
**/
public function dispose():Void
{
#if (js && html5 && lime_howlerjs)
__srcHowl.unload();
#end
}

/**
Creates an `AudioBuffer` from a Base64-encoded string.
@param base64String The Base64-encoded audio data.
@return An `AudioBuffer` instance with the decoded audio data.
**/
public static function fromBase64(base64String:String):AudioBuffer
{
if (base64String == null) return null;
Expand Down Expand Up @@ -112,6 +153,12 @@ class AudioBuffer
return null;
}

/**
Creates an `AudioBuffer` from a `Bytes` object.
@param bytes The `Bytes` object containing the audio data.
@return An `AudioBuffer` instance with the decoded audio data.
**/
public static function fromBytes(bytes:Bytes):AudioBuffer
{
if (bytes == null) return null;
Expand Down Expand Up @@ -145,6 +192,12 @@ class AudioBuffer
return null;
}

/**
Creates an `AudioBuffer` from a file.
@param path The file path to the audio data.
@return An `AudioBuffer` instance with the audio data loaded from the file.
**/
public static function fromFile(path:String):AudioBuffer
{
if (path == null) return null;
Expand Down Expand Up @@ -196,6 +249,12 @@ class AudioBuffer
#end
}

/**
Creates an `AudioBuffer` from an array of file paths.
@param paths An array of file paths to search for audio data.
@return An `AudioBuffer` instance with the audio data loaded from the first valid file found.
**/
public static function fromFiles(paths:Array<String>):AudioBuffer
{
#if (js && html5 && lime_howlerjs)
Expand All @@ -221,7 +280,14 @@ class AudioBuffer
#end
}

/**
Creates an `AudioBuffer` from a `VorbisFile`.
@param vorbisFile The `VorbisFile` object containing the audio data.
@return An `AudioBuffer` instance with the decoded audio data.
**/
#if lime_vorbis

public static function fromVorbisFile(vorbisFile:VorbisFile):AudioBuffer
{
if (vorbisFile == null) return null;
Expand All @@ -243,6 +309,12 @@ class AudioBuffer
}
#end

/**
Asynchronously loads an `AudioBuffer` from a file.
@param path The file path to the audio data.
@return A `Future` that resolves to the loaded `AudioBuffer`.
**/
public static function loadFromFile(path:String):Future<AudioBuffer>
{
#if (flash || (js && html5))
Expand Down Expand Up @@ -307,6 +379,12 @@ class AudioBuffer
#end
}

/**
Asynchronously loads an `AudioBuffer` from multiple files.
@param paths An array of file paths to search for audio data.
@return A `Future` that resolves to the loaded `AudioBuffer`.
**/
public static function loadFromFiles(paths:Array<String>):Future<AudioBuffer>
{
#if (js && html5 && lime_howlerjs)
Expand Down

0 comments on commit 0b93684

Please sign in to comment.