%DIAL.M synthesizes sound to make a phone-call. 
% Example Usage: 
%    dial('123-456-7789');

function dial(number_str)
   [tmp len] = size(number_str);
   for i=1:len
      c = number_str(i);
      if c>='1' && c<='9' 
         idx = c-'0';
      elseif c=='*'
         idx = 10;
      elseif c=='0'
         idx = 11;
      elseif c=='#'
         idx = 12;
      else
         idx = 0; % Nop
      end
      SoundOne(idx);
   end
end

function SoundOne(idx)
   % Buttons 1 2 3 4 5 6 7 8 9 * 0 # 
   Frequency_L = [697 697 697 770 770 770 852 852 852 941 941 941];
   Frequency_H = [1209 1336 1477 1209 1336 1477 1209 1336 1477 1209 1336 1477];

   Fs = 8192; % Sample Rate
   TimeLen = 1/3; % TimeLength

   if idx~=0
      x = 1:Fs*TimeLen/2; % Sound for TimeLength/2
      y_L = sin(2*3.14159265/(1/Frequency_L(idx)*Fs)*x);
      y_H = sin(2*3.14159265/(1/Frequency_H(idx)*Fs)*x);
      y = (y_L+y_H)/2;
      sound(y, Fs);
   end
   pause(TimeLen);
end