ADSR Envelope - formula needed to fade in and out whole, half, quarter, eighth notes (dsp.js)
I am applying an ADSR Envelope to fade in and out notes so I don't hear a pop after each note. I am programming in JavaScript with the Firefox 4 Audio Data API. The dsp.js library I am using (https://github.com/corbanbrook/dsp.js) has a ADSR Envelope function like so: ADSR(attack, decay, sustainLevel, sustain, release, sampleRate) (measured in seconds).
The following sounds pretty good for a quarter note (assuming 120 beats per minute):
var envelope = new ADSR(0.01, 0.1, 0.5, 0.1, 0.2, 44100);
What f开发者_StackOverflow中文版ormula can I use to determine the proper ADSR parameters to apply for a whole, half, quarter, or eighth note?
I am brand new to digital signal processing and I need the calculation to increase/decrease the attack, decay, sustain, and release based on the duration of a note.
I haven't taken piano lessons since junior high, but as I recall the only difference between whole, half, quarter and eight notes is the length you hear the note. So I'd think that you need to adjust the sustain.
If you're happy with the value for the quarter note, double it for a half, double that for a whole, and halve it for an eighth.
You might find that for a more natural sound you want to change some of the other parameters, but I'd guess that you will need to experiment to figure it out. You might find you want to reduce the release time for the eighth note too, but that should be a minor adjustment. Staccato, on the other hand, will need very short release, and possibly short attack too, and possibly higher sustainLevel.
Two handy functions
- SyncToSamples converts from musical time to samples at X sample rate.
- SamplesToSeconds converts as the name suggests.
function SyncToSamples(SyncFactor, BPM, SampleRate: single): single;
begin
result := (SyncFactor * 4) * SampleRate * 60 / BPM;
end;
function SamplesToSeconds(Samples, SampleRate: single): single;
begin
result := Samples / SampleRate;
end;
To calculate the length of
- a whole note use SyncFactor = 1
- a half note use SyncFactor = 1/2
- a quarter note use SyncFactor = 1/4
The above functions can be used to calculate the length of a quarter note in seconds. From there the individual ADSR stage times can be adjusted to meet the time requirement.
As the others have suggested, only adjusting the sustain time with tempo changes will probably sound more natural. Changing the attack, decay and release times will alter the note charactor.
If you want the notes to sound about the same, but only change in duration between quarter, half, eighth notes, etc., then try changing only the sustain time by an amount such that the sum of the attack, decay and sustain times gets doubled, halved, etc. That would roughly correspond to the finger down to finger up time when fingering an instrument.
精彩评论