-
Notifications
You must be signed in to change notification settings - Fork 0
Sample Editing
This page contains information about techniques that manipulate a sample's raw sound data. For information about other aspects of using samples (including configuring loops) see Sampled Instruments.
Some methods modify the sample "in place", that is, they overwrite the previous sample data, while others leave the original sample unchanged and return a new Synth.Sample
object.
Category | Applies To |
---|---|
Modification in place |
amplify() , normalize() , removeOffset() , reverse() , separateStereo()
|
Returns a new sample |
clone() , copy() , mixToMono() , pingPong() , remove()
|
Returns a promise resolving to a new sample |
chord() , insert() , mix()
|
Returns some other value |
amplitude() , findZero()
|
Modify buffer directly / Replace buffer | buffer |
mySample.amplify(gain);
If gain
is greater than 1 then the sample's volume is increased (using a linear scale) and if gain
is less than 1 then the sample's volume is decreased. amplify()
modifies the raw sound samples. The playback volume can also be altered without modifying the sample data by setting the Sample
object's gain
property.
mySample.removeOffset();
To reverse a sample:
mySample.reverse();
To create a new sample that has the sound of the original sample followed by a reversed copy:
newSample = mySample.pingPong();
mySample.reverse(from, to);
where from
and to
are offsets measured in numbers of individual sampling points.
Half as wide:
mySample.separateStereo(0.5);
Twice as wide:
mySample.separateStereo(2);
Values that are too large will cause clipping.
mySample.separateStereo(-1);
newSample = mySample.clone();
newSample = mySample.copy(from, to);
from
and to
are measured in sample points.
newSample = mySample.remove(from, to);
The new sample is a copy of the original sample but with the relevant section removed. The original sample is unaffected. from
and to
are measured in sample points.
mySample.insert(otherSample, position).then(function (newSample) {
...
});
A new sample is created by combining the original sample and the other sample. The original sample is unaltered. position
is measured in sample points.
Because the synthesizer system has a limited number of sound channels, it's useful to be able to mix a sample with pitch shifted versions of itself so that a chord pattern can be played with a single playback instruction. For example, to create a new sample that plays a chord with 0.6 cents/semitone of stretched tuning:
mySample.chord([1, 5, 8], system.getNotes(0.6)).then(function (newSample) {
...
});
This creates chords with a bass note, a second note four semitones higher than the bass note, and a third note seven semitones higher than the bass note. It's a good idea to normalize the instrument after creating chords to prevent distorted playback.
mySample.mix(otherSample, position, loop).then(function (newSample) {
...
});
position
is measured in sample points and determines when otherSample
should begin playing into the mix. loop
is true
or false
and determines whether or not otherSample
will loop over until the end of mySample
is reached.
peakAmplitude = mySample.amplitude();
peakAmplitude = mySample.amplitude(from, to);
from
and to
are measured in sample points.
nearestMinimum = mySample.findZero(targetPosition, channelNumber);
This finds the closest position to targetPosition
where the sample waveform crosses the x-axis. The position that it computes may come before or after the original target. This method is useful for finding good positions to start and end a loop at to avoid creating a loud clicking sound each time the loop repeats.
Simple reversal:
myInstrument.reverse();
Ping pong variant:
myInstrument.pingPong();
myInstrument.normalize();
The instrument's samples will be amplified so that the peak amplitude (across all samples) becomes 1. It's a good idea to call removeOffset()
first before normalizing.