comparison scripts/audio/record.m @ 19717:f96671da51a6

record.m: Improve input validation * record.m: Improve input validation. Avoid attempting to record for zero duration. Add %!tests.
author Mike Miller <mtmiller@ieee.org>
date Sun, 08 Feb 2015 23:24:45 -0500
parents 890ff06d84ce
children 4197fc428c7d
comparison
equal deleted inserted replaced
19716:c2478360291f 19717:f96671da51a6
33 fs = 8000; 33 fs = 8000;
34 elseif (nargin != 2) 34 elseif (nargin != 2)
35 print_usage (); 35 print_usage ();
36 endif 36 endif
37 37
38 rec = audiorecorder (fs, 16, 1); 38 if (! (isscalar (sec) && (sec >= 0)))
39 error ("record: recording duration SEC must be a non-negative number");
40 endif
39 41
40 recordblocking (rec, sec); 42 if (! (isscalar (fs) && (fs > 0)))
43 error ("record: sample rate FS must be a positive number");
44 endif
41 45
42 x = getaudiodata (rec); 46 x = [];
47
48 if (sec > 0)
49
50 rec = audiorecorder (fs, 16, 1);
51
52 recordblocking (rec, sec);
53
54 x = getaudiodata (rec);
55
56 endif
43 57
44 endfunction 58 endfunction
45 59
46 60
47 ## No test possible for recording audio. 61 ## Tests of record must not actually record anything.
48 %!assert (1)
49 62
63 %!assert (isempty (record (0)))
64
65 %% Test input validation
66 %!error record ()
67 %!error record (1,2,3)
68 %!error record (-1)
69 %!error record (1, -1)
70