Home > voicebox > readau.m

readau

PURPOSE ^

READAU Read a SUN .AU format sound file [Y,FS,H]=(FILENAME)

SYNOPSIS ^

function [y,fs,h]=readau(filename,mode)

DESCRIPTION ^

READAU  Read a SUN .AU format sound file [Y,FS,H]=(FILENAME)

 Inputs:
           filename : character string containing filename (default extension .au)
           mode:    't' = trim leading and trailing silences
                    'h' = read header only
             'd'    Look in data directory: voicebox('dir_data')

 Outputs:
           y  : matrix containing one channel per column
           fs : sample frequency
           h  : parameter array:
                h(1) = header length (bytes)
                h(2) = data length (bytes)
                h(3) = data format (see below)
                h(4) = sample rate (Hz)
                h(5) = number of channels

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SOURCE CODE ^

0001 function [y,fs,h]=readau(filename,mode)
0002 %READAU  Read a SUN .AU format sound file [Y,FS,H]=(FILENAME)
0003 %
0004 % Inputs:
0005 %           filename : character string containing filename (default extension .au)
0006 %           mode:    't' = trim leading and trailing silences
0007 %                    'h' = read header only
0008 %             'd'    Look in data directory: voicebox('dir_data')
0009 %
0010 % Outputs:
0011 %           y  : matrix containing one channel per column
0012 %           fs : sample frequency
0013 %           h  : parameter array:
0014 %                h(1) = header length (bytes)
0015 %                h(2) = data length (bytes)
0016 %                h(3) = data format (see below)
0017 %                h(4) = sample rate (Hz)
0018 %                h(5) = number of channels
0019 
0020 %       Copyright (C) Mike Brookes 2008
0021 %      Version: $Id: readau.m 713 2011-10-16 14:45:43Z dmb $
0022 %
0023 %   VOICEBOX is a MATLAB toolbox for speech processing.
0024 %   Home page: http://www.ee.ic.ac.uk/hp/staff/dmb/voicebox/voicebox.html
0025 %
0026 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
0027 %   This program is free software; you can redistribute it and/or modify
0028 %   it under the terms of the GNU General Public License as published by
0029 %   the Free Software Foundation; either version 2 of the License, or
0030 %   (at your option) any later version.
0031 %
0032 %   This program is distributed in the hope that it will be useful,
0033 %   but WITHOUT ANY WARRANTY; without even the implied warranty of
0034 %   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
0035 %   GNU General Public License for more details.
0036 %
0037 %   You can obtain a copy of the GNU General Public License from
0038 %   http://www.gnu.org/copyleft/gpl.html or by writing to
0039 %   Free Software Foundation, Inc.,675 Mass Ave, Cambridge, MA 02139, USA.
0040 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
0041 
0042 
0043 if nargin<2,  mode='0'; end
0044 if any(mode=='d')
0045     filename=fullfile(voicebox('dir_data'),filename);
0046 end
0047 fid=fopen(filename,'rb','b');       % big endian
0048 if fid == -1
0049     fn=[filename,'.au'];
0050     fid=fopen(fn,'rb','l');
0051     if fid ~= -1, filename=fn; end
0052 end
0053 if fid == -1, error('Can''t open %s for input',filename); end
0054 [hdr,n]=fread(fid,6,'int');
0055 if n ~= 6 || hdr(1)~=779316836, error('Can''t read header from AU file %s',filename); end
0056 
0057 if any(mode =='h')
0058     y=hdr(2:6);
0059 else
0060     if nargout>1
0061         fs=hdr(5);
0062         if nargout>2
0063             h=hdr(2:6);
0064         end
0065     end
0066     fseek(fid,hdr(2),-1);
0067     switch hdr(4)
0068         case 1
0069                         y=fread(fid,inf,'uchar');
0070                         y=pcmu2lin(y);
0071                 case 2
0072             y=fread(fid,inf,'schar');
0073         case 3
0074             y=fread(fid,inf,'short');
0075         otherwise
0076             error('Unsupported format type %d in AU file %s',hdr(4),filename);
0077     end
0078     nsamp=length(y);
0079     msamp=floor(nsamp/hdr(6));
0080     y=reshape(y,hdr(6),msamp)';
0081 end
0082 fclose(fid);

Generated on Tue 10-Oct-2017 08:30:10 by m2html © 2003