Re: oscillators and the Web Audio API

Hey Phil!

On Wed, Feb 8, 2012 at 11:20 PM, Phil Burk <philburk@mobileer.com> wrote:

> Hello Jussi,
>
>
> On 2/8/12 12:24 PM, Jussi Kalliokoski wrote:
>
>> I think pulse wave can be ditched in favour of pulse width modulation
>> for all waveforms (quite simple actually, I'm doing it in audiolib.js,
>> allows for some really awesome sounds).
>>
>
> I'm not sure I understand the semantics. What is "pulse width modulation"
> if there is no pulse? Is it some form of phase modulation?
>

I'm not sure my semantics are even correct. :) Let me explain, I see the
traditional pulse wave as a pulse width modulated square wave. So
basically, to me, it's compressing one side of the waveform and expanding
the other. To achieve PWM, I've used the following method, maybe it's more
explanatory:

Store the oscillator's real phase (0.0 - 1.0) as a private variable, then
use a modified version of that as the phase variable for the waveforms. Let
p = phase, r = real phase, w = pulse width (0.0 - 1.0, default to 0.5 for
unaltered waveforms)

p = r < w ? r / w : (r-w) / (1-w)

I'd need graphics to explain better but I'm in a bit of a hurry right now,
so maybe later, if I failed to communicate the idea.

PWM for multiple waveforms is also a reasonably common paradigm in trance
synths (although far less common than the triangle pulse wave), for example
if you apply it to a sine wave, you get a very nice and fat core tone for a
bassline or such.


Phase modulation on all waveforms could be handy. Note that in synthesizers
> that do "FM", eg. Yamaha DX7, are typically doing phase modulation. It is
> simpler and sounds as good.
>
>
> > Also, invert sawtooth is quite useful.
>
> Yes. It is really handy when used as an LFO. You can get an inverted
> sawtooth either by using a negative frequency or a negative gain.
>
>
>  Another thing to consider is the waveshape that mistakenly has the same
>> name as pulse wave, it's basically the same as a normal pulse wave,
>> except that it's linear, and hence looks like a triangle wave. The exact
>> algorithm is something like a = p < 0.5 ? p < 0.25 ? p * 8.0 - 1.0 : 1.0
>> - (p - 0.25) * 8 : -1, where a is amplitude (-1.0 - 1.0) and p is phase
>> (0.0 - 1.0).
>>
>
> I'm trying to figure it out. Is this an equivalent?
>
> a = (p < 0.5)
>    ? ( (p < 0.25) ? ((p * 8.0) - 1.0) : (1.0 - ((p - 0.25) * 8)) )
>    : -1,
>
>  p         a
> 0.00     -1.0
> 0.25     +1.0
> 0.5      -1.0
> 0.75     -1.0
>
> So half of it looks like a triangle wave and half is -1.0.  Cool. I'll
> have to try that.
>
> BTW, I forgot and left triangle out of my list.
>
> Phil Burk
>
>

Received on Thursday, 9 February 2012 09:45:06 UTC