node-tonegenerator
node-tonegenerator copied to clipboard
Add control over tone length precision
The current tonegenerator is inconsistent with duration; if you attempt to create 3 tones of different frequencies but the same duration, the 3 tones will have slightly different sample counts. This is undesirable when generating tones for any scenario that requires precise durations.
This PR mostly preserves the current default behavior (rounds the number of cycles to the nearest match) but introduces 2 precise modes:
-
lengthPrecision: 'padextact'- When needed, this will generate 1 cycle less than the target duration, but pad the remaining time with silence to precisely/consistently meet the requested duration.
-
lengthPrecision: 'clipexact'- This will always create tones with a precise/consistent length, but tones may be clipped in the middle of their last cycle. That can produce audio pops in some cases, but ensures that the audible tone duration is exactly as specified.