volume: base off math node
Shares code with math node rather than having it twice.
This commit is contained in:
@@ -60,35 +60,18 @@ QString VolumeNode::Description() const
|
||||
|
||||
NodeValueTable VolumeNode::Value(NodeValueDatabase &value) const
|
||||
{
|
||||
SampleJob job(samples_input_, value);
|
||||
job.InsertValue(volume_input_, value);
|
||||
|
||||
NodeValueTable table = value.Merge();
|
||||
|
||||
if (job.HasSamples()) {
|
||||
float volume_val = job.GetValue(volume_input_).data().toFloat();
|
||||
if (volume_input_->is_static()) {
|
||||
// Volume never changes so we can make some performance optimizations here
|
||||
if (!qFuzzyCompare(volume_val, 1.0f)) {
|
||||
job.samples()->transform_volume(volume_val);
|
||||
}
|
||||
|
||||
table.Push(NodeParam::kSamples, QVariant::fromValue(job.samples()), this);
|
||||
} else {
|
||||
table.Push(NodeParam::kSampleJob, QVariant::fromValue(job), this);
|
||||
}
|
||||
}
|
||||
|
||||
return table;
|
||||
return ValueInternal(value,
|
||||
kOpMultiply,
|
||||
kPairSampleNumber,
|
||||
samples_input_,
|
||||
value[samples_input_].TakeWithMeta(NodeParam::kSamples),
|
||||
volume_input_,
|
||||
value[volume_input_].TakeWithMeta(NodeParam::kFloat));
|
||||
}
|
||||
|
||||
void VolumeNode::ProcessSamples(NodeValueDatabase &values, const SampleBufferPtr input, SampleBufferPtr output, int index) const
|
||||
{
|
||||
float volume_val = values[volume_input_].Get(NodeParam::kFloat).toFloat();
|
||||
|
||||
for (int i=0;i<output->audio_params().channel_count();i++) {
|
||||
output->data()[i][index] = input->data()[i][index] * volume_val;
|
||||
}
|
||||
return ProcessSamplesInternal(values, kOpMultiply, samples_input_, volume_input_, input, output, index);
|
||||
}
|
||||
|
||||
void VolumeNode::Retranslate()
|
||||
|
||||
Reference in New Issue
Block a user