Marsyas
0.6.0-alpha
|
00001 /* 00002 ** Copyright (C) 1998-2010 George Tzanetakis <gtzan@cs.uvic.ca> 00003 ** 00004 ** This program is free software; you can redistribute it and/or modify 00005 ** it under the terms of the GNU General Public License as published by 00006 ** the Free Software Foundation; either version 2 of the License, or 00007 ** (at your option) any later version. 00008 ** 00009 ** This program is distributed in the hope that it will be useful, 00010 ** but WITHOUT ANY WARRANTY; without even the implied warranty of 00011 ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00012 ** GNU General Public License for more details. 00013 ** 00014 ** You should have received a copy of the GNU General Public License 00015 ** along with this program; if not, write to the Free Software 00016 ** Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 00017 */ 00018 00019 #ifndef MARSYAS_WAVFILESINK_H 00020 #define MARSYAS_WAVFILESINK_H 00021 00022 #include <marsyas/common_header.h> 00023 #include "SoundFileSink.h" 00024 #include "WavFileSource.h" 00025 #include <marsyas/FileName.h> 00026 #include "AbsSoundFileSink.h" 00027 00028 namespace Marsyas 00029 { 00030 struct wavhdr { 00031 char riff[4]; // "RIFF" 00032 signed int file_size; // in bytes 00033 00034 char wave[4]; // "WAVE" 00035 00036 char fmt[4]; // "fmt " 00037 signed int chunk_size; // in bytes (16 for PCM) 00038 signed short format_tag; // 1=PCM, 2=ADPCM, 3=IEEE float, 6=A-Law, 7=Mu-Law 00039 signed short num_chans; // 1=mono, 2=stereo 00040 signed int sample_rate; 00041 signed int bytes_per_sec; 00042 signed short bytes_per_samp; // 2=16-bit mono, 4=16-bit stereo 00043 signed short bits_per_samp; 00044 char data[4]; // "data" 00045 signed int data_length; // in bytes 00046 }; 00047 00052 class WavFileSink: public AbsSoundFileSink 00053 { 00054 private: 00055 wavhdr hdr_; 00056 unsigned long written_; 00057 long fpos_; 00058 00059 short * sdata_; 00060 unsigned char *cdata_; 00061 00062 std::string filename_; 00063 FILE *sfp_; 00064 long sfp_begin_; 00065 mrs_natural nChannels_; 00066 00067 unsigned long ByteSwapLong(unsigned long nLongNumber); 00068 unsigned short ByteSwapShort (unsigned short nValue); 00069 00070 void addControls(); 00071 void myUpdate(MarControlPtr sender); 00072 00073 public: 00074 WavFileSink(std::string name); 00075 ~WavFileSink(); 00076 MarSystem* clone() const; 00077 00078 void putLinear16Swap(realvec& slice); 00079 void putHeader(std::string filename); 00080 bool checkExtension(std::string filename); 00081 void myProcess(realvec& in, realvec& out); 00082 }; 00083 00084 }//namespace Marsyas 00085 00086 #endif /* !MARSYAS_WAVFILESINK_H */ 00087 00088 00089 00090 00091