Blame Octave/sndfile_save.m

Packit Service 17f94a
## Copyright (C) 2002-2011  Erik de Castro Lopo
Packit Service 17f94a
##
Packit Service 17f94a
## This program is free software; you can redistribute it and/or modify
Packit Service 17f94a
## it under the terms of the GNU General Public License as published by
Packit Service 17f94a
## the Free Software Foundation; either version 2, or (at your option)
Packit Service 17f94a
## any later version.
Packit Service 17f94a
##
Packit Service 17f94a
## This program is distributed in the hope that it will be useful, but
Packit Service 17f94a
## WITHOUT ANY WARRANTY; without even the implied warranty of
Packit Service 17f94a
## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
Packit Service 17f94a
## General Public License for more details.
Packit Service 17f94a
##
Packit Service 17f94a
## You should have received a copy of the GNU General Public License
Packit Service 17f94a
## along with this file.  If not, write to the Free Software Foundation,
Packit Service 17f94a
## 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
Packit Service 17f94a
Packit Service 17f94a
## -*- texinfo -*-
Packit Service 17f94a
## @deftypefn {Function File} {} sndfile_save (@var{filename, data, fs})
Packit Service 17f94a
## Save the given @var{data} as audio data to the given at @var{fs}. Set
Packit Service 17f94a
## the sample rate to @var{fs}.
Packit Service 17f94a
## @end deftypefn
Packit Service 17f94a
Packit Service 17f94a
## Author: Erik de Castro Lopo <erikd@mega-nerd.com>
Packit Service 17f94a
## Description: Save data as a sound file
Packit Service 17f94a
Packit Service 17f94a
function sndfile_save (filename, data, fs)
Packit Service 17f94a
Packit Service 17f94a
if nargin != 3,
Packit Service 17f94a
	error ("Need three input arguments: filename, data and fs.") ;
Packit Service 17f94a
	endif
Packit Service 17f94a
Packit Service 17f94a
if (! isstr (filename)),
Packit Service 17f94a
	error ("First parameter 'filename' is must be a string.") ;
Packit Service 17f94a
	endif
Packit Service 17f94a
Packit Service 17f94a
if (max (size (fs)) > 1),
Packit Service 17f94a
	error ("Second parameter 'fs' must be a single value, not an array or matrix.") ;
Packit Service 17f94a
	endif
Packit Service 17f94a
Packit Service 17f94a
[nr nc] = size (data) ;
Packit Service 17f94a
Packit Service 17f94a
if (nr > nc),
Packit Service 17f94a
	data = data' ;
Packit Service 17f94a
	endif
Packit Service 17f94a
Packit Service 17f94a
samplerate = fs ;
Packit Service 17f94a
wavedata = data ;
Packit Service 17f94a
Packit Service 17f94a
str = sprintf ("save -mat-binary %s samplerate wavedata", filename) ;
Packit Service 17f94a
Packit Service 17f94a
eval (str) ;
Packit Service 17f94a
Packit Service 17f94a
endfunction