/*************************************************************************** * Copyright (C) 2004 by Johan Maes - ON4QZ * * on4qz@telenet.be * * http://users.telenet.be/on4qz * * * * This program is free software; you can redistribute it and/or modify * * it under the terms of the GNU General Public License as published by * * the Free Software Foundation; either version 2 of the License, or * * (at your option) any later version. * * * * This program is distributed in the hope that it will be useful, * * but WITHOUT ANY WARRANTY; without even the implied warranty of * * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * * GNU General Public License for more details. * * * * You should have received a copy of the GNU General Public License * * along with this program; if not, write to the * * Free Software Foundation, Inc., * * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * ***************************************************************************/ #ifndef WAVEIO_H #define WAVEIO_H #include //! structure describing the header of a .wav file struct sWave { char chunkID[4]; int chunkSize; char format[4]; char subChunk1ID[4]; int subChunk1Size; short int audioFormat; short int numChannels; unsigned int sampleRate; unsigned int byteRate; short int blockAlign; short int bitsPerSample; char subChunk2ID[4]; int subChunk2Size; }; //! class for accessing .wav files class wavIO { public: wavIO(unsigned int samplingR); ~wavIO(); bool readFile(QString fname,bool ask); bool writeFile(QString fname,bool ask,bool blockMode); bool dumpData(QString fname,bool ask); void createDataArray(unsigned long numSamples); /** if len ==0 then file will be closed */ bool writeData (char *dPtr,int len); unsigned long getNumberOfSamples() { return numberOfSamples; } short int *getDataPointer() { return dataPtr; } unsigned long getIndex() { return dataIndex; } void setIndex(unsigned long i) { dataIndex=i; } short int getData() { return dataPtr[dataIndex++]; } void putData(short int d) { dataPtr[dataIndex++]=d; } double *getdblDataPointer() { return dblDataPtr; } double *toDouble(); void toShort(); private: sWave waveHeader; short int *dataPtr; double *dblDataPtr; unsigned long numberOfSamples; unsigned long dataIndex; unsigned int samplingrate; QFile inopf; void initHeader(); bool writeHeader(); bool checkString(char *str,const char *cstr); }; #endif