giuliomoro@23: /* giuliomoro@19: * giuliomoro@19: * First assignment for ECS732 RTDSP, to implement a 2-way audio crossover giuliomoro@19: * using the BeagleBone Black. giuliomoro@19: * giuliomoro@19: * Andrew McPherson and Victor Zappi giuliomoro@19: * Queen Mary, University of London giuliomoro@19: */ giuliomoro@19: andrewm@22: #include "../../include/render.h" giuliomoro@19: #include giuliomoro@19: #include giuliomoro@19: giuliomoro@19: /* TASK: declare any global variables you need here */ giuliomoro@19: giuliomoro@19: // initialise_render() is called once before the audio rendering starts. giuliomoro@19: // Use it to perform any initialisation and allocation which is dependent giuliomoro@19: // on the period size or sample rate. giuliomoro@19: // giuliomoro@19: // userData holds an opaque pointer to a data structure that was passed giuliomoro@19: // in from the call to initAudio(). giuliomoro@19: // giuliomoro@19: // Return true on success; returning false halts the program. giuliomoro@20: int gNumDigitalFrames=0; giuliomoro@20: bool initialise_render(int numAnalogChannels, int numDigitalChannels, int numAudioChannels, giuliomoro@20: int numAnalogFramesPerPeriod, giuliomoro@19: int numAudioFramesPerPeriod, giuliomoro@20: float analogSampleRate, float audioSampleRate, giuliomoro@33: void *userData, RTAudioSettings* settings) giuliomoro@19: { giuliomoro@20: gNumAnalogChannels=numAnalogChannels; giuliomoro@23: gNumDigitalChannels=numDigitalChannels; giuliomoro@19: return true; giuliomoro@19: } giuliomoro@19: giuliomoro@19: // render() is called regularly at the highest priority by the audio engine. giuliomoro@19: // Input and output are given from the audio hardware and the other giuliomoro@20: // ADCs and DACs (if available). If only audio is available, numAnalogFrames giuliomoro@19: // will be 0. giuliomoro@19: giuliomoro@19: long int gCountFrames=0; giuliomoro@20: void render(int numAnalogFrames, int numDigitalFrames, int numAudioFrames, float *audioIn, float *audioOut, giuliomoro@20: float *analogIn, float *analogOut, uint32_t *digital) giuliomoro@19: /* giuliomoro@23: we assume that gNumAnalogChannels=8, numAnalogFrames==8 and numDigitalFrames==numAudioFrames giuliomoro@19: * */ giuliomoro@19: { giuliomoro@23: if((gCountFrames&31)==0){ //every 32 frames... giuliomoro@23: //ANALOG channels giuliomoro@23: analogWrite(0, 0, analogRead(0,0)); // read the input0 at frame0 and write it to output0 frame0. Using analogWrite will fill the rest of the buffer with the same value giuliomoro@23: // The value at the last frame will persist through the successive buffers until is set again. giuliomoro@23: // This effectively is a pass-through with downsampling by 32 times giuliomoro@23: analogWrite(3, 0, 1.0); // write 1.0 to channel3 from frame0 to the end of the buffer giuliomoro@23: analogWrite(3, 4, 0.1); // write 0.1 to channel3 from frame4 to the end of the buffer giuliomoro@23: analogWriteFrame(3,6,0.2); //write 0.2 to channel3 only on frame 6 giuliomoro@23: //this buffer for channel 3 will look like this: 1 1 1 1 0.1 0.1 0.2 0.1 giuliomoro@23: //the next buffers for channel 3 will be filled up with 0.1 .... giuliomoro@23: //DIGITAL channels giuliomoro@23: digitalWrite(P8_07,0,GPIO_HIGH); //sets all the frames to HIGH for channel 0 giuliomoro@23: digitalWriteFrame(P8_07,4,GPIO_LOW); //only frame 4 will be LOW for channel 0 giuliomoro@23: // in this buffer the frames of channel 0 will look like this: 1 1 1 1 0 1 1 1 ...... 1 giuliomoro@23: // in the next buffer each frame of channel 0 will be initialized to 1 (the last value of this buffer) giuliomoro@23: digitalWrite(P8_08,0,GPIO_HIGH); giuliomoro@23: digitalWrite(P8_08,2,GPIO_LOW); giuliomoro@23: digitalWrite(P8_08,4,GPIO_HIGH); giuliomoro@23: digitalWrite(P8_08,5,GPIO_LOW); giuliomoro@33: setDigitalDirection(P9_16,0,GPIO_INPUT); // set channel 10 to input giuliomoro@23: // in this buffer the frames of channel 1 will look like this: 1 1 0 0 1 0 0 0 .... 0 giuliomoro@23: // in the next buffer each frame of channel 1 will be initialized to 0 (the last value of this buffer) giuliomoro@19: } giuliomoro@23: for(int n=0; n