Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions building/libs.xml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
<git name="hxdiscord_rpc" url="https://github.com/CodenameCrew/cne-hxdiscord_rpc" skipDeps="true" />
<git name="funkin-modchart" url="https://github.com/TheoDevelops/FunkinModchart" ref="f30676579d8de7ccac7d12e13b664e8b2c42c6bf" skipDeps="true" />
<lib name="hxvlc" version="1.9.3" skipDeps="true" />
<git name="hxopus" url="https://github.com/HEIHUAa/hxopus" skipDeps="true" />

<!-- Documentation and other features -->
<git name="away3d" url="https://github.com/CodenameCrew/away3d" />
Expand Down
7 changes: 7 additions & 0 deletions project.xml
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,11 @@
<!-- Disable a optimization, to allow reflection to use more functions -->
<define name="FLX_NO_GENERIC" />

<!-- Comment this out to disable opus audio !-->
<section if="cpp">
<define name="OPUS_AUDIO_PLAYBACK" />
</section>

<!-- _______________________________ Libraries ______________________________ -->

<!-- KEEP BOTH OF THESE AS THERE ARE SOME PARTICULAR CASES! -->
Expand All @@ -127,6 +132,8 @@
<haxelib name="flixel" />
<haxelib name="flixel-addons" />

<haxelib name="hxopus" if="OPUS_AUDIO_PLAYBACK"/>

<haxelib name="hxvlc" if="VIDEO_CUTSCENES" />
<haxelib name="away3d" if="THREE_D_SUPPORT" />
<haxelib name="format" />
Expand Down
57 changes: 54 additions & 3 deletions source/funkin/backend/assets/Paths.hx
Original file line number Diff line number Diff line change
Expand Up @@ -81,25 +81,76 @@ class Paths
return getPath('data/$key.ps1', library);

static public function sound(key:String, ?library:String, ?ext:String)
{
if (ext == null)
for (path in Flags.SOUND_EXTENSIONS) {
var path = 'sounds/$key.$path';
if (OpenFlAssets.exists(path))
return getPath(path, library);
}

return getPath('sounds/$key.${ext != null ? ext : Flags.SOUND_EXT}', library);
}

public static inline function soundRandom(key:String, min:Int, max:Int, ?library:String)
return sound(key + FlxG.random.int(min, max), library);

inline static public function music(key:String, ?library:String, ?ext:String)
static public function music(key:String, ?library:String, ?ext:String)
{
if (ext == null)
for (path in Flags.SOUND_EXTENSIONS)
{
var path = 'music/$key.$path';
if (OpenFlAssets.exists(getPath(path, library)))
return getPath(path, library);
}

return getPath('music/$key.${ext != null ? ext : Flags.SOUND_EXT}', library);
}

inline static public function voices(song:String, ?difficulty:String, ?suffix:String = "", ?ext:String) {
static public function voices(song:String, ?difficulty:String, ?suffix:String = "", ?ext:String) {
if (difficulty == null) difficulty = Flags.DEFAULT_DIFFICULTY;

if (ext == null)
for (e in Flags.SOUND_EXTENSIONS)
{
var path = 'songs/$song/song/Voices$suffix-${difficulty}.$e';
trace(path + " | " + OpenFlAssets.exists(getPath(path, null)));
if (OpenFlAssets.exists(getPath(path, null)))
return getPath(path, null);

path = 'songs/$song/song/Voices$suffix.$e';
trace(path + " | " + OpenFlAssets.exists(getPath(path, null)));
if (OpenFlAssets.exists(getPath(path, null)))
return getPath(path, null);
}

if (ext == null) ext = Flags.SOUND_EXT;
var diff = getPath('songs/$song/song/Voices$suffix-${difficulty}.${ext}', null);
trace(diff);
return OpenFlAssets.exists(diff) ? diff : getPath('songs/$song/song/Voices$suffix.${ext}', null);
}

inline static public function inst(song:String, ?difficulty:String, ?suffix:String = "", ?ext:String) {
static public function inst(song:String, ?difficulty:String, ?suffix:String = "", ?ext:String) {
if (difficulty == null) difficulty = Flags.DEFAULT_DIFFICULTY;

if (ext == null)
for (e in Flags.SOUND_EXTENSIONS)
{
var path = 'songs/$song/song/Inst$suffix-${difficulty}.$e';
trace(path + " | " + OpenFlAssets.exists(getPath(path, null)));
if (OpenFlAssets.exists(getPath(path, null)))
return getPath(path, null);

path = 'songs/$song/song/Inst$suffix.$e';
trace(path + " | " + OpenFlAssets.exists(getPath(path, null)));
if (OpenFlAssets.exists(getPath(path, null)))
return getPath(path, null);
}

if (ext == null) ext = Flags.SOUND_EXT;
var diff = getPath('songs/$song/song/Inst$suffix-${difficulty}.${ext}', null);
trace(diff);
return OpenFlAssets.exists(diff) ? diff : getPath('songs/$song/song/Inst$suffix.${ext}', null);
}

Expand Down
2 changes: 2 additions & 0 deletions source/funkin/backend/chart/ChartData.hx
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@ typedef ChartMetaData = {
public var ?instSuffix:String;
public var ?vocalsSuffix:String;
public var ?needsVoices:Bool;

public var ?musicExt:String;
}

typedef ChartStrumLine = {
Expand Down
2 changes: 1 addition & 1 deletion source/funkin/backend/scripting/Script.hx
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ class Script extends FlxBasic implements IFlxDestroyable {

#if TRANSLATIONS_SUPPORT
"TranslationUtil" => funkin.backend.utils.TranslationUtil,
"translate" => funkin.backend.utils.TranslationUtil.get,
"translate" => funkin.backend.utils.TranslationUtil.get,
#end
];
}
Expand Down
5 changes: 5 additions & 0 deletions source/funkin/backend/system/Flags.hx
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,11 @@ class Flags {
public static var REPO_OWNER:String = "CodenameCrew";
public static var REPO_URL:String = 'https://github.com/$REPO_OWNER/$REPO_NAME';

public static var SOUND_EXTENSIONS:Array<String> = [
#if web "mp3" #else "ogg" #end,
"opus"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wouldn't it make more sense to include this as part of the #else macro, since Opus support is only available on C++ builds?

];

/**
* Preferred sound extension for the game's audio files.
* Currently is set to `mp3` for web targets, and `ogg` for other targets.
Expand Down
6 changes: 3 additions & 3 deletions source/funkin/editors/charter/Charter.hx
Original file line number Diff line number Diff line change
Expand Up @@ -608,9 +608,9 @@ class Charter extends UIState {
Conductor.setupSong(PlayState.SONG);
noteTypes = PlayState.SONG.noteTypes;

FlxG.sound.setMusic(FlxG.sound.load(Paths.inst(__song, __diff, PlayState.SONG.meta.instSuffix)));
if (Assets.exists(Paths.voices(__song, __diff, PlayState.SONG.meta.vocalsSuffix)))
vocals = FlxG.sound.load(Paths.voices(__song, __diff, PlayState.SONG.meta.vocalsSuffix));
FlxG.sound.setMusic(FlxG.sound.load(Paths.inst(__song, __diff, PlayState.SONG.meta.instSuffix, PlayState.SONG.meta.musicExt)));
if (Assets.exists(Paths.voices(__song, __diff, PlayState.SONG.meta.vocalsSuffix, PlayState.SONG.meta.musicExt)))
vocals = FlxG.sound.load(Paths.voices(__song, __diff, PlayState.SONG.meta.vocalsSuffix, PlayState.SONG.meta.musicExt));
else
vocals = new FlxSound();

Expand Down
6 changes: 3 additions & 3 deletions source/funkin/game/PlayState.hx
Original file line number Diff line number Diff line change
Expand Up @@ -1129,11 +1129,11 @@ class PlayState extends MusicBeatState
curSong = songData.meta.name.toLowerCase();
curSongID = curSong.replace(" ", "-");

FlxG.sound.setMusic(inst = FlxG.sound.load(Assets.getMusic(Paths.inst(SONG.meta.name, difficulty, SONG.meta.instSuffix))));
FlxG.sound.setMusic(inst = FlxG.sound.load(Assets.getMusic(Paths.inst(SONG.meta.name, difficulty, SONG.meta.instSuffix, SONG.meta.musicExt))));

var vocalsPath = Paths.voices(SONG.meta.name, difficulty, SONG.meta.vocalsSuffix);
var vocalsPath = Paths.voices(SONG.meta.name, difficulty, SONG.meta.vocalsSuffix, SONG.meta.musicExt);
if (SONG.meta.needsVoices && Assets.exists(vocalsPath))
vocals = FlxG.sound.load(Options.streamedVocals ? Assets.getMusic(vocalsPath) : vocalsPath);
vocals = FlxG.sound.load(Options.streamedVocals ? Assets.getMusic(vocalsPath) : vocalsPath, SONG.meta.musicExt);
else
vocals = new FlxSound();

Expand Down
2 changes: 1 addition & 1 deletion source/funkin/menus/FreeplayState.hx
Original file line number Diff line number Diff line change
Expand Up @@ -259,7 +259,7 @@ class FreeplayState extends MusicBeatState
var dontPlaySongThisFrame = false;
autoplayElapsed += elapsed;
if (!disableAutoPlay && !songInstPlaying && (autoplayElapsed > timeUntilAutoplay)) {
if (curPlayingInst != (curPlayingInst = Paths.inst(curSong.name, curDifficulties[curDifficulty], curSong.instSuffix))) {
if (curPlayingInst != (curPlayingInst = Paths.inst(curSong.name, curDifficulties[curDifficulty], curSong.instSuffix, curSong.musicExt))) {
var streamed = false;
if (Options.streamedMusic) {
var sound = Assets.getMusic(curPlayingInst, true, false);
Expand Down
23 changes: 18 additions & 5 deletions source/openfl/utils/Assets.hx
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,9 @@ import lime.utils.Assets as LimeAssets;
import lime.media.AudioBuffer;
import lime.media.vorbis.VorbisFile;
#end
#if OPUS_AUDIO_PLAYBACK
import hxopus.Opus;
#end

/**
The Assets class provides a cross-platform interface to access
Expand Down Expand Up @@ -288,13 +291,10 @@ class Assets
var sound = cache.getSound(id);

if (isValidSound(sound))
{
return sound;
}
}

var buffer = LimeAssets.getAudioBuffer(id, false);

if (buffer != null)
{
#if flash
Expand All @@ -304,12 +304,25 @@ class Assets
#end

if (useCache && cache.enabled)
{
cache.setSound(id, sound);
}

return sound;
}

#if OPUS_AUDIO_PLAYBACK
// Try to load as Opus if normal loading failed
var bytes = getBytes(id);
if (bytes != null)
{
var sound = Opus.toOpenFL(bytes);

if (useCache && cache.enabled)
cache.setSound(id, sound);

return sound;
}
#end

#end

return null;
Expand Down