blob: e8a34a74cb3d4cc0905930678a4d97d5eec92dca [file] [log] [blame]
Alexandre Lision7c6f4a62013-09-05 13:27:01 -04001## Copyright (C) 2002-2011 Erik de Castro Lopo
2##
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, or (at your option)
6## any later version.
7##
8## This program is distributed in the hope that it will be useful, but
9## WITHOUT ANY WARRANTY; without even the implied warranty of
10## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11## General Public License for more details.
12##
13## You should have received a copy of the GNU General Public License
14## along with this file. If not, write to the Free Software Foundation,
15## 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
16
17## -*- texinfo -*-
18## @deftypefn {Function File} {} sndfile_play (@var{data, fs})
19## Play @var{data} at sample rate @var{fs} using the sndfile-play
20## program.
21## @end deftypefn
22
23## Author: Erik de Castro Lopo <erikd@mega-nerd.com>
24## Description: Play the given data as a sound file
25
26function sndfile_play (data, fs)
27
28if nargin != 2,
29 error ("Need two input arguments: data and fs.") ;
30 endif
31
32if (max (size (fs)) > 1),
33 error ("Second parameter fs must be a single value.") ;
34 endif
35
36[nr nc] = size (data) ;
37
38if (nr > nc),
39 data = data' ;
40 endif
41
42samplerate = fs ;
43wavedata = data ;
44
45filename = tmpnam () ;
46
47cmd = sprintf ("save -mat-binary %s fs data", filename) ;
48
49eval (cmd) ;
50
51cmd = sprintf ("sndfile-play %s", filename) ;
52
53[output, status] = system (cmd) ;
54
55if (status),
56 disp (outout) ;
57 endif
58
59endfunction