<commit_before>/*
*   TrebleBoost_wComp
*
*   Created: <NAME>, OpenAudio, Apr 2017
*   Purpose: Process audio by applying a high-pass filter followed by gain followed
*            by a dynamic range compressor.
*
*   Uses Tympan Audio Adapter.
*   Blue potentiometer adjusts the digital gain applied to the filtered audio signal.
*   
*   MIT License.  use at your own risk.
*/

//here are the libraries that we need
#include <Audio.h>           //include the Teensy Audio Library
#include <Tympan_Library.h>  //include the Tympan Library

//set the sample rate and block size
const float sample_rate_Hz = 24000.0f ; //24000 or 44117 (or other frequencies in the table in AudioOutputI2S_F32)
const int audio_block_samples = 32;     //do not make bigger than AUDIO_BLOCK_SAMPLES from AudioStream.h (which is 128)
AudioSettings_F32 audio_settings(sample_rate_Hz, audio_block_samples);

//create audio library objects for handling the audio
AudioControlTLV320AIC3206 audioHardware;
AudioInputI2S_F32         i2s_in(audio_settings);     //Digital audio in *from* the Teensy Audio Board ADC. 
AudioFilterBiquad_F32     hp_filt1(audio_settings);   //IIR filter doing a highpass filter.  Left.
AudioFilterBiquad_F32     hp_filt2(audio_settings);   //IIR filter doing a highpass filter.  Right.
AudioEffectCompWDRC_F32   comp1(audio_settings);      //Compresses the dynamic range of the audio.  Left.
AudioEffectCompWDRC_F32   comp2(audio_settings);      //Compresses the dynamic range of the audio.  Right.
AudioOutputI2S_F32        i2s_out(audio_settings);    //Digital audio out *to* the Teensy Audio Board DAC. 

//Make all of the audio connections
AudioConnection_F32       patchCord1(i2s_in, 0, hp_filt1, 0);   //connect the Left input to the left highpass filter
AudioConnection_F32       patchCord2(i2s_in, 1, hp_filt2, 0);   //connect the Right input to the right highpass filter
AudioConnection_F32       patchCord3(hp_filt1, 0, comp1, 0);    //connect to the left gain/compressor/limiter 
AudioConnection_F32       patchCord4(hp_filt2, 0, comp2, 0);    //connect to the right gain/compressor/limiter
AudioConnection_F32       patchCord5(comp1, 0, i2s_out, 0);     //connectto the Left output
AudioConnection_F32       patchCord6(comp2, 0, i2s_out, 1);     //connect to the Right output

//define a function to configure the left and right compressors
void setupMyCompressors(void) {
  //set the speed of the compressor's response
  float attack_msec = 5.0;
  float release_msec = 300.0;
  comp1.setAttackRelease_msec(attack_msec, release_msec); //left channel
  comp2.setAttackRelease_msec(attack_msec, release_msec); //right channel

  //Single point system calibration.  what is the SPL of a full scale input (including effect of input_gain_dB)?
  float SPL_of_full_scale_input = 115.0;  
  comp1.setMaxdB(SPL_of_full_scale_input);  //left channel
  comp2.setMaxdB(SPL_of_full_scale_input);  //right channel

  //now define the compression parameters
  float knee_compressor_dBSPL = 55.0;  //follows setMaxdB() above
  float comp_ratio = 1.5;
  comp1.setKneeCompressor_dBSPL(knee_compressor_dBSPL);  //left channel
  comp2.setKneeCompressor_dBSPL(knee_compressor_dBSPL);  //right channel
  comp1.setCompRatio(comp_ratio); //left channel
  comp2.setCompRatio(comp_ratio);

  //finally, the WDRC module includes a limiter at the end.  set its parameters
  float knee_limiter_dBSPL = SPL_of_full_scale_input - 20.0;  //follows setMaxdB() above
  //note: the WDRC limiter is hard-wired to a compression ratio of 10:1
  comp1.setKneeLimiter_dBSPL(knee_limiter_dBSPL);  //left channel
  comp2.setKneeLimiter_dBSPL(knee_limiter_dBSPL);  //right channel
  
}

//I have a potentiometer on the Teensy Audio Board
#define POT_PIN A1  //potentiometer is tied to this pin

// define the setup() function, the function that is called once when the device is booting
const float input_gain_dB = 20.0f; //gain on the microphone
float vol_knob_gain_dB = 0.0;      //will be overridden by volume knob
void setup() {
  //begin the serial comms (for debugging)
  Serial.begin(115200);  delay(500);
  Serial.println("TrebleBoost_wComp: Starting setup()...");
  
  //allocate the audio memory first
  AudioMemory(10); AudioMemory_F32(10,audio_settings); //allocate both kinds of memory

  //Enable the Tympan to start the audio flowing!
  audioHardware.enable(); // activate AIC
  
  //Choose the desired input
  audioHardware.inputSelect(TYMPAN_INPUT_ON_BOARD_MIC); // use the on board microphones
  // audioHardware.inputSelect(TYMPAN_INPUT_JACK_AS_MIC); // use the microphone jack - defaults to mic bias 2.5V
  // audioHardware.inputSelect(TYMPAN_INPUT_JACK_AS_LINEIN); // use the microphone jack - defaults to mic bias OFF

  //Set the desired volume levels<commit_msg>Update TrebleBoost_wComp.ino<commit_after>/*
*   TrebleBoost_wComp
*
*   Created: <NAME>, OpenAudio, Apr 2017
*   Purpose: Process audio by applying a high-pass filter followed by gain followed
*            by a dynamic range compressor.
*
*   Uses Tympan Audio Adapter.
*   Blue potentiometer adjusts the digital gain applied to the filtered audio signal.
*   
*   MIT License.  use at your own risk.
*/

//here are the libraries that we need
#include <Audio.h>           //include the Teensy Audio Library
#include <Tympan_Library.h>  //include the Tympan Library

//set the sample rate and block size
const float sample_rate_Hz = 24000.0f ; //24000 or 44117 (or other frequencies in the table in AudioOutputI2S_F32)
const int audio_block_samples = 32;     //do not make bigger than AUDIO_BLOCK_SAMPLES from AudioStream.h (which is 128)
AudioSettings_F32 audio_settings(sample_rate_Hz, audio_block_samples);

//create audio library objects for handling the audio
AudioControlTLV320AIC3206 audioHardware;
AudioInputI2S_F32         i2s_in(audio_settings);     //Digital audio in *from* the Teensy Audio Board ADC. 
AudioFilterBiquad_F32     hp_filt1(audio_settings);   //IIR filter doing a highpass filter.  Left.
AudioFilterBiquad_F32     hp_filt2(audio_settings);   //IIR filter doing a highpass filter.  Right.
AudioEffectCompWDRC_F32   comp1(audio_settings);      //Compresses the dynamic range of the audio.  Left.
AudioEffectCompWDRC_F32   comp2(audio_settings);      //Compresses the dynamic range of the audio.  Right.
AudioOutputI2S_F32        i2s_out(audio_settings);    //Digital audio out *to* the Teensy Audio Board DAC. 

//Make all of the audio connections
AudioConnection_F32       patchCord1(i2s_in, 0, hp_filt1, 0);   //connect the Left input to the left highpass filter
AudioConnection_F32       patchCord2(i2s_in, 1, hp_filt2, 0);   //connect the Right input to the right highpass filter
AudioConnection_F32       patchCord3(hp_filt1, 0, comp1, 0);    //connect to the left gain/compressor/limiter 
AudioConnection_F32       patchCord4(hp_filt2, 0, comp2, 0);    //connect to the right gain/compressor/limiter
AudioConnection_F32       patchCord5(comp1, 0, i2s_out, 0);     //connectto the Left output
AudioConnection_F32       patchCord6(comp2, 0, i2s_out, 1);     //connect to the Right output

//define a function to configure the left and right compressors
void setupMyCompressors(void) {
  //set the speed of the compressor's response
  float attack_msec = 5.0;
  float release_msec = 300.0;
  comp1.setAttackRelease_msec(attack_msec, release_msec); //left channel
  comp2.setAttackRelease_msec(attack_msec, release_msec); //right channel

  //Single point system calibration.  what is the SPL of a full scale input (including effect of input_gain_dB)?
  float SPL_of_full_scale_input = 115.0;  
  comp1.setMaxdB(SPL_of_full_scale_input);  //left channel
  comp2.setMaxdB(SPL_of_full_scale_input);  //right channel

  //now define the compression parameters
  float knee_compressor_dBSPL = 55.0;  //follows setMaxdB() above
  float comp_ratio = 1.5;
  comp1.setKneeCompressor_dBSPL(knee_compressor_dBSPL);  //left channel
  comp2.setKneeCompressor_dBSPL(knee_compressor_dBSPL);  //right channel
  comp1.setCompRatio(comp_ratio); //left channel
  comp2.setCompRatio(comp_ratio);

  //finally, the WDRC module includes a limiter at the end.  set its parameters
  float knee_limiter_dBSPL = SPL_of_full_scale_input - 20.0;  //follows setMaxdB() above
  //note: the WDRC limiter is hard-wired to a compression ratio of 10:1
  comp1.setKneeLimiter_dBSPL(knee_limiter_dBSPL);  //left channel
  comp2.setKneeLimiter_dBSPL(knee_limiter_dBSPL);  //right channel
  
}

//I have a potentiometer on the Teensy Audio Board
#define POT_PIN A1  //potentiometer is tied to this pin

// define the setup() function, the function that is called once when the device is booting
const float input_gain_dB = 20.0f; //gain on the microphone
float vol_knob_gain_dB = 0.0;      //will be overridden by volume knob
void setup() {
  //begin the serial comms (for debugging)
  Serial.begin(115200);  delay(500);
  Serial.println("TrebleBoost_wComp: Starting setup()...");
  
  //allocate the audio memory first
  AudioMemory(10); AudioMemory_F32(10,audio_settings); //allocate both kinds of memory

  //Enable the Tympan to start the audio flowing!
  audioHardware.enable(); // activate AIC
  
  //Choose the desired input
  //audioHardware.inputSelect(TYMPAN_INPUT_ON_BOARD_MIC); // use the on board microphones
  audioHardware.inputSelect(TYMPAN_INPUT_JACK_AS_MIC); // use the microphone jack - defaults to mic bias 2.5V
  // audioHardware.inputSelect(TYMPAN_INPUT_JACK_AS_LINEIN); // use the microphone jack - defaults to mic bias OFF

  //Set the desired volume levels
{'fraction_non_alphanumeric': 0.07820701238715096, 'fraction_numerical': 0.03212261179928617, 'mean_word_length': 4.0036764705882355, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 9, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '977612', 'n_tokens_mistral': 3360, 'n_tokens_neox': 3091, 'n_words': 984}