1 /***************************************************************************
2  copyright            : (C) 2016 by Damien Plisson, Audirvana
3  email                : damien78@audirvana.com
4  ***************************************************************************/
5 
6 /***************************************************************************
7  *   This library is free software; you can redistribute it and/or modify  *
8  *   it under the terms of the GNU Lesser General Public License version   *
9  *   2.1 as published by the Free Software Foundation.                     *
10  *                                                                         *
11  *   This library is distributed in the hope that it will be useful, but   *
12  *   WITHOUT ANY WARRANTY; without even the implied warranty of            *
13  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU     *
14  *   Lesser General Public License for more details.                       *
15  *                                                                         *
16  *   You should have received a copy of the GNU Lesser General Public      *
17  *   License along with this library; if not, write to the Free Software   *
18  *   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA         *
19  *   02110-1301  USA                                                       *
20  *                                                                         *
21  *   Alternatively, this file is available under the Mozilla Public        *
22  *   License Version 1.1.  You may obtain a copy of the License at         *
23  *   http://www.mozilla.org/MPL/                                           *
24  ***************************************************************************/
25 
26 #include <tstring.h>
27 #include <tdebug.h>
28 
29 #include "dsdiffproperties.h"
30 
31 using namespace TagLib;
32 
33 class DSDIFF::Properties::PropertiesPrivate
34 {
35 public:
PropertiesPrivate()36   PropertiesPrivate() :
37   length(0),
38   bitrate(0),
39   sampleRate(0),
40   channels(0),
41   sampleWidth(0),
42   sampleCount(0)
43   {
44   }
45 
46   int length;
47   int bitrate;
48   int sampleRate;
49   int channels;
50   int sampleWidth;
51   unsigned long long sampleCount;
52 };
53 
54 ////////////////////////////////////////////////////////////////////////////////
55 // public members
56 ////////////////////////////////////////////////////////////////////////////////
57 
Properties(const unsigned int sampleRate,const unsigned short channels,const unsigned long long samplesCount,const int bitrate,ReadStyle style)58 DSDIFF::Properties::Properties(const unsigned int sampleRate,
59                                const unsigned short channels,
60                                const unsigned long long samplesCount,
61                                const int bitrate,
62                                ReadStyle style) : AudioProperties(style)
63 {
64   d = new PropertiesPrivate;
65 
66   d->channels    = channels;
67   d->sampleCount = samplesCount;
68   d->sampleWidth = 1;
69   d->sampleRate  = sampleRate;
70   d->bitrate     = bitrate;
71   d->length      = d->sampleRate > 0
72     ? static_cast<int>((d->sampleCount * 1000.0) / d->sampleRate + 0.5)
73     : 0;
74 }
75 
~Properties()76 DSDIFF::Properties::~Properties()
77 {
78   delete d;
79 }
80 
length() const81 int DSDIFF::Properties::length() const
82 {
83   return lengthInSeconds();
84 }
85 
lengthInSeconds() const86 int DSDIFF::Properties::lengthInSeconds() const
87 {
88   return d->length / 1000;
89 }
90 
lengthInMilliseconds() const91 int DSDIFF::Properties::lengthInMilliseconds() const
92 {
93   return d->length;
94 }
95 
bitrate() const96 int DSDIFF::Properties::bitrate() const
97 {
98   return d->bitrate;
99 }
100 
sampleRate() const101 int DSDIFF::Properties::sampleRate() const
102 {
103   return d->sampleRate;
104 }
105 
channels() const106 int DSDIFF::Properties::channels() const
107 {
108   return d->channels;
109 }
110 
bitsPerSample() const111 int DSDIFF::Properties::bitsPerSample() const
112 {
113   return d->sampleWidth;
114 }
115 
sampleCount() const116 long long DSDIFF::Properties::sampleCount() const
117 {
118   return d->sampleCount;
119 }
120 
121