10-Bit Oscillator Frequency Resolution

Basic and Machine Language

Moderator: Moderators

aeb
Vic 20 Drifter
Posts: 30
Joined: Sat Jun 19, 2004 2:06 pm

10-Bit Oscillator Frequency Resolution

Postby aeb » 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! :D

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:

Image

Image

User avatar
pixel
Vic 20 Nerd
Posts: 913
Joined: Fri Feb 28, 2014 3:56 am
Website: http://hugbox.org/pixel/
Location: various
Occupation: Pan–galactic shaman

Re: 10-Bit Oscillator Frequency Resolution

Postby pixel » Sat Jun 10, 2017 3:09 am

aeb wrote:Fantastic! :D

Absolutely! And genius!

Am wondering what games will look like in 2020! :D
A man without talent or ambition is most easily pleased. Others set his path and he is content.
https://github.com/SvenMichaelKlose

tlr
Vic 20 Afficionado
Posts: 438
Joined: Mon Oct 04, 2004 10:53 am

Re: 10-Bit Oscillator Frequency Resolution

Postby tlr » Sat Jun 10, 2017 12:34 pm

Interesting approach. Special +1 for posting source code. Haven't tried it on hw, how good quality can you get?

User avatar
R'zo
Vic 20 Afficionado
Posts: 361
Joined: Fri Jan 16, 2015 11:48 pm

Re: 10-Bit Oscillator Frequency Resolution

Postby R'zo » Sat Jun 10, 2017 1:31 pm

I can't wait to find the time to rest it out.
R'zo
I do not believe in obsolete...

armypavarmy
Vic 20 Amateur
Posts: 54
Joined: Wed Oct 02, 2013 1:54 am
Location: Italy

Re: 10-Bit Oscillator Frequency Resolution

Postby armypavarmy » Mon Dec 18, 2017 7:24 am

Hello .
I tried to adapt the song “sonata c major”
with 10bit program.
I like writing basic music with the Vic20.
Unpacked the .zip file for
play with winvice or true vic20 and drive or Sd2iec
Armando .
10bit-sonata.zip
(1.95 KiB) Downloaded 11 times

aeb
Vic 20 Drifter
Posts: 30
Joined: Sat Jun 19, 2004 2:06 pm

Re: 10-Bit Oscillator Frequency Resolution

Postby aeb » Mon Dec 18, 2017 2:37 pm

You're using it wrong... Your program only sets the high 7 bits of frequency, so there's no difference from normal VIC frequency resolution.

You need to include also the low 3 bits in the data for each note - the small values 0-7 in the frequency table at start of this thread - and write them to the other zero page register. Now you're writing the same 8-bit value to both registers, on line 230, which doesn't make any sense.

- Registers S2,S3 defined in 130 should be 248,251 or 249,252 or 250,253 depending on the voice you want to use
- Line 210: READP,L,D
- 230 POKES2,P:POKES3,L
- Edit all data statements on lines 300-1730 and add the low 3 bits (0-7) for each note
300 DATA 225,8,231,4,235,4,... =>
300 DATA 225,4,8,231,5,4,235,3,4,... etc

:shock: :)

armypavarmy wrote:Hello .
I tried to adapt the song “sonata c major”
with 10bit program.
I like writing basic music with the Vic20.
Unpacked the .zip file for
play with winvice or true vic20 and drive or Sd2iec
Armando .
10bit-sonata.zip

armypavarmy
Vic 20 Amateur
Posts: 54
Joined: Wed Oct 02, 2013 1:54 am
Location: Italy

Re: 10-Bit Oscillator Frequency Resolution

Postby armypavarmy » Wed Dec 20, 2017 3:24 am

10 bit test
Hello
please check this music
that I wrote to try
your corrections.
and tell me if it's okay.
For the songs already written I have to
change the value of the note too
that in your table is different.
from those used in 8-bit for Pal
thanks greetings Armando
10bit-pr.prg.zip
(655 Bytes) Downloaded 11 times

aeb
Vic 20 Drifter
Posts: 30
Joined: Sat Jun 19, 2004 2:06 pm

Re: 10-Bit Oscillator Frequency Resolution

Postby aeb » Wed Dec 20, 2017 7:13 am

Very nice! :D

armypavarmy wrote:10 bit test
Hello
please check this music
that I wrote to try
your corrections.
and tell me if it's okay.
For the songs already written I have to
change the value of the note too
that in your table is different.
from those used in 8-bit for Pal
thanks greetings Armando
10bit-pr.prg.zip

User avatar
beamrider
Vic 20 Nerd
Posts: 872
Joined: Sun Oct 17, 2010 2:28 pm
Location: UK

Re: 10-Bit Oscillator Frequency Resolution

Postby beamrider » Wed Dec 20, 2017 11:18 am

How does this work exactly? I.e. the theory behind it as opposed to how to use it...

armypavarmy
Vic 20 Amateur
Posts: 54
Joined: Wed Oct 02, 2013 1:54 am
Location: Italy

Re: 10-Bit Oscillator Frequency Resolution

Postby armypavarmy » Thu Dec 21, 2017 1:38 am

Hello
composed song using
the 10bit oscillator program
new simple Christmas song
Best wishes to all.
Armando

10bit-christmas.prg.zip
(1022 Bytes) Downloaded 9 times

armypavarmy
Vic 20 Amateur
Posts: 54
Joined: Wed Oct 02, 2013 1:54 am
Location: Italy

Re: 10-Bit Oscillator Frequency Resolution

Postby armypavarmy » Sun Dec 24, 2017 1:47 am

Hello
composed a new song using
the 10bit oscillator program
Name “ Let Is Snow “

let is snow-10bit.prg.zip
(1.31 KiB) Downloaded 12 times

User avatar
Kweepa
Vic 20 Scientist
Posts: 1128
Joined: Fri Jan 04, 2008 5:11 pm
Location: Austin, Texas
Occupation: Game maker

Re: 10-Bit Oscillator Frequency Resolution

Postby Kweepa » Sun Dec 24, 2017 12:31 pm

It toggles between the high byte and the high byte + 1, depending on the low byte.
The data table determines when to add 1 to the high byte, on an eight bit cycle.

EDIT Ah, I didn't notice there was already source code in the ZIP! :)

Code: Select all

rolledbit $FE
freq $F8 ; one byte per channel
mod $FB ; one byte per channel
VIA_NMIENABLE $80
VIA_T1ENABLE $40
VIA1_CTRLBYTE $911E

.C:0340  A9 63       LDA #>interrupt ; install interrupt handler
.C:0342  8D 18 03    STA $0318
.C:0345  A9 03       LDA #<interrupt
.C:0347  8D 19 03    STA $0319
.C:034a  A9 80       LDA #$80        ; set T1 freq to $580
.C:034c  8D 14 91    STA timer1low
.C:034f  85 FE       STA rolledbit
.C:0351  A2 05       LDX #$05
.C:0353  8E 15 91    STX timer1hi
.C:0356  A9 00       LDA #$00        ; turn off all channels
-
.C:0358  95 F8       STA freq,X
.C:035a  CA          DEX
.C:035b  10 FB       BPL -
.C:035d  A9 C0       LDA #(VIA_NMIENABLE+VIA_T1ENABLE)
.C:035f  8D 1E 91    STA VIA1_CTRLBYTE
.C:0362  60          RTS

interrupt:
.C:0363  48          PHA
.C:0364  98          TYA
.C:0365  48          PHA
.C:0366  8A          TXA
.C:0367  48          PHA
.C:0368  06 FE       ASL rolledbit ; roll a bit around a byte
.C:036a  90 02       BCC +
.C:036c  E6 FE       INC rolledbit
+
.C:036e  A2 02       LDX #$02 ; loop over channels
loop:
.C:0370  B4 FB       LDY mod,X
.C:0372  B9 8C 03    LDA datatable,Y
.C:0375  B4 F8       LDY freq,X
.C:0377  25 FE       AND rolledbit ; check if rolled bit is set
.C:0379  F0 01       BEQ +
.C:037b  C8          INY
+
.C:037c  98          TYA
.C:037d  9D 0A 90    STA $900A,X ; set channel freq
.C:0380  CA          DEX
.C:0381  10 ED       BPL loop
.C:0383  68          PLA
.C:0384  AA          TAX
.C:0385  68          PLA
.C:0386  A8          TAY
.C:0387  68          PLA
.C:0388  2C 14 91    BIT $9114
.C:038b  40          RTI

datatable:
.C:038c  %0, %10000000, %10001000, %10010010, %10101010, %11011010, %11101110, %11111110

armypavarmy
Vic 20 Amateur
Posts: 54
Joined: Wed Oct 02, 2013 1:54 am
Location: Italy

Re: 10-Bit Oscillator Frequency Resolution

Postby armypavarmy » Thu Jan 18, 2018 2:58 am

Hello
two new music
rewritten by me at 10Bit.
Sonata in D major
Turkish march
Armando

10bson.zip
(2.12 KiB) Downloaded 5 times

mt10sc.zip
(2.71 KiB) Downloaded 5 times

armypavarmy
Vic 20 Amateur
Posts: 54
Joined: Wed Oct 02, 2013 1:54 am
Location: Italy

Re: 10-Bit Oscillator Frequency Resolution

Postby armypavarmy » Thu Feb 01, 2018 8:29 am

Hello
one new music
rewritten by me at 10Bit.
Somethin’ Stupid
Armando
10bstup.zip
(1.22 KiB) Downloaded 5 times


Return to “Programming”

Who is online

Users browsing this forum: No registered users and 1 guest