You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

86 lines
2.1KB

  1. /* SpiralSynth
  2. * Copyleft (C) 2000 David Griffiths <dave@pawfal.org>
  3. *
  4. * This program is free software; you can redistribute it and/or modify
  5. * it under the terms of the GNU General Public License as published by
  6. * the Free Software Foundation; either version 2 of the License, or
  7. * (at your option) any later version.
  8. *
  9. * This program is distributed in the hope that it will be useful,
  10. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. * GNU General Public License for more details.
  13. *
  14. * You should have received a copy of the GNU General Public License
  15. * along with this program; if not, write to the Free Software
  16. * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
  17. */
  18. #include <string>
  19. #ifndef WAVFILE
  20. #define WAVFILE
  21. #include <stdio.h>
  22. #include "Sample.h"
  23. struct CanonicalWavHeader
  24. {
  25. char RiffName[4];
  26. int RiffFileLength;
  27. char RiffTypeName[4];
  28. char FmtName[4];
  29. int FmtLength;
  30. short FmtTag;
  31. short FmtChannels;
  32. int FmtSamplerate;
  33. int FmtBytesPerSec;
  34. short FmtBlockAlign;
  35. short FmtBitsPerSample;
  36. };
  37. struct DataHeader
  38. {
  39. char DataName[4];
  40. int DataLengthBytes;
  41. };
  42. class WavFile
  43. {
  44. public:
  45. WavFile() : m_Stream(NULL), m_Samplerate(44100), m_DataStart(0) {}
  46. ~WavFile() {Close();}
  47. enum Mode{READ,WRITE};
  48. enum Channels{MONO,STEREO};
  49. int Open(string FileName, Mode mode, Channels channels=MONO);
  50. int Close();
  51. int Save(Sample &data);
  52. int Load(Sample &data);
  53. int Save(short *data, int Bytes);
  54. int Load(short *data);
  55. int SeekToChunk(int Pos);
  56. int LoadChunk(int NumSamples, Sample &ldata, Sample &rdata);
  57. int GetSize(); // in samples
  58. bool Recording() {return (m_Stream!=NULL);}
  59. void SetSamplerate(int s) { m_Samplerate=s; }
  60. int GetSamplerate() { return m_Header.FmtSamplerate; }
  61. bool IsStereo() { return (m_Header.FmtChannels==2); }
  62. bool IsOpen() { return m_Stream!=NULL; }
  63. private:
  64. FILE *m_Stream;
  65. int m_Samplerate;
  66. long m_DataStart;
  67. long m_CurSeekPos;
  68. CanonicalWavHeader m_Header;
  69. DataHeader m_DataHeader;
  70. };
  71. #endif