-
- double current_slope = (next_target - previous_target) /
- target_samples;
- double *trigger_buffer = input_buffer[trigger]->get_data();
- for(int i = 0; i < size; i++)
- {
-// Get slope from current sample to every sample in preview_samples.
-// Take highest one or first one after target_samples are up.
-
-// For optimization, calculate the first slope we really need.
-// Assume every slope up to the end of preview_samples has been calculated and
-// found <= to current slope.
- int first_slope = preview_samples - 1;
-// Need new slope immediately
- if(target_current_sample >= target_samples)
- first_slope = 1;
- for(int j = first_slope;
- j < preview_samples;
- j++)
- {
- double sample = 0.;
- switch(config.input)
- {
- case CompressorConfig::MAX:
- {
- double max = 0;
- for(int k = 0; k < total_buffers; k++)
- {
- sample = fabs(input_buffer[k]->get_data()[i + j]);
- if(sample > max) max = sample;
- }
- sample = max;
- break;
- }
-
- case CompressorConfig::TRIGGER:
- sample = fabs(trigger_buffer[i + j]);
- break;
-
- case CompressorConfig::SUM:
- {
- double max = 0;
- for(int k = 0; k < total_buffers; k++)
- {
- sample = fabs(input_buffer[k]->get_data()[i + j]);
- max += sample;
- }
- sample = max;
- break;
- }
- }
-
-
-
-
-
-
- double new_slope = (sample - current_value) /
- j;
-// Got equal or higher slope
- if(new_slope >= current_slope &&
- (current_slope >= 0 ||
- new_slope >= 0))
- {
- target_current_sample = 0;
- target_samples = j;
- current_slope = new_slope;
- next_target = sample;
- previous_target = current_value;
- }
- else
- if(sample > next_target && current_slope < 0)
- {
- target_current_sample = 0;
- target_samples = decay_samples;
- current_slope = (sample - current_value) /
- decay_samples;
- next_target = sample;
- previous_target = current_value;
- }
-
-// Hit end of current slope range without finding higher slope
- if(target_current_sample >= target_samples)
- {
- target_current_sample = 0;
- target_samples = decay_samples;
- current_slope = (sample - current_value) / decay_samples;
- next_target = sample;
- previous_target = current_value;
- }
- }
-
-// Update current value and multiply gain
- current_value = (next_target * target_current_sample +
- previous_target * (target_samples - target_current_sample)) /
- target_samples;
-//buffer[0][i] = current_value;
- target_current_sample++;
-
- if(config.smoothing_only)
- {
- for(int j = 0; j < total_buffers; j++)
- {
- buffer[j]->get_data()[i] = current_value;
- }
- }
- else
- {
- double gain = calculate_gain(current_value);
- for(int j = 0; j < total_buffers; j++)
- {
- buffer[j]->get_data()[i] = input_buffer[j]->get_data()[i] * gain;
- }
+// Expand buffer to handle preview size
+ if( size + preview_samples > input_allocated ) {
+ Samples **new_input_buffer = new Samples*[channels];
+ for( int i = 0; i < channels; i++ ) {
+ new_input_buffer[i] = new Samples(size + preview_samples);
+ if( input_buffer ) {
+ memcpy(new_input_buffer[i]->get_data(),
+ input_buffer[i]->get_data(),
+ input_size * sizeof(double));
+ delete input_buffer[i];