2020-09-14 00:00:00 +00:00
|
|
|
#include "./music.h"
|
|
|
|
|
|
|
|
#include <assert.h>
|
|
|
|
#include <stddef.h>
|
|
|
|
|
|
|
|
#include "util/jukebox/amp.h"
|
|
|
|
#include "util/jukebox/composite.h"
|
|
|
|
#include "util/jukebox/decoder.h"
|
|
|
|
#include "util/jukebox/format.h"
|
|
|
|
#include "util/jukebox/mixer.h"
|
|
|
|
|
|
|
|
/* resources */
|
2020-10-09 00:00:00 +00:00
|
|
|
#include "core/loresource/anysrc/music/biome_boss.mp3.h"
|
|
|
|
#include "core/loresource/anysrc/music/biome_cavias_camp.mp3.h"
|
|
|
|
#include "core/loresource/anysrc/music/biome_laboratory.mp3.h"
|
|
|
|
#include "core/loresource/anysrc/music/biome_metaphysical_gate.mp3.h"
|
|
|
|
#include "core/loresource/anysrc/music/boss_big_warder.mp3.h"
|
|
|
|
#include "core/loresource/anysrc/music/boss_greedy_scientist.mp3.h"
|
|
|
|
#include "core/loresource/anysrc/music/boss_theists_child.mp3.h"
|
|
|
|
#include "core/loresource/anysrc/music/boss_theists_child.mp3.h"
|
|
|
|
#include "core/loresource/anysrc/music/title.mp3.h"
|
|
|
|
|
|
|
|
static void loresource_music_initialize_(
|
|
|
|
loresource_music_t* m,
|
|
|
|
const jukebox_format_t* format,
|
|
|
|
const void* buf,
|
|
|
|
size_t len) {
|
|
|
|
assert(m != NULL);
|
2020-09-14 00:00:00 +00:00
|
|
|
assert(jukebox_format_valid(format));
|
|
|
|
assert(buf != NULL || len == 0);
|
|
|
|
|
2020-10-09 00:00:00 +00:00
|
|
|
*m = (typeof(*m)) {
|
2020-09-14 00:00:00 +00:00
|
|
|
.decoder = jukebox_decoder_new_from_memory_mp3(format, buf, len),
|
|
|
|
.compo = jukebox_composite_new(format, 2),
|
|
|
|
};
|
2020-10-09 00:00:00 +00:00
|
|
|
jukebox_amp_initialize(&m->amp, format);
|
2020-09-14 00:00:00 +00:00
|
|
|
|
2020-10-09 00:00:00 +00:00
|
|
|
jukebox_composite_add_effect(m->compo, (jukebox_effect_t*) m->decoder);
|
|
|
|
jukebox_composite_add_effect(m->compo, (jukebox_effect_t*) &m->amp);
|
|
|
|
jukebox_composite_play(m->compo);
|
2020-09-14 00:00:00 +00:00
|
|
|
}
|
2020-10-09 00:00:00 +00:00
|
|
|
static void loresource_music_deinitialize_(loresource_music_t* m) {
|
|
|
|
assert(m != NULL);
|
2020-09-14 00:00:00 +00:00
|
|
|
|
2020-10-09 00:00:00 +00:00
|
|
|
jukebox_composite_delete(m->compo);
|
|
|
|
jukebox_amp_deinitialize(&m->amp);
|
|
|
|
jukebox_decoder_delete(m->decoder);
|
2020-09-14 00:00:00 +00:00
|
|
|
}
|
|
|
|
|
2020-10-09 00:00:00 +00:00
|
|
|
void loresource_music_set_initialize(
|
|
|
|
loresource_music_set_t* set,
|
2020-09-14 00:00:00 +00:00
|
|
|
jukebox_mixer_t* mixer,
|
|
|
|
const jukebox_format_t* format) {
|
2020-10-09 00:00:00 +00:00
|
|
|
assert(set != NULL);
|
2020-09-14 00:00:00 +00:00
|
|
|
assert(mixer != NULL);
|
|
|
|
assert(jukebox_format_valid(format));
|
|
|
|
|
2020-10-09 00:00:00 +00:00
|
|
|
*set = (typeof(*set)) {0};
|
|
|
|
|
|
|
|
# define each_(N, n) do { \
|
|
|
|
loresource_music_t* p = \
|
|
|
|
&set->items[LORESOURCE_MUSIC_ID_##N]; \
|
|
|
|
*p = (typeof(*p)) { \
|
|
|
|
.id = LORESOURCE_MUSIC_ID_##N, \
|
|
|
|
.name = #N, \
|
|
|
|
}; \
|
|
|
|
loresource_music_initialize_( \
|
|
|
|
p, \
|
2020-09-14 00:00:00 +00:00
|
|
|
format, \
|
|
|
|
loresource_music_##n##_mp3_, \
|
|
|
|
sizeof(loresource_music_##n##_mp3_)); \
|
2020-10-09 00:00:00 +00:00
|
|
|
jukebox_mixer_add_effect(mixer, (jukebox_effect_t*) p->compo); \
|
2020-09-14 00:00:00 +00:00
|
|
|
} while (0)
|
2020-10-09 00:00:00 +00:00
|
|
|
LORESOURCE_MUSIC_ID_EACH(each_);
|
2020-09-14 00:00:00 +00:00
|
|
|
# undef each_
|
|
|
|
}
|
|
|
|
|
2020-10-09 00:00:00 +00:00
|
|
|
void loresource_music_set_deinitialize(loresource_music_set_t* set) {
|
|
|
|
assert(set != NULL);
|
2020-09-14 00:00:00 +00:00
|
|
|
|
2020-10-09 00:00:00 +00:00
|
|
|
for (size_t i = 0; i < LORESOURCE_MUSIC_ID_COUNT; ++i) {
|
|
|
|
loresource_music_deinitialize_(&set->items[i]);
|
|
|
|
}
|
|
|
|
}
|
2020-09-14 00:00:00 +00:00
|
|
|
|
2020-10-09 00:00:00 +00:00
|
|
|
loresource_music_t* loresource_music_set_get(
|
|
|
|
loresource_music_set_t* set, loresource_music_id_t id) {
|
|
|
|
assert(set != NULL);
|
2020-09-14 00:00:00 +00:00
|
|
|
|
2020-10-09 00:00:00 +00:00
|
|
|
return &set->items[id];
|
2020-09-14 00:00:00 +00:00
|
|
|
}
|