Skip to content

Commit

Permalink
ogg loading support
Browse files Browse the repository at this point in the history
  • Loading branch information
PaoloMazzon committed Feb 8, 2023
1 parent 7b550c6 commit 74a9051
Show file tree
Hide file tree
Showing 6 changed files with 22 additions and 9 deletions.
2 changes: 1 addition & 1 deletion JamUtil
Submodule JamUtil updated 1 files
+5 −2 JamUtil.c
3 changes: 1 addition & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,6 @@ TODO
====

+ TrueType fonts
+ OGG loading
+ Built-in mod support
+ Way to package games
+ Release builds sprites being messed up
+ Spatial hash maps
2 changes: 1 addition & 1 deletion docs/classes/AudioData.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ information on playing audio.
Parameters
+ `filename -> String` Filename of the audio to load.

Loads a piece of audio, currently only loading `.wav` files is supported.
Loads a piece of audio, only `.wav` and `.ogg` files are supported.

### free
`foreign free()`
Expand Down
2 changes: 1 addition & 1 deletion src/AssetCompiler.c
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ static void addFileToAssets(VKSK_Config conf, const char *file, String loaderFun
snprintf(tmpCode, 1024, " static tex_%s { __tex%s }\n", tmpName, tmpName);
appendString(getterFunctions, tmpCode);
}
} else if (strcmp(ext, "wav") == 0) {
} else if (strcmp(ext, "wav") == 0 || strcmp(ext, "ogg") == 0) {
// Generate loader function bit first
snprintf(tmpCode, 1024, " __aud%s = AudioData.open(\"assets/%s\")\n __asset_map[\"aud_%s\"] = __aud%s\n", tmpName, file, tmpName, tmpName);
appendString(loaderFunction, tmpCode);
Expand Down
20 changes: 17 additions & 3 deletions src/JUTypes.c
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
/// \file JUTypes.c
/// \author Paolo Mazzon
#include <JamUtil/JamUtil.h>
#include <JamUtil/cute_sound.h>
#include <src/stb_vorbis.h>
#define CUTE_SOUND_IMPLEMENTATION
#define CUTE_SOUND_FORCE_SDL
#define STB_VORBIS_INCLUDE_STB_VORBIS_H
#include <JamUtil/cute_sound.h>

#include "src/Validation.h"
#include "src/JUTypes.h"
Expand Down Expand Up @@ -198,8 +201,19 @@ void vksk_RuntimeJUSpriteGetHeight(WrenVM *vm) {
void vksk_RuntimeJUAudioDataAllocate(WrenVM *vm) {
VALIDATE_FOREIGN_ARGS(vm, FOREIGN_STRING, FOREIGN_END)
VKSK_RuntimeForeign *snd = wrenSetSlotNewForeign(vm, 0, 0, sizeof(VKSK_RuntimeForeign));
snd->audioData = juSoundLoad(wrenGetSlotString(vm, 1));
// TODO: Load OGG files with stb_vorbis
const char *fname = wrenGetSlotString(vm, 1);
const char *ext = strrchr(fname, '.');
if (strcmp(ext, ".wav") == 0) {
snd->audioData = juSoundLoad(fname);
} else if (strcmp(ext, ".ogg") == 0) {
snd->audioData = malloc(sizeof(struct JUSound));
snd->audioData->sound = cs_load_ogg(fname);
memset(&snd->audioData->soundInfo, 0, sizeof(snd->audioData->soundInfo));
} else {
snd->audioData = NULL;
vksk_Log("Unrecognized sound file type for file \"%s\"", fname);
}

snd->type = FOREIGN_AUDIO_DATA;
}

Expand Down
2 changes: 1 addition & 1 deletion src/Runtime.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

#define ASTRO_VERSION_MAJOR 0
#define ASTRO_VERSION_MINOR 6
#define ASTRO_VERSION_PATCH 3
#define ASTRO_VERSION_PATCH 5

// Engine configuration
typedef struct VKSK_EngineConfig {
Expand Down

0 comments on commit 74a9051

Please sign in to comment.