PageRenderTime 41ms CodeModel.GetById 14ms RepoModel.GetById 1ms app.codeStats 0ms

/libtunepimp-0.5.3/plugins/tta/ttaproperties.cpp

#
C++ | 134 lines | 81 code | 24 blank | 29 comment | 1 complexity | 1ccefb476d8816918afb671b68ebf388 MD5 | raw file
Possible License(s): LGPL-2.1, LGPL-3.0, GPL-2.0, LGPL-2.0
  1. /***************************************************************************
  2. copyright : (C) 2006 by LukᚠLalinský
  3. email : lalinsky@gmail.com
  4. copyright : (C) 2004 by Allan Sandfeld Jensen
  5. email : kde@carewolf.org
  6. (original MPC implementation)
  7. ***************************************************************************/
  8. /***************************************************************************
  9. * This library is free software; you can redistribute it and/or modify *
  10. * it under the terms of the GNU Lesser General Public License version *
  11. * 2.1 as published by the Free Software Foundation. *
  12. * *
  13. * This library is distributed in the hope that it will be useful, but *
  14. * WITHOUT ANY WARRANTY; without even the implied warranty of *
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU *
  16. * Lesser General Public License for more details. *
  17. * *
  18. * You should have received a copy of the GNU Lesser General Public *
  19. * License along with this library; if not, write to the Free Software *
  20. * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 *
  21. * USA *
  22. ***************************************************************************/
  23. #include <tstring.h>
  24. #if 0
  25. #include <tdebug.h>
  26. #endif
  27. #include <bitset>
  28. #include "ttaproperties.h"
  29. #include "ttafile.h"
  30. using namespace TagLib;
  31. class TTA::Properties::PropertiesPrivate
  32. {
  33. public:
  34. PropertiesPrivate(const ByteVector &d, long length, ReadStyle s) :
  35. data(d),
  36. streamLength(length),
  37. style(s),
  38. version(0),
  39. length(0),
  40. bitrate(0),
  41. sampleRate(0),
  42. channels(0),
  43. bitsPerSample(0) {}
  44. ByteVector data;
  45. long streamLength;
  46. ReadStyle style;
  47. int version;
  48. int length;
  49. int bitrate;
  50. int sampleRate;
  51. int channels;
  52. int bitsPerSample;
  53. };
  54. ////////////////////////////////////////////////////////////////////////////////
  55. // public members
  56. ////////////////////////////////////////////////////////////////////////////////
  57. TTA::Properties::Properties(const ByteVector &data, long streamLength, ReadStyle style) : AudioProperties(style)
  58. {
  59. d = new PropertiesPrivate(data, streamLength, style);
  60. read();
  61. }
  62. TTA::Properties::~Properties()
  63. {
  64. delete d;
  65. }
  66. int TTA::Properties::length() const
  67. {
  68. return d->length;
  69. }
  70. int TTA::Properties::bitrate() const
  71. {
  72. return d->bitrate;
  73. }
  74. int TTA::Properties::sampleRate() const
  75. {
  76. return d->sampleRate;
  77. }
  78. int TTA::Properties::bitsPerSample() const
  79. {
  80. return d->bitsPerSample;
  81. }
  82. int TTA::Properties::channels() const
  83. {
  84. return d->channels;
  85. }
  86. int TTA::Properties::ttaVersion() const
  87. {
  88. return d->version;
  89. }
  90. ////////////////////////////////////////////////////////////////////////////////
  91. // private members
  92. ////////////////////////////////////////////////////////////////////////////////
  93. void TTA::Properties::read()
  94. {
  95. if(!d->data.startsWith("TTA"))
  96. return;
  97. int pos = 3;
  98. d->version = d->data[pos] - '0';
  99. pos += 1 + 2;
  100. d->channels = d->data.mid(pos, 2).toShort(false);
  101. pos += 2;
  102. d->bitsPerSample = d->data.mid(pos, 2).toShort(false);
  103. pos += 2;
  104. d->sampleRate = d->data.mid(pos, 4).toUInt(false);
  105. pos += 4;
  106. unsigned long samples = d->data.mid(pos, 4).toUInt(false);
  107. d->length = samples / d->sampleRate;
  108. d->bitrate = d->length > 0 ? ((d->streamLength * 8L) / d->length) / 1000 : 0;
  109. }