tweak cx16 adpcm example

This commit is contained in:
Irmen de Jong 2023-02-24 01:38:03 +01:00
parent f20356e9be
commit e62ea388e0
2 changed files with 33 additions and 26 deletions

View File

@ -27,10 +27,10 @@ main {
sub start() { sub start() {
wavfile.parse() wavfile.parse()
txt.print_uw(wavfile.adpcm_size)
txt.print(" adpcm data size = ")
txt.print_ub(wavfile.num_adpcm_blocks) txt.print_ub(wavfile.num_adpcm_blocks)
txt.print(" blocks\nsamplerate = ") txt.print(" blocks = ")
txt.print_uw(wavfile.adpcm_size)
txt.print(" adpcm bytes\nsamplerate = ")
txt.print_uw(wavfile.sample_rate) txt.print_uw(wavfile.sample_rate)
txt.print(" vera rate = ") txt.print(" vera rate = ")
txt.print_uw(wavfile.vera_rate_hz) txt.print_uw(wavfile.vera_rate_hz)
@ -58,9 +58,15 @@ main {
} }
} }
float duration_secs = (c64.RDTIM16() as float) / 60.0 float duration_secs = (c64.RDTIM16() as float) / 60.0
float words_per_second = 505.0 * (wavfile.num_adpcm_blocks as float) / duration_secs floats.print_f(duration_secs)
txt.print(" seconds (approx)\n")
const float PCM_WORDS_PER_BLOCK = 1 + 252*2
float words_per_second = PCM_WORDS_PER_BLOCK * (wavfile.num_adpcm_blocks as float) / duration_secs
txt.print_uw(words_per_second as uword) txt.print_uw(words_per_second as uword)
txt.print(" words/sec\n") txt.print(" decoded pcm words/sec\n")
float src_per_second = wavfile.adpcm_size as float / duration_secs
txt.print_uw(src_per_second as uword)
txt.print(" adpcm data bytes/sec\n")
} }
sub playback() { sub playback() {
@ -97,27 +103,28 @@ main {
; AFLOW irq. ; AFLOW irq.
;; cx16.vpoke(1,$fa0c, $a0) ; paint a screen color ;; cx16.vpoke(1,$fa0c, $a0) ; paint a screen color
; refill the fifo buffer with two decoded adpcm blocks (252 nibbles -> 1008 bytes per block) ; refill the fifo buffer with one decoded adpcm block (1010 bytes of pcm data)
repeat 2 { adpcm.init(peekw(nibblesptr), @(nibblesptr+2))
adpcm.init(peekw(nibblesptr), @(nibblesptr+2)) cx16.VERA_AUDIO_DATA = lsb(adpcm.predict)
nibblesptr += 4 cx16.VERA_AUDIO_DATA = msb(adpcm.predict)
repeat 252 { nibblesptr += 4
ubyte @zp nibble = @(nibblesptr) repeat 252 {
adpcm.decode_nibble(nibble & 15) ; first word ubyte @zp nibble = @(nibblesptr)
cx16.VERA_AUDIO_DATA = lsb(adpcm.predict) adpcm.decode_nibble(nibble & 15) ; first word
cx16.VERA_AUDIO_DATA = msb(adpcm.predict) cx16.VERA_AUDIO_DATA = lsb(adpcm.predict)
adpcm.decode_nibble(nibble>>4) ; second word cx16.VERA_AUDIO_DATA = msb(adpcm.predict)
cx16.VERA_AUDIO_DATA = lsb(adpcm.predict) adpcm.decode_nibble(nibble>>4) ; second word
cx16.VERA_AUDIO_DATA = msb(adpcm.predict) cx16.VERA_AUDIO_DATA = lsb(adpcm.predict)
nibblesptr++ cx16.VERA_AUDIO_DATA = msb(adpcm.predict)
} nibblesptr++
}
adpcm_blocks_left-- adpcm_blocks_left--
if adpcm_blocks_left==0 { if adpcm_blocks_left==0 {
; restart adpcm data from the beginning ; restart adpcm data from the beginning
nibblesptr = wavfile.adpcm_data_ptr nibblesptr = wavfile.adpcm_data_ptr
adpcm_blocks_left = wavfile.num_adpcm_blocks adpcm_blocks_left = wavfile.num_adpcm_blocks
} txt.print("end of data, restarting.\n")
} }
} else { } else {
@ -184,7 +191,7 @@ adpcm {
cx16.r0s = -cx16.r0s cx16.r0s = -cx16.r0s
predict += cx16.r0s as uword predict += cx16.r0s as uword
index += t_index[nibble] index += t_index[nibble]
if index & 128 if_neg ; was: if index & 128
index = 0 index = 0
else if index > len(t_step)-1 else if index > len(t_step)-1
index = len(t_step)-1 index = len(t_step)-1