1 /***************************************************************************
2     copyright            : (C) 2002 - 2008 by Scott Wheeler
3     email                : wheeler@kde.org
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 #ifndef TAGLIB_AUDIOPROPERTIES_H
27 #define TAGLIB_AUDIOPROPERTIES_H
28 
29 #include "taglib_export.h"
30 
31 namespace TagLib {
32 
33   //! A simple, abstract interface to common audio properties
34 
35   /*!
36    * The values here are common to most audio formats.  For more specific, codec
37    * dependent values, please see see the subclasses APIs.  This is meant to
38    * compliment the TagLib::File and TagLib::Tag APIs in providing a simple
39    * interface that is sufficient for most applications.
40    */
41 
42   class TAGLIB_EXPORT AudioProperties
43   {
44   public:
45 
46     /*!
47      * Reading audio properties from a file can sometimes be very time consuming
48      * and for the most accurate results can often involve reading the entire
49      * file.  Because in many situations speed is critical or the accuracy of the
50      * values is not particularly important this allows the level of desired
51      * accuracy to be set.
52      */
53     enum ReadStyle {
54       //! Read as little of the file as possible
55       Fast,
56       //! Read more of the file and make better values guesses
57       Average,
58       //! Read as much of the file as needed to report accurate values
59       Accurate
60     };
61 
62     /*!
63      * Destroys this AudioProperties instance.
64      */
65     virtual ~AudioProperties();
66 
67     /*!
68      * Returns the length of the file in seconds.
69      */
70     virtual int length() const = 0;
71 
72     /*!
73      * Returns the length of the file in seconds.  The length is rounded down to
74      * the nearest whole second.
75      *
76      * \see lengthInMilliseconds()
77      */
78     // BIC: make virtual
79     int lengthInSeconds() const;
80 
81     /*!
82      * Returns the length of the file in milliseconds.
83      *
84      * \see lengthInSeconds()
85      */
86     // BIC: make virtual
87     int lengthInMilliseconds() const;
88 
89     /*!
90      * Returns the most appropriate bit rate for the file in kb/s.  For constant
91      * bitrate formats this is simply the bitrate of the file.  For variable
92      * bitrate formats this is either the average or nominal bitrate.
93      */
94     virtual int bitrate() const = 0;
95 
96     /*!
97      * Returns the sample rate in Hz.
98      */
99     virtual int sampleRate() const = 0;
100 
101     /*!
102      * Returns the number of audio channels.
103      */
104     virtual int channels() const = 0;
105 
106   protected:
107 
108     /*!
109      * Construct an audio properties instance.  This is protected as this class
110      * should not be instantiated directly, but should be instantiated via its
111      * subclasses and can be fetched from the FileRef or File APIs.
112      *
113      * \see ReadStyle
114      */
115     AudioProperties(ReadStyle style);
116 
117   private:
118     AudioProperties(const AudioProperties &);
119     AudioProperties &operator=(const AudioProperties &);
120 
121     class AudioPropertiesPrivate;
122     AudioPropertiesPrivate *d;
123   };
124 
125 }
126 
127 #endif
128