implemented volume and pan effects

This commit implements a structure for sample processing and two implemenations
of this structure in volume and pan effects.
This commit is contained in:
itsmattkc
2019-12-24 12:34:30 +11:00
parent 3a7b3ffac6
commit 7ad2eae7a2
13 changed files with 275 additions and 1 deletions
+23
View File
@@ -0,0 +1,23 @@
# Olive - Non-Linear Video Editor
# Copyright (C) 2019 Olive Team
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
add_subdirectory(pan)
add_subdirectory(volume)
set(OLIVE_SOURCES
${OLIVE_SOURCES}
PARENT_SCOPE
)
+22
View File
@@ -0,0 +1,22 @@
# Olive - Non-Linear Video Editor
# Copyright (C) 2019 Olive Team
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
set(OLIVE_SOURCES
${OLIVE_SOURCES}
node/audio/pan/pan.h
node/audio/pan/pan.cpp
PARENT_SCOPE
)
+67
View File
@@ -0,0 +1,67 @@
#include "pan.h"
PanNode::PanNode()
{
samples_input_ = new NodeInput("samples_in");
samples_input_->set_data_type(NodeParam::kSamples);
AddInput(samples_input_);
panning_input_ = new NodeInput("panning_in");
panning_input_->set_data_type(NodeParam::kFloat);
panning_input_->set_minimum(-1);
panning_input_->set_maximum(1);
panning_input_->set_value_at_time(0, 0);
AddInput(panning_input_);
}
Node *PanNode::copy() const
{
return new PanNode();
}
QString PanNode::Name() const
{
return tr("Pan");
}
QString PanNode::id() const
{
return "org.olivevideoeditor.Olive.pan";
}
QString PanNode::Category() const
{
return tr("Audio");
}
QString PanNode::Description() const
{
return tr("Adjust the stereo panning of an audio source.");
}
bool PanNode::ProcessesSamples() const
{
return true;
}
void PanNode::ProcessSamples(const NodeValueDatabase &values, const AudioRenderingParams &params, const float *input, float *output, int index) const
{
if (params.channel_count() != 2) {
// This node currently only works for stereo audio
return;
}
float pan_val = values[panning_input_].Get(NodeParam::kFloat).toFloat();
if (index%2 == 0) {
// Sample is left channel
if (pan_val > 0) {
output[index] = input[index] * (1.0F - pan_val);
}
} else {
// Sample is right channel
if (pan_val < 0) {
output[index] = input[index] * (1.0F - qAbs(pan_val));
}
}
}
+27
View File
@@ -0,0 +1,27 @@
#ifndef PANNODE_H
#define PANNODE_H
#include "node/node.h"
class PanNode : public Node
{
public:
PanNode();
virtual Node* copy() const override;
virtual QString Name() const override;
virtual QString id() const override;
virtual QString Category() const override;
virtual QString Description() const override;
virtual bool ProcessesSamples() const override;
virtual void ProcessSamples(const NodeValueDatabase& values, const AudioRenderingParams& params, const float* input, float* output, int index) const override;
private:
NodeInput* samples_input_;
NodeInput* panning_input_;
};
#endif // PANNODE_H
+22
View File
@@ -0,0 +1,22 @@
# Olive - Non-Linear Video Editor
# Copyright (C) 2019 Olive Team
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
set(OLIVE_SOURCES
${OLIVE_SOURCES}
node/audio/volume/volume.h
node/audio/volume/volume.cpp
PARENT_SCOPE
)
+52
View File
@@ -0,0 +1,52 @@
#include "volume.h"
VolumeNode::VolumeNode()
{
samples_input_ = new NodeInput("samples_in");
samples_input_->set_data_type(NodeParam::kSamples);
AddInput(samples_input_);
volume_input_ = new NodeInput("volume_in");
volume_input_->set_data_type(NodeParam::kFloat);
volume_input_->set_minimum(0);
volume_input_->set_maximum(1);
volume_input_->set_value_at_time(0, 1);
AddInput(volume_input_);
}
Node *VolumeNode::copy() const
{
return new VolumeNode();
}
QString VolumeNode::Name() const
{
return tr("Volume");
}
QString VolumeNode::id() const
{
return "org.olivevideoeditor.Olive.volume";
}
QString VolumeNode::Category() const
{
return tr("Audio");
}
QString VolumeNode::Description() const
{
return tr("Adjusts the volume of an audio source.");
}
bool VolumeNode::ProcessesSamples() const
{
return true;
}
void VolumeNode::ProcessSamples(const NodeValueDatabase& values, const AudioRenderingParams& params, const float* input, float* output, int index) const
{
float volume_val = values[volume_input_].Get(NodeParam::kFloat).toFloat();
output[index] = input[index] * volume_val;
}
+27
View File
@@ -0,0 +1,27 @@
#ifndef VOLUMENODE_H
#define VOLUMENODE_H
#include "node/node.h"
class VolumeNode : public Node
{
public:
VolumeNode();
virtual Node* copy() const override;
virtual QString Name() const override;
virtual QString id() const override;
virtual QString Category() const override;
virtual QString Description() const override;
virtual bool ProcessesSamples() const override;
virtual void ProcessSamples(const NodeValueDatabase& values, const AudioRenderingParams& params, const float* input, float* output, int index) const override;
private:
NodeInput* samples_input_;
NodeInput* volume_input_;
};
#endif // VOLUMENODE_H