diff options
Diffstat (limited to 'src/main.c')
-rw-r--r-- | src/main.c | 46 |
1 files changed, 7 insertions, 39 deletions
@@ -20,7 +20,7 @@ WITH REGARD TO THIS SOFTWARE. | |||
20 | #include "uxn/uxn.c" | 20 | #include "uxn/uxn.c" |
21 | #include "uxn/devices/ppu.h" | 21 | #include "uxn/devices/ppu.h" |
22 | #include "uxn/devices/ppu.c" | 22 | #include "uxn/devices/ppu.c" |
23 | #include "uxn/devices/apu.c" | 23 | #include "apu.c" |
24 | 24 | ||
25 | #include "text.h" | 25 | #include "text.h" |
26 | 26 | ||
@@ -124,44 +124,12 @@ audio_talk(Device *d, u8 b0, u8 w) { | |||
124 | } | 124 | } |
125 | } else if(b0 == 0xf) { | 125 | } else if(b0 == 0xf) { |
126 | u16 length = mempeek16(d->dat, 0xa); | 126 | u16 length = mempeek16(d->dat, 0xa); |
127 | 127 | u8 *data = &d->mem[mempeek16(d->dat, 0xc)]; | |
128 | // Disable the channel before updating. | 128 | u8 pitch = d->dat[0xf] & 0x7f; |
129 | c->data = NULL; | ||
130 | |||
131 | // Data. | ||
132 | c->pos = 0; | ||
133 | c->length = length; | ||
134 | c->length <<= 12; // fixed point. | ||
135 | c->data = &d->mem[mempeek16(d->dat, 0xc)]; | ||
136 | |||
137 | // Volume (Mono only for now). | ||
138 | c->vol = MAX(d->dat[0xe] >> 4, d->dat[0xe] & 0xf); // 0-64 | ||
139 | c->vol *= 4 / 3; | ||
140 | |||
141 | // Looping. | ||
142 | if (!(d->dat[0xf] & 0x80)) { | ||
143 | c->loop_length = c->length; | ||
144 | } else { | ||
145 | c->loop_length = 0; | ||
146 | } | ||
147 | |||
148 | // Pitch | ||
149 | c->pitch = d->dat[0xf] & 0x7f; | ||
150 | |||
151 | // Initialization. | ||
152 | u32 sampling_rate = length; | ||
153 | if (length > 256) { | ||
154 | sampling_rate = 44100; | ||
155 | } | ||
156 | c->inc = (pitch_table[c->pitch] * sampling_rate) >> 5; | ||
157 | |||
158 | u16 adsr = mempeek16(d->dat, 0x8); | 129 | u16 adsr = mempeek16(d->dat, 0x8); |
159 | build_adsr(c, adsr); | 130 | u32 vol = MAX(d->dat[0xe] >> 4, d->dat[0xe] & 0xf) * 4 / 3; |
160 | txt_position(0, 0); | 131 | bool loop = !(d->dat[0xf] & 0x80); |
161 | txt_printf("note: %d \n", c->pitch); | 132 | update_channel(c, data, length, pitch, adsr, vol, loop); |
162 | txt_printf("inc: %lu \n", c->inc); | ||
163 | txt_printf("length: %lu \n", c->length >> 12); | ||
164 | txt_printf("chan: %lu \n", d - devaudio); | ||
165 | } | 133 | } |
166 | } | 134 | } |
167 | 135 | ||
@@ -412,7 +380,7 @@ int main(void) { | |||
412 | // irs_set(IRQ_TIMER_1, irs_stop_sample); | 380 | // irs_set(IRQ_TIMER_1, irs_stop_sample); |
413 | 381 | ||
414 | // Initialize VM. | 382 | // Initialize VM. |
415 | memset(&u, 0, sizeof(u)); | 383 | dma_fill(&u, 0, sizeof(u), 3); |
416 | u.ram.dat = umem; | 384 | u.ram.dat = umem; |
417 | init_uxn(&u); | 385 | init_uxn(&u); |
418 | 386 | ||