view audio/rawpipe.m @ 6:0ce3c2070089

Removed duplicate code and fixed doc in timed_action.
author samer
date Mon, 14 Jan 2013 14:33:37 +0000
parents 672052bd81f8
children 62e31e7980e6
line wrap: on
line source
% rawpipe - pipe reader implementation of sndstream (raw audio stream)
%
% rawpipe ::
%    string     ~'shell pipe',
%    AudioFormat~'stream format',
%    options {
%       channels :: natural/nan ~'desired number of channels';
%       rate     :: nonneg/nan ~'desired sampling rate';
%       bits     :: natural/16 ~'desired bits per sample';
%    }
% -> signal(C,R).
%
% If channels or rate are not nan, audio format will be converted to match.
% If either of them are nan, the corresponding value from the audio file will
% be left unchanged.
function s=rawpipe(cmd,fmt,varargin)
	s=sndstream(@pipestream,'stringfn',@()sprintf('rawpipe(''%s'')',cmd),varargin{:});

	function [str,cleanup]=pipestream(q)
		[str,cleanup]=pipein(cmd,q);
		str=javax.sound.sampled.AudioInputStream(str,fmt,-1);
	end
end