Audacity  2.2.2
Types.h
Go to the documentation of this file.
1 /**********************************************************************
2 
3  Audacity: A Digital Audio Editor
4 
5  Types.h
6 
7  Leland Lucius
8 
9  Copyright (c) 2014, Audacity Team
10  All rights reserved.
11 
12  Redistribution and use in source and binary forms, with or without
13  modification, are permitted provided that the following conditions
14  are met:
15 
16  1. Redistributions of source code must retain the above copyright
17  notice, this list of conditions and the following disclaimer.
18 
19  2. Redistributions in binary form must reproduce the above copyright
20  notice, this list of conditions and the following disclaimer in the
21  documentation and/or other materials provided with the distribution.
22 
23  3. Neither the name of the copyright holder nor the names of its
24  contributors may be used to endorse or promote products derived from
25  this software without specific prior written permission.
26 
27  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
28  "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
29  LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
30  FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
31  COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
32  INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
33  BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
34  LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
35  CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
36  LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
37  ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
38  POSSIBILITY OF SUCH DAMAGE.
39 
40 **********************************************************************/
41 
42 #ifndef __AUDACITY_TYPES_H__
43 #define __AUDACITY_TYPES_H__
44 
45 #include <algorithm>
46 #include <wx/string.h>
47 #include <wx/arrstr.h>
48 #include <type_traits>
49 
50 // ----------------------------------------------------------------------------
51 // TODO: I'd imagine this header may be replaced by other public headers. But,
52 // to try and minimize more changes to the base code, we can use this
53 // until proper public headers are created for the stuff in here.
54 // ----------------------------------------------------------------------------
55 
56 // ----------------------------------------------------------------------------
57 // A native 64-bit integer...used when referring to any number of samples
58 // ----------------------------------------------------------------------------
59 
61 {
62 public:
63  using type = long long;
64  static_assert(sizeof(type) == 8, "Wrong width of sampleCount");
65 
66  sampleCount () : value { 0 } {}
67 
68  // Allow implicit conversion from integral types
69  sampleCount ( type v ) : value { v } {}
70  sampleCount ( unsigned long long v ) : value ( v ) {}
71  sampleCount ( int v ) : value { v } {}
72  sampleCount ( unsigned v ) : value { v } {}
73  sampleCount ( long v ) : value { v } {}
74 
75  // unsigned long is 64 bit on some platforms. Let it narrow.
76  sampleCount ( unsigned long v ) : value ( v ) {}
77 
78  // Beware implicit conversions from floating point values!
79  // Otherwise the meaning of binary operators with sampleCount change
80  // their meaning when sampleCount is not an alias!
81  explicit sampleCount ( float f ) : value ( f ) {}
82  explicit sampleCount ( double d ) : value ( d ) {}
83 
84  sampleCount ( const sampleCount& ) = default;
85  sampleCount &operator= ( const sampleCount& ) = default;
86 
87  float as_float() const { return value; }
88  double as_double() const { return value; }
89 
90  long long as_long_long() const { return value; }
91 
92  size_t as_size_t() const {
93  wxASSERT(value >= 0);
94  wxASSERT(static_cast<std::make_unsigned<type>::type>(value) <= std::numeric_limits<size_t>::max());
95  return value;
96  }
97 
98  sampleCount &operator += (sampleCount b) { value += b.value; return *this; }
99  sampleCount &operator -= (sampleCount b) { value -= b.value; return *this; }
100  sampleCount &operator *= (sampleCount b) { value *= b.value; return *this; }
101  sampleCount &operator /= (sampleCount b) { value /= b.value; return *this; }
102  sampleCount &operator %= (sampleCount b) { value %= b.value; return *this; }
103 
104  sampleCount operator - () const { return -value; }
105 
106  sampleCount &operator ++ () { ++value; return *this; }
108  { sampleCount result{ *this }; ++value; return result; }
109 
110  sampleCount &operator -- () { --value; return *this; }
112  { sampleCount result{ *this }; --value; return result; }
113 
114 private:
116 };
117 
119 {
120  return a.as_long_long() == b.as_long_long();
121 }
122 
124 {
125  return !(a == b);
126 }
127 
129 {
130  return a.as_long_long() < b.as_long_long();
131 }
132 
134 {
135  return !(a < b);
136 }
137 
139 {
140  return b < a;
141 }
142 
144 {
145  return !(b < a);
146 }
147 
149 {
150  return sampleCount{ a } += b;
151 }
152 
154 {
155  return sampleCount{ a } -= b;
156 }
157 
159 {
160  return sampleCount{ a } *= b;
161 }
162 
164 {
165  return sampleCount{ a } /= b;
166 }
167 
169 {
170  return sampleCount{ a } %= b;
171 }
172 
173 // ----------------------------------------------------------------------------
174 // Function returning the minimum of a sampleCount and a size_t,
175 // hiding the casts
176 // ----------------------------------------------------------------------------
177 
178 inline size_t limitSampleBufferSize( size_t bufferSize, sampleCount limit )
179 {
180  return
181  std::min( sampleCount( bufferSize ), std::max( sampleCount(0), limit ) )
182  .as_size_t();
183 }
184 
185 // ----------------------------------------------------------------------------
186 // Supported sample formats
187 // ----------------------------------------------------------------------------
188 enum sampleFormat : unsigned
189 {
190  int16Sample = 0x00020001,
191  int24Sample = 0x00040001,
192  floatSample = 0x0004000F
193 };
194 
195 // ----------------------------------------------------------------------------
196 // Provide the number of bytes a specific sample will take
197 // ----------------------------------------------------------------------------
198 #define SAMPLE_SIZE(SampleFormat) (SampleFormat >> 16)
199 
200 // ----------------------------------------------------------------------------
201 // Generic pointer to sample data
202 // ----------------------------------------------------------------------------
203 typedef char *samplePtr;
204 typedef const char *constSamplePtr;
205 
206 // ----------------------------------------------------------------------------
207 // The type for plugin IDs
208 // ----------------------------------------------------------------------------
209 typedef wxString PluginID;
210 
211 // ----------------------------------------------------------------------------
212 // Supported channel assignments
213 // ----------------------------------------------------------------------------
214 
215 typedef enum
216 {
217  // Use to mark end of list
219  // The default channel assignment
221  // From this point, the channels follow the 22.2 surround sound format
247 
248 // LLL FIXME: Until a complete API is devised, we have to use
249 // AUDACITY_DLL_API when defining API classes. This
250 // it ugly, but a part of the game. Remove it when
251 // the API is complete.
252 
253 
254 #if !defined(AUDACITY_DLL_API)
255  // This was copied from "Audacity.h" so these headers wouldn't have
256  // to include it.
257 
258  /* Magic for dynamic library import and export. This is unfortunately
259  * compiler-specific because there isn't a standard way to do it. Currently it
260  * works with the Visual Studio compiler for windows, and for GCC 4+. Anything
261  * else gets all symbols made public, which gets messy */
262  /* The Visual Studio implementation */
263  #ifdef _MSC_VER
264  #ifndef AUDACITY_DLL_API
265  #ifdef BUILDING_AUDACITY
266  #define AUDACITY_DLL_API _declspec(dllexport)
267  #else
268  #ifdef _DLL
269  #define AUDACITY_DLL_API _declspec(dllimport)
270  #else
271  #define AUDACITY_DLL_API
272  #endif
273  #endif
274  #endif
275  #endif //_MSC_VER
276 
277  #ifdef __GNUC__
278  #ifndef __CONFIG_UNIX_INCLUDED
279  #define __CONFIG_UNIX_INCLUDED
280  #include "configunix.h"
281  #endif
282  #endif
283 
284  /* The GCC-elf implementation */
285  #ifdef HAVE_VISIBILITY // this is provided by the configure script, is only
286  // enabled for suitable GCC versions
287  /* The incantation is a bit weird here because it uses ELF symbol stuff. If we
288  * make a symbol "default" it makes it visible (for import or export). Making it
289  * "hidden" means it is invisible outside the shared object. */
290  #ifndef AUDACITY_DLL_API
291  #ifdef BUILDING_AUDACITY
292  #define AUDACITY_DLL_API __attribute__((visibility("default")))
293  #else
294  #define AUDACITY_DLL_API __attribute__((visibility("default")))
295  #endif
296  #endif
297  #endif
298 
299  /* The GCC-win32 implementation */
300  // bizzarely, GCC-for-win32 supports Visual Studio style symbol visibility, so
301  // we use that if building on Cygwin
302  #if defined __CYGWIN__ && defined __GNUC__
303  #ifndef AUDACITY_DLL_API
304  #ifdef BUILDING_AUDACITY
305  #define AUDACITY_DLL_API _declspec(dllexport)
306  #else
307  #ifdef _DLL
308  #define AUDACITY_DLL_API _declspec(dllimport)
309  #else
310  #define AUDACITY_DLL_API
311  #endif
312  #endif
313  #endif
314  #endif
315 #endif
316 
317 #endif // __AUDACITY_TYPES_H__
sampleCount(unsigned v)
Definition: Types.h:72
bool operator==(sampleCount a, sampleCount b)
Definition: Types.h:118
sampleCount & operator-=(sampleCount b)
Definition: Types.h:99
sampleCount operator-() const
Definition: Types.h:104
sampleCount & operator--()
Definition: Types.h:110
sampleCount & operator+=(sampleCount b)
Definition: Types.h:98
bool operator>(sampleCount a, sampleCount b)
Definition: Types.h:138
sampleCount(double d)
Definition: Types.h:82
wxString PluginID
Definition: Types.h:209
double as_double() const
Definition: Types.h:88
sampleCount(unsigned long long v)
Definition: Types.h:70
sampleCount(type v)
Definition: Types.h:69
sampleCount & operator/=(sampleCount b)
Definition: Types.h:101
size_t limitSampleBufferSize(size_t bufferSize, sampleCount limit)
Definition: Types.h:178
long long type
Definition: Types.h:63
sampleCount()
Definition: Types.h:66
sampleCount(long v)
Definition: Types.h:73
sampleCount(unsigned long v)
Definition: Types.h:76
bool operator<(sampleCount a, sampleCount b)
Definition: Types.h:128
sampleCount & operator*=(sampleCount b)
Definition: Types.h:100
sampleFormat
Definition: Types.h:188
ChannelName
Definition: Types.h:215
char * samplePtr
Definition: Types.h:203
bool operator>=(sampleCount a, sampleCount b)
Definition: Types.h:133
sampleCount(int v)
Definition: Types.h:71
sampleCount operator*(sampleCount a, sampleCount b)
Definition: Types.h:158
int min(int a, int b)
sampleCount & operator=(const sampleCount &)=default
float as_float() const
Definition: Types.h:87
sampleCount operator%(sampleCount a, sampleCount b)
Definition: Types.h:168
type value
Definition: Types.h:115
enum ChannelName * ChannelNames
bool operator!=(sampleCount a, sampleCount b)
Definition: Types.h:123
sampleCount(float f)
Definition: Types.h:81
sampleCount operator+(sampleCount a, sampleCount b)
Definition: Types.h:148
bool operator<=(sampleCount a, sampleCount b)
Definition: Types.h:143
long long as_long_long() const
Definition: Types.h:90
const char * constSamplePtr
Definition: Types.h:204
sampleCount & operator%=(sampleCount b)
Definition: Types.h:102
size_t as_size_t() const
Definition: Types.h:92
sampleCount operator-(sampleCount a, sampleCount b)
Definition: Types.h:153
sampleCount operator/(sampleCount a, sampleCount b)
Definition: Types.h:163
sampleCount & operator++()
Definition: Types.h:106