The Disintegrator – Random Project Idea Realized


Volume:
Distortion Level - 0
Load any track (give it a second to load fully) and listen to it disintegrate. Works well in Chrome but may have issues in Firefox

A few days ago I posted this random idea to Twitter

So naturally I went ahead and built a reasonable approximation using my new Web Audio API powers.

The Web Audio API has a built-in module for creating distortion modules called createWaveShaper which takes two optional attributes- curve and overSample. A null value for curve applies no distortion, whereas an array containing a distortion curve function (like this onelook at distortion curve equations you can see page 74 of this PDF for an equation and matlab implementation.

Creating the waveShaper node is easily accomplished just by calling the createWaveShaper method

VolumeSample.distNode = context.createWaveShaper();

This creates a waveShaper node with a null value for curve. We can add a distortion curve by calling it with the curve attribute.

VolumeSample.distNode.curve = makeDistortionCurve(50);

(where makeDistortionCurve is from the code linked above)

We can then use setInterval to update the curve every 1000 milliseconds to increase the distortion.

setInterval(update,1000);
function update(){

VolumeSample.distNode.curve = makeDistortionCurve(updateIndex++);
}

We then chain our nodes together to connect the source to the destination

source.connect(this.distNode);
 this.distNode.connect(this.gNode);
 this.gNode.connect(context.destination);

Try it out for yourself. Load any track (give it a second to load fully) and listen to it disintegrate. Now I wonder what Michael Gordon’s ‘Industry’ would sound like?
UPDATE: It sounds great!

Javascript Source Code Here

Share this post
  , , , , , , , ,


4 thoughts on “The Disintegrator – Random Project Idea Realized

  1. I’m having a bizarre issue…when I try to load some longer classical pieces, what comes out is the first two seconds of “And Your Bird Can Sing” by the Beatles. I swear I am not making this up. I have no idea what it could be.

    • Oh actually that’s the default audio snippet that loads with the page to load something into the buffer. With longer tracks it takes a while to load the new buffer. I guess a ‘loading’ progress message would be good!

  2. Distortion level might be better off as a percentage indicator. I have no idea how progressed a ‘distortion level’ of 200 is, but that’s where my song ended.

    • I’m hoping to change that pretty soon actually. Right now the distortion level is the variable of the equation that controls the shape of the distortion curve, but it would definitely be better to have the distortion vary proportional to the length of the song (so shorter songs would still hit the ‘full distortion’ level) so a percentage would be the correct way to reflect that!

Leave a Reply

Your email address will not be published. Required fields are marked *