aRts audio server
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.

datahandle.h 5.1KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220
  1. /*
  2. Copyright (C) 2002 Hans Meine
  3. hans_meine@gmx.net
  4. This library is free software; you can redistribute it and/or
  5. modify it under the terms of the GNU Library General Public
  6. License as published by the Free Software Foundation; either
  7. version 2 of the License, or (at your option) any later version.
  8. This library is distributed in the hope that it will be useful,
  9. but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  11. Library General Public License for more details.
  12. You should have received a copy of the GNU Library General Public License
  13. along with this library; see the file COPYING.LIB. If not, write to
  14. the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
  15. Boston, MA 02110-1301, USA.
  16. */
  17. #ifndef GSLPP_DATAHANDLE_H
  18. #define GSLPP_DATAHANDLE_H
  19. #include <gsl/gsldatahandle.h>
  20. #include <gsl/gslloader.h>
  21. #include <string>
  22. namespace GSL
  23. {
  24. class WaveFileInfo;
  25. class WaveDataHandle;
  26. class WaveDescription;
  27. class DataHandle
  28. {
  29. protected:
  30. GslDataHandle *handle_;
  31. void clearHandle();
  32. void copyFrom(const DataHandle &other);
  33. DataHandle(GslDataHandle *handle);
  34. public:
  35. static DataHandle null() { return DataHandle(); }
  36. DataHandle(): handle_(0) {}
  37. DataHandle(const DataHandle &other);
  38. DataHandle &operator =(const DataHandle &other);
  39. bool operator ==(const DataHandle &other) const;
  40. bool isNull() const;
  41. virtual ~DataHandle();
  42. /**
  43. * returns error code with errno meaning
  44. */
  45. virtual gint open();
  46. virtual void close();
  47. bool isOpen() const;
  48. /**
  49. * read from this datahandle and fill buffer pointed to by
  50. * values with sample data from the range
  51. * [valueOffset..valueOffset+valueCount-1]
  52. *
  53. * returns number of sample values actually read, -1 on error
  54. * (errno _may_ be useful then)
  55. */
  56. virtual GslLong read(GslLong valueOffset, GslLong valueCount, gfloat *values);
  57. /**
  58. * Create a new data handle by chopping off headCutValueCount
  59. * values at the start, and tailCutValueCount values at the
  60. * end of this data handle.
  61. */
  62. DataHandle createCropped(GslLong headCutValueCount,
  63. GslLong tailCutValueCount);
  64. /**
  65. * Create a new data handle by removing the values
  66. * [cutOffset..cutOffset+cutValueCount-1].
  67. */
  68. DataHandle createCut(GslLong cutOffset,
  69. GslLong cutValueCount);
  70. /**
  71. * Create a new data handle which contains the same values as
  72. * this one but in reversed order.
  73. */
  74. DataHandle createReversed();
  75. // this will maybe be made private in the future, having a
  76. // better interface instead
  77. GslDataCache *createGslDataCache();
  78. GslLong valueCount() const;
  79. guint bitDepth() const;
  80. guint channelCount() const;
  81. };
  82. class WaveChunkDescription
  83. {
  84. friend class WaveDescription;
  85. const GslWaveDsc *parent_;
  86. guint parentIndex_;
  87. WaveChunkDescription(const GslWaveDsc *parent, guint index);
  88. public:
  89. float oscillatorFrequency();
  90. float mixerFrequency();
  91. GslWaveLoopType loopType();
  92. GslLong loopStart(); /* sample offset */
  93. GslLong loopEnd(); /* sample offset */
  94. guint loopCount();
  95. WaveDataHandle createDataHandle();
  96. };
  97. class WaveDescription
  98. {
  99. friend class WaveFileInfo; // for construction of WaveDescriptions
  100. mutable GslWaveFileInfo *parentInfo_; // mutable for ensurePointer()
  101. std::string name_;
  102. guint parentIndex_;
  103. mutable GslWaveDsc *desc_;
  104. mutable GslErrorType error_;
  105. void ensurePointer() const; // lazy construction
  106. void copyFrom(const WaveDescription &other);
  107. WaveDescription(GslWaveFileInfo *parent, guint index, const std::string &name);
  108. public:
  109. ~WaveDescription();
  110. WaveDescription(const WaveDescription &other);
  111. WaveDescription &operator =(const WaveDescription &other);
  112. const std::string &name() const;
  113. GslErrorType error() const;
  114. guint chunkCount() const;
  115. WaveChunkDescription chunkDescription(guint index) const;
  116. guint channelCount() const;
  117. };
  118. class WaveFileInfo
  119. {
  120. GslWaveFileInfo *info_;
  121. GslErrorType error_;
  122. std::string filename_;
  123. void copyFrom(const WaveFileInfo &other);
  124. public:
  125. WaveFileInfo(const std::string &filename);
  126. ~WaveFileInfo();
  127. WaveFileInfo(const WaveFileInfo &other);
  128. WaveFileInfo &operator =(const WaveFileInfo &other);
  129. guint waveCount() const;
  130. std::string waveName(guint index) const;
  131. WaveDescription waveDescription(guint index);
  132. GslErrorType error() const;
  133. };
  134. class WaveDataHandle: public DataHandle
  135. {
  136. friend class WaveChunkDescription;
  137. GslErrorType error_;
  138. float oscillatorFrequency_;
  139. float mixerFrequency_;
  140. WaveDataHandle();
  141. WaveDataHandle(const GslWaveDsc *waveDesc, guint chunkIndex = 0);
  142. public:
  143. WaveDataHandle(const std::string& filename,
  144. guint waveIndex = 0,
  145. guint chunkIndex = 0);
  146. static WaveDataHandle null() { return WaveDataHandle(); }
  147. GslErrorType error() const;
  148. float oscillatorFrequency() const;
  149. float mixerFrequency() const;
  150. };
  151. }
  152. #endif // GSLPP_DATAHANDLE_H