pimp_mod_context.cpp 1.6 KB
Newer Older
Erik Faye-Lund's avatar
Erik Faye-Lund committed
1
2
3
4
5
6
7
8
9
10
11
12
13
#include "pimp_mod_context.h"

void __pimp_mod_context_init(pimp_mod_context *ctx, const pimp_module *mod, const u8 *sample_bank, pimp_mixer *mixer)
{
	ASSERT(ctx != NULL);
	
	ctx->mod = mod;
	ctx->sample_bank = sample_bank;
	ctx->mixer = mixer;
	
	/* setup default player-state */
	ctx->tick_len      = 0;
	ctx->curr_tick_len = 0;
Erik Faye-Lund's avatar
Erik Faye-Lund committed
14
15
	ctx->report_row   = ctx->curr_row   = 0;
	ctx->report_order = ctx->curr_order = 0;
Erik Faye-Lund's avatar
Erik Faye-Lund committed
16
17
18
19
20
21
22
23
24
25
26
27
28
29
	ctx->curr_pattern  = 0;
	ctx->curr_tick     = 0;
	
	ctx->curr_bpm   = 125;
	ctx->curr_tempo = 5;
	
	ctx->global_volume = 1 << 9; /* 24.8 fixed point */
	
	ctx->curr_pattern = __pimp_module_get_pattern(mod, __pimp_module_get_order(mod, ctx->curr_order));
	__pimp_mod_context_set_bpm(ctx, ctx->mod->bpm);
	ctx->curr_tempo = mod->tempo;
	
	for (unsigned i = 0; i < CHANNELS; ++i)
	{
30
31
32
33
34
		pimp_channel_state *chan = &ctx->channels[i];
		chan->instrument  = (const pimp_instrument*)NULL;
		chan->sample      = (const pimp_sample*)    NULL;
		chan->vol_env.env = (const pimp_envelope*)  NULL;
		__pimp_envelope_reset(&chan->vol_env);
Erik Faye-Lund's avatar
Erik Faye-Lund committed
35
36
37
38
39
40
41
	}
	
	ctx->callback = (pimp_callback)NULL;

	__pimp_mixer_reset(ctx->mixer);
}

Erik Faye-Lund's avatar
Erik Faye-Lund committed
42
43
44
45
46
47
48
49
50
51
void __pimp_mod_context_set_pos(pimp_mod_context *ctx, int row, int order)
{
	ASSERT(ctx != NULL);

	ctx->curr_tick = 0;
	ctx->curr_row = row;
	ctx->curr_order = order;
	ctx->curr_pattern = __pimp_module_get_pattern(ctx->mod, __pimp_module_get_order(ctx->mod, ctx->curr_order));
}

Erik Faye-Lund's avatar
Erik Faye-Lund committed
52
53
54
55
56
57
58
59
void __pimp_mod_context_set_bpm(pimp_mod_context *ctx, int bpm)
{
	ASSERT(ctx != NULL);
	ASSERT(bpm > 0);
	
	/* we're using 8 fractional-bits for the tick-length */
	ctx->tick_len = int((SAMPLERATE * 5) * (1 << 8)) / (bpm * 2);
}