00001 /*---------------------------------------------------------------------------- 00002 MoMu: A Mobile Music Toolkit 00003 Copyright (c) 2010 Nicholas J. Bryan, Jorge Herrera, Jieun Oh, and Ge Wang 00004 All rights reserved. 00005 http://momu.stanford.edu/toolkit/ 00006 00007 Mobile Music Research @ CCRMA 00008 Music, Computing, Design Group 00009 Stanford University 00010 http://momu.stanford.edu/ 00011 http://ccrma.stanford.edu/groups/mcd/ 00012 00013 MoMu is distributed under the following BSD style open source license: 00014 00015 Permission is hereby granted, free of charge, to any person obtaining a 00016 copy of this software and associated documentation files (the 00017 "Software"), to deal in the Software without restriction, including 00018 without limitation the rights to use, copy, modify, merge, publish, 00019 distribute, sublicense, and/or sell copies of the Software, and to 00020 permit persons to whom the Software is furnished to do so, subject to 00021 the following conditions: 00022 00023 The authors encourage users of MoMu to include this copyright notice, 00024 and to let us know that you are using MoMu. Any person wishing to 00025 distribute modifications to the Software is encouraged to send the 00026 modifications to the original authors so that they can be incorporated 00027 into the canonical version. 00028 00029 The Software is provided "as is", WITHOUT ANY WARRANTY, express or implied, 00030 including but not limited to the warranties of MERCHANTABILITY, FITNESS 00031 FOR A PARTICULAR PURPOSE and NONINFRINGEMENT. In no event shall the authors 00032 or copyright holders by liable for any claim, damages, or other liability, 00033 whether in an actino of a contract, tort or otherwise, arising from, out of 00034 or in connection with the Software or the use or other dealings in the 00035 software. 00036 -----------------------------------------------------------------------------*/ 00037 00038 /*----------------------------------------------------------------------------*/ 00049 /*----------------------------------------------------------------------------*/ 00050 00051 #ifndef __MO_IO_H__ 00052 #define __MO_IO_H__ 00053 00054 #include "mo_def.h" 00055 #include <string> 00056 00057 /*----------------------------------------------------------------------------*/ 00067 /*----------------------------------------------------------------------------*/ 00068 class MoAudioFileIn 00069 { 00070 public: 00072 MoAudioFileIn(); 00073 00075 virtual ~MoAudioFileIn(); 00076 00078 virtual bool openFile( const char * fileName, const char * extension, bool raw = FALSE, 00079 bool doNormalize = TRUE, bool generate = true ); 00080 00082 void closeFile(); 00083 00085 void reset(); 00086 00088 /* 00089 for large, incrementally loaded files with integer data types, 00090 normalization is computed relative to the data type maximum. 00091 No normalization is performed for incrementally loaded files 00092 with floating-point data types. */ 00093 void normalize(); 00094 00096 /* 00097 for large, incrementally loaded files with integer data types, 00098 normalization is computed relative to the data type maximum 00099 (peak/maximum). For incrementally loaded files with floating- 00100 point data types, direct scaling by peak is performed. */ 00101 void normalize( SAMPLE peak ); 00102 00104 unsigned long getSize() const; 00105 00107 unsigned int getChannels() const; 00108 00110 /* 00111 WAV, SND, and AIF formatted files specify a sample rate in 00112 their headers. STK RAW files have a sample rate of 22050 Hz 00113 by definition. MAT-files are assumed to have a rate of 44100 Hz. */ 00114 SAMPLE getFileRate() const; 00115 00117 bool isFinished() const; 00118 00120 void setRate( SAMPLE aRate ); 00121 00123 virtual void addTime( SAMPLE aTime ); 00124 00126 00131 void setInterpolate( bool doInterpolate ); 00132 00134 virtual SAMPLE lastOut() const; 00135 00137 virtual SAMPLE tick(); 00138 00140 virtual SAMPLE * tick( SAMPLE * vector, unsigned int vectorSize ); 00141 00143 virtual const SAMPLE * lastFrame() const; 00144 00146 virtual const SAMPLE * tickFrame(); 00147 00149 virtual SAMPLE * tickFrame( SAMPLE *frameVector, unsigned int frames ); 00150 00151 public: // SWAP formerly protected 00152 typedef unsigned long STK_FORMAT; 00153 static const STK_FORMAT STK_SINT8; /* -128 to +127 */ 00154 static const STK_FORMAT STK_SINT16; /* -32768 to +32767 */ 00155 static const STK_FORMAT STK_SINT32; /* -2147483648 to +2147483647. */ 00156 static const STK_FORMAT MY_FLOAT32; /* normalized between plus/minus 1.0. */ 00157 static const STK_FORMAT MY_FLOAT64; /* normalized between plus/minus 1.0. */ 00158 00159 // initialize class variables 00160 void init(); 00161 // read file data 00162 virtual bool readData( unsigned long index ); 00163 // get STK RAW file information 00164 bool getRawInfo( const char *fileName ); 00165 // get WAV file header information 00166 bool getWavInfo( const char *fileName ); 00167 // get SND (AU) file header information 00168 bool getSndInfo( const char *fileName ); 00169 // get AIFF file header information 00170 bool getAifInfo( const char *fileName ); 00171 // get MAT-file header information 00172 bool getMatInfo( const char *fileName ); 00173 00174 // char msg[256]; 00175 const char * m_filename; // chuck data 00176 FILE * fd; 00177 SAMPLE * data; 00178 SAMPLE * lastOutput; 00179 bool chunking; 00180 bool finished; 00181 bool interpolate; 00182 bool byteswap; 00183 unsigned long fileSize; 00184 unsigned long bufferSize; 00185 unsigned long dataOffset; 00186 unsigned int channels; 00187 long chunkPointer; 00188 STK_FORMAT dataType; 00189 SAMPLE fileRate; 00190 SAMPLE gain; 00191 SAMPLE time; 00192 SAMPLE rate; 00193 00194 public: 00195 bool m_loaded; 00196 SAMPLE m_gain; 00197 }; 00198 00199 00200 00201 00202 #endif