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

Postby bishop144 » Sat Jul 22, 2017 11:27 am

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 Afficionado
Posts: 468
Joined: Mon Jun 16, 2014 3:19 pm

Re: Music on VIC

Postby srowe » Sat Jul 22, 2017 1:27 pm

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 Afficionado
Posts: 354
Joined: Fri Jan 16, 2015 11:48 pm

Re: Music on VIC

Postby R'zo » Sat Jul 22, 2017 11:04 pm

Are you writing in basic or ml?
R'zo
I do not believe in obsolete...

User avatar
srowe
Vic 20 Afficionado
Posts: 468
Joined: Mon Jun 16, 2014 3:19 pm

Re: Music on VIC

Postby srowe » Sun Jul 23, 2017 1:09 am

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 Afficionado
Posts: 354
Joined: Fri Jan 16, 2015 11:48 pm

Re: Music on VIC

Postby R'zo » Sun Jul 23, 2017 2:06 am

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 Afficionado
Posts: 354
Joined: Fri Jan 16, 2015 11:48 pm

Re: Music on VIC

Postby R'zo » Sun Jul 23, 2017 2:23 am

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 Afficionado
Posts: 468
Joined: Mon Jun 16, 2014 3:19 pm

Re: Music on VIC

Postby srowe » Sun Jul 23, 2017 7:26 am

Here's something to annoy the neighbours with.
Attachments
tune.zip
(3.57 KiB) Downloaded 19 times

User avatar
vicist
Vic 20 Devotee
Posts: 207
Joined: Tue Oct 09, 2012 5:26 am
Location: Surrey, UK

Re: Music on VIC

Postby vicist » Sun Jul 23, 2017 10:06 am

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 Drifter
Posts: 30
Joined: Wed Oct 02, 2013 1:54 am
Location: Italy

Re: Music on VIC

Postby armypavarmy » Thu Sep 07, 2017 6:06 am

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 13 times

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

Re: Music on VIC

Postby armypavarmy » Mon Nov 20, 2017 6:50 am

Success of the moment
"Havana" music in basic
for Vic20 Piano and xylophone
Armando --------------

havana.prg.zip
(1.09 KiB) Downloaded 6 times


Return to “Programming”

Who is online

Users browsing this forum: No registered users and 1 guest