Add ogg_vorbis loading from packs
This commit is contained in:
parent
e8f6dad025
commit
c1bba2ee48
@ -306,6 +306,9 @@ add_resources_from_pack :: (pack: *Loaded_Pack) {
|
|||||||
case "wav";
|
case "wav";
|
||||||
audio := load_wav_from_memory(v.data);
|
audio := load_wav_from_memory(v.data);
|
||||||
table_set(*pack.audio, name, audio);
|
table_set(*pack.audio, name, audio);
|
||||||
|
case "ogg";
|
||||||
|
audio := load_ogg_from_memory(v.data);
|
||||||
|
table_set(*pack.audio, name, audio);
|
||||||
case "json";
|
case "json";
|
||||||
if name == "particles" {
|
if name == "particles" {
|
||||||
s := create_string_from_memory(v.data);
|
s := create_string_from_memory(v.data);
|
||||||
|
|||||||
@ -64,6 +64,29 @@ load_hex_palette_from_memory :: (data: []u8) -> [..]Palette_Entry {
|
|||||||
return entries;
|
return entries;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Decoded in full up front, so the mixer sees the same float samples as from a wav;
|
||||||
|
// only the pack stays small.
|
||||||
|
load_ogg_from_memory :: (data: []u8) -> Audio_Data {
|
||||||
|
Vorbis :: #import "stb_vorbis";
|
||||||
|
audio : Audio_Data;
|
||||||
|
error : s32;
|
||||||
|
v := Vorbis.stb_vorbis_open_memory(data.data, cast(s32) data.count, *error, null);
|
||||||
|
if !v {
|
||||||
|
log_error("Failed to load ogg file! (stb_vorbis error %)", error);
|
||||||
|
return audio;
|
||||||
|
}
|
||||||
|
defer Vorbis.stb_vorbis_close(v);
|
||||||
|
|
||||||
|
info := Vorbis.stb_vorbis_get_info(v);
|
||||||
|
frames := cast(s64) Vorbis.stb_vorbis_stream_length_in_samples(v);
|
||||||
|
array_resize(*audio.data, frames * info.channels);
|
||||||
|
got := Vorbis.stb_vorbis_get_samples_float_interleaved(v, info.channels, audio.data.data, cast(s32) audio.data.count);
|
||||||
|
audio.data.count = got * info.channels;
|
||||||
|
audio.channels = cast(s16) info.channels;
|
||||||
|
audio.sample_rate = cast(s32) info.sample_rate;
|
||||||
|
return audio;
|
||||||
|
}
|
||||||
|
|
||||||
load_wav_from_memory :: (data: []u8) -> Audio_Data {
|
load_wav_from_memory :: (data: []u8) -> Audio_Data {
|
||||||
Wav :: #import "Wav_File";
|
Wav :: #import "Wav_File";
|
||||||
audio : Audio_Data;
|
audio : Audio_Data;
|
||||||
|
|||||||
@ -302,6 +302,7 @@ entity_saved_members :: (type: Type) -> []Type_Info_Struct_Member {
|
|||||||
result.allocator = temp;
|
result.allocator = temp;
|
||||||
for (cast(*Type_Info_Struct) type).members {
|
for (cast(*Type_Info_Struct) type).members {
|
||||||
if it.flags & (.CONSTANT | .USING) continue;
|
if it.flags & (.CONSTANT | .USING) continue;
|
||||||
|
if array_find(it.notes, "NoSave") continue;
|
||||||
array_add(*result, it);
|
array_add(*result, it);
|
||||||
}
|
}
|
||||||
return result;
|
return result;
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user