annotate include/BeagleRT.h @ 257:1606b50a58c6 aux_task_args

missing semicolon
author Liam Donovan <l.b.donovan@qmul.ac.uk>
date Sat, 07 May 2016 12:51:10 +0100
parents 3e93d9793da3
children 88cf310417cd
rev   line source
andrewm@47 1 /**
andrewm@47 2 * @file
andrewm@47 3 * @brief Main BeagleRT public API
andrewm@46 4 *
andrewm@46 5 * Central control code for hard real-time audio on BeagleBone Black
andrewm@46 6 * using PRU and Xenomai Linux extensions. This code began as part
andrewm@46 7 * of the Hackable Instruments project (EPSRC) at Queen Mary University
andrewm@46 8 * of London, 2013-14.
andrewm@46 9 *
andrewm@47 10 * (c) 2014-15 Andrew McPherson, Victor Zappi and Giulio Moro,
andrewm@46 11 * Queen Mary University of London
andrewm@46 12 */
andrewm@46 13
andrewm@48 14 /**
andrewm@48 15 * \mainpage
andrewm@48 16 *
andrewm@48 17 * BeagleRT is a hard-real-time, ultra-low latency audio and sensor environment for
andrewm@48 18 * BeagleBone Black, which works with the BeagleBone Audio Cape or a custom "BeagleRT Cape"
andrewm@48 19 * which incorporates stereo audio with 8x, 16-bit analog inputs and outputs.
andrewm@48 20 *
andrewm@48 21 * BeagleRT is based on the Xenomai real-time Linux extensions (http://xenomai.org) and
andrewm@48 22 * uses the BeagleBone %PRU subsystem to address the audio and sensor hardware.
andrewm@48 23 *
andrewm@48 24 * Further information can be found at http://beaglert.cc
andrewm@48 25 */
andrewm@48 26
andrewm@46 27
andrewm@46 28 #ifndef BEAGLERT_H_
andrewm@46 29 #define BEAGLERT_H_
andrewm@46 30
andrewm@46 31 #include <stdint.h>
giuliomoro@173 32 #include <unistd.h>
andrewm@55 33 #include <rtdk.h>
andrewm@46 34 #include "digital_gpio_mapping.h"
giuliomoro@237 35 #include <GPIOcontrol.h>
andrewm@46 36
andrewm@46 37 // Useful constants
andrewm@47 38
andrewm@47 39 /** \cond PRIVATE */
andrewm@46 40 #define DBOX_CAPE // New custom cape
andrewm@46 41 #ifdef DBOX_CAPE
andrewm@46 42 #define CODEC_I2C_ADDRESS 0x18 // Address of TLV320AIC3104 codec
andrewm@46 43 #else
andrewm@46 44 #define CODEC_I2C_ADDRESS 0x1B // Address of TLV320AIC3106 codec
andrewm@46 45 #endif
andrewm@46 46
andrewm@46 47 #define MAX_PRU_FILENAME_LENGTH 256
andrewm@46 48 #define MAX_SERVERNAME_LENGTH 256
andrewm@47 49 /** \endcond */
andrewm@46 50
andrewm@47 51 /**
andrewm@47 52 * \ingroup auxtask
andrewm@47 53 *
andrewm@47 54 * Xenomai priority level for audio processing. Maximum possible priority is 99.
andrewm@47 55 * In general, all auxiliary tasks should have a level lower than this unless for\
andrewm@47 56 * special purposes where the task needs to interrupt audio processing.
andrewm@47 57 */
andrewm@46 58 #define BEAGLERT_AUDIO_PRIORITY 95
andrewm@46 59
andrewm@47 60 // Default volume levels
andrewm@47 61
andrewm@47 62 /**
andrewm@47 63 * \addtogroup levels
andrewm@47 64 *
andrewm@47 65 * @{
andrewm@47 66 */
andrewm@47 67
andrewm@47 68 /**
andrewm@47 69 * Default level of the audio DAC in decibels. See BeagleRT_setDACLevel().
andrewm@47 70 */
andrewm@47 71 #define DEFAULT_DAC_LEVEL 0.0
andrewm@47 72
andrewm@47 73 /**
andrewm@47 74 * Default level of the audio ADC in decibels. See BeagleRT_setADCLevel().
andrewm@47 75 */
andrewm@47 76 #define DEFAULT_ADC_LEVEL -6.0
andrewm@47 77
giuliomoro@171 78
giuliomoro@171 79 /**
giuliomoro@171 80 * Default level of the Programmable Gain Amplifier in decibels.
giuliomoro@171 81 */
giuliomoro@171 82 #define DEFAULT_PGA_GAIN 16
giuliomoro@171 83
andrewm@47 84 /**
andrewm@47 85 * Default level of the headphone output in decibels. See BeagleRT_setHeadphoneLevel().
andrewm@47 86 */
andrewm@47 87 #define DEFAULT_HP_LEVEL -6.0
andrewm@47 88 /** @} */
andrewm@47 89
andrewm@47 90 /**
andrewm@47 91 * Flag for BeagleRTContext. If set, indicates the audio and analog buffers are interleaved.
andrewm@47 92 */
andrewm@46 93 #define BEAGLERT_FLAG_INTERLEAVED (1 << 0) // Set if buffers are interleaved
andrewm@47 94 /**
andrewm@47 95 * Flag for BeagleRTContext. If set, indicates analog outputs persist for future frames.
andrewm@47 96 */
andrewm@46 97 #define BEAGLERT_FLAG_ANALOG_OUTPUTS_PERSIST (1 << 1) // Set if analog/digital outputs persist for future buffers
andrewm@46 98
andrewm@47 99 /**
andrewm@47 100 * \ingroup control
andrewm@47 101 * \brief Structure containing initialisation parameters for the real-time
andrewm@47 102 * audio control system.
andrewm@47 103 *
andrewm@47 104 * This structure is initialised using BeagleRT_defaultSettings(). Its contents
andrewm@47 105 * are used up through the point of calling
andrewm@47 106 * BeagleRT_initAudio() at which point it is no longer needed.
andrewm@47 107 */
andrewm@46 108 typedef struct {
andrewm@46 109 // These items might be adjusted by the user:
andrewm@46 110
andrewm@47 111 /// \brief Number of (analog) frames per period.
andrewm@47 112 ///
andrewm@47 113 /// Number of audio frames depends on relative sample rates of the two. By default,
andrewm@47 114 /// audio is twice the sample rate, so has twice the period size.
andrewm@47 115 int periodSize;
andrewm@47 116 /// Whether to use the analog input and output
andrewm@47 117 int useAnalog;
andrewm@47 118 /// Whether to use the 16 programmable GPIOs
andrewm@47 119 int useDigital;
andrewm@47 120 /// How many channels for the ADC and DAC
andrewm@47 121 int numAnalogChannels;
andrewm@47 122 /// How many channels for the GPIOs
andrewm@47 123 int numDigitalChannels;
andrewm@46 124
andrewm@47 125 /// Whether to begin with the speakers muted
andrewm@47 126 int beginMuted;
andrewm@47 127 /// Level for the audio DAC output
andrewm@47 128 float dacLevel;
andrewm@47 129 /// Level for the audio ADC input
andrewm@47 130 float adcLevel;
giuliomoro@171 131 /// Gains for the PGA, left and right channels
giuliomoro@171 132 float pgaGain[2];
andrewm@47 133 /// Level for the headphone output
andrewm@47 134 float headphoneLevel;
andrewm@47 135
andrewm@47 136 /// The external .bin file to load. If empty will use PRU code from pru_rtaudio_bin.h
andrewm@47 137 char pruFilename[MAX_PRU_FILENAME_LENGTH];
andrewm@47 138 /// Whether to use verbose logging
andrewm@47 139 int verbose;
andrewm@46 140
andrewm@46 141 // These items are application-dependent but should probably be
andrewm@46 142 // determined by the programmer rather than the user
andrewm@47 143
andrewm@47 144 /// Whether audio/analog data should be interleaved
andrewm@47 145 int interleave;
andrewm@47 146 /// \brief Whether analog outputs should persist to future frames.
andrewm@47 147 ///
andrewm@47 148 /// n.b. digital pins always persist, audio never does
andrewm@47 149 int analogOutputsPersist;
andrewm@46 150
andrewm@46 151 // These items are hardware-dependent and should only be changed
andrewm@46 152 // to run on different hardware
andrewm@47 153
andrewm@47 154 /// Where the codec can be found on the I2C bus
andrewm@47 155 int codecI2CAddress;
andrewm@47 156 /// Pin where amplifier mute can be found
andrewm@47 157 int ampMutePin;
andrewm@47 158 /// Port where the UDP server will listen
andrewm@47 159 int receivePort;
andrewm@47 160 /// Port where the UDP client will transmit
andrewm@47 161 int transmitPort;
andrewm@46 162 char serverName[MAX_SERVERNAME_LENGTH];
andrewm@46 163 } BeagleRTInitSettings;
andrewm@46 164
andrewm@46 165
andrewm@47 166 /**
andrewm@47 167 * \ingroup render
andrewm@47 168 * \brief Structure holding current audio and sensor settings and pointers to data buffers.
andrewm@47 169 *
andrewm@56 170 * This structure is passed to setup(), render() and cleanup(). It is
andrewm@47 171 * initialised in BeagleRT_initAudio() based on the contents of the BeagleRTInitSettings
andrewm@47 172 * structure.
andrewm@47 173 */
andrewm@46 174 typedef struct {
andrewm@47 175 /// \brief Buffer holding audio input samples
andrewm@47 176 ///
andrewm@47 177 /// This buffer may be in either interleaved or non-interleaved format,
andrewm@47 178 /// depending on the contents of the BeagleRTInitSettings structure.
andrewm@47 179 /// \b Note: this element is available in render() only.
andrewm@46 180 float *audioIn;
andrewm@47 181
andrewm@47 182 /// \brief Buffer holding audio output samples
andrewm@47 183 ///
andrewm@47 184 /// This buffer may be in either interleaved or non-interleaved format,
andrewm@47 185 /// depending on the contents of the BeagleRTInitSettings structure.
andrewm@47 186 /// \b Note: this element is available in render() only.
andrewm@46 187 float *audioOut;
andrewm@47 188
andrewm@47 189 /// \brief Buffer holding analog input samples
andrewm@47 190 ///
andrewm@47 191 /// This buffer may be in either interleaved or non-interleaved format,
andrewm@47 192 /// depending on the contents of the BeagleRTInitSettings structure.
andrewm@47 193 /// \b Note: this element is available in render() only.
andrewm@46 194 float *analogIn;
andrewm@47 195
andrewm@47 196 /// \brief Buffer holding analog output samples
andrewm@47 197 ///
andrewm@47 198 /// This buffer may be in either interleaved or non-interleaved format,
andrewm@47 199 /// depending on the contents of the BeagleRTInitSettings structure.
andrewm@47 200 /// \b Note: this element is available in render() only.
andrewm@46 201 float *analogOut;
andrewm@47 202
andrewm@47 203 /// \brief Buffer holding digital input/output samples
andrewm@47 204 ///
andrewm@47 205 /// \b Note: this element is available in render() only.
andrewm@46 206 uint32_t *digital;
andrewm@46 207
andrewm@47 208 /// Number of audio frames per period
andrewm@46 209 uint32_t audioFrames;
andrewm@47 210 /// Number of audio channels (currently always 2)
andrewm@46 211 uint32_t audioChannels;
andrewm@47 212 /// Audio sample rate in Hz (currently always 44100.0)
andrewm@46 213 float audioSampleRate;
andrewm@46 214
andrewm@47 215 /// \brief Number of analog frames per period
andrewm@47 216 ///
andrewm@47 217 /// This will be 0 if analog I/O is disabled.
andrewm@46 218 uint32_t analogFrames;
andrewm@47 219
andrewm@47 220 /// \brief Number of analog channels
andrewm@47 221 ///
andrewm@47 222 /// This could take a value of 8, 4 or 2. This will be 0 if analog I/O is disabled.
andrewm@46 223 uint32_t analogChannels;
andrewm@47 224
andrewm@47 225 /// \brief Analog sample rate in Hz
andrewm@47 226 ///
andrewm@47 227 /// The analog sample rate depends on the number of analog channels used. If
andrewm@47 228 /// 8 channels are used, the sample rate is 22050. If 4 channels are used, the sample
andrewm@47 229 /// rate is 44100. If 2 channels are used, the sample rate is 88200. If analog I/O
andrewm@47 230 /// is disabled, the sample rate is 0.
andrewm@46 231 float analogSampleRate;
andrewm@46 232
andrewm@47 233 /// Number of digital frames per period
andrewm@46 234 uint32_t digitalFrames;
andrewm@47 235 /// \brief Number of digital channels
andrewm@47 236 ///
andrewm@47 237 /// Currently this will always be 16, unless digital I/O is disabled, in which case it will be 0.
andrewm@46 238 uint32_t digitalChannels;
andrewm@47 239 /// Digital sample rate in Hz (currently always 44100.0)
andrewm@46 240 float digitalSampleRate;
andrewm@46 241
andrewm@47 242 /// \brief Number of elapsed audio samples since the start of rendering.
andrewm@47 243 ///
andrewm@47 244 /// This holds the total number of audio samples as of the beginning of the current period. To
andrewm@47 245 /// find the current number of analog or digital samples elapsed, multiply by the ratio of the
andrewm@47 246 /// sample rates (e.g. half the number of analog samples will have elapsed if the analog sample
andrewm@47 247 /// rate is 22050).
andrewm@46 248 uint64_t audioSampleCount;
andrewm@47 249
andrewm@47 250 /// \brief Other audio/sensor settings
andrewm@47 251 ///
andrewm@47 252 /// Binary combination of flags including:
andrewm@47 253 ///
andrewm@47 254 /// BEAGLERT_FLAG_INTERLEAVED: indicates the audio and analog buffers are interleaved
andrewm@47 255 ///
andrewm@47 256 /// BEAGLERT_FLAG_ANALOG_OUTPUTS_PERSIST: indicates that writes to the analog outputs will
andrewm@47 257 /// persist for future frames. If not set, writes affect one frame only.
andrewm@46 258 uint32_t flags;
andrewm@46 259 } BeagleRTContext;
andrewm@46 260
andrewm@47 261 /** \ingroup auxtask
andrewm@47 262 *
andrewm@47 263 * Auxiliary task variable. Auxiliary tasks are created using createAuxiliaryTask() and
andrewm@56 264 * automatically cleaned up after cleanup() finishes.
andrewm@47 265 */
andrewm@46 266 typedef void* AuxiliaryTask; // Opaque data type to keep track of aux tasks
andrewm@46 267
andrewm@47 268 /** \ingroup render
andrewm@47 269 *
andrewm@47 270 * Flag that indicates when the audio will stop. Threads can poll this variable to indicate when
andrewm@47 271 * they should stop. Additionally, a program can set this to \c true
andrewm@47 272 * to indicate that audio processing should terminate. Calling BeagleRT_stopAudio()
andrewm@47 273 * has the effect of setting this to \c true.
andrewm@47 274 */
giuliomoro@233 275 extern int gShouldStop;
andrewm@46 276
andrewm@46 277 // *** User-defined render functions ***
andrewm@46 278
andrewm@46 279 /**
andrewm@47 280 * \defgroup render User-defined render functions
andrewm@47 281 *
andrewm@47 282 * These three functions must be implemented by the developer in every BeagleRT program.
andrewm@47 283 * Typically they appear in their own .cpp source file.
andrewm@47 284 *
andrewm@47 285 * @{
andrewm@47 286 */
andrewm@47 287
andrewm@47 288 /**
andrewm@46 289 * \brief User-defined initialisation function which runs before audio rendering begins.
andrewm@46 290 *
andrewm@46 291 * This function runs once at the beginning of the program, after most of the system
andrewm@46 292 * initialisation has begun but before audio rendering starts. Use it to prepare any
andrewm@46 293 * memory or resources that will be needed in render().
andrewm@46 294 *
andrewm@46 295 * \param context Data structure holding information on sample rates, numbers of channels,
andrewm@46 296 * frame sizes and other state. Note: the buffers for audio, analog and digital data will
andrewm@46 297 * \b not yet be available to use. Do not attempt to read or write audio or sensor data
andrewm@56 298 * in setup().
andrewm@46 299 * \param userData An opaque pointer to an optional user-defined data structure. Whatever
andrewm@46 300 * is passed as the second argument to BeagleRT_initAudio() will appear here.
andrewm@46 301 *
andrewm@46 302 * \return true on success, or false if an error occurred. If no initialisation is
andrewm@56 303 * required, setup() should return true.
andrewm@46 304 */
andrewm@56 305 bool setup(BeagleRTContext *context, void *userData);
andrewm@46 306
andrewm@46 307 /**
andrewm@46 308 * \brief User-defined callback function to process audio and sensor data.
andrewm@46 309 *
andrewm@46 310 * This function is called regularly by the system every time there is a new block of
andrewm@46 311 * audio and/or sensor data to process. Your code should process the requested samples
andrewm@46 312 * of data, store the results within \c context, and return.
andrewm@46 313 *
andrewm@46 314 * \param context Data structure holding buffers for audio, analog and digital data. The
andrewm@46 315 * structure also holds information on numbers of channels, frame sizes and sample rates,
andrewm@46 316 * which are guaranteed to remain the same throughout the program and to match what was
andrewm@56 317 * passed to setup().
andrewm@46 318 * \param userData An opaque pointer to an optional user-defined data structure. Will
andrewm@56 319 * be the same as the \c userData parameter passed to setup().
andrewm@46 320 */
andrewm@46 321 void render(BeagleRTContext *context, void *userData);
andrewm@46 322
andrewm@46 323 /**
andrewm@46 324 * \brief User-defined cleanup function which runs when the program finishes.
andrewm@46 325 *
andrewm@46 326 * This function is called by the system once after audio rendering has finished, before the
andrewm@56 327 * program quits. Use it to release any memory allocated in setup() and to perform
andrewm@56 328 * any other required cleanup. If no initialisation is performed in setup(), then
andrewm@46 329 * this function will usually be empty.
andrewm@46 330 *
andrewm@46 331 * \param context Data structure holding information on sample rates, numbers of channels,
andrewm@46 332 * frame sizes and other state. Note: the buffers for audio, analog and digital data will
andrewm@46 333 * no longer be available to use. Do not attempt to read or write audio or sensor data
andrewm@56 334 * in cleanup().
andrewm@46 335 * \param userData An opaque pointer to an optional user-defined data structure. Will
andrewm@56 336 * be the same as the \c userData parameter passed to setup() and render().
andrewm@46 337 */
andrewm@56 338 void cleanup(BeagleRTContext *context, void *userData);
andrewm@46 339
andrewm@47 340 /** @} */
andrewm@47 341
andrewm@47 342 /**
andrewm@47 343 * \defgroup control Control and command line functions
andrewm@47 344 *
andrewm@47 345 * These functions are used to initialise the BeagleRT settings, process arguments
andrewm@47 346 * from the command line, and start/stop the audio and sensor system.
andrewm@47 347 *
andrewm@47 348 * @{
andrewm@47 349 */
andrewm@47 350
andrewm@46 351 // *** Command-line settings ***
andrewm@46 352
andrewm@46 353 /**
andrewm@46 354 * \brief Initialise the data structure containing settings for BeagleRT.
andrewm@46 355 *
andrewm@46 356 * This function should be called in main() before parsing any command-line arguments. It
andrewm@46 357 * sets default values in the data structure which specifies the BeagleRT settings, including
andrewm@46 358 * frame sizes, numbers of channels, volume levels and other parameters.
andrewm@46 359 *
andrewm@46 360 * \param settings Structure holding initialisation data for BeagleRT.
andrewm@46 361 */
andrewm@46 362 void BeagleRT_defaultSettings(BeagleRTInitSettings *settings);
andrewm@46 363
andrewm@46 364 /**
andrewm@46 365 * \brief Get long options from command line argument list, including BeagleRT standard options
andrewm@46 366 *
andrewm@46 367 * This function should be used in main() to process command line options, in place of the
andrewm@46 368 * standard library getopt_long(). Internally, it parses standard BeagleRT command-line options,
andrewm@46 369 * storing the results in the settings data structure. Any options which are not part of the
andrewm@46 370 * BeagleRT standard options will be returned, as they would normally be in getopt_long().
andrewm@46 371 *
andrewm@46 372 * \param argc Number of command line options, as passed to main().
andrewm@46 373 * \param argv Array of command line options, as passed to main().
andrewm@46 374 * \param customShortOptions List of short options to be parsed, analogous to getopt_long(). This
andrewm@46 375 * list should not include any characters already parsed as part of the BeagleRT standard options.
andrewm@46 376 * \param customLongOptions List of long options to parsed, analogous to getopt_long(). This
andrewm@46 377 * list should not include any long options already parsed as part of the BeagleRT standard options.
andrewm@46 378 * \param settings Data structure holding initialisation settings for BeagleRT. Any standard options
andrewm@46 379 * parsed will automatically update this data structure.
andrewm@46 380 *
andrewm@46 381 * \return Value of the next option parsed which is not a BeagleRT standard option, or -1 when the
andrewm@46 382 * argument list has been exhausted. Similar to the return value of getopt_long() except that BeagleRT
andrewm@46 383 * standard options are handled internally and not returned.
andrewm@46 384 */
andrewm@46 385 int BeagleRT_getopt_long(int argc, char *argv[], const char *customShortOptions,
andrewm@46 386 const struct option *customLongOptions, BeagleRTInitSettings *settings);
andrewm@46 387
andrewm@46 388 /**
andrewm@46 389 * \brief Print usage information for BeagleRT standard options.
andrewm@46 390 *
andrewm@46 391 * This function should be called from your code wherever you wish to print usage information for the
andrewm@46 392 * user. It will print usage information on BeagleRT standard options, after which you can print usage
andrewm@46 393 * information for your own custom options.
andrewm@46 394 */
andrewm@46 395 void BeagleRT_usage();
andrewm@46 396
andrewm@46 397 /**
andrewm@46 398 * \brief Set level of verbose (debugging) printing.
andrewm@46 399 *
andrewm@46 400 * \param level Verbosity level of the internal BeagleRT system. 0 by default; higher values will
andrewm@46 401 * print more information. Presently all positive numbers produce the same level of printing.
andrewm@46 402 */
andrewm@46 403 void BeagleRT_setVerboseLevel(int level);
andrewm@46 404
andrewm@47 405
andrewm@46 406 // *** Audio control functions ***
andrewm@46 407
andrewm@46 408 /**
andrewm@46 409 * \brief Initialise audio and sensor rendering environment.
andrewm@46 410 *
andrewm@46 411 * This function prepares audio rendering in BeagleRT. It should be called from main() sometime
andrewm@46 412 * after command line option parsing has finished. It will initialise the rendering system, which
andrewm@56 413 * in the process will result in a call to the user-defined setup() function.
andrewm@46 414 *
andrewm@46 415 * \param settings Data structure holding system settings, including numbers of channels, frame sizes,
andrewm@46 416 * volume levels and other information.
andrewm@46 417 * \param userData An opaque pointer to a user-defined data structure which will be passed to
andrewm@56 418 * setup(), render() and cleanup(). You can use this to pass custom information
andrewm@46 419 * to the rendering functions, as an alternative to using global variables.
andrewm@46 420 *
andrewm@46 421 * \return 0 on success, or nonzero if an error occurred.
andrewm@46 422 */
andrewm@46 423 int BeagleRT_initAudio(BeagleRTInitSettings *settings, void *userData);
andrewm@46 424
andrewm@46 425 /**
andrewm@46 426 * \brief Begin processing audio and sensor data.
andrewm@46 427 *
andrewm@46 428 * This function will start the BeagleRT audio/sensor system. After this function is called, the
andrewm@46 429 * system will make periodic calls to render() until BeagleRT_stopAudio() is called.
andrewm@46 430 *
andrewm@46 431 * \return 0 on success, or nonzero if an error occurred.
andrewm@46 432 */
andrewm@46 433 int BeagleRT_startAudio();
andrewm@46 434
andrewm@46 435 /**
andrewm@46 436 * \brief Stop processing audio and sensor data.
andrewm@46 437 *
andrewm@46 438 * This function will stop the BeagleRT audio/sensor system. After this function returns, no further
andrewm@46 439 * calls to render() will be issued.
andrewm@46 440 */
giuliomoro@174 441 int BeagleRT_startAuxiliaryTask(AuxiliaryTask it);
andrewm@46 442 void BeagleRT_stopAudio();
andrewm@46 443
andrewm@46 444 /**
andrewm@46 445 * \brief Clean up resources from audio and sensor processing.
andrewm@46 446 *
andrewm@46 447 * This function should only be called after BeagleRT_stopAudio(). It will release any
andrewm@46 448 * internal resources for audio and sensor processing. In the process, it will call the
andrewm@56 449 * user-defined cleanup() function.
andrewm@46 450 */
andrewm@46 451 void BeagleRT_cleanupAudio();
andrewm@46 452
andrewm@47 453 /** @} */
andrewm@47 454
andrewm@47 455 /**
andrewm@47 456 * \defgroup levels Audio level controls
andrewm@47 457 *
andrewm@47 458 * These functions control the input and output levels for the audio codec. If a BeagleRT program
andrewm@47 459 * does not call these functions, sensible default levels will be used.
andrewm@47 460 *
andrewm@47 461 * @{
andrewm@47 462 */
andrewm@46 463
andrewm@46 464 // *** Volume and level controls ***
andrewm@46 465
andrewm@46 466 /**
andrewm@46 467 * \brief Set the level of the audio DAC.
andrewm@46 468 *
andrewm@46 469 * This function sets the level of all audio outputs (headphone, line, speaker). It does
andrewm@46 470 * not affect the level of the (non-audio) analog outputs.
andrewm@46 471 *
andrewm@46 472 * \b Important: do not call this function from within render(), as it does not make
andrewm@46 473 * any guarantees on real-time performance.
andrewm@46 474 *
andrewm@46 475 * \param decibels Level of the DAC output. Valid levels range from -63.5 (lowest) to
andrewm@46 476 * 0 (highest) in steps of 0.5dB. Levels between increments of 0.5 will be rounded down.
andrewm@46 477 *
andrewm@46 478 * \return 0 on success, or nonzero if an error occurred.
andrewm@46 479 */
andrewm@46 480 int BeagleRT_setDACLevel(float decibels);
andrewm@46 481
andrewm@46 482 /**
andrewm@46 483 * \brief Set the level of the audio ADC.
andrewm@46 484 *
andrewm@46 485 * This function sets the level of the audio input. It does not affect the level of the
andrewm@46 486 * (non-audio) analog inputs.
andrewm@46 487 *
andrewm@46 488 * \b Important: do not call this function from within render(), as it does not make
andrewm@46 489 * any guarantees on real-time performance.
andrewm@46 490 *
andrewm@46 491 * \param decibels Level of the ADC input. Valid levels range from -12 (lowest) to
andrewm@46 492 * 0 (highest) in steps of 1.5dB. Levels between increments of 1.5 will be rounded down.
andrewm@46 493 *
andrewm@46 494 * \return 0 on success, or nonzero if an error occurred.
andrewm@46 495 */
andrewm@46 496 int BeagleRT_setADCLevel(float decibels);
andrewm@46 497
giuliomoro@171 498
giuliomoro@171 499 /**
giuliomoro@171 500 * \brief Set the gain of the audio preamplifier.
giuliomoro@171 501 *
giuliomoro@171 502 * This function sets the level of the Programmable Gain Amplifier(PGA), which
giuliomoro@171 503 * amplifies the signal before the ADC.
giuliomoro@171 504 *
giuliomoro@171 505 * \b Important: do not call this function from within render(), as it does not make
giuliomoro@171 506 * any guarantees on real-time performance.
giuliomoro@171 507 *
giuliomoro@171 508 * \param decibels Level of the PGA Valid levels range from 0 (lowest) to
giuliomoro@171 509 * 59.5 (highest) in steps of 0.5dB. Levels between increments of 0.5 will be rounded.
giuliomoro@171 510 * \param channel Specifies which channel to apply the gain to. Channel 0 is left,
giuliomoro@171 511 * channel 1 is right
giuliomoro@171 512 *
giuliomoro@171 513 * \return 0 on success, or nonzero if an error occurred.
giuliomoro@171 514 */
giuliomoro@171 515 int BeagleRT_setPgaGain(float decibels, int channel);
giuliomoro@171 516
andrewm@46 517 /**
andrewm@46 518 * \brief Set the level of the onboard headphone amplifier.
andrewm@46 519 *
andrewm@46 520 * This function sets the level of the headphone output only (3-pin connector on the BeagleRT
andrewm@46 521 * cape or the output jack on the BeagleBone Audio Cape). It does not affect the level of the
andrewm@46 522 * speakers or the line out pads on the cape.
andrewm@46 523 *
andrewm@46 524 * \b Important: do not call this function from within render(), as it does not make
andrewm@46 525 * any guarantees on real-time performance.
andrewm@46 526 *
andrewm@46 527 * \param decibels Level of the DAC output. Valid levels range from -63.5 (lowest) to
andrewm@46 528 * 0 (highest) in steps of 0.5dB. Levels between increments of 0.5 will be rounded down.
andrewm@46 529 *
andrewm@46 530 * \return 0 on success, or nonzero if an error occurred.
andrewm@46 531 */
andrewm@46 532 int BeagleRT_setHeadphoneLevel(float decibels);
andrewm@46 533
andrewm@46 534 /**
andrewm@46 535 * \brief Mute or unmute the onboard speaker amplifiers.
andrewm@46 536 *
andrewm@46 537 * This function mutes or unmutes the amplifiers on the BeagleRT cape. Whether the speakers begin
andrewm@46 538 * muted or unmuted depends on the BeagleRTInitSettings structure passed to BeagleRT_initAudio().
andrewm@46 539 *
andrewm@46 540 * \b Important: do not call this function from within render(), as it does not make
andrewm@46 541 * any guarantees on real-time performance.
andrewm@46 542 *
andrewm@46 543 * \param mute 0 to enable the speakers, nonzero to mute the speakers.
andrewm@46 544 *
andrewm@46 545 * \return 0 on success, or nonzero if an error occurred.
andrewm@46 546 */
andrewm@46 547 int BeagleRT_muteSpeakers(int mute);
andrewm@46 548
andrewm@47 549 /** @} */
andrewm@47 550
andrewm@47 551 /**
andrewm@47 552 * \defgroup auxtask Auxiliary task support
andrewm@47 553 *
andrewm@47 554 * These functions are used to create separate real-time tasks (threads) which run at lower
andrewm@47 555 * priority than the audio processing. They can be used, for example, for large time-consuming
andrewm@47 556 * calculations which would take more than one audio frame length to process, or they could be
andrewm@47 557 * used to communicate with external hardware when that communication might block or be delayed.
andrewm@47 558 *
andrewm@56 559 * All auxiliary tasks used by the program should be created in setup(). The tasks
andrewm@47 560 * can then be scheduled at will within the render() function.
andrewm@47 561 *
andrewm@47 562 * @{
andrewm@47 563 */
andrewm@47 564
andrewm@46 565 // *** Functions for creating auxiliary tasks ***
andrewm@46 566
andrewm@46 567 /**
andrewm@46 568 * \brief Create a new auxiliary task.
andrewm@46 569 *
andrewm@46 570 * This function creates a new auxiliary task which, when scheduled, runs the function specified
andrewm@46 571 * in the first argument. Note that the task does not run until scheduleAuxiliaryTask() is called.
andrewm@56 572 * Auxiliary tasks should be created in setup() and never in render() itself.
andrewm@46 573 *
andrewm@46 574 * The second argument specifies the real-time priority. Valid values are between 0
andrewm@47 575 * and 99, and usually should be lower than \ref BEAGLERT_AUDIO_PRIORITY. Tasks with higher priority always
andrewm@46 576 * preempt tasks with lower priority.
andrewm@46 577 *
andrewm@46 578 * \param functionToCall Function which will run each time the auxiliary task is scheduled.
andrewm@46 579 * \param priority Xenomai priority level at which the task should run.
andrewm@47 580 * \param name Name for this task, which should be unique system-wide (no other running program should use this name).
andrewm@46 581 */
l@254 582 AuxiliaryTask BeagleRT_createAuxiliaryTask(void (*functionToCall)(void*), int priority, const char *name, void* args);
l@257 583 AuxiliaryTask BeagleRT_createAuxiliaryTask(void (*functionToCall)(void), int priority, const char *name);
andrewm@46 584
andrewm@46 585 /**
giuliomoro@174 586 * \brief Start an auxiliary task so that it can be run.
giuliomoro@174 587 *
giuliomoro@174 588 * This function will start an auxiliary task but will NOT schedule it.
giuliomoro@174 589 * It will also set a flag in the associate InternalAuxiliaryTask to flag the
giuliomoro@174 590 * task as "started", so that successive calls to the same function for a given AuxiliaryTask
giuliomoro@174 591 * have no effect.
giuliomoro@174 592 * The user should never be required to call this function directly, as it is called
giuliomoro@174 593 * by BeagleRT_scheduleAuxiliaryTask if needed (e.g.: if a task is scheduled in setup() )
giuliomoro@174 594 * or immediately after starting the audio thread.
giuliomoro@174 595 *
giuliomoro@174 596 * \param task Task to start.
giuliomoro@174 597 */
giuliomoro@174 598
giuliomoro@174 599 int BeagleRT_startAuxiliaryTask(AuxiliaryTask task);
giuliomoro@174 600 /**
andrewm@46 601 * \brief Run an auxiliary task which has previously been created.
andrewm@46 602 *
andrewm@46 603 * This function will schedule an auxiliary task to run. When the task runs, the function in the first
andrewm@46 604 * argument of createAuxiliaryTaskLoop() will be called.
andrewm@46 605 *
andrewm@46 606 * scheduleAuxiliaryTask() is typically called from render() to start a lower-priority task. The function
andrewm@46 607 * will not run immediately, but only once any active higher priority tasks have finished.
andrewm@46 608 *
andrewm@46 609 * \param task Task to schedule for running.
andrewm@46 610 */
andrewm@47 611 void BeagleRT_scheduleAuxiliaryTask(AuxiliaryTask task);
andrewm@47 612
andrewm@47 613 /** @} */
giuliomoro@187 614 #include <Utilities.h>
andrewm@46 615
andrewm@46 616 #endif /* BEAGLERT_H_ */