view audio/rawpipe.m @ 42:ae596261e75f

Various fixes and development to audio handling
author samer
date Tue, 02 Dec 2014 14:51:13 +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