## Copyright (C) 2013 John Ellinger
## 
## This program is free software; you can redistribute it and/or modify
## it under the terms of the GNU General Public License as published by
## the Free Software Foundation; either version 3 of the License, or
## (at your option) any later version.
## 
## This program is distributed in the hope that it will be useful,
## but WITHOUT ANY WARRANTY; without even the implied warranty of
## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
## GNU General Public License for more details.
## 
## You should have received a copy of the GNU General Public License
## along with Octave; see the file COPYING.  If not, see
## <http://www.gnu.org/licenses/>.

## usage: playsamples(samples [, sampleRate, bitDepth] )
## bitDepth values must be 8 or 16

## Author: John Ellinger <je@jemac.mibac.lan>
## Created: 2012-12-27


function playsamples(samples,sampleRate, bitdepth)
	sr = 0;
	bd = 0;
	if (nargin == 1)
		sr = 44100;
		bd = 16;
	elseif (nargin == 3)
		sr = sampleRate;
		bd = bitdepth;	
	else
		usage("playsamples( samples [, sampleRate, bitDepth] )");
	endif
	
	[r, c] = size(samples);
	
	if (r == 1)
		wavwrite(samples', sr, bd, "/tmp/octave_snd.wav");
	elseif (c == 1)
		wavwrite(samples, sr, bd, "/tmp/octave_snd.wav");
	else
		printf('Error: incorrect format for samples.\n');
		return;
	endif

	system("afplay /tmp/octave_snd.wav");
	system("rm -f /tmp/octave_snd.wav");
end
