Commit 2c7faea5 authored by Raymond Toy's avatar Raymond Toy Committed by Commit Bot

Split up OscillatorNode processing for a- and k-rate

Split the processing into sample accurate and not sample accurate so we
can work on them independently to optimize each.

No functional changes.

Bug: 1013118
Change-Id: I58bce37b33fee9e4a272e164a6b0b4f37c7f8d1d
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2174994
Commit-Queue: Raymond Toy <rtoy@chromium.org>
Reviewed-by: default avatarHongchan Choi <hongchan@chromium.org>
Cr-Commit-Position: refs/heads/master@{#771109}
parent be32e763
......@@ -351,6 +351,84 @@ static float DoInterpolation(double virtual_read_index,
return sample;
}
double OscillatorHandler::ProcessKRate(int n,
float* dest_p,
double virtual_read_index) const {
unsigned periodic_wave_size = periodic_wave_->PeriodicWaveSize();
double inv_periodic_wave_size = 1.0 / periodic_wave_size;
unsigned read_index_mask = periodic_wave_size - 1;
float frequency = 0;
float* higher_wave_data = nullptr;
float* lower_wave_data = nullptr;
float table_interpolation_factor = 0;
frequency = frequency_->FinalValue();
float detune = detune_->FinalValue();
float detune_scale = DetuneToFrequencyMultiplier(detune);
frequency *= detune_scale;
ClampFrequency(&frequency, 1, Context()->sampleRate() / 2);
periodic_wave_->WaveDataForFundamentalFrequency(
frequency, lower_wave_data, higher_wave_data, table_interpolation_factor);
float rate_scale = periodic_wave_->RateScale();
float incr = frequency * rate_scale;
for (int k = 0; k < n; ++k) {
float sample = DoInterpolation(virtual_read_index, fabs(incr),
read_index_mask, table_interpolation_factor,
lower_wave_data, higher_wave_data);
*dest_p++ = sample;
// Increment virtual read index and wrap virtualReadIndex into the range
// 0 -> periodicWaveSize.
virtual_read_index += incr;
virtual_read_index -=
floor(virtual_read_index * inv_periodic_wave_size) * periodic_wave_size;
}
return virtual_read_index;
}
double OscillatorHandler::ProcessARate(int n,
float* dest_p,
double virtual_read_index,
float* phase_increments) const {
float rate_scale = periodic_wave_->RateScale();
float inv_rate_scale = 1 / rate_scale;
unsigned periodic_wave_size = periodic_wave_->PeriodicWaveSize();
double inv_periodic_wave_size = 1.0 / periodic_wave_size;
unsigned read_index_mask = periodic_wave_size - 1;
float* higher_wave_data = nullptr;
float* lower_wave_data = nullptr;
float table_interpolation_factor = 0;
for (int k = 0; k < n; ++k) {
float incr = *phase_increments++;
float frequency = inv_rate_scale * incr;
periodic_wave_->WaveDataForFundamentalFrequency(frequency, lower_wave_data,
higher_wave_data,
table_interpolation_factor);
float sample = DoInterpolation(virtual_read_index, fabs(incr),
read_index_mask, table_interpolation_factor,
lower_wave_data, higher_wave_data);
*dest_p++ = sample;
// Increment virtual read index and wrap virtualReadIndex into the range
// 0 -> periodicWaveSize.
virtual_read_index += incr;
virtual_read_index -=
floor(virtual_read_index * inv_periodic_wave_size) * periodic_wave_size;
}
return virtual_read_index;
}
void OscillatorHandler::Process(uint32_t frames_to_process) {
AudioBus* output_bus = Output(0).Bus();
......@@ -390,7 +468,6 @@ void OscillatorHandler::Process(uint32_t frames_to_process) {
}
unsigned periodic_wave_size = periodic_wave_->PeriodicWaveSize();
double inv_periodic_wave_size = 1.0 / periodic_wave_size;
float* dest_p = output_bus->Channel(0)->MutableData();
......@@ -400,7 +477,6 @@ void OscillatorHandler::Process(uint32_t frames_to_process) {
double virtual_read_index = virtual_read_index_;
float rate_scale = periodic_wave_->RateScale();
float inv_rate_scale = 1 / rate_scale;
bool has_sample_accurate_values =
CalculateSampleAccuratePhaseIncrements(frames_to_process);
......@@ -420,11 +496,8 @@ void OscillatorHandler::Process(uint32_t frames_to_process) {
table_interpolation_factor);
}
float incr = frequency * rate_scale;
float* phase_increments = phase_increments_.Data();
unsigned read_index_mask = periodic_wave_size - 1;
// Start rendering at the correct offset.
dest_p += quantum_frame_offset;
int n = non_silent_frames_to_process;
......@@ -442,27 +515,11 @@ void OscillatorHandler::Process(uint32_t frames_to_process) {
virtual_read_index = -start_frame_offset * frequency * rate_scale;
}
while (n--) {
if (has_sample_accurate_values) {
incr = *phase_increments++;
frequency = inv_rate_scale * incr;
periodic_wave_->WaveDataForFundamentalFrequency(
frequency, lower_wave_data, higher_wave_data,
table_interpolation_factor);
}
float sample = DoInterpolation(virtual_read_index, fabs(incr),
read_index_mask, table_interpolation_factor,
lower_wave_data, higher_wave_data);
*dest_p++ = sample;
// Increment virtual read index and wrap virtualReadIndex into the range
// 0 -> periodicWaveSize.
virtual_read_index += incr;
virtual_read_index -=
floor(virtual_read_index * inv_periodic_wave_size) * periodic_wave_size;
if (has_sample_accurate_values) {
virtual_read_index =
ProcessARate(n, dest_p, virtual_read_index, phase_increments);
} else {
virtual_read_index = ProcessKRate(n, dest_p, virtual_read_index);
}
virtual_read_index_ = virtual_read_index;
......
......@@ -86,6 +86,15 @@ class OscillatorHandler final : public AudioScheduledSourceHandler {
bool PropagatesSilence() const override;
// Compute the output for k-rate AudioParams
double ProcessKRate(int n, float* dest_p, double virtual_read_index) const;
// Compute the output for a-rate AudioParams
double ProcessARate(int n,
float* dest_p,
double virtual_read_index,
float* phase_increments) const;
// One of the waveform types defined in the enum.
uint8_t type_;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment