2021-04-08 16:14:40 -04:00
|
|
|
/*
|
|
|
|
Copyright (c) 2021 Devine Lu Linvega
|
|
|
|
Copyright (c) 2021 Andrew Alderwick
|
|
|
|
|
|
|
|
Permission to use, copy, modify, and distribute this software for any
|
|
|
|
purpose with or without fee is hereby granted, provided that the above
|
|
|
|
copyright notice and this permission notice appear in all copies.
|
|
|
|
|
|
|
|
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
|
|
|
|
WITH REGARD TO THIS SOFTWARE.
|
|
|
|
*/
|
|
|
|
|
|
|
|
typedef unsigned int Uint32;
|
|
|
|
typedef signed int Sint32;
|
|
|
|
|
2021-04-13 16:50:49 -04:00
|
|
|
#define SAMPLE_FREQUENCY 44100
|
2021-04-08 16:14:40 -04:00
|
|
|
|
|
|
|
typedef struct {
|
|
|
|
Uint16 *dat;
|
2021-04-13 16:54:18 -04:00
|
|
|
Uint8 i, n, sz, finishes, is_envelope;
|
2021-04-08 16:14:40 -04:00
|
|
|
} Queue;
|
|
|
|
|
|
|
|
typedef struct {
|
|
|
|
Uint32 count, advance, period;
|
|
|
|
Uint16 vector;
|
|
|
|
Sint16 start_value, end_value;
|
|
|
|
Queue queue;
|
|
|
|
} WaveformGenerator;
|
|
|
|
|
|
|
|
typedef struct {
|
|
|
|
WaveformGenerator wv[2];
|
2021-04-13 16:52:54 -04:00
|
|
|
Sint8 volume[2];
|
|
|
|
Uint8 playing, impl;
|
2021-04-08 16:14:40 -04:00
|
|
|
} Note;
|
|
|
|
|
|
|
|
typedef struct {
|
2021-04-08 16:21:46 -04:00
|
|
|
Queue *queue;
|
|
|
|
Note *notes;
|
|
|
|
int n_notes;
|
2021-04-08 16:22:27 -04:00
|
|
|
Uint16 channel_addr;
|
2021-04-08 16:14:40 -04:00
|
|
|
} Apu;
|
|
|
|
|
|
|
|
void apu_render(Apu *apu, Uxn *u, Sint16 *samples, int n_samples);
|
2021-04-13 16:52:54 -04:00
|
|
|
void apu_play_note(Note *note, Uint16 wave_vector, Uint16 envelope_vector, Uint8 volume, Uint8 pitch, Uint8 impl);
|