October 27, 2020

Coding2 - Sounds and Sample

I synthesized a piece of my audio through Maximilian.js, and learned more about other ways to adjust the sample.


1.Sample!

Sample!

In this article, I will start trying to synthesize different waveforms; “samples” are the numbers and values we use to describe between -1 and 1.

We can run the sample values at a certain rate through the speaker. If the rate is fast, the pitch will be high, the rate will be slow, and the pitch will be very low. Another tip is that you can halve the playback speed by playing each sample value twice.

What if we play sample data at a speed of 3/4 (75%). Values between two values may not exist in the array. For example, mySampleArray[1.5] cannot be obtained. So at this time, we can process it through interpolation.

Here, we will create the maxiSample object through the Maximilian library:

var mySample = new maximJs.maxiSample();

Then use the webAudio API method to import audio:

maxiAudio.loadSample('uploaded-sample.wav', mySample);

maxiClock is a simple metronome. BPM can set the playback rate through events that need to be touched every minute. Here is how to set it:

var myClock = new maximJs.maxiClock();
myClock.setTempo(myTempo);
myClock.setTicksPerBeat(2);

In order to take effect in the code correctly, we need to add the maxiClock.ticker() method.

if (myClock.tick) {mySample.trigger();}

Or add other control methods:

if (myClock.tick && myClock.playHead>=100) {mySample.trigger();}

Here is a piece of audio I synthesized:

https://mimicproject.com/code/edd851ca-026b-b2d9-7b96-848f874139e9


There is also a more advanced, Louis demo, which can be controlled by a webcam:

https://mimicproject.com/code/90def343-a896-31d4-d818-20d89b9bc631


About this Post

This post is written by Siqi Shu, licensed under CC BY-NC 4.0.