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;
|
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;
|
|
|
|
|
2023-12-06 20:04:24 +00:00
|
|
|
var openflSound:OpenFLSound = new OpenFLSound();
|
2023-10-26 09:46:22 +00:00
|
|
|
openflSound.loadCompressedDataFromByteArray(openfl.utils.ByteArray.fromBytes(input), input.length);
|
2023-12-06 20:04:24 +00:00
|
|
|
var output:FunkinSound = FunkinSound.load(openflSound, 1.0, false);
|
2023-10-26 09:46:22 +00:00
|
|
|
return output;
|
|
|
|
}
|
|
|
|
}
|