starting work on apu

This commit is contained in:
Samuel Walker 2025-02-02 12:35:53 -07:00
parent e0fc6123fc
commit 243e13b19e
Signed by: piwalker
GPG Key ID: 616B1928705EA4C9
3 changed files with 21 additions and 6 deletions

View File

@ -12,3 +12,4 @@ typedef struct {
} audio_context;
void audio_init();
void audio_tick();

View File

@ -77,13 +77,13 @@ void audio_init(){
PaStream *stream;
PaError err;
ctx.sq1_amp = 0;
ctx.sq1_duty = 0;
ctx.sq1_freq = 0;
ctx.sq1_amp = 0.2;
ctx.sq1_duty = 0.5;
ctx.sq1_freq = 200;
ctx.sq2_amp = 0;
ctx.sq2_duty = 0;
ctx.sq2_freq = 0;
ctx.sq2_duty = 0.5;
ctx.sq2_freq = 400;
for(int i = 0; i < TABLE_SIZE; i++) {
sine[i] = (float) sin(((double)i/(double)TABLE_SIZE) * M_PI * 2.);
@ -117,3 +117,12 @@ error:
Pa_Terminate();
fprintf(stderr, "portaudio stream error\n\tError Number: %d\n\tError Message: %s\n", err, Pa_GetErrorText(err));
}
static int change = 1;
void audio_tick(){
ctx.sq1_freq += change;
if(ctx.sq1_freq >= 600 || ctx.sq1_freq <= 200) {
change = -change;
}
}

View File

@ -1,6 +1,7 @@
#include <timer.h>
#include <interrupts.h>
#include <audio.h>
static timer_context ctx = {0};
@ -37,6 +38,10 @@ void timer_tick() {
cpu_request_interrupt(IT_TIMER);
}
}
if((prev_div & (1 << 12)) && (!(ctx.div & (1 << 12)))){
audio_tick();
}
}
void timer_write(u16 address, u8 value){