#!/usr/bin/perl # Spoob (Spoonm's Orange Box) # Version 1.1 # http://lab.digitol.net/callerid.html # # caller id specs: # http://www.testmark.com/develop/tml_callerid_cnt.html # # This is an intial version written in handful of hours on request # # Written for Lucky225 and TraySmee's H2K2 presentation # And no, I won't try to make you pay for this (caugh SOB caugh) use strict; use constant M_PI => 3.1415926535897932384626433832795029; use Audio::Wav; my $wav = new Audio::Wav; my $debug = 1; my $bits = 8; my $sampleRate = 44100; my $tabsize = 256; my @costab; my @cidData; my @binData; my $length = 0; my $waveFile = './spoob.wav'; print "Spoob v1.0 by spoonm\n"; print "Written for Lucky225 and TraySmee for H2K2\n\n"; if(@ARGV < 6) { print "Month Day Hour Minutes Number Name\n"; exit; } my $month = sprintf('%02d', shift(@ARGV)); my $day = sprintf('%02d', shift(@ARGV)); my $hour = sprintf('%02d', shift(@ARGV)); my $minutes = sprintf('%02d', shift(@ARGV)); my $number = shift(@ARGV); my $name = shift(@ARGV); ## MDMF push(@cidData, 128); push(@binData, dectobin(128)); ## Message Length push(@cidData, 0); # We will change this later push(@binData, dectobin(0)); ## Date Time push(@cidData, 1); push(@binData, dectobin(1)); $length++; ## Date Time Length push(@cidData, length($month . $day . $hour . $minutes)); push(@binData, dectobin(length($month . $day . $hour . $minutes))); $length += length($month . $day . $hour . $minutes) + 1; foreach my $char (split('', $month)) { push(@cidData, ord($char)); push(@binData, dectobin(ord($char))); } foreach my $char (split('', $day)) { push(@cidData, ord($char)); push(@binData, dectobin(ord($char))); } foreach my $char (split('', $hour)) { push(@cidData, ord($char)); push(@binData, dectobin(ord($char))); } foreach my $char (split('', $minutes)) { push(@cidData, ord($char)); push(@binData, dectobin(ord($char))); } ## Number push(@cidData, 2); push(@binData, dectobin(2)); $length++; ## Number Length push(@cidData, length($number)); push(@binData, dectobin(length($number))); $length += length($number) + 1; foreach my $char (split('', $number)) { push(@cidData, ord($char)); push(@binData, dectobin(ord($char))); } ## Name push(@cidData, 7); push(@binData, dectobin(7)); $length++; ## Name Length push(@cidData, length($name)); push(@binData, dectobin(length($name))); $length += length($name) + 1; foreach my $char (split('', $name)) { push(@cidData, ord($char)); push(@binData, dectobin(ord($char))); } ## Set length value $cidData[1] = $length; $binData[1] = dectobin($length); my $checksum = checksum(); push(@cidData, $checksum); push(@binData, dectobin($checksum)); ## My super cool column printy thingy my $midpoint = int((@cidData / 2) + .5); for(my $i = 0; $i < $midpoint ; $i++) { print "$cidData[$i]\t$binData[$i]\t$cidData[$i + $midpoint]\t$binData[$i + $midpoint]\n"; } my $details = { 'bits_sample', $bits, 'sample_rate', $sampleRate, 'channels', 1, }; my $write = $wav->write($waveFile, $details); add_sine(440, .3); add_dtmf(2130, 2750, .08); add_silence(.22); add_sine(1200, .066666); playfsk(); $write->finish(); sub playfsk { foreach my $val (@binData) { add_sine(2200, .00083333333); foreach my $bit (reverse(split('', $val))) { if($bit == 1) { add_sine(1200, .00083333333); } else { add_sine(2200, .00083333333); } } add_sine(1200, .00083333333); } } sub checksum { my $runningTotal = 0; foreach my $val (@cidData) { $runningTotal += $val; } return(256 - ($runningTotal % 256)); } sub dectobin { join '', unpack "B8", pack "S", shift; } sub add_sine { my $hz = shift; my $length = shift; my $pi = M_PI * 2; $length *= $sampleRate; my $max_no = ( 2 ** $bits ) / 2; for my $pos ( 0 .. $length ) { my $time = $pos / $sampleRate; $time *= $hz; my $val = sin $pi * $time; my $samp = $val * $max_no; $write -> write( $samp ); } } sub add_dtmf { my $hz = shift; my $hz2 = shift; my $length = shift; my $pi = M_PI * 2; $length *= $sampleRate; my $max_no = ( 2 ** $bits ) / 2; for my $pos ( 0 .. $length ) { my $time = $pos / $sampleRate; my $time2 = $pos / $sampleRate; $time *= $hz; $time2 *= $hz2; my $val = sin $pi * $time; $val += sin $pi * $time2; $val /= 2; my $samp = $val * $max_no; $write->write($samp); } } sub add_silence { my $length = shift; my $pi = M_PI * 2; $length *= $sampleRate; for my $pos ( 0 .. $length ) { my $samp = 0; $write->write($samp); } }