comparison core/PRU.cpp @ 235:3d41a6fa1830

Merge
author Giulio Moro <giuliomoro@yahoo.it>
date Sun, 10 Apr 2016 04:08:06 +0200
parents c0bf6157f67e
children 33e0e4831763 88cf310417cd
comparison
equal deleted inserted replaced
216:869f5e703844 235:3d41a6fa1830
97 97
98 const unsigned int PRU::kPruGPIOTestPin = 60; // GPIO1(28); P9-12 98 const unsigned int PRU::kPruGPIOTestPin = 60; // GPIO1(28); P9-12
99 const unsigned int PRU::kPruGPIOTestPin2 = 31; // GPIO0(31); P9-13 99 const unsigned int PRU::kPruGPIOTestPin2 = 31; // GPIO0(31); P9-13
100 const unsigned int PRU::kPruGPIOTestPin3 = 26; // GPIO0(26); P8-14 100 const unsigned int PRU::kPruGPIOTestPin3 = 26; // GPIO0(26); P8-14
101 101
102 extern bool gShouldStop; 102 extern int gShouldStop;
103 extern int gRTAudioVerbose; 103 extern int gRTAudioVerbose;
104 104
105 // Constructor: specify a PRU number (0 or 1) 105 // Constructor: specify a PRU number (0 or 1)
106 PRU::PRU(BeagleRTContext *input_context) 106 PRU::PRU(BeagleRTContext *input_context)
107 : context(input_context), pru_number(0), running(false), analog_enabled(false), 107 : context(input_context), pru_number(0), running(false), analog_enabled(false),
559 } 559 }
560 560
561 // Convert short (16-bit) samples to float 561 // Convert short (16-bit) samples to float
562 // TODO: NEON 562 // TODO: NEON
563 for(unsigned int n = 0; n < 2 * context->audioFrames; n++) 563 for(unsigned int n = 0; n < 2 * context->audioFrames; n++)
564 context->audioIn[n] = (float)pru_buffer_audio_adc[n + pru_audio_offset] / 32768.0; 564 context->audioIn[n] = (float)pru_buffer_audio_adc[n + pru_audio_offset] / 32768.0f;
565 565
566 if(analog_enabled) { 566 if(analog_enabled) {
567 // TODO: NEON 567 // TODO: NEON
568 for(unsigned int n = 0; n < context->analogChannels * context->analogFrames; n++) 568 for(unsigned int n = 0; n < context->analogChannels * context->analogFrames; n++)
569 context->analogIn[n] = (float)pru_buffer_spi_adc[n + pru_spi_offset] / 65536.0; 569 context->analogIn[n] = (float)pru_buffer_spi_adc[n + pru_spi_offset] / 65536.0f;
570 570
571 if(context->flags & BEAGLERT_FLAG_ANALOG_OUTPUTS_PERSIST) { 571 if(context->flags & BEAGLERT_FLAG_ANALOG_OUTPUTS_PERSIST) {
572 // Initialize the output buffer with the values that were in the last frame of the previous output 572 // Initialize the output buffer with the values that were in the last frame of the previous output
573 for(unsigned int ch = 0; ch < context->analogChannels; ch++){ 573 for(unsigned int ch = 0; ch < context->analogChannels; ch++){
574 for(unsigned int n = 0; n < context->analogFrames; n++){ 574 for(unsigned int n = 0; n < context->analogFrames; n++){
612 } 612 }
613 } 613 }
614 614
615 // Convert float back to short for SPI output 615 // Convert float back to short for SPI output
616 for(unsigned int n = 0; n < context->analogChannels * context->analogFrames; n++) { 616 for(unsigned int n = 0; n < context->analogChannels * context->analogFrames; n++) {
617 int out = context->analogOut[n] * 65536.0; 617 int out = context->analogOut[n] * 65536.0f;
618 if(out < 0) out = 0; 618 if(out < 0) out = 0;
619 else if(out > 65535) out = 65535; 619 else if(out > 65535) out = 65535;
620 pru_buffer_spi_dac[n + pru_spi_offset] = (uint16_t)out; 620 pru_buffer_spi_dac[n + pru_spi_offset] = (uint16_t)out;
621 } 621 }
622 } 622 }
628 } 628 }
629 629
630 // Convert float back to short for audio 630 // Convert float back to short for audio
631 // TODO: NEON 631 // TODO: NEON
632 for(unsigned int n = 0; n < 2 * context->audioFrames; n++) { 632 for(unsigned int n = 0; n < 2 * context->audioFrames; n++) {
633 int out = context->audioOut[n] * 32768.0; 633 int out = context->audioOut[n] * 32768.0f;
634 if(out < -32768) out = -32768; 634 if(out < -32768) out = -32768;
635 else if(out > 32767) out = 32767; 635 else if(out > 32767) out = 32767;
636 pru_buffer_audio_dac[n + pru_audio_offset] = (int16_t)out; 636 pru_buffer_audio_dac[n + pru_audio_offset] = (int16_t)out;
637 } 637 }
638 638