How to do Pulsewidth modulation?

Basic and Machine Language

Moderator: Moderators

Post Reply
tlr
Vic 20 Nerd
Posts: 567
Joined: Mon Oct 04, 2004 10:53 am

How to do Pulsewidth modulation?

Post by tlr »

I'm thinking about adding Pulsewidth modulation to victracker. I have a couple of ideas, but haven't really tried any of them.

The idea is to reset an oscillator by setting it to the highest frequency with no gate, and then setting the correct frequency.
Assuming the oscillator wrapped to 0 during the high frequency period, its counter would be close to zero. The sign of the wave will be random, but it probably doesn't matter.
Once we have a known starting point, we count cycles (using a continously running timer) and when we know the frequency counter has wrapped, we set a new frequency value for the second half of the wave and repeat.
This way we can (within limits) set the length of both the positive part and the negative part of the waveform. The limits will be determined by how often we poll our timer. I we miss a transition it will sound crap!
The same system can also be used to achieve higher frequency resolution by selectively changing the pulsewidth one tick.

What are your thoughts on this?
Is there a better way to reset the oscillator?
aneurysm
not your PAL
Posts: 178
Joined: Sat Mar 06, 2004 11:06 pm

Post by aneurysm »

sounds crazy
wish i knew how to help
carlsson
Class of '6502
Posts: 5516
Joined: Wed Mar 10, 2004 1:41 am

Post by carlsson »

Albert of Pu-239 sent me a document (or rather notes) written by Aleksi a few years ago. For a while, those notes were published on Aleksi's download area, but he took it away. I'm not sure if I can find my copy, but he had worked out the approximate timing.
Anders Carlsson

Image Image Image Image Image
Boray
Musical Smurf
Posts: 4064
Joined: Mon May 03, 2004 10:47 am

Post by Boray »

Ask the guy who did those crazy robot demos with speech synthesis. I think there was a document included somewhere on how he did something like square waves etc...

/Anders
PRG Starter - a VICE helper / Vic Software (Boray Gammon, SD2IEC music player, Vic Disk Menu, Tribbles, Mega Omega, How Many 8K etc.)
carlsson
Class of '6502
Posts: 5516
Joined: Wed Mar 10, 2004 1:41 am

Post by carlsson »

I still don't know an answer to this question, but I just got the feeling that even VICE somehow emulates this behavior? At least when I play music using my own player (which doesn't have any intended pulsewidth modulation), I get a slightly different pulse wave sound depending on at which timing I start the music, just like one could get on a real VIC-20. After a few notes, the pulse resets to normal.

A bit off-topic, but it seems my current (old) player - without any vibrato, arpeggio or other effects - uses about 16 raster lines if I update all four channels once in each frame. If I spread it out to one channel per frame, making less accurate timing and less tempo control, it seems to max at 8 lines.

The player itself is 310 bytes. After adding load address, Basic stub, IRQ synchronizing and a dummy border flash for approximate raster line count, it ends at 459 bytes. Those things typically go into the main program (demo/game) which would use the music player though.

Song data for the current music assembles as 488 bytes plus load address. I could remove another 2+4 bytes by forcing all channels to restart at end of their tracks. I haven't tried to compose this piece in vic-tracker yet, and somehow I wonder if it would be possible to get even the most optimized and stripped version of the vic-tracker player below 400 bytes?

Edit: I even managed to squeeze in a hard-coded vibrato (one channel) in 26 bytes.
Anders Carlsson

Image Image Image Image Image
carlsson
Class of '6502
Posts: 5516
Joined: Wed Mar 10, 2004 1:41 am

Post by carlsson »

At second thought, I need a way to switch vibrato on and off. On some musics, it adds to the sound, while on other tunes it makes it sound awful.

Some previous examples, all assembled for unexpanded PAL VIC-20:

Action Biker, part cover of Rob Hubbard. The constant vibrato is .. hrm.
Höstvisa, poppy cover of Finnish folk song writer (?) Erna Tauro.
Your Latest Trick, uninspired cover of Dire Straits. This one lacks slide and has some odd rhythms.
Anders Carlsson

Image Image Image Image Image
tlr
Vic 20 Nerd
Posts: 567
Joined: Mon Oct 04, 2004 10:53 am

Post by tlr »

carlsson wrote: A bit off-topic, but it seems my current (old) player - without any vibrato, arpeggio or other effects - uses about 16 raster lines if I update all four channels once in each frame. If I spread it out to one channel per frame, making less accurate timing and less tempo control, it seems to max at 8 lines.
The player itself is 310 bytes. After adding load address, Basic stub, IRQ synchronizing and a dummy border flash for approximate raster line count, it ends at 459 bytes. Those things typically go into the main program (demo/game) which would use the music player though.

Song data for the current music assembles as 488 bytes plus load address. I could remove another 2+4 bytes by forcing all channels to restart at end of their tracks. I haven't tried to compose this piece in vic-tracker yet, and somehow I wonder if it would be possible to get even the most optimized and stripped version of the vic-tracker player below 400 bytes?

Edit: I even managed to squeeze in a hard-coded vibrato (one channel) in 26 bytes.
The victracker tune "blippbloppblopp" takes about 16 raster lines. It has simple arpeggios triggered from the sound. The channels are spread out one per frame, but the playback is pipelined so the timing is not affected.
The player is currently 800 bytes.

The victracker tune "slowride" uses the full player, which takes around 32 raster lines.
The player is 1048 bytes.

The aim of victracker is more sound/feature oriented. If you, for example, don't want arpeggios with the possibility of simultaneous applied portamento on selected steps, or if you need a really, really short player, you should probably not use it.

That said, you can probably make the player a lot shorter by hand optimizing the source you get from vtcomp.

It will always be possible to do a shorter player by making it from scratch by hand like you did. :wink:
Last edited by tlr on Fri Nov 25, 2005 2:21 pm, edited 1 time in total.
carlsson
Class of '6502
Posts: 5516
Joined: Wed Mar 10, 2004 1:41 am

Post by carlsson »

I agree, victracker is really useful in a dedicated music demo or in productions for expanded VIC.
Anders Carlsson

Image Image Image Image Image
corpsicle
Vic 20 Drifter
Posts: 20
Joined: Fri Dec 26, 2014 10:31 am

Re: How to do Pulsewidth modulation?

Post by corpsicle »

What happened to this!?
I want my pulsewidths modulated!
User avatar
darkatx
Vic 20 Afficionado
Posts: 470
Joined: Wed Feb 04, 2009 2:17 pm
Location: Canada

Re: How to do Pulsewidth modulation?

Post by darkatx »

Hurst got the digi-player going on the Vic a few years ago and I recall someone else recorded an actual radio broadcast with playback years before that (sounded really good too).

C-Hacking covers this
http://www.ffd2.com/fridge/chacking/c=hacking20.txt

and this covers the PWM
http://www.ffd2.com/fridge/chacking/ch20addendum.txt

It should be possible to transfer this over to the Vic-20.
Learning all the time... :)
tlr
Vic 20 Nerd
Posts: 567
Joined: Mon Oct 04, 2004 10:53 am

Re: How to do Pulsewidth modulation?

Post by tlr »

corpsicle wrote:What happened to this!?
I want my pulsewidths modulated!
I eventually implemented PWM using this technique here: Datapop!
corpsicle
Vic 20 Drifter
Posts: 20
Joined: Fri Dec 26, 2014 10:31 am

Re: How to do Pulsewidth modulation?

Post by corpsicle »

Wow nice!

But i want it in Victracker. =)

Btw Victracker is amazing.
Im having so much fun with it atm.
Going to release a VT tune on the Edison demoparty in stockholm this summer.
Havent tried compiling anything yet though.
I heard there might be some issues regarding that ?
I dont think they will mind playing the tune in the tracker during the compo so theres no cow on the ice (to use a swedish expression).
tlr
Vic 20 Nerd
Posts: 567
Joined: Mon Oct 04, 2004 10:53 am

Re: How to do Pulsewidth modulation?

Post by tlr »

corpsicle wrote:Btw Victracker is amazing.
Im having so much fun with it atm.
Going to release a VT tune on the Edison demoparty in stockholm this summer.
Havent tried compiling anything yet though.
I heard there might be some issues regarding that ?
I'm glad you like it. Looking forward to hearing your tune!

There could be issues with compiling, I don't remember exactly what. If you have problems with that, pm me and I'll see if I can make it work.
Post Reply