//Tremolo(panner) effect has its parameters precalculated here in software. //The user only takes care of choosing the depth and rate of the trembling, //whereas the hardware receives calculated slope parameters. static void tremoloSendParams() { float slope, diff, best_diff; float actualRate; unsigned int a, b, j, k, depth; if (_tremoloDepth < 0 || _tremoloRate < 0) return; //The actual, ideal slope slope = 2 * _tremoloDepth*((1<<16)-1)*_tremoloRate / 48000; best_diff = infinityf(); //The hardware receives the slope of the trembling in the form of a //rational number a/b. //We find the closest approximation of the actual slope. for (k = 1; k<16; k++) { j = (int)roundf(slope*k); if (j < 1) j = 1; if (j > 15) j = 15; diff = fabsf( ((float)a/b) - slope); if (diff < best_diff) { a = j; b = k; best_diff = diff; } } depth = (int)floorf(_tremoloDepth * ((1<<16)-1)); IOWR_16DIRECT(PIO_TREMOLO_STEREO_DEPTH_BASE, 0, depth); IOWR_16DIRECT(PIO_TREMOLO_STEREO_SWEEP_A_BASE, 0, a); IOWR_16DIRECT(PIO_TREMOLO_STEREO_SWEEP_B_BASE, 0, b); }
float Thermistor::adc_value_to_temperature(int adc_value) { if ((adc_value == 4095) || (adc_value == 0)) return infinityf(); float r = r2 / ((4095.0 / adc_value) - 1.0); if (r1 > 0) r = (r1 * r) / (r1 - r); return (1.0 / (k + (j * log(r / r0)))) - 273.15; }
float Thermistor::adc_value_to_temperature(int adc_value) { if ((adc_value == 4095) || (adc_value == 0)) return infinityf(); // resistance of the thermistor in ohms float r = r2 / ((4095.0F / adc_value) - 1.0F); if (r1 > 0.0F) r = (r1 * r) / (r1 - r); float t; if(this->use_steinhart_hart) { float l = logf(r); t= (1.0F / (this->c1 + this->c2 * l + this->c3 * powf(l,3))) - 273.15F; }else{ // use Beta value t= (1.0F / (k + (j * logf(r / r0)))) - 273.15F; } return t; }
float Thermistor::get_temperature() { if(bad_config) return infinityf(); return adc_value_to_temperature(new_thermistor_reading()); }