f@0
|
1 #ifndef STK_STK_H
|
f@0
|
2 #define STK_STK_H
|
f@0
|
3
|
f@0
|
4 #include <string>
|
f@0
|
5 #include <cstring>
|
f@0
|
6 #include <iostream>
|
f@0
|
7 #include <sstream>
|
f@0
|
8 #include <vector>
|
f@0
|
9 //#include <cstdlib>
|
f@0
|
10
|
f@0
|
11 /*! \namespace stk
|
f@0
|
12 \brief The STK namespace.
|
f@0
|
13
|
f@0
|
14 Most Stk classes are defined within the STK namespace. Exceptions
|
f@0
|
15 to this include the classes RtAudio and RtMidi.
|
f@0
|
16 */
|
f@0
|
17 namespace stk {
|
f@0
|
18
|
f@0
|
19 /***************************************************/
|
f@0
|
20 /*! \class Stk
|
f@0
|
21 \brief STK base class
|
f@0
|
22
|
f@0
|
23 Nearly all STK classes inherit from this class.
|
f@0
|
24 The global sample rate and rawwave path variables
|
f@0
|
25 can be queried and modified via Stk. In addition,
|
f@0
|
26 this class provides error handling and
|
f@0
|
27 byte-swapping functions.
|
f@0
|
28
|
f@0
|
29 The Synthesis ToolKit in C++ (STK) is a set of open source audio
|
f@0
|
30 signal processing and algorithmic synthesis classes written in the
|
f@0
|
31 C++ programming language. STK was designed to facilitate rapid
|
f@0
|
32 development of music synthesis and audio processing software, with
|
f@0
|
33 an emphasis on cross-platform functionality, realtime control,
|
f@0
|
34 ease of use, and educational example code. STK currently runs
|
f@0
|
35 with realtime support (audio and MIDI) on Linux, Macintosh OS X,
|
f@0
|
36 and Windows computer platforms. Generic, non-realtime support has
|
f@0
|
37 been tested under NeXTStep, Sun, and other platforms and should
|
f@0
|
38 work with any standard C++ compiler.
|
f@0
|
39
|
f@0
|
40 STK WWW site: http://ccrma.stanford.edu/software/stk/
|
f@0
|
41
|
f@0
|
42 The Synthesis ToolKit in C++ (STK)
|
f@0
|
43 Copyright (c) 1995--2014 Perry R. Cook and Gary P. Scavone
|
f@0
|
44
|
f@0
|
45 Permission is hereby granted, free of charge, to any person
|
f@0
|
46 obtaining a copy of this software and associated documentation files
|
f@0
|
47 (the "Software"), to deal in the Software without restriction,
|
f@0
|
48 including without limitation the rights to use, copy, modify, merge,
|
f@0
|
49 publish, distribute, sublicense, and/or sell copies of the Software,
|
f@0
|
50 and to permit persons to whom the Software is furnished to do so,
|
f@0
|
51 subject to the following conditions:
|
f@0
|
52
|
f@0
|
53 The above copyright notice and this permission notice shall be
|
f@0
|
54 included in all copies or substantial portions of the Software.
|
f@0
|
55
|
f@0
|
56 Any person wishing to distribute modifications to the Software is
|
f@0
|
57 asked to send the modifications to the original developer so that
|
f@0
|
58 they can be incorporated into the canonical version. This is,
|
f@0
|
59 however, not a binding provision of this license.
|
f@0
|
60
|
f@0
|
61 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
f@0
|
62 EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
f@0
|
63 MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
f@0
|
64 IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR
|
f@0
|
65 ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF
|
f@0
|
66 CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
f@0
|
67 WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
f@0
|
68 */
|
f@0
|
69 /***************************************************/
|
f@0
|
70
|
f@0
|
71 //#define _STK_DEBUG_
|
f@0
|
72
|
f@0
|
73 // Most data in STK is passed and calculated with the
|
f@0
|
74 // following user-definable floating-point type. You
|
f@0
|
75 // can change this to "float" if you prefer or perhaps
|
f@0
|
76 // a "long double" in the future.
|
f@0
|
77 typedef double StkFloat;
|
f@0
|
78
|
f@0
|
79 //! STK error handling class.
|
f@0
|
80 /*!
|
f@0
|
81 This is a fairly abstract exception handling class. There could
|
f@0
|
82 be sub-classes to take care of more specific error conditions ... or
|
f@0
|
83 not.
|
f@0
|
84 */
|
f@0
|
85 class StkError
|
f@0
|
86 {
|
f@0
|
87 public:
|
f@0
|
88 enum Type {
|
f@0
|
89 STATUS,
|
f@0
|
90 WARNING,
|
f@0
|
91 DEBUG_PRINT,
|
f@0
|
92 MEMORY_ALLOCATION,
|
f@0
|
93 MEMORY_ACCESS,
|
f@0
|
94 FUNCTION_ARGUMENT,
|
f@0
|
95 FILE_NOT_FOUND,
|
f@0
|
96 FILE_UNKNOWN_FORMAT,
|
f@0
|
97 FILE_ERROR,
|
f@0
|
98 PROCESS_THREAD,
|
f@0
|
99 PROCESS_SOCKET,
|
f@0
|
100 PROCESS_SOCKET_IPADDR,
|
f@0
|
101 AUDIO_SYSTEM,
|
f@0
|
102 MIDI_SYSTEM,
|
f@0
|
103 UNSPECIFIED
|
f@0
|
104 };
|
f@0
|
105
|
f@0
|
106 protected:
|
f@0
|
107 std::string message_;
|
f@0
|
108 Type type_;
|
f@0
|
109
|
f@0
|
110 public:
|
f@0
|
111 //! The constructor.
|
f@0
|
112 StkError(const std::string& message, Type type = StkError::UNSPECIFIED)
|
f@0
|
113 : message_(message), type_(type) {}
|
f@0
|
114
|
f@0
|
115 //! The destructor.
|
f@0
|
116 virtual ~StkError(void) {};
|
f@0
|
117
|
f@0
|
118 //! Prints thrown error message to stderr.
|
f@0
|
119 virtual void printMessage(void) { std::cerr << '\n' << message_ << "\n\n"; }
|
f@0
|
120
|
f@0
|
121 //! Returns the thrown error message type.
|
f@0
|
122 virtual const Type& getType(void) { return type_; }
|
f@0
|
123
|
f@0
|
124 //! Returns the thrown error message string.
|
f@0
|
125 virtual const std::string& getMessage(void) { return message_; }
|
f@0
|
126
|
f@0
|
127 //! Returns the thrown error message as a C string.
|
f@0
|
128 virtual const char *getMessageCString(void) { return message_.c_str(); }
|
f@0
|
129 };
|
f@0
|
130
|
f@0
|
131
|
f@0
|
132 class Stk
|
f@0
|
133 {
|
f@0
|
134 public:
|
f@0
|
135
|
f@0
|
136 typedef unsigned long StkFormat;
|
f@0
|
137 static const StkFormat STK_SINT8; /*!< -128 to +127 */
|
f@0
|
138 static const StkFormat STK_SINT16; /*!< -32768 to +32767 */
|
f@0
|
139 static const StkFormat STK_SINT24; /*!< Lower 3 bytes of 32-bit signed integer. */
|
f@0
|
140 static const StkFormat STK_SINT32; /*!< -2147483648 to +2147483647. */
|
f@0
|
141 static const StkFormat STK_FLOAT32; /*!< Normalized between plus/minus 1.0. */
|
f@0
|
142 static const StkFormat STK_FLOAT64; /*!< Normalized between plus/minus 1.0. */
|
f@0
|
143
|
f@0
|
144 //! Static method that returns the current STK sample rate.
|
f@0
|
145 static StkFloat sampleRate( void ) { return srate_; }
|
f@0
|
146
|
f@0
|
147 //! Static method that sets the STK sample rate.
|
f@0
|
148 /*!
|
f@0
|
149 The sample rate set using this method is queried by all STK
|
f@0
|
150 classes that depend on its value. It is initialized to the
|
f@0
|
151 default SRATE set in Stk.h. Many STK classes use the sample rate
|
f@0
|
152 during instantiation. Therefore, if you wish to use a rate that
|
f@0
|
153 is different from the default rate, it is imperative that it be
|
f@0
|
154 set \e BEFORE STK objects are instantiated. A few classes that
|
f@0
|
155 make use of the global STK sample rate are automatically notified
|
f@0
|
156 when the rate changes so that internal class data can be
|
f@0
|
157 appropriately updated. However, this has not been fully
|
f@0
|
158 implemented. Specifically, classes that appropriately update
|
f@0
|
159 their own data when either a setFrequency() or noteOn() function
|
f@0
|
160 is called do not currently receive the automatic notification of
|
f@0
|
161 rate change. If the user wants a specific class instance to
|
f@0
|
162 ignore such notifications, perhaps in a multi-rate context, the
|
f@0
|
163 function Stk::ignoreSampleRateChange() should be called.
|
f@0
|
164 */
|
f@0
|
165 static void setSampleRate( StkFloat rate );
|
f@0
|
166
|
f@0
|
167 //! A function to enable/disable the automatic updating of class data when the STK sample rate changes.
|
f@0
|
168 /*!
|
f@0
|
169 This function allows the user to enable or disable class data
|
f@0
|
170 updates in response to global sample rate changes on a class by
|
f@0
|
171 class basis.
|
f@0
|
172 */
|
f@0
|
173 void ignoreSampleRateChange( bool ignore = true ) { ignoreSampleRateChange_ = ignore; };
|
f@0
|
174
|
f@0
|
175 //! Static method that returns the current rawwave path.
|
f@0
|
176 static std::string rawwavePath(void) { return rawwavepath_; }
|
f@0
|
177
|
f@0
|
178 //! Static method that sets the STK rawwave path.
|
f@0
|
179 static void setRawwavePath( std::string path );
|
f@0
|
180
|
f@0
|
181 //! Static method that byte-swaps a 16-bit data type.
|
f@0
|
182 static void swap16( unsigned char *ptr );
|
f@0
|
183
|
f@0
|
184 //! Static method that byte-swaps a 32-bit data type.
|
f@0
|
185 static void swap32( unsigned char *ptr );
|
f@0
|
186
|
f@0
|
187 //! Static method that byte-swaps a 64-bit data type.
|
f@0
|
188 static void swap64( unsigned char *ptr );
|
f@0
|
189
|
f@0
|
190 //! Static cross-platform method to sleep for a number of milliseconds.
|
f@0
|
191 static void sleep( unsigned long milliseconds );
|
f@0
|
192
|
f@0
|
193 //! Static method to check whether a value is within a specified range.
|
f@0
|
194 static bool inRange( StkFloat value, StkFloat min, StkFloat max ) {
|
f@0
|
195 if ( value < min ) return false;
|
f@0
|
196 else if ( value > max ) return false;
|
f@0
|
197 else return true;
|
f@0
|
198 }
|
f@0
|
199
|
f@0
|
200 //! Static function for error reporting and handling using c-strings.
|
f@0
|
201 static void handleError( const char *message, StkError::Type type );
|
f@0
|
202
|
f@0
|
203 //! Static function for error reporting and handling using c++ strings.
|
f@0
|
204 static void handleError( std::string message, StkError::Type type );
|
f@0
|
205
|
f@0
|
206 //! Toggle display of WARNING and STATUS messages.
|
f@0
|
207 static void showWarnings( bool status ) { showWarnings_ = status; }
|
f@0
|
208
|
f@0
|
209 //! Toggle display of error messages before throwing exceptions.
|
f@0
|
210 static void printErrors( bool status ) { printErrors_ = status; }
|
f@0
|
211
|
f@0
|
212 private:
|
f@0
|
213 static StkFloat srate_;
|
f@0
|
214 static std::string rawwavepath_;
|
f@0
|
215 static bool showWarnings_;
|
f@0
|
216 static bool printErrors_;
|
f@0
|
217 static std::vector<Stk *> alertList_;
|
f@0
|
218
|
f@0
|
219 protected:
|
f@0
|
220
|
f@0
|
221 static std::ostringstream oStream_;
|
f@0
|
222 bool ignoreSampleRateChange_;
|
f@0
|
223
|
f@0
|
224 //! Default constructor.
|
f@0
|
225 Stk( void );
|
f@0
|
226
|
f@0
|
227 //! Class destructor.
|
f@0
|
228 virtual ~Stk( void );
|
f@0
|
229
|
f@0
|
230 //! This function should be implemented in subclasses that depend on the sample rate.
|
f@0
|
231 virtual void sampleRateChanged( StkFloat newRate, StkFloat oldRate );
|
f@0
|
232
|
f@0
|
233 //! Add class pointer to list for sample rate change notification.
|
f@0
|
234 void addSampleRateAlert( Stk *ptr );
|
f@0
|
235
|
f@0
|
236 //! Remove class pointer from list for sample rate change notification.
|
f@0
|
237 void removeSampleRateAlert( Stk *ptr );
|
f@0
|
238
|
f@0
|
239 //! Internal function for error reporting that assumes message in \c oStream_ variable.
|
f@0
|
240 void handleError( StkError::Type type ) const;
|
f@0
|
241 };
|
f@0
|
242
|
f@0
|
243
|
f@0
|
244 /***************************************************/
|
f@0
|
245 /*! \class StkFrames
|
f@0
|
246 \brief An STK class to handle vectorized audio data.
|
f@0
|
247
|
f@0
|
248 This class can hold single- or multi-channel audio data. The data
|
f@0
|
249 type is always StkFloat and the channel format is always
|
f@0
|
250 interleaved. In an effort to maintain efficiency, no
|
f@0
|
251 out-of-bounds checks are performed in this class unless
|
f@0
|
252 _STK_DEBUG_ is defined.
|
f@0
|
253
|
f@0
|
254 Internally, the data is stored in a one-dimensional C array. An
|
f@0
|
255 indexing operator is available to set and retrieve data values.
|
f@0
|
256 Alternately, one can use pointers to access the data, using the
|
f@0
|
257 index operator to get an address for a particular location in the
|
f@0
|
258 data:
|
f@0
|
259
|
f@0
|
260 StkFloat* ptr = &myStkFrames[0];
|
f@0
|
261
|
f@0
|
262 Note that this class can also be used as a table with interpolating
|
f@0
|
263 lookup.
|
f@0
|
264
|
f@0
|
265 Possible future improvements in this class could include functions
|
f@0
|
266 to convert to and return other data types.
|
f@0
|
267
|
f@0
|
268 by Perry R. Cook and Gary P. Scavone, 1995--2014.
|
f@0
|
269 */
|
f@0
|
270 /***************************************************/
|
f@0
|
271
|
f@0
|
272 class StkFrames
|
f@0
|
273 {
|
f@0
|
274 public:
|
f@0
|
275
|
f@0
|
276 //! The default constructor initializes the frame data structure to size zero.
|
f@0
|
277 StkFrames( unsigned int nFrames = 0, unsigned int nChannels = 0 );
|
f@0
|
278
|
f@0
|
279 //! Overloaded constructor that initializes the frame data to the specified size with \c value.
|
f@0
|
280 StkFrames( const StkFloat& value, unsigned int nFrames, unsigned int nChannels );
|
f@0
|
281
|
f@0
|
282 //! The destructor.
|
f@0
|
283 ~StkFrames();
|
f@0
|
284
|
f@0
|
285 // A copy constructor.
|
f@0
|
286 StkFrames( const StkFrames& f );
|
f@0
|
287
|
f@0
|
288 // Assignment operator that returns a reference to self.
|
f@0
|
289 StkFrames& operator= ( const StkFrames& f );
|
f@0
|
290
|
f@0
|
291 //! Subscript operator that returns a reference to element \c n of self.
|
f@0
|
292 /*!
|
f@0
|
293 The result can be used as an lvalue. This reference is valid
|
f@0
|
294 until the resize function is called or the array is destroyed. The
|
f@0
|
295 index \c n must be between 0 and size less one. No range checking
|
f@0
|
296 is performed unless _STK_DEBUG_ is defined.
|
f@0
|
297 */
|
f@0
|
298 StkFloat& operator[] ( size_t n );
|
f@0
|
299
|
f@0
|
300 //! Subscript operator that returns the value at element \c n of self.
|
f@0
|
301 /*!
|
f@0
|
302 The index \c n must be between 0 and size less one. No range
|
f@0
|
303 checking is performed unless _STK_DEBUG_ is defined.
|
f@0
|
304 */
|
f@0
|
305 StkFloat operator[] ( size_t n ) const;
|
f@0
|
306
|
f@0
|
307 //! Assignment by sum operator into self.
|
f@0
|
308 /*!
|
f@0
|
309 The dimensions of the argument are expected to be the same as
|
f@0
|
310 self. No range checking is performed unless _STK_DEBUG_ is
|
f@0
|
311 defined.
|
f@0
|
312 */
|
f@0
|
313 void operator+= ( StkFrames& f );
|
f@0
|
314
|
f@0
|
315 //! Assignment by product operator into self.
|
f@0
|
316 /*!
|
f@0
|
317 The dimensions of the argument are expected to be the same as
|
f@0
|
318 self. No range checking is performed unless _STK_DEBUG_ is
|
f@0
|
319 defined.
|
f@0
|
320 */
|
f@0
|
321 void operator*= ( StkFrames& f );
|
f@0
|
322
|
f@0
|
323 //! Channel / frame subscript operator that returns a reference.
|
f@0
|
324 /*!
|
f@0
|
325 The result can be used as an lvalue. This reference is valid
|
f@0
|
326 until the resize function is called or the array is destroyed. The
|
f@0
|
327 \c frame index must be between 0 and frames() - 1. The \c channel
|
f@0
|
328 index must be between 0 and channels() - 1. No range checking is
|
f@0
|
329 performed unless _STK_DEBUG_ is defined.
|
f@0
|
330 */
|
f@0
|
331 StkFloat& operator() ( size_t frame, unsigned int channel );
|
f@0
|
332
|
f@0
|
333 //! Channel / frame subscript operator that returns a value.
|
f@0
|
334 /*!
|
f@0
|
335 The \c frame index must be between 0 and frames() - 1. The \c
|
f@0
|
336 channel index must be between 0 and channels() - 1. No range checking
|
f@0
|
337 is performed unless _STK_DEBUG_ is defined.
|
f@0
|
338 */
|
f@0
|
339 StkFloat operator() ( size_t frame, unsigned int channel ) const;
|
f@0
|
340
|
f@0
|
341 //! Return an interpolated value at the fractional frame index and channel.
|
f@0
|
342 /*!
|
f@0
|
343 This function performs linear interpolation. The \c frame
|
f@0
|
344 index must be between 0.0 and frames() - 1. The \c channel index
|
f@0
|
345 must be between 0 and channels() - 1. No range checking is
|
f@0
|
346 performed unless _STK_DEBUG_ is defined.
|
f@0
|
347 */
|
f@0
|
348 StkFloat interpolate( StkFloat frame, unsigned int channel = 0 ) const;
|
f@0
|
349
|
f@0
|
350 //! Returns the total number of audio samples represented by the object.
|
f@0
|
351 size_t size() const { return size_; };
|
f@0
|
352
|
f@0
|
353 //! Returns \e true if the object size is zero and \e false otherwise.
|
f@0
|
354 bool empty() const;
|
f@0
|
355
|
f@0
|
356 //! Resize self to represent the specified number of channels and frames.
|
f@0
|
357 /*!
|
f@0
|
358 Changes the size of self based on the number of frames and
|
f@0
|
359 channels. No element assignment is performed. No memory
|
f@0
|
360 deallocation occurs if the new size is smaller than the previous
|
f@0
|
361 size. Further, no new memory is allocated when the new size is
|
f@0
|
362 smaller or equal to a previously allocated size.
|
f@0
|
363 */
|
f@0
|
364 void resize( size_t nFrames, unsigned int nChannels = 1 );
|
f@0
|
365
|
f@0
|
366 //! Resize self to represent the specified number of channels and frames and perform element initialization.
|
f@0
|
367 /*!
|
f@0
|
368 Changes the size of self based on the number of frames and
|
f@0
|
369 channels, and assigns \c value to every element. No memory
|
f@0
|
370 deallocation occurs if the new size is smaller than the previous
|
f@0
|
371 size. Further, no new memory is allocated when the new size is
|
f@0
|
372 smaller or equal to a previously allocated size.
|
f@0
|
373 */
|
f@0
|
374 void resize( size_t nFrames, unsigned int nChannels, StkFloat value );
|
f@0
|
375
|
f@0
|
376 //! Return the number of channels represented by the data.
|
f@0
|
377 unsigned int channels( void ) const { return nChannels_; };
|
f@0
|
378
|
f@0
|
379 //! Return the number of sample frames represented by the data.
|
f@0
|
380 unsigned int frames( void ) const { return (unsigned int)nFrames_; };
|
f@0
|
381
|
f@0
|
382 //! Set the sample rate associated with the StkFrames data.
|
f@0
|
383 /*!
|
f@0
|
384 By default, this value is set equal to the current STK sample
|
f@0
|
385 rate at the time of instantiation.
|
f@0
|
386 */
|
f@0
|
387 void setDataRate( StkFloat rate ) { dataRate_ = rate; };
|
f@0
|
388
|
f@0
|
389 //! Return the sample rate associated with the StkFrames data.
|
f@0
|
390 /*!
|
f@0
|
391 By default, this value is set equal to the current STK sample
|
f@0
|
392 rate at the time of instantiation.
|
f@0
|
393 */
|
f@0
|
394 StkFloat dataRate( void ) const { return dataRate_; };
|
f@0
|
395
|
f@0
|
396 private:
|
f@0
|
397
|
f@0
|
398 StkFloat *data_;
|
f@0
|
399 StkFloat dataRate_;
|
f@0
|
400 size_t nFrames_;
|
f@0
|
401 unsigned int nChannels_;
|
f@0
|
402 size_t size_;
|
f@0
|
403 size_t bufferSize_;
|
f@0
|
404
|
f@0
|
405 };
|
f@0
|
406
|
f@0
|
407 inline bool StkFrames :: empty() const
|
f@0
|
408 {
|
f@0
|
409 if ( size_ > 0 ) return false;
|
f@0
|
410 else return true;
|
f@0
|
411 }
|
f@0
|
412
|
f@0
|
413 inline StkFloat& StkFrames :: operator[] ( size_t n )
|
f@0
|
414 {
|
f@0
|
415 #if defined(_STK_DEBUG_)
|
f@0
|
416 if ( n >= size_ ) {
|
f@0
|
417 std::ostringstream error;
|
f@0
|
418 error << "StkFrames::operator[]: invalid index (" << n << ") value!";
|
f@0
|
419 Stk::handleError( error.str(), StkError::MEMORY_ACCESS );
|
f@0
|
420 }
|
f@0
|
421 #endif
|
f@0
|
422
|
f@0
|
423 return data_[n];
|
f@0
|
424 }
|
f@0
|
425
|
f@0
|
426 inline StkFloat StkFrames :: operator[] ( size_t n ) const
|
f@0
|
427 {
|
f@0
|
428 #if defined(_STK_DEBUG_)
|
f@0
|
429 if ( n >= size_ ) {
|
f@0
|
430 std::ostringstream error;
|
f@0
|
431 error << "StkFrames::operator[]: invalid index (" << n << ") value!";
|
f@0
|
432 Stk::handleError( error.str(), StkError::MEMORY_ACCESS );
|
f@0
|
433 }
|
f@0
|
434 #endif
|
f@0
|
435
|
f@0
|
436 return data_[n];
|
f@0
|
437 }
|
f@0
|
438
|
f@0
|
439 inline StkFloat& StkFrames :: operator() ( size_t frame, unsigned int channel )
|
f@0
|
440 {
|
f@0
|
441 #if defined(_STK_DEBUG_)
|
f@0
|
442 if ( frame >= nFrames_ || channel >= nChannels_ ) {
|
f@0
|
443 std::ostringstream error;
|
f@0
|
444 error << "StkFrames::operator(): invalid frame (" << frame << ") or channel (" << channel << ") value!";
|
f@0
|
445 Stk::handleError( error.str(), StkError::MEMORY_ACCESS );
|
f@0
|
446 }
|
f@0
|
447 #endif
|
f@0
|
448
|
f@0
|
449 return data_[ frame * nChannels_ + channel ];
|
f@0
|
450 }
|
f@0
|
451
|
f@0
|
452 inline StkFloat StkFrames :: operator() ( size_t frame, unsigned int channel ) const
|
f@0
|
453 {
|
f@0
|
454 #if defined(_STK_DEBUG_)
|
f@0
|
455 if ( frame >= nFrames_ || channel >= nChannels_ ) {
|
f@0
|
456 std::ostringstream error;
|
f@0
|
457 error << "StkFrames::operator(): invalid frame (" << frame << ") or channel (" << channel << ") value!";
|
f@0
|
458 Stk::handleError( error.str(), StkError::MEMORY_ACCESS );
|
f@0
|
459 }
|
f@0
|
460 #endif
|
f@0
|
461
|
f@0
|
462 return data_[ frame * nChannels_ + channel ];
|
f@0
|
463 }
|
f@0
|
464
|
f@0
|
465 inline void StkFrames :: operator+= ( StkFrames& f )
|
f@0
|
466 {
|
f@0
|
467 #if defined(_STK_DEBUG_)
|
f@0
|
468 if ( f.frames() != nFrames_ || f.channels() != nChannels_ ) {
|
f@0
|
469 std::ostringstream error;
|
f@0
|
470 error << "StkFrames::operator+=: frames argument must be of equal dimensions!";
|
f@0
|
471 Stk::handleError( error.str(), StkError::MEMORY_ACCESS );
|
f@0
|
472 }
|
f@0
|
473 #endif
|
f@0
|
474
|
f@0
|
475 StkFloat *fptr = &f[0];
|
f@0
|
476 StkFloat *dptr = data_;
|
f@0
|
477 for ( unsigned int i=0; i<size_; i++ )
|
f@0
|
478 *dptr++ += *fptr++;
|
f@0
|
479 }
|
f@0
|
480
|
f@0
|
481 inline void StkFrames :: operator*= ( StkFrames& f )
|
f@0
|
482 {
|
f@0
|
483 #if defined(_STK_DEBUG_)
|
f@0
|
484 if ( f.frames() != nFrames_ || f.channels() != nChannels_ ) {
|
f@0
|
485 std::ostringstream error;
|
f@0
|
486 error << "StkFrames::operator*=: frames argument must be of equal dimensions!";
|
f@0
|
487 Stk::handleError( error.str(), StkError::MEMORY_ACCESS );
|
f@0
|
488 }
|
f@0
|
489 #endif
|
f@0
|
490
|
f@0
|
491 StkFloat *fptr = &f[0];
|
f@0
|
492 StkFloat *dptr = data_;
|
f@0
|
493 for ( unsigned int i=0; i<size_; i++ )
|
f@0
|
494 *dptr++ *= *fptr++;
|
f@0
|
495 }
|
f@0
|
496
|
f@0
|
497 // Here are a few other useful typedefs.
|
f@0
|
498 typedef unsigned short UINT16;
|
f@0
|
499 typedef unsigned int UINT32;
|
f@0
|
500 typedef signed short SINT16;
|
f@0
|
501 typedef signed int SINT32;
|
f@0
|
502 typedef float FLOAT32;
|
f@0
|
503 typedef double FLOAT64;
|
f@0
|
504
|
f@0
|
505 // The default sampling rate.
|
f@0
|
506 const StkFloat SRATE = 44100.0;
|
f@0
|
507
|
f@0
|
508 // The default real-time audio input and output buffer size. If
|
f@0
|
509 // clicks are occuring in the input and/or output sound stream, a
|
f@0
|
510 // larger buffer size may help. Larger buffer sizes, however, produce
|
f@0
|
511 // more latency.
|
f@0
|
512 const unsigned int RT_BUFFER_SIZE = 512;
|
f@0
|
513
|
f@0
|
514 // The default rawwave path value is set with the preprocessor
|
f@0
|
515 // definition RAWWAVE_PATH. This can be specified as an argument to
|
f@0
|
516 // the configure script, in an integrated development environment, or
|
f@0
|
517 // below. The global STK rawwave path variable can be dynamically set
|
f@0
|
518 // with the Stk::setRawwavePath() function. This value is
|
f@0
|
519 // concatenated to the beginning of all references to rawwave files in
|
f@0
|
520 // the various STK core classes (ex. Clarinet.cpp). If you wish to
|
f@0
|
521 // move the rawwaves directory to a different location in your file
|
f@0
|
522 // system, you will need to set this path definition appropriately.
|
f@0
|
523 #if !defined(RAWWAVE_PATH)
|
f@0
|
524 #define RAWWAVE_PATH "../../rawwaves/"
|
f@0
|
525 #endif
|
f@0
|
526
|
f@0
|
527 #ifndef PI
|
f@0
|
528 const StkFloat PI = 3.14159265358979;
|
f@0
|
529 #endif
|
f@0
|
530 const StkFloat TWO_PI = 2 * PI;
|
f@0
|
531 const StkFloat ONE_OVER_128 = 0.0078125;
|
f@0
|
532
|
f@0
|
533 #if defined(__WINDOWS_DS__) || defined(__WINDOWS_ASIO__) || defined(__WINDOWS_MM__)
|
f@0
|
534 #define __OS_WINDOWS__
|
f@0
|
535 #define __STK_REALTIME__
|
f@0
|
536 #elif defined(__LINUX_OSS__) || defined(__LINUX_ALSA__) || defined(__UNIX_JACK__)
|
f@0
|
537 #define __OS_LINUX__
|
f@0
|
538 #define __STK_REALTIME__
|
f@0
|
539 #elif defined(__IRIX_AL__)
|
f@0
|
540 #define __OS_IRIX__
|
f@0
|
541 #elif defined(__MACOSX_CORE__) || defined(__UNIX_JACK__)
|
f@0
|
542 #define __OS_MACOSX__
|
f@0
|
543 #define __STK_REALTIME__
|
f@0
|
544 #endif
|
f@0
|
545
|
f@0
|
546 } // stk namespace
|
f@0
|
547
|
f@0
|
548 #endif
|