1b815c7f3Sopenharmony_ci## Copyright (C) 2002-2011  Erik de Castro Lopo
2b815c7f3Sopenharmony_ci##
3b815c7f3Sopenharmony_ci## This program is free software; you can redistribute it and/or modify
4b815c7f3Sopenharmony_ci## it under the terms of the GNU General Public License as published by
5b815c7f3Sopenharmony_ci## the Free Software Foundation; either version 2, or (at your option)
6b815c7f3Sopenharmony_ci## any later version.
7b815c7f3Sopenharmony_ci##
8b815c7f3Sopenharmony_ci## This program is distributed in the hope that it will be useful, but
9b815c7f3Sopenharmony_ci## WITHOUT ANY WARRANTY; without even the implied warranty of
10b815c7f3Sopenharmony_ci## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
11b815c7f3Sopenharmony_ci## General Public License for more details.
12b815c7f3Sopenharmony_ci##
13b815c7f3Sopenharmony_ci## You should have received a copy of the GNU General Public License
14b815c7f3Sopenharmony_ci## along with this file.  If not, write to the Free Software Foundation,
15b815c7f3Sopenharmony_ci## 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
16b815c7f3Sopenharmony_ci
17b815c7f3Sopenharmony_ci## -*- texinfo -*-
18b815c7f3Sopenharmony_ci## @deftypefn {Function File} {} sndfile_save (@var{filename, data, fs})
19b815c7f3Sopenharmony_ci## Save the given @var{data} as audio data to the given at @var{fs}. Set
20b815c7f3Sopenharmony_ci## the sample rate to @var{fs}.
21b815c7f3Sopenharmony_ci## @end deftypefn
22b815c7f3Sopenharmony_ci
23b815c7f3Sopenharmony_ci## Author: Erik de Castro Lopo <erikd@mega-nerd.com>
24b815c7f3Sopenharmony_ci## Description: Save data as a sound file
25b815c7f3Sopenharmony_ci
26b815c7f3Sopenharmony_cifunction sndfile_save (filename, data, fs)
27b815c7f3Sopenharmony_ci
28b815c7f3Sopenharmony_ciif nargin != 3,
29b815c7f3Sopenharmony_ci	error ("Need three input arguments: filename, data and fs.") ;
30b815c7f3Sopenharmony_ci	endif
31b815c7f3Sopenharmony_ci
32b815c7f3Sopenharmony_ciif (! isstr (filename)),
33b815c7f3Sopenharmony_ci	error ("First parameter 'filename' is must be a string.") ;
34b815c7f3Sopenharmony_ci	endif
35b815c7f3Sopenharmony_ci
36b815c7f3Sopenharmony_ciif (max (size (fs)) > 1),
37b815c7f3Sopenharmony_ci	error ("Second parameter 'fs' must be a single value, not an array or matrix.") ;
38b815c7f3Sopenharmony_ci	endif
39b815c7f3Sopenharmony_ci
40b815c7f3Sopenharmony_ci[nr nc] = size (data) ;
41b815c7f3Sopenharmony_ci
42b815c7f3Sopenharmony_ciif (nr > nc),
43b815c7f3Sopenharmony_ci	data = data' ;
44b815c7f3Sopenharmony_ci	endif
45b815c7f3Sopenharmony_ci
46b815c7f3Sopenharmony_cisamplerate = fs ;
47b815c7f3Sopenharmony_ciwavedata = data ;
48b815c7f3Sopenharmony_ci
49b815c7f3Sopenharmony_cistr = sprintf ("save -mat-binary %s samplerate wavedata", filename) ;
50b815c7f3Sopenharmony_ci
51b815c7f3Sopenharmony_cieval (str) ;
52b815c7f3Sopenharmony_ci
53b815c7f3Sopenharmony_ciendfunction
54