From 0b936846d9fb59b8c4b2e9c5cc9ab5db3f9d390d Mon Sep 17 00:00:00 2001 From: Chris Speciale Date: Thu, 22 Aug 2024 17:40:58 -0400 Subject: [PATCH] AudioBuffer: docs Missing docs. --- src/lime/media/AudioBuffer.hx | 78 +++++++++++++++++++++++++++++++++++ 1 file changed, 78 insertions(+) diff --git a/src/lime/media/AudioBuffer.hx b/src/lime/media/AudioBuffer.hx index 967c8fbbe..e74b531ec 100644 --- a/src/lime/media/AudioBuffer.hx +++ b/src/lime/media/AudioBuffer.hx @@ -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; @@ -57,8 +86,14 @@ 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) @@ -66,6 +101,12 @@ class AudioBuffer #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; @@ -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; @@ -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; @@ -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):AudioBuffer { #if (js && html5 && lime_howlerjs) @@ -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; @@ -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 { #if (flash || (js && html5)) @@ -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):Future { #if (js && html5 && lime_howlerjs)