Music on VIC

Basic and Machine Language

Moderator: Moderators

bishop144
Vic 20 Newbie
Posts: 2
Joined: Wed Mar 29, 2017 2:33 pm

Music on VIC

Post by bishop144 »

Hello,

I'm trying to write a program on my VIC that will play a song. The problem I'm having is that I don't know how to make the VIC play all 3 voices plus noise in the program. I've been using the S assignments (S1=36874 S2=36875 S3=36876 S4=36877). However, I am unsure how to assign specific note & duration values to different voices, as well as timing the voices so they play at the right times with each other.

Any help would be appreciated.
User avatar
srowe
Vic 20 Scientist
Posts: 1325
Joined: Mon Jun 16, 2014 3:19 pm

Re: Music on VIC

Post by srowe »

Welcome to Denial.

I recently implemented something that might be of help. It's best to think in terms of setting register values for relative intervals of time.

So, for example, you define a sequence of 'notes' which have a time, a register and a value

* Note1: time = 0, reg = voice1, value = 135
* Note2: time = 30, reg = voice1, value = 147
* Note3: time = 60, reg = voice1, value = 0
* Note4: time = 60, reg = voice2, value = 167
* Note5: time = 90, reg = voice2, value = 0

The time durations are in jiffies (60ths of a second). The 'play' routine does the following:

* takes the current jiffie clock as a starting reference
* looks at the current note, if the current jiffie time minus the start is greater than or equal to the note time then it sets the register to the value. Then it repeats for the next note
* if the current time minus the start is less than the note time the routine returns

This routine is then repeatedly called unto the tune is complete. This also allows the program to manage other tasks, such as moving graphics, polling the keyboard etc.
User avatar
R'zo
Vic 20 Nerd
Posts: 514
Joined: Fri Jan 16, 2015 11:48 pm

Re: Music on VIC

Post by R'zo »

Are you writing in basic or ml?
R'zo
I do not believe in obsolete...
User avatar
srowe
Vic 20 Scientist
Posts: 1325
Joined: Mon Jun 16, 2014 3:19 pm

Re: Music on VIC

Post by srowe »

I have an implementation in Forth. It would be easy enough to port to machine code, I don't think BASIC would be fast enough.
User avatar
R'zo
Vic 20 Nerd
Posts: 514
Joined: Fri Jan 16, 2015 11:48 pm

Re: Music on VIC

Post by R'zo »

srowe wrote:I have an implementation in Forth. It would be easy enough to port to machine code, I don't think BASIC would be fast enough.
Why not?

Code: Select all

1 data140,5,145,10,140,8,255,2          ; (note1, duration 1, note2...)

2 data 0                                                              ;(0=continue, 1= end)

3 data160,5,145,10,180,8,0,0 

4 data 1

5 s=36874:pokes+4,15  ; (sets s as voice at voice 1 add 1-3 for other voices 4 for volume, pokes volume to 15)

6 readn1:readd1:readn2:readd2:readn3:readd3:readn4:readd4     ; (reads note and duration values from data)

7 pokes,n1:pokes+1,n2:pokes+2,n3:pokes+3,n4         ; (pokes note values into voices)

8 fort=0to10               ; (time loop for duration)

9 ift=d1thenpokes,0      ; (lines 9 through 12 poke voices to 0 when t= duration value)

10 ift=d2thenpokes+1,0

11 ift=d3thenpokes+2,0

12 ift=d4thenpokes+3,0

13 next t

14 reade                                    ; (checks for song end)

15 ife=1 then restore:end      ; (ends song)

16goto6                          ; (loops to the next set of notes)

This format in basic works fine. It may not be superfast but it is fast enough for most tunes. There is even room to add in effects if your creative enough.
R'zo
I do not believe in obsolete...
User avatar
R'zo
Vic 20 Nerd
Posts: 514
Joined: Fri Jan 16, 2015 11:48 pm

Re: Music on VIC

Post by R'zo »

Ml is faster but if all your doing is writing a piece of music with no graphic or other processes to occupancy it basic is plenty fast enough to write a piece of music.

If the music is part of a greater program i.e. a game then yes I recommend writing the music routine in ml. Particularly as an Irq if it needs to play alongside with other processes.
R'zo
I do not believe in obsolete...
User avatar
srowe
Vic 20 Scientist
Posts: 1325
Joined: Mon Jun 16, 2014 3:19 pm

Re: Music on VIC

Post by srowe »

Here's something to annoy the neighbours with.
Attachments
tune.zip
(3.57 KiB) Downloaded 210 times
User avatar
vicist
Vic 20 Afficionado
Posts: 352
Joined: Tue Oct 09, 2012 5:26 am
Location: Sheffield, UK

Re: Music on VIC

Post by vicist »

Or this, from 'An Introduction to Basic Part 2'
gavotte.prg

It's in basic so list it to get an idea of how it works.
armypavarmy
Vic 20 Hobbyist
Posts: 107
Joined: Wed Oct 02, 2013 1:54 am
Location: Italy

Re: Music on VIC

Post by armypavarmy »

hello everyone is Armando
These two music tracks are
realized by me with a program in Basic
The listed ones are available to those who have them.
The notes and the value match
to the original score.
I hope they are happy ......
Greetings ...... Armando
Attachments
Music-Vic.rar
(7.37 KiB) Downloaded 198 times
armypavarmy
Vic 20 Hobbyist
Posts: 107
Joined: Wed Oct 02, 2013 1:54 am
Location: Italy

Re: Music on VIC

Post by armypavarmy »

Success of the moment
"Havana" music in basic
for Vic20 Piano and xylophone
Armando --------------
havana.prg.zip
(1.09 KiB) Downloaded 225 times
armypavarmy
Vic 20 Hobbyist
Posts: 107
Joined: Wed Oct 02, 2013 1:54 am
Location: Italy

Re: Music on VIC

Post by armypavarmy »

For Christmas
Vic 20 piano
"What Christmas Mean To Me"
Merry Christmas to all
Armando --------------
Christmas.zip
(4.03 KiB) Downloaded 209 times
armypavarmy
Vic 20 Hobbyist
Posts: 107
Joined: Wed Oct 02, 2013 1:54 am
Location: Italy

Re: Music on VIC

Post by armypavarmy »

Hello
music in BASIC
the piano medley for Vic20
if you like music or song
send me the title.
I compose it with the Vic 20 for you.
medley.zip
(4.42 KiB) Downloaded 219 times
armypavarmy
Vic 20 Hobbyist
Posts: 107
Joined: Wed Oct 02, 2013 1:54 am
Location: Italy

Re: Music on VIC-Jukebox-

Post by armypavarmy »

Hello to all
my basic music program
called "Jukebox".
For the characters of the text I used
the "Fat Swedish" program by Boray.
Vic20 with 8k + Ram.
For file .d64 load "jbox",8 :Run
Note:
The zip file works "directly"
only with Winvice V 3.1
Armando
jukebox.d64.zip
(13.85 KiB) Downloaded 214 times
Forbidden64
Vic 20 Hobbyist
Posts: 146
Joined: Sun Feb 28, 2016 9:59 pm
Location: CA USA

Re: Music on VIC

Post by Forbidden64 »

srowe wrote:Here's something to annoy the neighbours with.
*types G1210 in monitor*

Crap! The neighbors called the cops after the 13th encore!
armypavarmy
Vic 20 Hobbyist
Posts: 107
Joined: Wed Oct 02, 2013 1:54 am
Location: Italy

Re: Music on VIC

Post by armypavarmy »

For Christmas
Vic 20 Xylophone
"Jingle Bell Rock"
Merry Christmas to all
Armando --------------
jbrock.zip
(1.07 KiB) Downloaded 98 times
Post Reply