| ... | ... |
@@ -16,8 +16,8 @@ then |
| 16 | 16 |
clang-format -i src/uxn.c |
| 17 | 17 |
clang-format -i src/devices/screen.h |
| 18 | 18 |
clang-format -i src/devices/screen.c |
| 19 |
- clang-format -i src/devices/apu.h |
|
| 20 |
- clang-format -i src/devices/apu.c |
|
| 19 |
+ clang-format -i src/devices/audio.h |
|
| 20 |
+ clang-format -i src/devices/audio.c |
|
| 21 | 21 |
clang-format -i src/devices/file.h |
| 22 | 22 |
clang-format -i src/devices/file.c |
| 23 | 23 |
clang-format -i src/devices/mouse.h |
| ... | ... |
@@ -62,7 +62,7 @@ fi |
| 62 | 62 |
|
| 63 | 63 |
echo "Building.." |
| 64 | 64 |
${CC} ${CFLAGS} src/uxnasm.c -o bin/uxnasm
|
| 65 |
-${CC} ${CFLAGS} ${CORE} src/devices/file.c src/devices/mouse.c src/devices/controller.c src/devices/screen.c src/devices/apu.c src/uxnemu.c ${UXNEMU_LDFLAGS} -o bin/uxnemu
|
|
| 65 |
+${CC} ${CFLAGS} ${CORE} src/devices/file.c src/devices/mouse.c src/devices/controller.c src/devices/screen.c src/devices/audio.c src/uxnemu.c ${UXNEMU_LDFLAGS} -o bin/uxnemu
|
|
| 66 | 66 |
${CC} ${CFLAGS} ${CORE} src/devices/file.c src/uxncli.c -o bin/uxncli
|
| 67 | 67 |
|
| 68 | 68 |
if [ -d "$HOME/bin" ] |
| ... | ... |
@@ -6,7 +6,7 @@ ROM=${USM:%.tal=%.rom}
|
| 6 | 6 |
CFLAGS=$CFLAGS -D__plan9__ -I/sys/include/npe -I/sys/include/npe/SDL2 |
| 7 | 7 |
HFILES=\ |
| 8 | 8 |
/sys/include/npe/stdio.h\ |
| 9 |
- src/devices/apu.h\ |
|
| 9 |
+ src/devices/audio.h\ |
|
| 10 | 10 |
src/devices/file.h\ |
| 11 | 11 |
src/devices/screen.h\ |
| 12 | 12 |
src/uxn.h\ |
| ... | ... |
@@ -35,13 +35,13 @@ bin/uxncli: file.$O uxncli.$O uxn.$O |
| 35 | 35 |
bin/uxnasm: uxnasm.$O |
| 36 | 36 |
$LD $LDFLAGS -o $target $prereq |
| 37 | 37 |
|
| 38 |
-bin/uxnemu: uxnemu.$O apu.$O file.$O screen.$O uxn.$O |
|
| 38 |
+bin/uxnemu: uxnemu.$O audio.$O file.$O screen.$O uxn.$O |
|
| 39 | 39 |
$LD $LDFLAGS -o $target $prereq |
| 40 | 40 |
|
| 41 | 41 |
(uxnasm|uxncli|uxnemu|uxn)\.$O:R: src/\1.c |
| 42 | 42 |
$CC $CFLAGS -Isrc -o $target src/$stem1.c |
| 43 | 43 |
|
| 44 |
-(apu|file|screen)\.$O:R: src/devices/\1.c |
|
| 44 |
+(audio|file|screen)\.$O:R: src/devices/\1.c |
|
| 45 | 45 |
$CC $CFLAGS -Isrc -o $target src/devices/$stem1.c |
| 46 | 46 |
|
| 47 | 47 |
nuke:V: clean |
| 48 | 48 |
similarity index 89% |
| 49 | 49 |
rename from src/devices/apu.c |
| 50 | 50 |
rename to src/devices/audio.c |
| ... | ... |
@@ -1,5 +1,5 @@ |
| 1 | 1 |
#include "../uxn.h" |
| 2 |
-#include "apu.h" |
|
| 2 |
+#include "audio.h" |
|
| 3 | 3 |
|
| 4 | 4 |
/* |
| 5 | 5 |
Copyright (c) 2021 Devine Lu Linvega |
| ... | ... |
@@ -23,10 +23,12 @@ static Uint32 advances[12] = {
|
| 23 | 23 |
0xb504f, 0xbfc88, 0xcb2ff, 0xd7450, 0xe411f, 0xf1a1c |
| 24 | 24 |
}; |
| 25 | 25 |
|
| 26 |
+Audio audio[POLYPHONY]; |
|
| 27 |
+ |
|
| 26 | 28 |
/* clang-format on */ |
| 27 | 29 |
|
| 28 | 30 |
static Sint32 |
| 29 |
-envelope(Apu *c, Uint32 age) |
|
| 31 |
+envelope(Audio *c, Uint32 age) |
|
| 30 | 32 |
{
|
| 31 | 33 |
if(!c->r) return 0x0888; |
| 32 | 34 |
if(age < c->a) return 0x0888 * age / c->a; |
| ... | ... |
@@ -38,7 +40,7 @@ envelope(Apu *c, Uint32 age) |
| 38 | 40 |
} |
| 39 | 41 |
|
| 40 | 42 |
int |
| 41 |
-apu_render(Apu *c, Sint16 *sample, Sint16 *end) |
|
| 43 |
+audio_render(Audio *c, Sint16 *sample, Sint16 *end) |
|
| 42 | 44 |
{
|
| 43 | 45 |
Sint32 s; |
| 44 | 46 |
if(!c->advance || !c->period) return 0; |
| ... | ... |
@@ -57,12 +59,12 @@ apu_render(Apu *c, Sint16 *sample, Sint16 *end) |
| 57 | 59 |
*sample++ += s * c->volume[0] / 0x180; |
| 58 | 60 |
*sample++ += s * c->volume[1] / 0x180; |
| 59 | 61 |
} |
| 60 |
- if(!c->advance) apu_finished_handler(c); |
|
| 62 |
+ if(!c->advance) audio_finished_handler(c); |
|
| 61 | 63 |
return 1; |
| 62 | 64 |
} |
| 63 | 65 |
|
| 64 | 66 |
void |
| 65 |
-apu_start(Apu *c, Uint16 adsr, Uint8 pitch) |
|
| 67 |
+audio_start(Audio *c, Uint16 adsr, Uint8 pitch) |
|
| 66 | 68 |
{
|
| 67 | 69 |
if(pitch < 108 && c->len) |
| 68 | 70 |
c->advance = advances[pitch % 12] >> (8 - pitch / 12); |
| ... | ... |
@@ -83,7 +85,7 @@ apu_start(Apu *c, Uint16 adsr, Uint8 pitch) |
| 83 | 85 |
} |
| 84 | 86 |
|
| 85 | 87 |
Uint8 |
| 86 |
-apu_get_vu(Apu *c) |
|
| 88 |
+audio_get_vu(Audio *c) |
|
| 87 | 89 |
{
|
| 88 | 90 |
int i; |
| 89 | 91 |
Sint32 sum[2] = {0, 0};
|
| 90 | 92 |
similarity index 71% |
| 91 | 93 |
rename from src/devices/apu.h |
| 92 | 94 |
rename to src/devices/audio.h |
| ... | ... |
@@ -13,6 +13,7 @@ WITH REGARD TO THIS SOFTWARE. |
| 13 | 13 |
typedef signed int Sint32; |
| 14 | 14 |
|
| 15 | 15 |
#define SAMPLE_FREQUENCY 44100 |
| 16 |
+#define POLYPHONY 4 |
|
| 16 | 17 |
|
| 17 | 18 |
typedef struct {
|
| 18 | 19 |
Uint8 *addr; |
| ... | ... |
@@ -20,9 +21,11 @@ typedef struct {
|
| 20 | 21 |
Uint16 i, len; |
| 21 | 22 |
Sint8 volume[2]; |
| 22 | 23 |
Uint8 pitch, repeat; |
| 23 |
-} Apu; |
|
| 24 |
+} Audio; |
|
| 24 | 25 |
|
| 25 |
-int apu_render(Apu *c, Sint16 *sample, Sint16 *end); |
|
| 26 |
-void apu_start(Apu *c, Uint16 adsr, Uint8 pitch); |
|
| 27 |
-Uint8 apu_get_vu(Apu *c); |
|
| 28 |
-void apu_finished_handler(Apu *c); |
|
| 26 |
+extern Audio audio[POLYPHONY]; |
|
| 27 |
+ |
|
| 28 |
+int audio_render(Audio *c, Sint16 *sample, Sint16 *end); |
|
| 29 |
+void audio_start(Audio *c, Uint16 adsr, Uint8 pitch); |
|
| 30 |
+Uint8 audio_get_vu(Audio *c); |
|
| 31 |
+void audio_finished_handler(Audio *c); |
|
| 29 | 32 |
\ No newline at end of file |
| ... | ... |
@@ -45,8 +45,7 @@ screen_write(Screen *p, Layer *layer, Uint16 x, Uint16 y, Uint8 color) |
| 45 | 45 |
{
|
| 46 | 46 |
if(x < p->width && y < p->height) {
|
| 47 | 47 |
Uint32 i = x + y * p->width; |
| 48 |
- Uint8 prev = layer->pixels[i]; |
|
| 49 |
- if(color != prev) {
|
|
| 48 |
+ if(color != layer->pixels[i]) {
|
|
| 50 | 49 |
layer->pixels[i] = color; |
| 51 | 50 |
layer->changed = 1; |
| 52 | 51 |
} |
| ... | ... |
@@ -9,7 +9,7 @@ |
| 9 | 9 |
#pragma clang diagnostic ignored "-Wtypedef-redefinition" |
| 10 | 10 |
#include <SDL.h> |
| 11 | 11 |
#include "devices/screen.h" |
| 12 |
-#include "devices/apu.h" |
|
| 12 |
+#include "devices/audio.h" |
|
| 13 | 13 |
#include "devices/file.h" |
| 14 | 14 |
#include "devices/controller.h" |
| 15 | 15 |
#include "devices/mouse.h" |
| ... | ... |
@@ -30,7 +30,6 @@ WITH REGARD TO THIS SOFTWARE. |
| 30 | 30 |
#define WIDTH 64 * 8 |
| 31 | 31 |
#define HEIGHT 40 * 8 |
| 32 | 32 |
#define PAD 4 |
| 33 |
-#define POLYPHONY 4 |
|
| 34 | 33 |
#define BENCH 0 |
| 35 | 34 |
|
| 36 | 35 |
static SDL_Window *gWindow; |
| ... | ... |
@@ -41,7 +40,6 @@ static SDL_Rect gRect; |
| 41 | 40 |
|
| 42 | 41 |
/* devices */ |
| 43 | 42 |
|
| 44 |
-static Apu apu[POLYPHONY]; |
|
| 45 | 43 |
static Device *devsystem, *devscreen, *devmouse, *devctrl, *devaudio0, *devconsole; |
| 46 | 44 |
static Uint8 zoom = 1; |
| 47 | 45 |
static Uint32 stdin_event, audio0_event; |
| ... | ... |
@@ -68,17 +66,17 @@ audio_callback(void *u, Uint8 *stream, int len) |
| 68 | 66 |
Sint16 *samples = (Sint16 *)stream; |
| 69 | 67 |
SDL_memset(stream, 0, len); |
| 70 | 68 |
for(i = 0; i < POLYPHONY; ++i) |
| 71 |
- running += apu_render(&apu[i], samples, samples + len / 2); |
|
| 69 |
+ running += audio_render(&audio[i], samples, samples + len / 2); |
|
| 72 | 70 |
if(!running) |
| 73 | 71 |
SDL_PauseAudioDevice(audio_id, 1); |
| 74 | 72 |
(void)u; |
| 75 | 73 |
} |
| 76 | 74 |
|
| 77 | 75 |
void |
| 78 |
-apu_finished_handler(Apu *c) |
|
| 76 |
+audio_finished_handler(Audio *c) |
|
| 79 | 77 |
{
|
| 80 | 78 |
SDL_Event event; |
| 81 |
- event.type = audio0_event + (c - apu); |
|
| 79 |
+ event.type = audio0_event + (c - audio); |
|
| 82 | 80 |
SDL_PushEvent(&event); |
| 83 | 81 |
} |
| 84 | 82 |
|
| ... | ... |
@@ -212,10 +210,10 @@ console_deo(Device *d, Uint8 port) |
| 212 | 210 |
static Uint8 |
| 213 | 211 |
audio_dei(Device *d, Uint8 port) |
| 214 | 212 |
{
|
| 215 |
- Apu *c = &apu[d - devaudio0]; |
|
| 213 |
+ Audio *c = &audio[d - devaudio0]; |
|
| 216 | 214 |
if(!audio_id) return d->dat[port]; |
| 217 | 215 |
switch(port) {
|
| 218 |
- case 0x4: return apu_get_vu(c); |
|
| 216 |
+ case 0x4: return audio_get_vu(c); |
|
| 219 | 217 |
case 0x2: poke16(d->dat, 0x2, c->i); /* fall through */ |
| 220 | 218 |
default: return d->dat[port]; |
| 221 | 219 |
} |
| ... | ... |
@@ -224,7 +222,7 @@ audio_dei(Device *d, Uint8 port) |
| 224 | 222 |
static void |
| 225 | 223 |
audio_deo(Device *d, Uint8 port) |
| 226 | 224 |
{
|
| 227 |
- Apu *c = &apu[d - devaudio0]; |
|
| 225 |
+ Audio *c = &audio[d - devaudio0]; |
|
| 228 | 226 |
if(!audio_id) return; |
| 229 | 227 |
if(port == 0xf) {
|
| 230 | 228 |
SDL_LockAudioDevice(audio_id); |
| ... | ... |
@@ -233,7 +231,7 @@ audio_deo(Device *d, Uint8 port) |
| 233 | 231 |
c->volume[0] = d->dat[0xe] >> 4; |
| 234 | 232 |
c->volume[1] = d->dat[0xe] & 0xf; |
| 235 | 233 |
c->repeat = !(d->dat[0xf] & 0x80); |
| 236 |
- apu_start(c, peek16(d->dat, 0x8), d->dat[0xf] & 0x7f); |
|
| 234 |
+ audio_start(c, peek16(d->dat, 0x8), d->dat[0xf] & 0x7f); |
|
| 237 | 235 |
SDL_UnlockAudioDevice(audio_id); |
| 238 | 236 |
SDL_PauseAudioDevice(audio_id, 0); |
| 239 | 237 |
} |