comparison include/Utilities.h @ 539:b486344aa796 prerelease

merge
author Giulio Moro <giuliomoro@yahoo.it>
date Fri, 24 Jun 2016 01:43:53 +0100
parents bfcbeb437869
children
comparison
equal deleted inserted replaced
538:58652b93ef7e 539:b486344aa796
40 #endif /* OUTPUT */ 40 #endif /* OUTPUT */
41 41
42 /** @} */ 42 /** @} */
43 43
44 /** 44 /**
45 * \ingroup wiring 45 * \cond BIT_FUNCTIONS
46 * 46 *
47 * @{ 47 * @{
48 */ 48 */
49 49
50 /// Set the given bit in \c word to 1. 50 /// Set the given bit in \c word to 1.
57 #define getBit(word,bit) (((word) >> (bit)) & 1) 57 #define getBit(word,bit) (((word) >> (bit)) & 1)
58 58
59 /// Set/clear the given bit in \c word to \c value. 59 /// Set/clear the given bit in \c word to \c value.
60 #define changeBit(word,bit,value) ((clearBit((word),(bit))) | ((value) << (bit))) 60 #define changeBit(word,bit,value) ((clearBit((word),(bit))) | ((value) << (bit)))
61 61
62 /** @} */ 62 /** @}
63 * \endcond
64 * */
63 65
64 /** 66 /**
65 * \ingroup iofunctions 67 * \ingroup iofunctions
66 * 68 *
67 * @{ 69 * @{
292 * \param max_val Maximum possible value. 294 * \param max_val Maximum possible value.
293 * \return Constrained value. 295 * \return Constrained value.
294 */ 296 */
295 static inline float constrain(float x, float min_val, float max_val); 297 static inline float constrain(float x, float min_val, float max_val);
296 298
299 /**
300 * \brief Returns the maximum of two numbers
301 *
302 * Returns the maximum of two numbers
303 */
304 static inline float min(float x, float y);
305
306 /**
307 * \brief Returns the minimum of two numbers
308 *
309 * Returns the minimum of two numbers
310 */
311 static inline float max(float x, float y);
312
297 /** @} */ 313 /** @} */
298 // audioRead() 314 // audioRead()
299 // 315 //
300 // Returns the value of the given audio input at the given frame number. 316 // Returns the value of the given audio input at the given frame number.
301 static inline float audioRead(BelaContext *context, int frame, int channel) { 317 static inline float audioRead(BelaContext *context, int frame, int channel) {
302 return context->audioIn[frame * context->audioChannels + channel]; 318 return context->audioIn[frame * context->audioInChannels + channel];
303 } 319 }
304 320
305 // audioWrite() 321 // audioWrite()
306 // 322 //
307 // Sets a given audio output channel to a value for the current frame 323 // Sets a given audio output channel to a value for the current frame
308 static inline void audioWrite(BelaContext *context, int frame, int channel, float value) { 324 static inline void audioWrite(BelaContext *context, int frame, int channel, float value) {
309 context->audioOut[frame * context->audioChannels + channel] = value; 325 context->audioOut[frame * context->audioOutChannels + channel] = value;
310 } 326 }
311 327
312 // analogRead() 328 // analogRead()
313 // 329 //
314 // Returns the value of the given analog input at the given frame number. 330 // Returns the value of the given analog input at the given frame number.
315 static inline float analogRead(BelaContext *context, int frame, int channel) { 331 static inline float analogRead(BelaContext *context, int frame, int channel) {
316 return context->analogIn[frame * context->analogChannels + channel]; 332 return context->analogIn[frame * context->analogInChannels + channel];
317 } 333 }
318 334
319 // analogWrite() 335 // analogWrite()
320 // 336 //
321 // Sets a given analog output channel to a value for the current frame and, if persistent outputs are 337 // Sets a given analog output channel to a value for the current frame and, if persistent outputs are
322 // enabled, for all subsequent frames 338 // enabled, for all subsequent frames
323 static inline void analogWrite(BelaContext *context, int frame, int channel, float value) { 339 static inline void analogWrite(BelaContext *context, int frame, int channel, float value) {
324 if(context->flags & BELA_FLAG_ANALOG_OUTPUTS_PERSIST) { 340 if(context->flags & BELA_FLAG_ANALOG_OUTPUTS_PERSIST) {
325 for(unsigned int f = frame; f < context->analogFrames; f++) 341 for(unsigned int f = frame; f < context->analogFrames; f++)
326 context->analogOut[frame * context->analogChannels + channel] = value; 342 context->analogOut[frame * context->analogOutChannels + channel] = value;
327 } 343 }
328 else 344 else
329 context->analogOut[frame * context->analogChannels + channel] = value; 345 context->analogOut[frame * context->analogOutChannels + channel] = value;
330 } 346 }
331 347
332 // analogWriteOnce() 348 // analogWriteOnce()
333 // 349 //
334 // Sets a given channel to a value for only the current frame 350 // Sets a given channel to a value for only the current frame
335 static inline void analogWriteOnce(BelaContext *context, int frame, int channel, float value) { 351 static inline void analogWriteOnce(BelaContext *context, int frame, int channel, float value) {
336 context->analogOut[frame * context->analogChannels + channel] = value; 352 context->analogOut[frame * context->analogOutChannels + channel] = value;
337 } 353 }
338 354
339 // digitalRead() 355 // digitalRead()
340 // 356 //
341 // Returns the value of a given digital input at the given frame number 357 // Returns the value of a given digital input at the given frame number
410 if(x < min_val) return min_val; 426 if(x < min_val) return min_val;
411 if(x > max_val) return max_val; 427 if(x > max_val) return max_val;
412 return x; 428 return x;
413 } 429 }
414 430
431 static inline float max(float x, float y){
432 return x > y ? x : y;
433 }
434
435 static inline float min(float x, float y){
436 return x < y ? x : y;
437 }
438
415 #endif /* UTILITIES_H_ */ 439 #endif /* UTILITIES_H_ */