10-Bit Oscillator Frequency Resolution
Posted: Fri Jun 09, 2017 10:15 pm
One of the most annoying things about VIC 20 is that the music all too often plays horribly out of tune. This program improves the frequency accuracy of square voices 1-3 from 7 bits (0-127) to 10 bits (0-1023).
Fantastic!
Download: http://www.cncd.fi/aeeben/download/10-bit-ofr.zip
To init: jsr $0340 or sys832
To stop: lda #$40, sta $911e or poke37150,64
Set VIA #1 timer 1 rate ($9114/$9115) to adjust sound quality. Default is $0580.
Set sound quality in basic: poke37141,x (x=5 default, x=0 highest, usable low quality range up to x=30)
Default value is usually quite fine unless you play very high notes.
$f8/248 Voice 1 enable (bit 7) & frequency high 7 bits (bits 6-0) (same as $900a/36874)
$f9/249 Voice 2 -"- (same as $900b/36875)
$fa/250 Voice 3 -"- (same as $900c/36876)
$fb/251 Voice 1 frequency low 3 bits (range 0-7)
$fc/252 Voice 2 -"-
$fd/253 Voice 3 -"-
Invalid values (>7) in $fb-$fd will cause inaccurate sound output.
The note and Hz values in frequency tables pal-freqtable.png and ntsc-freqtable.png are calculated for Voice 1, the lowest voice.
Voice 2 plays an octave higher (Hz * 2)
Voice 3 plays two octaves higher (Hz * 4)
pal-freqtable.bin / ntsc-freqtable.bin format:
The first 72 ($48) bytes are high bytes for writing to $f8-$fa
The next 72 bytes are low 3 bit values for $fb-$fd
LOAD"10-BIT-OFR.PRG",8,1
SEARCHING FOR 10-BIT-OFR.PRG
LOADING
READY.
NEW
READY.
SYS832:POKE36878,15:REM Init and set volume
POKE248,215:POKE251,5:REM Play A-1 / 110Hz on ch 1 (36874)
POKE249,215:POKE252,5:REM Play A-2 / 220Hz on ch 2 (36875)
POKE250,215:POKE253,5:REM Play A-3 / 440Hz on ch 3 (36876)
POKE248,0:POKE249,0:POKE250,0:REM Stop all voices
POKE36877,130:REM You can use noise channel normally
POKE37141,0 - Set highest quality (great for high notes, but slows down basic)
POKE37141,5 - Set default quality (good quality/cpu load balance)
POKE37150,64 - Disable timer NMI, sys832 to start again
Basic Loader:
1 fora=832to915:readb:pokea,b:next
100 data169,99,141,24,3,169,3,141,25,3,169,128,141,20,145,133,254,162,5,142,21,145,169
101 data0,149,248,202,16,251,169,192,141,30,145,96,72,152,72,138,72,6,254,144,2,230,254
102 data162,2,180,251,185,140,3,180,248,37,254,240,1,200,152,157,10,144,202,16,237,104
103 data170,104,168,104,44,20,145,64,0,128,136,146,170,218,238,254
Frequency Tables:
Fantastic!
Download: http://www.cncd.fi/aeeben/download/10-bit-ofr.zip
To init: jsr $0340 or sys832
To stop: lda #$40, sta $911e or poke37150,64
Set VIA #1 timer 1 rate ($9114/$9115) to adjust sound quality. Default is $0580.
Set sound quality in basic: poke37141,x (x=5 default, x=0 highest, usable low quality range up to x=30)
Default value is usually quite fine unless you play very high notes.
$f8/248 Voice 1 enable (bit 7) & frequency high 7 bits (bits 6-0) (same as $900a/36874)
$f9/249 Voice 2 -"- (same as $900b/36875)
$fa/250 Voice 3 -"- (same as $900c/36876)
$fb/251 Voice 1 frequency low 3 bits (range 0-7)
$fc/252 Voice 2 -"-
$fd/253 Voice 3 -"-
Invalid values (>7) in $fb-$fd will cause inaccurate sound output.
The note and Hz values in frequency tables pal-freqtable.png and ntsc-freqtable.png are calculated for Voice 1, the lowest voice.
Voice 2 plays an octave higher (Hz * 2)
Voice 3 plays two octaves higher (Hz * 4)
pal-freqtable.bin / ntsc-freqtable.bin format:
The first 72 ($48) bytes are high bytes for writing to $f8-$fa
The next 72 bytes are low 3 bit values for $fb-$fd
LOAD"10-BIT-OFR.PRG",8,1
SEARCHING FOR 10-BIT-OFR.PRG
LOADING
READY.
NEW
READY.
SYS832:POKE36878,15:REM Init and set volume
POKE248,215:POKE251,5:REM Play A-1 / 110Hz on ch 1 (36874)
POKE249,215:POKE252,5:REM Play A-2 / 220Hz on ch 2 (36875)
POKE250,215:POKE253,5:REM Play A-3 / 440Hz on ch 3 (36876)
POKE248,0:POKE249,0:POKE250,0:REM Stop all voices
POKE36877,130:REM You can use noise channel normally
POKE37141,0 - Set highest quality (great for high notes, but slows down basic)
POKE37141,5 - Set default quality (good quality/cpu load balance)
POKE37150,64 - Disable timer NMI, sys832 to start again
Basic Loader:
1 fora=832to915:readb:pokea,b:next
100 data169,99,141,24,3,169,3,141,25,3,169,128,141,20,145,133,254,162,5,142,21,145,169
101 data0,149,248,202,16,251,169,192,141,30,145,96,72,152,72,138,72,6,254,144,2,230,254
102 data162,2,180,251,185,140,3,180,248,37,254,240,1,200,152,157,10,144,202,16,237,104
103 data170,104,168,104,44,20,145,64,0,128,136,146,170,218,238,254
Frequency Tables: