# HG changeset patch # User Mike Miller # Date 1423375772 18000 # Node ID 0f557da98f5b774e0941ee9d0ff77f499932c8f9 # Parent f4361ca47463b67ac6de151a133bebfad4ecbcc4 record.m: Overhaul function. * record.m: Rewrite as a simple wrapper around audiorecorder. Rewrite docstring. Add seealso link to audiorecorder. Add %!assert (1) to mark function as not needing tests. diff -r f4361ca47463 -r 0f557da98f5b scripts/audio/record.m --- a/scripts/audio/record.m Sat Feb 07 21:48:35 2015 -0800 +++ b/scripts/audio/record.m Sun Feb 08 01:09:32 2015 -0500 @@ -1,3 +1,4 @@ +## Copyright (C) 2015 Mike Miller ## Copyright (C) 1995-2013 John W. Eaton ## ## This file is part of Octave. @@ -17,50 +18,33 @@ ## . ## -*- texinfo -*- -## @deftypefn {Function File} {} record (@var{sec}, @var{sampling_rate}) -## Record @var{sec} seconds of audio input into the vector @var{x}. The -## default value for @var{sampling_rate} is 8000 samples per second, or -## 8kHz. The program waits until the user types @key{RET} and then -## immediately starts to record. -## @seealso{lin2mu, mu2lin} +## @deftypefn {Function File} {} record (@var{sec}) +## @deftypefnx {Function File} {} record (@var{sec}, @var{fs}) +## Record @var{sec} seconds of audio from the system's default audio input at +## a sampling rate of 8000 samples per second. If the optional argument +## @var{fs} is given, it specifies the sampling rate for recording. +## +## For more control over audio recording, use the @code{audiorecorder} class. +## @seealso{@audiorecorder/audiorecorder} ## @end deftypefn -## Author: AW -## Created: 19 September 1994 -## Adapted-By: jwe - -function X = record (sec, sampling_rate) +function x = record (sec, fs) if (nargin == 1) - sampling_rate = 8000; + fs = 8000; elseif (nargin != 2) print_usage (); endif - unwind_protect - - file = tempname (); - - input ("Please hit ENTER and speak afterwards!\n", 1); - - cmd = sprintf ("dd if=/dev/dsp of=\"%s\" bs=%d count=%d", - file, sampling_rate, sec); - - system (cmd); + rec = audiorecorder (fs, 16, 1); - num = fopen (file, "rb"); - - [Y, c] = fread (num, sampling_rate * sec, "uchar"); - - fclose (num); + recordblocking (rec, sec); - unwind_protect_cleanup - - unlink (file); - - end_unwind_protect - - X = Y - 127; + x = getaudiodata (rec); endfunction + +## No test possible for recording audio. +%!assert (1) +