PcmData.cpp 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138
  1. /****************************************************************************
  2. Copyright (c) 2016-2017 Chukong Technologies Inc.
  3. http://www.cocos2d-x.org
  4. Permission is hereby granted, free of charge, to any person obtaining a copy
  5. of this software and associated documentation files (the "Software"), to deal
  6. in the Software without restriction, including without limitation the rights
  7. to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  8. copies of the Software, and to permit persons to whom the Software is
  9. furnished to do so, subject to the following conditions:
  10. The above copyright notice and this permission notice shall be included in
  11. all copies or substantial portions of the Software.
  12. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  13. IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  14. FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  15. AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  16. LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  17. OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  18. THE SOFTWARE.
  19. ****************************************************************************/
  20. #define LOG_TAG "PcmData"
  21. #include "audio/android/OpenSLHelper.h"
  22. #include "audio/android/PcmData.h"
  23. namespace cocos2d { namespace experimental {
  24. PcmData::PcmData()
  25. {
  26. // ALOGV("In the constructor of PcmData (%p)", this);
  27. reset();
  28. }
  29. PcmData::~PcmData()
  30. {
  31. // ALOGV("In the destructor of PcmData (%p)", this);
  32. }
  33. PcmData::PcmData(const PcmData &o)
  34. {
  35. // ALOGV("In the copy constructor of PcmData (%p)", this);
  36. numChannels = o.numChannels;
  37. sampleRate = o.sampleRate;
  38. bitsPerSample = o.bitsPerSample;
  39. containerSize = o.containerSize;
  40. channelMask = o.channelMask;
  41. endianness = o.endianness;
  42. numFrames = o.numFrames;
  43. duration = o.duration;
  44. pcmBuffer = std::move(o.pcmBuffer);
  45. }
  46. PcmData::PcmData(PcmData &&o)
  47. {
  48. // ALOGV("In the move constructor of PcmData (%p)", this);
  49. numChannels = o.numChannels;
  50. sampleRate = o.sampleRate;
  51. bitsPerSample = o.bitsPerSample;
  52. containerSize = o.containerSize;
  53. channelMask = o.channelMask;
  54. endianness = o.endianness;
  55. numFrames = o.numFrames;
  56. duration = o.duration;
  57. pcmBuffer = std::move(o.pcmBuffer);
  58. o.reset();
  59. }
  60. PcmData &PcmData::operator=(const PcmData &o)
  61. {
  62. // ALOGV("In the copy assignment of PcmData");
  63. numChannels = o.numChannels;
  64. sampleRate = o.sampleRate;
  65. bitsPerSample = o.bitsPerSample;
  66. containerSize = o.containerSize;
  67. channelMask = o.channelMask;
  68. endianness = o.endianness;
  69. numFrames = o.numFrames;
  70. duration = o.duration;
  71. pcmBuffer = o.pcmBuffer;
  72. return *this;
  73. }
  74. PcmData &PcmData::operator=(PcmData &&o)
  75. {
  76. // ALOGV("In the move assignment of PcmData");
  77. numChannels = o.numChannels;
  78. sampleRate = o.sampleRate;
  79. bitsPerSample = o.bitsPerSample;
  80. containerSize = o.containerSize;
  81. channelMask = o.channelMask;
  82. endianness = o.endianness;
  83. numFrames = o.numFrames;
  84. duration = o.duration;
  85. pcmBuffer = std::move(o.pcmBuffer);
  86. o.reset();
  87. return *this;
  88. }
  89. void PcmData::reset()
  90. {
  91. numChannels = -1;
  92. sampleRate = -1;
  93. bitsPerSample = -1;
  94. containerSize = -1;
  95. channelMask = -1;
  96. endianness = -1;
  97. numFrames = -1;
  98. duration = -1.0f;
  99. pcmBuffer = nullptr;
  100. }
  101. bool PcmData::isValid() const
  102. {
  103. return numChannels > 0 && sampleRate > 0 && bitsPerSample > 0 && containerSize > 0
  104. && numFrames > 0 && duration > 0 && pcmBuffer != nullptr;
  105. }
  106. std::string PcmData::toString() const
  107. {
  108. std::string ret;
  109. char buf[256] = {0};
  110. snprintf(buf, sizeof(buf),
  111. "numChannels: %d, sampleRate: %d, bitPerSample: %d, containerSize: %d, "
  112. "channelMask: %d, endianness: %d, numFrames: %d, duration: %f",
  113. numChannels, sampleRate, bitsPerSample, containerSize, channelMask, endianness,
  114. numFrames, duration
  115. );
  116. ret = buf;
  117. return ret;
  118. }
  119. }} // namespace cocos2d { namespace experimental {