How to do Pulsewidth modulation?
Moderator: Moderators
How to do Pulsewidth modulation?
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?
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?
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
/Anders
PRG Starter - a VICE helper / Vic Software (Boray Gammon, SD2IEC music player, Vic Disk Menu, Tribbles, Mega Omega, How Many 8K etc.)
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.
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
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.
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
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.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 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.
Last edited by tlr on Fri Nov 25, 2005 2:21 pm, edited 1 time in total.
Re: How to do Pulsewidth modulation?
What happened to this!?
I want my pulsewidths modulated!
I want my pulsewidths modulated!
Re: How to do Pulsewidth modulation?
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.
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...
Re: How to do Pulsewidth modulation?
I eventually implemented PWM using this technique here: Datapop!corpsicle wrote:What happened to this!?
I want my pulsewidths modulated!
Re: How to do Pulsewidth modulation?
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).
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).
Re: How to do Pulsewidth modulation?
I'm glad you like it. Looking forward to hearing your tune!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 ?
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.