2023-10-26 05:46:22 -04:00
|
|
|
package funkin.util.assets;
|
|
|
|
|
|
|
|
import haxe.io.Bytes;
|
2023-12-06 15:04:24 -05:00
|
|
|
import openfl.media.Sound as OpenFLSound;
|
|
|
|
import funkin.audio.FunkinSound;
|
2023-10-26 05:46:22 -04: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 15:04:24 -05:00
|
|
|
public static function buildSoundFromBytes(input:Null<Bytes>):Null<FunkinSound>
|
2023-10-26 05:46:22 -04:00
|
|
|
{
|
|
|
|
if (input == null) return null;
|
|
|
|
|
2023-12-06 15:04:24 -05:00
|
|
|
var openflSound:OpenFLSound = new OpenFLSound();
|
2023-10-26 05:46:22 -04:00
|
|
|
openflSound.loadCompressedDataFromByteArray(openfl.utils.ByteArray.fromBytes(input), input.length);
|
2023-12-06 15:04:24 -05:00
|
|
|
var output:FunkinSound = FunkinSound.load(openflSound, 1.0, false);
|
2023-10-26 05:46:22 -04:00
|
|
|
return output;
|
|
|
|
}
|
|
|
|
}
|