| 120 | } |
| 121 | |
| 122 | void Recorder::config_callback(SensorConfigurationPacket *config) { |
| 123 | // Check for PDM MIC ID |
| 124 | if (config->sensorId != PDM_MIC) return; |
| 125 | |
| 126 | // Get sample rate |
| 127 | int sample_rate = int(config->sampleRate); |
| 128 | |
| 129 | // Make sure that pdm mic is not running |
| 130 | recorder.stop(); |
| 131 | |
| 132 | // only end recording if sample rate is 0 or both mics are turned off |
| 133 | if (sample_rate == 0 || (config->latency & 0xFFFF) == 0xFFFF) { |
| 134 | return; |
| 135 | } |
| 136 | |
| 137 | // Check for valid sample rate |
| 138 | recorder.setSampleRate(sample_rate); |
| 139 | |
| 140 | int8_t gain_l = config->latency & 0xFF; |
| 141 | int8_t gain_r = (config->latency >> 8) & 0xFF; |
| 142 | |
| 143 | // number of channels |
| 144 | recorder.setChannels((gain_l >= 0) + (gain_r >= 0)); |
| 145 | |
| 146 | // set gain for each channel |
| 147 | pdm_mic.setGain(gain_l, gain_r); |
| 148 | |
| 149 | if (((config->latency >> 16) & 0xFF) == 1) { |
| 150 | // ocllusion test |
| 151 | recorder.setTarget(new BLEStream()); |
| 152 | } else { |
| 153 | // find the next available file name for the recording |
| 154 | const String recording_dir = "Recordings"; |
| 155 | |
| 156 | if (!sd_manager.exists(recording_dir)) sd_manager.mkdir(recording_dir); |
| 157 | |
| 158 | ExFile file; |
| 159 | ExFile dir = sd_manager.sd->open(recording_dir); |
| 160 | |
| 161 | char fileName[64]; |
| 162 | char * split; |
| 163 | |
| 164 | int n = 1; |
| 165 | |
| 166 | // find highest Recording number |
| 167 | while (file = dir.openNextFile()) { |
| 168 | file.getName(fileName, sizeof(fileName)); |
| 169 | |
| 170 | split = strtok(fileName, "_"); |
| 171 | if (strcmp(split,"Recording") == 0) { |
| 172 | split = strtok(NULL, "_"); |
| 173 | n = max(n, atoi(split) + 1); |
| 174 | } |
| 175 | } |
| 176 | |
| 177 | // file name of the new recording |
| 178 | String file_name = "/" + recording_dir + "/Recording_" + String(n) + "_" + String(millis()) + ".wav"; |
| 179 |
nothing calls this directly
no test coverage detected