ref: 94c87a5b3fb7e94e4a8fdf6151b909f54da031ad
parent: 30922f4f2ba178d03bcde9d18afc9327c73aa742
author: robs <robs>
date: Sun Apr 20 16:31:02 EDT 2008
synth can now sweep linearly (as well as logarithmically)
--- a/ChangeLog
+++ b/ChangeLog
@@ -57,8 +57,9 @@
o New `norm' (normalise) effect. (robs)
o New `delay' effect; delay one or more channels. (robs)
o New `contrast' enhancement effect [FR 708923]. (robs)
- o Fix crash on 64-bit arch. with tempo & key effects. (Sami Liedes)
+ o `synth' can now sweep linearly (as well as logarithmically). (robs)
o Fix synth max. level setting for some output encodings. (robs)
+ o Fix crash on 64-bit arch. with tempo & key effects. (Sami Liedes)
o `gain' alias for the vol effect. (robs)
Other new features:
@@ -77,6 +78,8 @@
be used to override the default audio device driver (rec/play)
and default audio device (all). (robs)
o Simpler file info display for `play'. (robs)
+ o Added example0: simpler example of how to use the libSoX effects
+ chain. (robs)
o Added example2: simple example of how to use libSoX to read an
audio file. (robs)
o For some file-types, warn if file size seems too short. (robs)
--- a/soxeffect.7
+++ b/soxeffect.7
@@ -1223,8 +1223,8 @@
will overwrite channel 1 with channel 2; creating a stereo
file with both channels containing the same audio.
.TP
-\fBsynth\fR [\fIlen\fR] {[\fItype\fR] [\fIcombine\fR] [\fIfreq\fR[\fI\-freq2\fR]] [\fIoff\fR] [\fIph\fR] [\fIp1\fR] [\fIp2\fR] [\fIp3\fR]}
-This effect can be used to generate fixed or linearly swept frequency audio tones
+\fBsynth\fR [\fIlen\fR] {[\fItype\fR] [\fIcombine\fR] [\fIfreq\fR[\fI\-freq2\fR|\fI~freq2\fR]] [\fIoff\fR] [\fIph\fR] [\fIp1\fR] [\fIp2\fR] [\fIp3\fR]}
+This effect can be used to generate fixed or swept frequency audio tones
with various wave shapes, or to generate wide-band noise of various
`colours'.
Multiple synth effects can be cascaded to produce more complex
@@ -1243,7 +1243,7 @@
effect that can has an associated length).
.SP
For example, the following produces a 3 second, 44\*d1\ kHz,
-audio file containing a sine-wave swept linearly from 300 to 3300\ Hz:
+audio file containing a sine-wave swept from 300 to 3300\ Hz:
.EX
sox -n output.au synth 3 sine 300-3300
.EE
@@ -1302,7 +1302,11 @@
.I freq2
is given, then
.I len
-must also have been given.
+must also have been given and the generated tone will be swept between
+the given frequencies. If
+.I freq2
+is preceded with `-', the tone will change by a fixed number of octaves
+per second; if `~', a fixed number of hertz per second.
Not used for noise.
.SP
\fIoff\fR is the bias (DC-offset) of the signal in percent; default=0.
--- a/src/synth.c
+++ b/src/synth.c
@@ -150,6 +150,7 @@
type_t type;
combine_t combine;
double freq, freq2;
+ sox_bool linear_sweep;
double offset, phase;
double p1, p2, p3; /* Use depends on synth type */
@@ -325,9 +326,10 @@
sox_fail("invalid freq");
return SOX_EOF;
}
- if (*char_ptr == '-') { /* freq2 given? */
+ if (*char_ptr == '-' || *char_ptr == '~') { /* freq2 given? */
char *hlp2;
+ chan->linear_sweep = *char_ptr == '~';
chan->freq2 = StringToFreq(char_ptr + 1, &hlp2);
if (chan->freq2 < 0) {
sox_fail("invalid freq2");
@@ -423,9 +425,9 @@
if (synth->samples_to_do <= 0)
f = chan->freq; /* Can't sweep if synth duration is unknown */
- else
- f = chan->freq * exp((log(chan->freq2) - log(chan->freq)) *
- synth->samples_done / synth->samples_to_do);
+ else if (chan->linear_sweep)
+ f = chan->freq + (chan->freq2 - chan->freq) * synth->samples_done / synth->samples_to_do;
+ else f = chan->freq * exp((log(chan->freq2) - log(chan->freq)) * synth->samples_done / synth->samples_to_do);
cycle_period_s = 1 / f;
total_elapsed_time_s = synth->samples_done / rate;
cycle_elapsed_time_s = total_elapsed_time_s - chan->cycle_start_time_s;
@@ -594,7 +596,7 @@
const sox_effect_handler_t *sox_synth_effect_fn(void)
{
static sox_effect_handler_t handler = {
- "synth", "[len] {type [combine] [freq[-freq2] [off [ph [p1 [p2 [p3]]]]]]}",
+ "synth", "[len] {type [combine] [freq[-freq2|~freq2] [off [ph [p1 [p2 [p3]]]]]]}",
SOX_EFF_MCHAN | SOX_EFF_PREC |SOX_EFF_LENGTH,
getopts, start, flow, 0, stop, kill, sizeof(priv_t)
};