Hi friends,
I am trying to emulate certain behaviour of the Game Boy sound processor.
I need to have a pulse wave that changes its width every cycle, but I can’t seem to make it work. Here’s what I have so far:
({
var duty, freq, period;
freq = 440;
period = 1/freq;
// Duty cycle to be iterated every period.
duty = Duty.ar(period, 0, Dseq([ 0.12, 0.25, 0.50, 0.75 ], inf));
// Now I create from scratch my pulse wave with DemandEnvGen using the duty values in the duration.
DemandEnvGen.ar(
level: Dseq([ 0, 0, 1, 1 ], inf),
dur: Dseq([ period*duty, 0, period*(1-duty), 0 ], inf)
)
}.plot(8/440, minval: -1.5, maxval: 1.5)
)
As you can see in the plot, it does create a pulse wave, but it doesn’t seem to iterate correctly through the duty values (at all). Plus, it sounds pretty bad if you play it.
Am I doing something wrong? Perhaps 1/freq is just too fast? Can you help me?
Thanks a lot!
♂