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 
49 // ----------------------------------------------------------------------------
50 // TODO: I'd imagine this header may be replaced by other public headers. But,
51 // to try and minimize more changes to the base code, we can use this
52 // until proper public headers are created for the stuff in here.
53 // ----------------------------------------------------------------------------
54 
55 // ----------------------------------------------------------------------------
56 // A native 64-bit integer...used when referring to any number of samples
57 // ----------------------------------------------------------------------------
58 
60 {
61 public:
62  using type = long long;
63  static_assert(sizeof(type) == 8, "Wrong width of sampleCount");
64 
65  sampleCount () : value { 0 } {}
66 
67  // Allow implicit conversion from integral types
68  sampleCount ( type v ) : value { v } {}
69  sampleCount ( unsigned long long v ) : value ( v ) {}
70  sampleCount ( int v ) : value { v } {}
71  sampleCount ( unsigned v ) : value { v } {}
72  sampleCount ( long v ) : value { v } {}
73 
74  // unsigned long is 64 bit on some platforms. Let it narrow.
75  sampleCount ( unsigned long v ) : value ( v ) {}
76 
77  // Beware implicit conversions from floating point values!
78  // Otherwise the meaning of binary operators with sampleCount change
79  // their meaning when sampleCount is not an alias!
80  explicit sampleCount ( float f ) : value ( f ) {}
81  explicit sampleCount ( double d ) : value ( d ) {}
82 
83  sampleCount ( const sampleCount& ) = default;
84  sampleCount &operator= ( const sampleCount& ) = default;
85 
86  float as_float() const { return value; }
87  double as_double() const { return value; }
88 
89  long long as_long_long() const { return value; }
90 
91  size_t as_size_t() const {
92  wxASSERT(value >= 0);
93  wxASSERT(value <= std::numeric_limits<size_t>::max());
94  return value;
95  }
96 
97  sampleCount &operator += (sampleCount b) { value += b.value; return *this; }
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 
103  sampleCount operator - () const { return -value; }
104 
105  sampleCount &operator ++ () { ++value; return *this; }
107  { sampleCount result{ *this }; ++value; return result; }
108 
109  sampleCount &operator -- () { --value; return *this; }
111  { sampleCount result{ *this }; --value; return result; }
112 
113 private:
115 };
116 
118 {
119  return a.as_long_long() == b.as_long_long();
120 }
121 
123 {
124  return !(a == b);
125 }
126 
128 {
129  return a.as_long_long() < b.as_long_long();
130 }
131 
133 {
134  return !(a < b);
135 }
136 
138 {
139  return b < a;
140 }
141 
143 {
144  return !(b < a);
145 }
146 
148 {
149  return sampleCount{ a } += b;
150 }
151 
153 {
154  return sampleCount{ a } -= b;
155 }
156 
158 {
159  return sampleCount{ a } *= b;
160 }
161 
163 {
164  return sampleCount{ a } /= b;
165 }
166 
168 {
169  return sampleCount{ a } %= b;
170 }
171 
172 // ----------------------------------------------------------------------------
173 // Function returning the minimum of a sampleCount and a size_t,
174 // hiding the casts
175 // ----------------------------------------------------------------------------
176 
177 inline size_t limitSampleBufferSize( size_t bufferSize, sampleCount limit )
178 {
179  return
180  std::min( sampleCount( bufferSize ), std::max( sampleCount(0), limit ) )
181  .as_size_t();
182 }
183 
184 // ----------------------------------------------------------------------------
185 // Supported sample formats
186 // ----------------------------------------------------------------------------
187 enum sampleFormat : unsigned
188 {
189  int16Sample = 0x00020001,
190  int24Sample = 0x00040001,
191  floatSample = 0x0004000F
192 };
193 
194 // ----------------------------------------------------------------------------
195 // Provide the number of bytes a specific sample will take
196 // ----------------------------------------------------------------------------
197 #define SAMPLE_SIZE(SampleFormat) (SampleFormat >> 16)
198 
199 // ----------------------------------------------------------------------------
200 // Generic pointer to sample data
201 // ----------------------------------------------------------------------------
202 typedef char *samplePtr;
203 typedef const char *constSamplePtr;
204 
205 // ----------------------------------------------------------------------------
206 // The type for plugin IDs
207 // ----------------------------------------------------------------------------
208 typedef wxString PluginID;
209 
210 // ----------------------------------------------------------------------------
211 // Supported channel assignments
212 // ----------------------------------------------------------------------------
213 
214 typedef enum
215 {
216  // Use to mark end of list
218  // The default channel assignment
220  // From this point, the channels follow the 22.2 surround sound format
246 
247 // LLL FIXME: Until a complete API is devised, we have to use
248 // AUDACITY_DLL_API when defining API classes. This
249 // it ugly, but a part of the game. Remove it when
250 // the API is complete.
251 
252 
253 #if !defined(AUDACITY_DLL_API)
254  // This was copied from "Audacity.h" so these headers wouldn't have
255  // to include it.
256 
257  /* Magic for dynamic library import and export. This is unfortunately
258  * compiler-specific because there isn't a standard way to do it. Currently it
259  * works with the Visual Studio compiler for windows, and for GCC 4+. Anything
260  * else gets all symbols made public, which gets messy */
261  /* The Visual Studio implementation */
262  #ifdef _MSC_VER
263  #ifndef AUDACITY_DLL_API
264  #ifdef BUILDING_AUDACITY
265  #define AUDACITY_DLL_API _declspec(dllexport)
266  #else
267  #ifdef _DLL
268  #define AUDACITY_DLL_API _declspec(dllimport)
269  #else
270  #define AUDACITY_DLL_API
271  #endif
272  #endif
273  #endif
274  #endif //_MSC_VER
275 
276  #ifdef __GNUC__
277  #ifndef __CONFIG_UNIX_INCLUDED
278  #define __CONFIG_UNIX_INCLUDED
279  #include "configunix.h"
280  #endif
281  #endif
282 
283  /* The GCC-elf implementation */
284  #ifdef HAVE_VISIBILITY // this is provided by the configure script, is only
285  // enabled for suitable GCC versions
286  /* The incantation is a bit weird here because it uses ELF symbol stuff. If we
287  * make a symbol "default" it makes it visible (for import or export). Making it
288  * "hidden" means it is invisible outside the shared object. */
289  #ifndef AUDACITY_DLL_API
290  #ifdef BUILDING_AUDACITY
291  #define AUDACITY_DLL_API __attribute__((visibility("default")))
292  #else
293  #define AUDACITY_DLL_API __attribute__((visibility("default")))
294  #endif
295  #endif
296  #endif
297 
298  /* The GCC-win32 implementation */
299  // bizzarely, GCC-for-win32 supports Visual Studio style symbol visibility, so
300  // we use that if building on Cygwin
301  #if defined __CYGWIN__ && defined __GNUC__
302  #ifndef AUDACITY_DLL_API
303  #ifdef BUILDING_AUDACITY
304  #define AUDACITY_DLL_API _declspec(dllexport)
305  #else
306  #ifdef _DLL
307  #define AUDACITY_DLL_API _declspec(dllimport)
308  #else
309  #define AUDACITY_DLL_API
310  #endif
311  #endif
312  #endif
313  #endif
314 #endif
315 
316 #endif // __AUDACITY_TYPES_H__
sampleCount(unsigned v)
Definition: Types.h:71
bool operator==(sampleCount a, sampleCount b)
Definition: Types.h:117
sampleCount & operator-=(sampleCount b)
Definition: Types.h:98
sampleCount operator-() const
Definition: Types.h:103
sampleCount & operator--()
Definition: Types.h:109
sampleCount & operator+=(sampleCount b)
Definition: Types.h:97
bool operator>(sampleCount a, sampleCount b)
Definition: Types.h:137
sampleCount(double d)
Definition: Types.h:81
wxString PluginID
Definition: Types.h:208
double as_double() const
Definition: Types.h:87
sampleCount(unsigned long long v)
Definition: Types.h:69
sampleCount(type v)
Definition: Types.h:68
sampleCount & operator/=(sampleCount b)
Definition: Types.h:100
size_t limitSampleBufferSize(size_t bufferSize, sampleCount limit)
Definition: Types.h:177
long long type
Definition: Types.h:62
sampleCount()
Definition: Types.h:65
sampleCount(long v)
Definition: Types.h:72
sampleCount(unsigned long v)
Definition: Types.h:75
bool operator<(sampleCount a, sampleCount b)
Definition: Types.h:127
sampleCount & operator*=(sampleCount b)
Definition: Types.h:99
sampleFormat
Definition: Types.h:187
ChannelName
Definition: Types.h:214
char * samplePtr
Definition: Types.h:202
bool operator>=(sampleCount a, sampleCount b)
Definition: Types.h:132
sampleCount(int v)
Definition: Types.h:70
sampleCount operator*(sampleCount a, sampleCount b)
Definition: Types.h:157
int min(int a, int b)
sampleCount & operator=(const sampleCount &)=default
float as_float() const
Definition: Types.h:86
sampleCount operator%(sampleCount a, sampleCount b)
Definition: Types.h:167
type value
Definition: Types.h:114
enum ChannelName * ChannelNames
bool operator!=(sampleCount a, sampleCount b)
Definition: Types.h:122
sampleCount(float f)
Definition: Types.h:80
sampleCount operator+(sampleCount a, sampleCount b)
Definition: Types.h:147
bool operator<=(sampleCount a, sampleCount b)
Definition: Types.h:142
long long as_long_long() const
Definition: Types.h:89
const char * constSamplePtr
Definition: Types.h:203
sampleCount & operator%=(sampleCount b)
Definition: Types.h:101
size_t as_size_t() const
Definition: Types.h:91
sampleCount operator-(sampleCount a, sampleCount b)
Definition: Types.h:152
sampleCount operator/(sampleCount a, sampleCount b)
Definition: Types.h:162
sampleCount & operator++()
Definition: Types.h:105