alt audio

This commit is contained in:
Brooke Vibber 2022-12-11 13:09:14 -08:00
parent 539ecdc5ae
commit 79ac4b750e
3 changed files with 17 additions and 21 deletions

View file

@ -21,5 +21,6 @@ SEGMENTS {
RODATA: load = MAIN, type = ro optional = yes;
DATA: load = MAIN, type = rw optional = yes;
BSS: load = MAIN, type = bss, optional = yes, define = yes;
AUDIO: load = MAIN, type = ro, optional = yes, define = yes, align = 256;
BUFFERS: load = MAIN, type = ro, optional = yes, define = yes, align = 4096;
}

View file

@ -168,6 +168,7 @@ wait_loop:
.macro audio_play_raw
;ldy VCOUNT ; set on entry
ldy #0 ; 2 cycles
lda (sample_ptr),y ; 5/6 cyc
sta AUDC1 ; 4 cyc
.endmacro
@ -187,22 +188,14 @@ wait_loop:
.macro audio_inc
; Increment sample ptr
; 18 cycles
clc ; 2
lda sample_ptrl ; 3
adc #131 ; 2
sta sample_ptrl ; 3
lda sample_ptrh ; 3
adc #0 ; 2
sta sample_ptrh ; 3
; 4 cycles
cmp #.hibyte(audio_samples_end) ; 2
bmi audio_cont ; 2
; 7 cycles
inc sample_ptrl ; 5
bne audio_cont ; 2
; 7 cycles, optional
lda sample_ptrl ; 3
cmp #.lobyte(audio_samples_end) ; 2
inc sample_ptrh ;5
lda sample_ptrh ; 3
cmp #.hibyte(audio_samples_end) ; 2
bmi audio_cont ; 2
; 10 cycles, optional
@ -221,21 +214,20 @@ wait_loop:
sty scanline ; 3 cycles
inner_scanline frame_offset, 0 ; 23-26 cycles before break, 12 cycles after
audio_play_raw ; 11-12 cycles
ldy scanline ; 3 cycles
audio_play_raw ; 9-10 cycles
;audio_play_lo
inner_scanline frame_offset, 128 ; 23-26 cycles before break, 12 cycles after
audio_inc ; 7-24 cycles
;audio_play_raw
;audio_play_hi ; too slow
; save for audio lookup
; save for later lookup
ldy VCOUNT ; 4 cycles
cpy #0 ; 2 cycles
bne each_scanline_pair ; 2 cycles
; only once when we hit scanline 0:
audio_inc ; 22-39 cycles
lda frame_counter ; 3 cycles
eor #1 ; 2 cycles
sta frame_counter ; 3 cycles

View file

@ -43,10 +43,13 @@ function pack(audio) {
}
function audio2assembly(audio) {
return `.data
return `
.segment "AUDIO"
.export audio_samples
.export audio_samples_end
.align 256
audio_samples:
${byte2byte(pack(audio))}
audio_samples_end:
@ -58,7 +61,7 @@ audio_samples_end:
function wav2assembly(buffer) {
let wav = new WaveFile(buffer);
let samples = wav.getSamples();
let n = samples.length - (samples.length % 131);
let n = samples.length - (samples.length % 256);
return audio2assembly(samples.slice(0, n));
}