home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / octa21fb.zip / octave / SCRIPTS.ZIP / scripts / audio / record.m < prev    next >
Encoding:
Text File  |  1999-11-02  |  2.1 KB  |  75 lines

  1. ## Copyright (C) 1996, 1997 John W. Eaton
  2. ##
  3. ## This file is part of Octave.
  4. ##
  5. ## Octave is free software; you can redistribute it and/or modify it
  6. ## under the terms of the GNU General Public License as published by
  7. ## the Free Software Foundation; either version 2, or (at your option)
  8. ## any later version.
  9. ##
  10. ## Octave is distributed in the hope that it will be useful, but
  11. ## WITHOUT ANY WARRANTY; without even the implied warranty of
  12. ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  13. ## General Public License for more details.
  14. ##
  15. ## You should have received a copy of the GNU General Public License
  16. ## along with Octave; see the file COPYING.  If not, write to the Free
  17. ## Software Foundation, 59 Temple Place - Suite 330, Boston, MA
  18. ## 02111-1307, USA.
  19.  
  20. ## -*- texinfo -*-
  21. ## @deftypefn {Function File} {} record (@var{sec}, @var{sampling_rate})
  22. ## Records @var{sec} seconds of audio input into the vector @var{x}.  The
  23. ## default value for @var{sampling_rate} is 8000 samples per second, or
  24. ## 8kHz.  The program waits until the user types @key{RET} and then
  25. ## immediately starts to record.
  26. ## @end deftypefn
  27.  
  28. ## See also: lin2mu, mu2lin, loadaudio, saveaudio, playaudio, setaudio
  29.  
  30. ## usage:  X = record (sec [, sampling_rate])
  31. ##
  32. ## Records sec seconds of audio into the vector X.
  33. ## The default value for the sampling_rate is 8000, ie. 8kHz.
  34. ## The program waits for you to hit the ENTER key, then the recording
  35. ## starts immediatly.
  36.  
  37. ## Author: AW <Andreas.Weingessel@ci.tuwien.ac.at>
  38. ## Created: 19 September 1994
  39. ## Adapted-By: jwe
  40.  
  41. function X = record (sec, sampling_rate)
  42.  
  43.   if (nargin == 1)
  44.     sampling_rate = 8000;
  45.   elseif (nargin != 2)
  46.     usage ("X = record (sec [, sampling_rate])");
  47.   endif
  48.  
  49.   unwind_protect
  50.  
  51.     file = tmpnam ();
  52.  
  53.     input ("Please hit ENTER and speak afterwards!\n", 1);
  54.  
  55.     cmd = sprintf ("dd if=/dev/dsp of=%s bs=%d count=%d",
  56.                    file, sampling_rate, sec)
  57.  
  58.     system (cmd);
  59.  
  60.     num = fopen (file, "rb");
  61.  
  62.     [Y, c] = fread (num, sampling_rate * sec, "uchar");
  63.  
  64.     fclose (num);
  65.  
  66.   unwind_protect_cleanup
  67.  
  68.     unlink (file);
  69.  
  70.   end_unwind_protect
  71.  
  72.   X = Y - 127;
  73.  
  74. endfunction
  75.