
function write8( Y, pcmfile );

% write8( Y, pcmfile );
% writes the vector Y into a binary file 'pcmfile' as 8 bit integers.
% All elements of the vector Y are automatically normalized to be within the interval
% [-127, +127]

Y=(2^7-1)*Y/max(abs(Y));    % normalization


if ~isstr( pcmfile )
  error( 'pcmfile must be a string.' );
end

% add default extension
if isempty( findstr( pcmfile, '.' ) )
  pcmfile = [ pcmfile '.pcm' ];
end

fid_out = fopen( pcmfile, 'w', 'ieee-le' );
if ( fid_out == -1 )
  error('Can''t open PCM file for output.');
end

fwrite( fid_out, Y, 'int8' );
fclose( fid_out );


