From c93d500bddf1ce86ba7df1599277d2921287950b Mon Sep 17 00:00:00 2001 From: "B. Watson" Date: Mon, 8 Apr 2024 18:56:08 -0400 Subject: soxdial: add --random option. --- soxdial | 32 ++++++++++++++++++++++++++------ 1 file changed, 26 insertions(+), 6 deletions(-) diff --git a/soxdial b/soxdial index e07b752..6bd23d1 100755 --- a/soxdial +++ b/soxdial @@ -69,6 +69,13 @@ Set the bits per sample. Default is 8. The only other choice is 16. as signed. If this option is used, it B occur on the command line B any dial string. +=item B<-X>, B<--random> + +Randomize the timing. Digit length (B<-l>), inter-digit timing +(B<-d>), and the comma (B<-c>) will vary from 1x to 2x the amount +specified. This does a pretty good impression of a human dialling a +number manually. + =item B<-S>, B<--stereo> Output stereo audio. The left and right channels will contain the same @@ -125,17 +132,17 @@ dial strings, until the same option is seen again. =item B<-l>, B<--length> [ I | IB ] Sets the time each digit's tones are played. Default is 0.25 -or 250ms. +or 250ms. Can be randomized with B<-X>, B<--random>. =item B<-d> I, B<--delay> [ I | IB ] Sets the delay between consecutive digits. Default is 0.1 -or 100ms. +or 100ms. Can be randomized with B<-X>, B<--random>. =item B<-c> I, B<--comma> [ I | IB ] Sets the delay added by commas in the dial strings. Default is 0.5 -or 500ms. +or 500ms. Can be randomized with B<-X>, B<--random>. =item B<-x>, B<--extended> @@ -268,6 +275,15 @@ sub letter2number { return $ret; } +sub randomize { + my $time = shift; + return $time unless $random; + + my $newtime = $time * (rand() + 1); + warn "$SELF: randomized $time to $newtime.\n" if $verbose; + return $newtime; +} + # sox -n -d synth 0.25 sine 697 sine 1209 sine 770 sine 1477 delay 0 0 .35 .35 remix - # ...plays DTMF 1 and 6, for 0.25 sec each, with a 0.10 sec delay between them. @@ -279,7 +295,7 @@ sub add_digit { push @freqs2, 0; push @delays, $time; - $time += $pausetime; + $time += randomize($pausetime); } else { #print "time $time\n"; #print "freq1 " . ($freqs{$d}->[0]) . "\n"; @@ -287,10 +303,11 @@ sub add_digit { push @freqs1, ($freqs{$d}->[0]); push @freqs2, ($freqs{$d}->[1]); + push @delays, $time; - $time += $digittime; - $time += $intertime; + $time += randomize($digittime); + $time += randomize($intertime); } warn "$SELF: added digit '$d', time now $time\n" if $verbose; } @@ -493,6 +510,9 @@ for ($argc = 0; $argc < @ARGV; $argc++) { } elsif(/^--?(?:R|right)$/) { $left = 0; $stereo = $right = 1; + } elsif(/^--?(?:X|random)$/) { + # sorry I had to use -X for this, -R was already taken. + $random = 1; } else { warn "$SELF: start dial string '$_'\n" if $verbose; for (split "", $_) { -- cgit v1.2.3