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_play (@var{data, fs}) 19b815c7f3Sopenharmony_ci## Play @var{data} at sample rate @var{fs} using the sndfile-play 20b815c7f3Sopenharmony_ci## program. 21b815c7f3Sopenharmony_ci## @end deftypefn 22b815c7f3Sopenharmony_ci 23b815c7f3Sopenharmony_ci## Author: Erik de Castro Lopo <erikd@mega-nerd.com> 24b815c7f3Sopenharmony_ci## Description: Play the given data as a sound file 25b815c7f3Sopenharmony_ci 26b815c7f3Sopenharmony_cifunction sndfile_play (data, fs) 27b815c7f3Sopenharmony_ci 28b815c7f3Sopenharmony_ciif nargin != 2, 29b815c7f3Sopenharmony_ci error ("Need two input arguments: data and fs.") ; 30b815c7f3Sopenharmony_ci endif 31b815c7f3Sopenharmony_ci 32b815c7f3Sopenharmony_ciif (max (size (fs)) > 1), 33b815c7f3Sopenharmony_ci error ("Second parameter fs must be a single value.") ; 34b815c7f3Sopenharmony_ci endif 35b815c7f3Sopenharmony_ci 36b815c7f3Sopenharmony_ci[nr nc] = size (data) ; 37b815c7f3Sopenharmony_ci 38b815c7f3Sopenharmony_ciif (nr > nc), 39b815c7f3Sopenharmony_ci data = data' ; 40b815c7f3Sopenharmony_ci endif 41b815c7f3Sopenharmony_ci 42b815c7f3Sopenharmony_cisamplerate = fs ; 43b815c7f3Sopenharmony_ciwavedata = data ; 44b815c7f3Sopenharmony_ci 45b815c7f3Sopenharmony_cifilename = tmpnam () ; 46b815c7f3Sopenharmony_ci 47b815c7f3Sopenharmony_cicmd = sprintf ("save -mat-binary %s fs data", filename) ; 48b815c7f3Sopenharmony_ci 49b815c7f3Sopenharmony_cieval (cmd) ; 50b815c7f3Sopenharmony_ci 51b815c7f3Sopenharmony_cicmd = sprintf ("sndfile-play %s", filename) ; 52b815c7f3Sopenharmony_ci 53b815c7f3Sopenharmony_ci[output, status] = system (cmd) ; 54b815c7f3Sopenharmony_ci 55b815c7f3Sopenharmony_ciif (status), 56b815c7f3Sopenharmony_ci disp (outout) ; 57b815c7f3Sopenharmony_ci endif 58b815c7f3Sopenharmony_ci 59b815c7f3Sopenharmony_ciendfunction 60