home *** CD-ROM | disk | FTP | other *** search
/ PC Welt 2004 March / PCWELT_3_2004.ISO / pcwsoft / flaskmpeg_078_39_src.z.exe / flaskmpeg / Audio / WaveOutput.h < prev   
Encoding:
C/C++ Source or Header  |  2002-10-28  |  4.4 KB  |  150 lines

  1. /* 
  2.  *  WaveOutput.h 
  3.  *         Original code by Timothy J. Weber.
  4.  *
  5.  *    Copyright (C) Alberto Vigata - January 2000 - ultraflask@yahoo.com
  6.  *
  7.  *  This file is part of FlasKMPEG, a free MPEG to MPEG/AVI converter
  8.  *    
  9.  *  FlasKMPEG is free software; you can redistribute it and/or modify
  10.  *  it under the terms of the GNU General Public License as published by
  11.  *  the Free Software Foundation; either version 2, or (at your option)
  12.  *  any later version.
  13.  *   
  14.  *  FlasKMPEG is distributed in the hope that it will be useful,
  15.  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
  16.  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  17.  *  GNU General Public License for more details.
  18.  *   
  19.  *  You should have received a copy of the GNU General Public License
  20.  *  along with GNU Make; see the file COPYING.  If not, write to
  21.  *  the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. 
  22.  *
  23.  */
  24.  
  25. #ifndef __WAVE_H
  26. #define __WAVE_H
  27.  
  28. /* Headers required to use this module */
  29. #include <stdio.h>
  30. #include "rifffile.h"
  31.  
  32. /***************************************************************************
  33.     macros, constants, and enums
  34. ***************************************************************************/
  35.  
  36. /***************************************************************************
  37.     typedefs, structs, classes
  38. ***************************************************************************/
  39.  
  40. class WaveFile
  41. {
  42. public:
  43.     WaveFile();
  44.     ~WaveFile();
  45.  
  46.     bool OpenRead(const char* name);
  47.     bool OpenWrite(const char* name);
  48.     bool Write(const char* data, unsigned int dataCount);
  49.     bool ResetToStart();
  50.     bool Close();
  51.  
  52.     unsigned short GetFormatType() const
  53.         { return formatType; };
  54.     void SetFormatType(unsigned short type)
  55.         { formatType = type; changed = true; };
  56.     bool IsCompressed() const
  57.         { return formatType != 1; };
  58.  
  59.     unsigned short GetNumChannels() const
  60.         { return numChannels; };
  61.     void SetNumChannels(unsigned short num)
  62.         { numChannels = num; changed = true; };
  63.  
  64.     unsigned long GetSampleRate() const
  65.         { return sampleRate; };
  66.     void SetSampleRate(unsigned long rate)
  67.         { sampleRate = rate; changed = true; };
  68.  
  69.     unsigned long GetBytesPerSecond() const
  70.         { return bytesPerSecond; };
  71.     void SetBytesPerSecond(unsigned long bytes)
  72.         { bytesPerSecond = bytes; changed = true; };
  73.  
  74.     unsigned short GetBytesPerSample() const
  75.         { return bytesPerSample; };
  76.     void SetBytesPerSample(unsigned short bytes)
  77.         { bytesPerSample = bytes; changed = true; };
  78.  
  79.     unsigned short GetBitsPerChannel() const
  80.         { return bitsPerChannel; };
  81.     void SetBitsPerChannel(unsigned short bits)
  82.         { bitsPerChannel = bits; changed = true; };
  83.  
  84.     unsigned long GetNumSamples() const
  85.         { return (GetBytesPerSample())?
  86.             GetDataLength() / GetBytesPerSample(): 0; };
  87.     void SetNumSamples(unsigned long num)
  88.         { SetDataLength(num * GetBytesPerSample()); };
  89.  
  90.     float GetNumSeconds() const
  91.         { return GetBytesPerSecond()?
  92.             float(GetDataLength()) / GetBytesPerSecond(): 0; };
  93.  
  94.     unsigned long GetDataLength() const
  95.         { return dataLength; };
  96.     void SetDataLength(unsigned long numBytes)
  97.         { dataLength = numBytes; changed = true; };
  98.  
  99.     bool FormatMatches(const WaveFile& other);
  100.  
  101.     void CopyFormatFrom(const WaveFile& other);
  102.  
  103.     FILE* GetFile()
  104.         { return readFile? readFile->filep(): writeFile; };
  105.  
  106.     RiffFile* GetRiffFile()
  107.         { return readFile? readFile : 0; };
  108.  
  109.     bool WriteHeaderToFile(FILE* fp);
  110.  
  111.     bool GetFirstExtraItem(std::string& type, std::string& value);
  112.     bool GetNextExtraItem(std::string& type, std::string& value);
  113.  
  114.     bool CopyFrom(WaveFile& other);
  115.  
  116.     const char* GetError() const
  117.         { return error; };
  118.     void ClearError()
  119.         { error = 0; };
  120.  
  121. protected:
  122.     RiffFile* readFile;
  123.     FILE* writeFile;
  124.  
  125.     unsigned short formatType;
  126.     unsigned short numChannels;
  127.     unsigned long sampleRate;
  128.     unsigned long bytesPerSecond;
  129.     unsigned short bytesPerSample;
  130.     unsigned short bitsPerChannel;
  131.     unsigned long dataLength;
  132.  
  133.     const char* error;
  134.     bool changed;  // true if any parameters changed since the header was last written
  135. };
  136.  
  137. /***************************************************************************
  138.     public variables
  139. ***************************************************************************/
  140.  
  141. #ifndef IN_WAVE
  142. #endif
  143.  
  144. /***************************************************************************
  145.     function prototypes
  146. ***************************************************************************/
  147.  
  148. #endif
  149. /* __WAVE_H */
  150.