diff options
author | Bad Diode <bd@badd10de.dev> | 2021-05-27 11:57:08 +0200 |
---|---|---|
committer | Bad Diode <bd@badd10de.dev> | 2021-05-27 11:57:08 +0200 |
commit | f32eda6df8e1df42e06eae55d28d9a45a92e7ecd (patch) | |
tree | 98a04c2e031038bcfe1d210049ca64af720959e2 /src/main.c | |
parent | 8fc709cc1d69c911ac36d18ea3fd6e3da3efc3f4 (diff) | |
download | uxngba-f32eda6df8e1df42e06eae55d28d9a45a92e7ecd.tar.gz uxngba-f32eda6df8e1df42e06eae55d28d9a45a92e7ecd.zip |
Update pitch_table LUT to avoid divisions
This also unifies both the 44100 and variable pitch tables, reducing the
amount of space needed.
Diffstat (limited to 'src/main.c')
-rw-r--r-- | src/main.c | 19 |
1 files changed, 9 insertions, 10 deletions
@@ -134,10 +134,9 @@ audio_talk(Device *d, u8 b0, u8 w) { | |||
134 | c->length <<= 12; // fixed point. | 134 | c->length <<= 12; // fixed point. |
135 | c->data = &d->mem[mempeek16(d->dat, 0xc)]; | 135 | c->data = &d->mem[mempeek16(d->dat, 0xc)]; |
136 | 136 | ||
137 | // TODO: Volume. | 137 | // Volume (Mono only for now). |
138 | c->vol = 12; // 0-64 | 138 | c->vol = MAX(d->dat[0xe] >> 4, d->dat[0xe] & 0xf); // 0-64 |
139 | // c->volume[0] = d->dat[0xe] >> 4; | 139 | c->vol *= 4 / 3; |
140 | // c->volume[1] = d->dat[0xe] & 0xf; | ||
141 | 140 | ||
142 | // Looping. | 141 | // Looping. |
143 | if (!(d->dat[0xf] & 0x80)) { | 142 | if (!(d->dat[0xf] & 0x80)) { |
@@ -150,16 +149,16 @@ audio_talk(Device *d, u8 b0, u8 w) { | |||
150 | c->pitch = d->dat[0xf] & 0x7f; | 149 | c->pitch = d->dat[0xf] & 0x7f; |
151 | 150 | ||
152 | // Initialization. | 151 | // Initialization. |
152 | u32 sampling_rate = length; | ||
153 | if (length > 256) { | 153 | if (length > 256) { |
154 | c->inc = pitch_table_44100[c->pitch]; | 154 | sampling_rate = 44100; |
155 | } else { | ||
156 | c->inc = pitch_table_variable[c->pitch] * length / AUDIO_FREQ; | ||
157 | } | 155 | } |
156 | c->inc = (pitch_table[c->pitch] * sampling_rate) >> 5; | ||
158 | 157 | ||
159 | txt_position(0, 0); | 158 | txt_position(0, 0); |
160 | txt_printf("note: %d \n", c->pitch); | 159 | txt_printf("note: %d \n", c->pitch); |
161 | txt_printf("inc: %ld \n", c->inc); | 160 | txt_printf("inc: %ld \n", c->inc); |
162 | txt_printf("length: %ld \n", c->length >> 12); | 161 | txt_printf("length: %ld \n", c->length >> 12); |
163 | } | 162 | } |
164 | } | 163 | } |
165 | 164 | ||