A while ago, a friend of mine and I wrote a little command line program in python which can take .csv data as an input and create sounds.
We recently discovered p5.js Sound and tone.js and were amazed by its capabilities. I'm especially in favour of p5.js Sound because it gives as the opportunity to easily visualize our sounds as well.
What we want
We want to create custom waveforms. p5.js provides standard waveforms like sine, triangle and so on, but we want to use our own waveforms.
What I tried
I had a look into the p5 sound source code to figure out how the function setType
works. This is what I found.
p5.Oscillator.prototype.setType = function (type) {
this.oscillator.type = type;
};
And this:
/**
* Constructor: <code>new p5.SinOsc()</code>.
* This creates a Sine Wave Oscillator and is
* equivalent to <code> new p5.Oscillator('sine')
* </code> or creating a p5.Oscillator and then calling
* its method <code>setType('sine')</code>.
* See p5.Oscillator for methods.
*
* @class p5.SinOsc
* @constructor
* @extends p5.Oscillator
* @param {Number} [freq] Set the frequency
*/
p5.SinOsc = function (freq) {
p5.Oscillator.call(this, freq, 'sine');
};
p5.SinOsc.prototype = Object.create(p5.Oscillator.prototype);
I thought there might be something like a switch case
case 'sine'
//something
So I searched for something like this in the source code but couldn't find anything.
So now I am completely lost and cannot find any example on custom wave forms. Any ideas or hints on this?