starting work on apu
This commit is contained in:
parent
e0fc6123fc
commit
243e13b19e
@ -11,4 +11,5 @@ typedef struct {
|
|||||||
float sq2_amp;
|
float sq2_amp;
|
||||||
} audio_context;
|
} audio_context;
|
||||||
|
|
||||||
void audio_init();
|
void audio_init();
|
||||||
|
void audio_tick();
|
19
lib/audio.c
19
lib/audio.c
@ -77,13 +77,13 @@ void audio_init(){
|
|||||||
PaStream *stream;
|
PaStream *stream;
|
||||||
PaError err;
|
PaError err;
|
||||||
|
|
||||||
ctx.sq1_amp = 0;
|
ctx.sq1_amp = 0.2;
|
||||||
ctx.sq1_duty = 0;
|
ctx.sq1_duty = 0.5;
|
||||||
ctx.sq1_freq = 0;
|
ctx.sq1_freq = 200;
|
||||||
|
|
||||||
ctx.sq2_amp = 0;
|
ctx.sq2_amp = 0;
|
||||||
ctx.sq2_duty = 0;
|
ctx.sq2_duty = 0.5;
|
||||||
ctx.sq2_freq = 0;
|
ctx.sq2_freq = 400;
|
||||||
|
|
||||||
for(int i = 0; i < TABLE_SIZE; i++) {
|
for(int i = 0; i < TABLE_SIZE; i++) {
|
||||||
sine[i] = (float) sin(((double)i/(double)TABLE_SIZE) * M_PI * 2.);
|
sine[i] = (float) sin(((double)i/(double)TABLE_SIZE) * M_PI * 2.);
|
||||||
@ -116,4 +116,13 @@ void audio_init(){
|
|||||||
error:
|
error:
|
||||||
Pa_Terminate();
|
Pa_Terminate();
|
||||||
fprintf(stderr, "portaudio stream error\n\tError Number: %d\n\tError Message: %s\n", err, Pa_GetErrorText(err));
|
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;
|
||||||
|
}
|
||||||
}
|
}
|
@ -1,6 +1,7 @@
|
|||||||
|
|
||||||
#include <timer.h>
|
#include <timer.h>
|
||||||
#include <interrupts.h>
|
#include <interrupts.h>
|
||||||
|
#include <audio.h>
|
||||||
|
|
||||||
static timer_context ctx = {0};
|
static timer_context ctx = {0};
|
||||||
|
|
||||||
@ -37,6 +38,10 @@ void timer_tick() {
|
|||||||
cpu_request_interrupt(IT_TIMER);
|
cpu_request_interrupt(IT_TIMER);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if((prev_div & (1 << 12)) && (!(ctx.div & (1 << 12)))){
|
||||||
|
audio_tick();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void timer_write(u16 address, u8 value){
|
void timer_write(u16 address, u8 value){
|
||||||
|
Loading…
Reference in New Issue
Block a user