mirror of https://git.sr.ht/~rabbits/uxn
Renamed Apu to Audio
This commit is contained in:
parent
7b33cf3d95
commit
c3506869b5
6
build.sh
6
build.sh
|
@ -16,8 +16,8 @@ then
|
||||||
clang-format -i src/uxn.c
|
clang-format -i src/uxn.c
|
||||||
clang-format -i src/devices/screen.h
|
clang-format -i src/devices/screen.h
|
||||||
clang-format -i src/devices/screen.c
|
clang-format -i src/devices/screen.c
|
||||||
clang-format -i src/devices/apu.h
|
clang-format -i src/devices/audio.h
|
||||||
clang-format -i src/devices/apu.c
|
clang-format -i src/devices/audio.c
|
||||||
clang-format -i src/devices/file.h
|
clang-format -i src/devices/file.h
|
||||||
clang-format -i src/devices/file.c
|
clang-format -i src/devices/file.c
|
||||||
clang-format -i src/devices/mouse.h
|
clang-format -i src/devices/mouse.h
|
||||||
|
@ -62,7 +62,7 @@ fi
|
||||||
|
|
||||||
echo "Building.."
|
echo "Building.."
|
||||||
${CC} ${CFLAGS} src/uxnasm.c -o bin/uxnasm
|
${CC} ${CFLAGS} src/uxnasm.c -o bin/uxnasm
|
||||||
${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
|
${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
|
||||||
${CC} ${CFLAGS} ${CORE} src/devices/file.c src/uxncli.c -o bin/uxncli
|
${CC} ${CFLAGS} ${CORE} src/devices/file.c src/uxncli.c -o bin/uxncli
|
||||||
|
|
||||||
if [ -d "$HOME/bin" ]
|
if [ -d "$HOME/bin" ]
|
||||||
|
|
6
mkfile
6
mkfile
|
@ -6,7 +6,7 @@ ROM=${USM:%.tal=%.rom}
|
||||||
CFLAGS=$CFLAGS -D__plan9__ -I/sys/include/npe -I/sys/include/npe/SDL2
|
CFLAGS=$CFLAGS -D__plan9__ -I/sys/include/npe -I/sys/include/npe/SDL2
|
||||||
HFILES=\
|
HFILES=\
|
||||||
/sys/include/npe/stdio.h\
|
/sys/include/npe/stdio.h\
|
||||||
src/devices/apu.h\
|
src/devices/audio.h\
|
||||||
src/devices/file.h\
|
src/devices/file.h\
|
||||||
src/devices/screen.h\
|
src/devices/screen.h\
|
||||||
src/uxn.h\
|
src/uxn.h\
|
||||||
|
@ -35,13 +35,13 @@ bin/uxncli: file.$O uxncli.$O uxn.$O
|
||||||
bin/uxnasm: uxnasm.$O
|
bin/uxnasm: uxnasm.$O
|
||||||
$LD $LDFLAGS -o $target $prereq
|
$LD $LDFLAGS -o $target $prereq
|
||||||
|
|
||||||
bin/uxnemu: uxnemu.$O apu.$O file.$O screen.$O uxn.$O
|
bin/uxnemu: uxnemu.$O audio.$O file.$O screen.$O uxn.$O
|
||||||
$LD $LDFLAGS -o $target $prereq
|
$LD $LDFLAGS -o $target $prereq
|
||||||
|
|
||||||
(uxnasm|uxncli|uxnemu|uxn)\.$O:R: src/\1.c
|
(uxnasm|uxncli|uxnemu|uxn)\.$O:R: src/\1.c
|
||||||
$CC $CFLAGS -Isrc -o $target src/$stem1.c
|
$CC $CFLAGS -Isrc -o $target src/$stem1.c
|
||||||
|
|
||||||
(apu|file|screen)\.$O:R: src/devices/\1.c
|
(audio|file|screen)\.$O:R: src/devices/\1.c
|
||||||
$CC $CFLAGS -Isrc -o $target src/devices/$stem1.c
|
$CC $CFLAGS -Isrc -o $target src/devices/$stem1.c
|
||||||
|
|
||||||
nuke:V: clean
|
nuke:V: clean
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
#include "../uxn.h"
|
#include "../uxn.h"
|
||||||
#include "apu.h"
|
#include "audio.h"
|
||||||
|
|
||||||
/*
|
/*
|
||||||
Copyright (c) 2021 Devine Lu Linvega
|
Copyright (c) 2021 Devine Lu Linvega
|
||||||
|
@ -23,10 +23,12 @@ static Uint32 advances[12] = {
|
||||||
0xb504f, 0xbfc88, 0xcb2ff, 0xd7450, 0xe411f, 0xf1a1c
|
0xb504f, 0xbfc88, 0xcb2ff, 0xd7450, 0xe411f, 0xf1a1c
|
||||||
};
|
};
|
||||||
|
|
||||||
|
Audio audio[POLYPHONY];
|
||||||
|
|
||||||
/* clang-format on */
|
/* clang-format on */
|
||||||
|
|
||||||
static Sint32
|
static Sint32
|
||||||
envelope(Apu *c, Uint32 age)
|
envelope(Audio *c, Uint32 age)
|
||||||
{
|
{
|
||||||
if(!c->r) return 0x0888;
|
if(!c->r) return 0x0888;
|
||||||
if(age < c->a) return 0x0888 * age / c->a;
|
if(age < c->a) return 0x0888 * age / c->a;
|
||||||
|
@ -38,7 +40,7 @@ envelope(Apu *c, Uint32 age)
|
||||||
}
|
}
|
||||||
|
|
||||||
int
|
int
|
||||||
apu_render(Apu *c, Sint16 *sample, Sint16 *end)
|
audio_render(Audio *c, Sint16 *sample, Sint16 *end)
|
||||||
{
|
{
|
||||||
Sint32 s;
|
Sint32 s;
|
||||||
if(!c->advance || !c->period) return 0;
|
if(!c->advance || !c->period) return 0;
|
||||||
|
@ -57,12 +59,12 @@ apu_render(Apu *c, Sint16 *sample, Sint16 *end)
|
||||||
*sample++ += s * c->volume[0] / 0x180;
|
*sample++ += s * c->volume[0] / 0x180;
|
||||||
*sample++ += s * c->volume[1] / 0x180;
|
*sample++ += s * c->volume[1] / 0x180;
|
||||||
}
|
}
|
||||||
if(!c->advance) apu_finished_handler(c);
|
if(!c->advance) audio_finished_handler(c);
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
apu_start(Apu *c, Uint16 adsr, Uint8 pitch)
|
audio_start(Audio *c, Uint16 adsr, Uint8 pitch)
|
||||||
{
|
{
|
||||||
if(pitch < 108 && c->len)
|
if(pitch < 108 && c->len)
|
||||||
c->advance = advances[pitch % 12] >> (8 - pitch / 12);
|
c->advance = advances[pitch % 12] >> (8 - pitch / 12);
|
||||||
|
@ -83,7 +85,7 @@ apu_start(Apu *c, Uint16 adsr, Uint8 pitch)
|
||||||
}
|
}
|
||||||
|
|
||||||
Uint8
|
Uint8
|
||||||
apu_get_vu(Apu *c)
|
audio_get_vu(Audio *c)
|
||||||
{
|
{
|
||||||
int i;
|
int i;
|
||||||
Sint32 sum[2] = {0, 0};
|
Sint32 sum[2] = {0, 0};
|
|
@ -13,6 +13,7 @@ WITH REGARD TO THIS SOFTWARE.
|
||||||
typedef signed int Sint32;
|
typedef signed int Sint32;
|
||||||
|
|
||||||
#define SAMPLE_FREQUENCY 44100
|
#define SAMPLE_FREQUENCY 44100
|
||||||
|
#define POLYPHONY 4
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
Uint8 *addr;
|
Uint8 *addr;
|
||||||
|
@ -20,9 +21,11 @@ typedef struct {
|
||||||
Uint16 i, len;
|
Uint16 i, len;
|
||||||
Sint8 volume[2];
|
Sint8 volume[2];
|
||||||
Uint8 pitch, repeat;
|
Uint8 pitch, repeat;
|
||||||
} Apu;
|
} Audio;
|
||||||
|
|
||||||
int apu_render(Apu *c, Sint16 *sample, Sint16 *end);
|
extern Audio audio[POLYPHONY];
|
||||||
void apu_start(Apu *c, Uint16 adsr, Uint8 pitch);
|
|
||||||
Uint8 apu_get_vu(Apu *c);
|
int audio_render(Audio *c, Sint16 *sample, Sint16 *end);
|
||||||
void apu_finished_handler(Apu *c);
|
void audio_start(Audio *c, Uint16 adsr, Uint8 pitch);
|
||||||
|
Uint8 audio_get_vu(Audio *c);
|
||||||
|
void audio_finished_handler(Audio *c);
|
|
@ -45,8 +45,7 @@ screen_write(Screen *p, Layer *layer, Uint16 x, Uint16 y, Uint8 color)
|
||||||
{
|
{
|
||||||
if(x < p->width && y < p->height) {
|
if(x < p->width && y < p->height) {
|
||||||
Uint32 i = x + y * p->width;
|
Uint32 i = x + y * p->width;
|
||||||
Uint8 prev = layer->pixels[i];
|
if(color != layer->pixels[i]) {
|
||||||
if(color != prev) {
|
|
||||||
layer->pixels[i] = color;
|
layer->pixels[i] = color;
|
||||||
layer->changed = 1;
|
layer->changed = 1;
|
||||||
}
|
}
|
||||||
|
|
18
src/uxnemu.c
18
src/uxnemu.c
|
@ -9,7 +9,7 @@
|
||||||
#pragma clang diagnostic ignored "-Wtypedef-redefinition"
|
#pragma clang diagnostic ignored "-Wtypedef-redefinition"
|
||||||
#include <SDL.h>
|
#include <SDL.h>
|
||||||
#include "devices/screen.h"
|
#include "devices/screen.h"
|
||||||
#include "devices/apu.h"
|
#include "devices/audio.h"
|
||||||
#include "devices/file.h"
|
#include "devices/file.h"
|
||||||
#include "devices/controller.h"
|
#include "devices/controller.h"
|
||||||
#include "devices/mouse.h"
|
#include "devices/mouse.h"
|
||||||
|
@ -30,7 +30,6 @@ WITH REGARD TO THIS SOFTWARE.
|
||||||
#define WIDTH 64 * 8
|
#define WIDTH 64 * 8
|
||||||
#define HEIGHT 40 * 8
|
#define HEIGHT 40 * 8
|
||||||
#define PAD 4
|
#define PAD 4
|
||||||
#define POLYPHONY 4
|
|
||||||
#define BENCH 0
|
#define BENCH 0
|
||||||
|
|
||||||
static SDL_Window *gWindow;
|
static SDL_Window *gWindow;
|
||||||
|
@ -41,7 +40,6 @@ static SDL_Rect gRect;
|
||||||
|
|
||||||
/* devices */
|
/* devices */
|
||||||
|
|
||||||
static Apu apu[POLYPHONY];
|
|
||||||
static Device *devsystem, *devscreen, *devmouse, *devctrl, *devaudio0, *devconsole;
|
static Device *devsystem, *devscreen, *devmouse, *devctrl, *devaudio0, *devconsole;
|
||||||
static Uint8 zoom = 1;
|
static Uint8 zoom = 1;
|
||||||
static Uint32 stdin_event, audio0_event;
|
static Uint32 stdin_event, audio0_event;
|
||||||
|
@ -68,17 +66,17 @@ audio_callback(void *u, Uint8 *stream, int len)
|
||||||
Sint16 *samples = (Sint16 *)stream;
|
Sint16 *samples = (Sint16 *)stream;
|
||||||
SDL_memset(stream, 0, len);
|
SDL_memset(stream, 0, len);
|
||||||
for(i = 0; i < POLYPHONY; ++i)
|
for(i = 0; i < POLYPHONY; ++i)
|
||||||
running += apu_render(&apu[i], samples, samples + len / 2);
|
running += audio_render(&audio[i], samples, samples + len / 2);
|
||||||
if(!running)
|
if(!running)
|
||||||
SDL_PauseAudioDevice(audio_id, 1);
|
SDL_PauseAudioDevice(audio_id, 1);
|
||||||
(void)u;
|
(void)u;
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
apu_finished_handler(Apu *c)
|
audio_finished_handler(Audio *c)
|
||||||
{
|
{
|
||||||
SDL_Event event;
|
SDL_Event event;
|
||||||
event.type = audio0_event + (c - apu);
|
event.type = audio0_event + (c - audio);
|
||||||
SDL_PushEvent(&event);
|
SDL_PushEvent(&event);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -212,10 +210,10 @@ console_deo(Device *d, Uint8 port)
|
||||||
static Uint8
|
static Uint8
|
||||||
audio_dei(Device *d, Uint8 port)
|
audio_dei(Device *d, Uint8 port)
|
||||||
{
|
{
|
||||||
Apu *c = &apu[d - devaudio0];
|
Audio *c = &audio[d - devaudio0];
|
||||||
if(!audio_id) return d->dat[port];
|
if(!audio_id) return d->dat[port];
|
||||||
switch(port) {
|
switch(port) {
|
||||||
case 0x4: return apu_get_vu(c);
|
case 0x4: return audio_get_vu(c);
|
||||||
case 0x2: poke16(d->dat, 0x2, c->i); /* fall through */
|
case 0x2: poke16(d->dat, 0x2, c->i); /* fall through */
|
||||||
default: return d->dat[port];
|
default: return d->dat[port];
|
||||||
}
|
}
|
||||||
|
@ -224,7 +222,7 @@ audio_dei(Device *d, Uint8 port)
|
||||||
static void
|
static void
|
||||||
audio_deo(Device *d, Uint8 port)
|
audio_deo(Device *d, Uint8 port)
|
||||||
{
|
{
|
||||||
Apu *c = &apu[d - devaudio0];
|
Audio *c = &audio[d - devaudio0];
|
||||||
if(!audio_id) return;
|
if(!audio_id) return;
|
||||||
if(port == 0xf) {
|
if(port == 0xf) {
|
||||||
SDL_LockAudioDevice(audio_id);
|
SDL_LockAudioDevice(audio_id);
|
||||||
|
@ -233,7 +231,7 @@ audio_deo(Device *d, Uint8 port)
|
||||||
c->volume[0] = d->dat[0xe] >> 4;
|
c->volume[0] = d->dat[0xe] >> 4;
|
||||||
c->volume[1] = d->dat[0xe] & 0xf;
|
c->volume[1] = d->dat[0xe] & 0xf;
|
||||||
c->repeat = !(d->dat[0xf] & 0x80);
|
c->repeat = !(d->dat[0xf] & 0x80);
|
||||||
apu_start(c, peek16(d->dat, 0x8), d->dat[0xf] & 0x7f);
|
audio_start(c, peek16(d->dat, 0x8), d->dat[0xf] & 0x7f);
|
||||||
SDL_UnlockAudioDevice(audio_id);
|
SDL_UnlockAudioDevice(audio_id);
|
||||||
SDL_PauseAudioDevice(audio_id, 0);
|
SDL_PauseAudioDevice(audio_id, 0);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue