1 ## Copyright (C) 2000 Paul Kienzle
3 ## This program is free software; you can redistribute it and/or modify
4 ## it under the terms of the GNU General Public License as published by
5 ## the Free Software Foundation; either version 2 of the License, or
6 ## (at your option) any later version.
8 ## This program is distributed in the hope that it will be useful,
9 ## but WITHOUT ANY WARRANTY; without even the implied warranty of
10 ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 ## GNU General Public License for more details.
13 ## You should have received a copy of the GNU General Public License
14 ## along with this program; If not, see <http://www.gnu.org/licenses/>.
16 ## usage: soundsc(x, fs, limit) or soundsc(x, fs, [ lo, hi ])
19 ## Scale the signal so that [min(x), max(x)] -> [-1, 1], then
20 ## play it through the speakers at 8000 Hz sampling rate. The
21 ## signal has one column per channel.
24 ## Scale the signal and play it at sampling rate fs.
26 ## soundsc(x, fs, limit)
27 ## Scale the signal so that [-|limit|, |limit|] -> [-1, 1], then
28 ## play it at sampling rate fs. If fs is empty, then the default
29 ## 8000 Hz sampling rate is used.
31 ## soundsc(x, fs, [ lo, hi ])
32 ## Scale the signal so that [lo, hi] -> [-1, 1], then play it
33 ## at sampling rate fs. If fs is empty, then the default 8000 Hz
34 ## sampling rate is used.
37 ## return the scaled waveform rather than play it.
39 ## See sound for more information.
41 function data_r = soundsc(data, rate, range)
43 if nargin < 1 || nargin > 3, usage("soundsc(x, fs, [lo, hi])") endif
44 if nargin < 2, rate = []; endif
45 if nargin < 3, range = [min(data(:)), max(data(:))]; endif
46 if isscalar(range), range = [-abs(range), abs(range)]; endif
48 data=(data - mean(range))/((range(2)-range(1))/2);
58 %! [x, fs] = auload(file_in_loadpath("sample.wav"));
62 %! [x, fs] = auload(file_in_loadpath("sample.wav"));
64 %!assert (min(y(:)), -1, eps)
65 %!assert (max(y(:)), 1, eps)