andrewm@0: /* andrewm@0: * RTAudio.h andrewm@0: * andrewm@0: * Central control code for hard real-time audio on BeagleBone Black andrewm@0: * using PRU and Xenomai Linux extensions. This code began as part andrewm@0: * of the Hackable Instruments project (EPSRC) at Queen Mary University andrewm@0: * of London, 2013-14. andrewm@0: * andrewm@0: * (c) 2014 Victor Zappi and Andrew McPherson andrewm@0: * Queen Mary University of London andrewm@0: */ andrewm@0: andrewm@0: andrewm@0: #ifndef RTAUDIO_H_ andrewm@0: #define RTAUDIO_H_ andrewm@0: andrewm@0: #include "render.h" andrewm@0: andrewm@0: // Useful constants andrewm@0: #define DBOX_CAPE // New custom cape andrewm@0: andrewm@0: #ifdef DBOX_CAPE andrewm@0: #define CODEC_I2C_ADDRESS 0x18 // Address of TLV320AIC3104 codec andrewm@0: #else andrewm@0: #define CODEC_I2C_ADDRESS 0x1B // Address of TLV320AIC3106 codec andrewm@0: #endif andrewm@0: andrewm@5: // Default volume levels andrewm@5: #define DEFAULT_DAC_LEVEL 0.0 andrewm@5: #define DEFAULT_ADC_LEVEL -6.0 andrewm@5: #define DEFAULT_HP_LEVEL -6.0 giuliomoro@16: #define MAX_PRU_FILENAME_LENGTH 256 andrewm@5: andrewm@0: enum { andrewm@0: kAmplifierMutePin = 61 // P8-26 controls amplifier mute andrewm@0: }; andrewm@0: andrewm@5: // Structure which contains initialisation parameters for the andrewm@5: // real-time audio system andrewm@5: typedef struct { andrewm@5: // These items might be adjusted by the user: giuliomoro@19: int periodSize; // Number of (analog) frames per period; audio is twice this andrewm@5: int beginMuted; // Whether to begin with the speakers muted andrewm@5: float dacLevel; // Level for the audio DAC output andrewm@5: float adcLevel; // Level for the audio ADC input andrewm@5: float headphoneLevel; // Level for the headphone output giuliomoro@19: int useAnalog; // Whether to use the analog giuliomoro@19: int useDigital; // Whether to use the 16 programmable GPIOs giuliomoro@19: int numAnalogChannels; // How many channels for the ADC and DAC giuliomoro@19: int numDigitalChannels; // How many channels for the GPIOs andrewm@5: int verbose; // Whether to use verbose logging giuliomoro@16: char pruFilename[MAX_PRU_FILENAME_LENGTH]; //the external .bin file to load. If empty will use PRU code from pru_rtaudio_bin.h andrewm@5: // These items are hardware-dependent and should only be changed andrewm@5: // to run on different hardware andrewm@5: int codecI2CAddress; // Where the codec can be found on the I2C bus andrewm@5: int ampMutePin; // Pin where amplifier mute can be found andrewm@5: } RTAudioSettings; andrewm@5: andrewm@0: typedef void* AuxiliaryTask; // Opaque data type to keep track of aux tasks andrewm@0: andrewm@0: // Flag that indicates when the audio will stop; can be read or andrewm@0: // set by other components which should end at the same time as the audio andrewm@0: extern bool gShouldStop; andrewm@0: andrewm@5: // Command-line settings andrewm@5: void BeagleRT_defaultSettings(RTAudioSettings *settings); andrewm@5: int BeagleRT_getopt_long(int argc, char *argv[], const char *customShortOptions, andrewm@5: const struct option *customLongOptions, RTAudioSettings *settings); andrewm@5: void BeagleRT_usage(); andrewm@0: andrewm@5: // Basic audio control functions: init, start, stop and clean up andrewm@5: int BeagleRT_initAudio(RTAudioSettings *settings, void *userData); andrewm@5: int BeagleRT_startAudio(); andrewm@5: void BeagleRT_stopAudio(); andrewm@5: void BeagleRT_cleanupAudio(); andrewm@5: andrewm@5: // Volume/level controls andrewm@5: // These return 0 on success andrewm@5: andrewm@5: // Set the level of the DAC; affects all outputs (headphone, line, speaker) andrewm@5: // 0dB is the maximum, -63.5dB is the minimum; 0.5dB steps andrewm@5: int BeagleRT_setDACLevel(float decibels); andrewm@5: andrewm@5: // Set the level of the ADC andrewm@5: // 0dB is the maximum, -12dB is the minimum; 1.5dB steps andrewm@5: int BeagleRT_setADCLevel(float decibels); andrewm@5: andrewm@5: // Set the level of the onboard headphone amplifier; affects headphone andrewm@5: // output only (not line out or speaker) andrewm@5: // 0dB is the maximum, -63.5dB is the minimum; 0.5dB steps andrewm@5: int BeagleRT_setHeadphoneLevel(float decibels); andrewm@5: andrewm@5: // Mute or unmute the onboard speaker amplifiers andrewm@5: // mute == 0 means unmute; otherwise mute andrewm@5: // Returns 0 on success andrewm@5: int BeagleRT_muteSpeakers(int mute); andrewm@5: andrewm@5: // Functions for creating auxiliary tasks andrewm@0: AuxiliaryTask createAuxiliaryTaskLoop(void (*functionToCall)(void), int priority, const char *name); andrewm@0: void scheduleAuxiliaryTask(AuxiliaryTask task); andrewm@0: andrewm@0: void setVerboseLevel(int level); andrewm@0: andrewm@0: #endif /* RTAUDIO_H_ */