simplified and optimized samplebuffer
This commit is contained in:
+18
-15
@@ -67,45 +67,48 @@ void PanNode::Value(const NodeValueRow &value, const NodeGlobals &globals, NodeV
|
||||
Q_UNUSED(globals)
|
||||
|
||||
// Create a sample job
|
||||
SampleJob job(kSamplesInput, value);
|
||||
|
||||
if (job.HasSamples()) {
|
||||
bool push_job = false;
|
||||
SampleBuffer samples = value[kSamplesInput].toSamples();
|
||||
if (samples.is_allocated()) {
|
||||
bool pushed_job = false;
|
||||
|
||||
// This node is only compatible with stereo audio
|
||||
if (job.samples()->audio_params().channel_count() == 2) {
|
||||
if (samples.audio_params().channel_count() == 2) {
|
||||
// If the input is static, we can just do it now which will be faster
|
||||
if (IsInputStatic(kPanningInput)) {
|
||||
float pan_volume = job.GetValue(kPanningInput).toDouble();
|
||||
float pan_volume = value[kPanningInput].toDouble();
|
||||
if (!qIsNull(pan_volume)) {
|
||||
if (pan_volume > 0) {
|
||||
job.samples()->transform_volume_for_channel(0, 1.0f - pan_volume);
|
||||
samples.transform_volume_for_channel(0, 1.0f - pan_volume);
|
||||
} else {
|
||||
job.samples()->transform_volume_for_channel(1, 1.0f + pan_volume);
|
||||
samples.transform_volume_for_channel(1, 1.0f + pan_volume);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
// Requires job
|
||||
push_job = true;
|
||||
|
||||
pushed_job = true;
|
||||
table->Push(NodeValue::kSamples, SampleJob(kSamplesInput, value), this);
|
||||
}
|
||||
}
|
||||
|
||||
table->Push(NodeValue::kSamples, push_job ? QVariant::fromValue(job) : QVariant::fromValue(job.samples()), this);
|
||||
if (!pushed_job) {
|
||||
table->Push(value[kSamplesInput]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void PanNode::ProcessSamples(const NodeValueRow &values, const SampleBufferPtr input, SampleBufferPtr output, int index) const
|
||||
void PanNode::ProcessSamples(const NodeValueRow &values, const SampleBuffer &input, SampleBuffer &output, int index) const
|
||||
{
|
||||
float pan_val = values[kPanningInput].toDouble();
|
||||
|
||||
for (int i=0;i<input->audio_params().channel_count();i++) {
|
||||
output->data(i)[index] = input->data(i)[index];
|
||||
for (int i=0;i<input.audio_params().channel_count();i++) {
|
||||
output.data(i)[index] = input.data(i)[index];
|
||||
}
|
||||
|
||||
if (pan_val > 0) {
|
||||
output->data(0)[index] *= (1.0F - pan_val);
|
||||
output.data(0)[index] *= (1.0F - pan_val);
|
||||
} else if (pan_val < 0) {
|
||||
output->data(1)[index] *= (1.0F - qAbs(pan_val));
|
||||
output.data(1)[index] *= (1.0F - qAbs(pan_val));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user