2023-10-26 09:46:22 +00:00
|
|
|
package funkin.util.assets;
|
|
|
|
|
|
|
|
import haxe.io.Bytes;
|
2023-12-06 20:04:24 +00:00
|
|
|
import openfl.media.Sound as OpenFLSound;
|
|
|
|
import funkin.audio.FunkinSound;
|
2025-03-26 02:00:51 +00:00
|
|
|
import lime.media.AudioBuffer;
|
2023-10-26 09:46:22 +00:00
|
|
|
|
2025-04-16 01:00:09 +00:00
|
|
|
@:nullSafety
|
2023-10-26 09:46:22 +00:00
|
|
|
class SoundUtil
|
|
|
|
{
|
|
|
|
/**
|
|
|
|
* Convert byte data into a playable sound.
|
|
|
|
*
|
|
|
|
* @param input The byte data.
|
|
|
|
* @return The playable sound, or `null` if loading failed.
|
|
|
|
*/
|
2023-12-06 20:04:24 +00:00
|
|
|
public static function buildSoundFromBytes(input:Null<Bytes>):Null<FunkinSound>
|
2023-10-26 09:46:22 +00:00
|
|
|
{
|
|
|
|
if (input == null) return null;
|
|
|
|
|
2025-03-26 02:00:51 +00:00
|
|
|
var openflSound:OpenFLSound = OpenFLSound.fromAudioBuffer(AudioBuffer.fromBytes(input));
|
2025-04-16 01:00:09 +00:00
|
|
|
if (openflSound == null) return null;
|
|
|
|
return FunkinSound.load(openflSound, 1.0, false);
|
2023-10-26 09:46:22 +00:00
|
|
|
}
|
|
|
|
}
|