Mercurial > hg > beaglert
comparison include/Utilities.h @ 528:5c8f46fcd4d0 API-update
Updated BelaContext to use separate values for in/ou channels
author | Giulio Moro <giuliomoro@yahoo.it> |
---|---|
date | Thu, 23 Jun 2016 18:17:35 +0100 |
parents | 02c4ca0e3718 |
children | bfcbeb437869 |
comparison
equal
deleted
inserted
replaced
527:1c68ad13bbe4 | 528:5c8f46fcd4d0 |
---|---|
292 * \param max_val Maximum possible value. | 292 * \param max_val Maximum possible value. |
293 * \return Constrained value. | 293 * \return Constrained value. |
294 */ | 294 */ |
295 static inline float constrain(float x, float min_val, float max_val); | 295 static inline float constrain(float x, float min_val, float max_val); |
296 | 296 |
297 /** | |
298 * Returns the maximum of two numbers | |
299 */ | |
300 static inline float min(float x, float y); | |
301 | |
302 /** | |
303 * Returns the minimum of two numbers | |
304 */ | |
305 static inline float max(float x, float y); | |
306 | |
297 /** @} */ | 307 /** @} */ |
298 // audioRead() | 308 // audioRead() |
299 // | 309 // |
300 // Returns the value of the given audio input at the given frame number. | 310 // Returns the value of the given audio input at the given frame number. |
301 static inline float audioRead(BelaContext *context, int frame, int channel) { | 311 static inline float audioRead(BelaContext *context, int frame, int channel) { |
302 return context->audioIn[frame * context->audioChannels + channel]; | 312 return context->audioIn[frame * context->audioInChannels + channel]; |
303 } | 313 } |
304 | 314 |
305 // audioWrite() | 315 // audioWrite() |
306 // | 316 // |
307 // Sets a given audio output channel to a value for the current frame | 317 // 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) { | 318 static inline void audioWrite(BelaContext *context, int frame, int channel, float value) { |
309 context->audioOut[frame * context->audioChannels + channel] = value; | 319 context->audioOut[frame * context->audioOutChannels + channel] = value; |
310 } | 320 } |
311 | 321 |
312 // analogRead() | 322 // analogRead() |
313 // | 323 // |
314 // Returns the value of the given analog input at the given frame number. | 324 // Returns the value of the given analog input at the given frame number. |
315 static inline float analogRead(BelaContext *context, int frame, int channel) { | 325 static inline float analogRead(BelaContext *context, int frame, int channel) { |
316 return context->analogIn[frame * context->analogChannels + channel]; | 326 return context->analogIn[frame * context->analogInChannels + channel]; |
317 } | 327 } |
318 | 328 |
319 // analogWrite() | 329 // analogWrite() |
320 // | 330 // |
321 // Sets a given analog output channel to a value for the current frame and, if persistent outputs are | 331 // Sets a given analog output channel to a value for the current frame and, if persistent outputs are |
322 // enabled, for all subsequent frames | 332 // enabled, for all subsequent frames |
323 static inline void analogWrite(BelaContext *context, int frame, int channel, float value) { | 333 static inline void analogWrite(BelaContext *context, int frame, int channel, float value) { |
324 if(context->flags & BELA_FLAG_ANALOG_OUTPUTS_PERSIST) { | 334 if(context->flags & BELA_FLAG_ANALOG_OUTPUTS_PERSIST) { |
325 for(unsigned int f = frame; f < context->analogFrames; f++) | 335 for(unsigned int f = frame; f < context->analogFrames; f++) |
326 context->analogOut[frame * context->analogChannels + channel] = value; | 336 context->analogOut[frame * context->analogOutChannels + channel] = value; |
327 } | 337 } |
328 else | 338 else |
329 context->analogOut[frame * context->analogChannels + channel] = value; | 339 context->analogOut[frame * context->analogOutChannels + channel] = value; |
330 } | 340 } |
331 | 341 |
332 // analogWriteOnce() | 342 // analogWriteOnce() |
333 // | 343 // |
334 // Sets a given channel to a value for only the current frame | 344 // 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) { | 345 static inline void analogWriteOnce(BelaContext *context, int frame, int channel, float value) { |
336 context->analogOut[frame * context->analogChannels + channel] = value; | 346 context->analogOut[frame * context->analogOutChannels + channel] = value; |
337 } | 347 } |
338 | 348 |
339 // digitalRead() | 349 // digitalRead() |
340 // | 350 // |
341 // Returns the value of a given digital input at the given frame number | 351 // Returns the value of a given digital input at the given frame number |
410 if(x < min_val) return min_val; | 420 if(x < min_val) return min_val; |
411 if(x > max_val) return max_val; | 421 if(x > max_val) return max_val; |
412 return x; | 422 return x; |
413 } | 423 } |
414 | 424 |
425 static inline float max(float x, float y){ | |
426 return x > y ? x : y; | |
427 } | |
428 | |
429 static inline float min(float x, float y){ | |
430 return x < y ? x : y; | |
431 } | |
432 | |
415 #endif /* UTILITIES_H_ */ | 433 #endif /* UTILITIES_H_ */ |