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
+1
View File
@@ -14,6 +14,7 @@
# 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(audio)
add_subdirectory(block)
add_subdirectory(distort)
add_subdirectory(input)
+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
+6
View File
@@ -1,5 +1,7 @@
#include "factory.h"
#include "audio/pan/pan.h"
#include "audio/volume/volume.h"
#include "block/clip/clip.h"
#include "block/gap/gap.h"
#include "block/transition/externaltransition.h"
@@ -131,6 +133,10 @@ Node *NodeFactory::CreateInternal(const NodeFactory::InternalID &id)
return new TrackOutput();
case kViewerOutput:
return new ViewerOutput();
case kAudioVolume:
return new VolumeNode();
case kAudioPanning:
return new PanNode();
case kInternalNodeCount:
break;
+2
View File
@@ -18,6 +18,8 @@ public:
kVideoInput,
kTimelineOutput,
kTrackOutput,
kAudioVolume,
kAudioPanning,
// Count value
kInternalNodeCount
+14
View File
@@ -390,6 +390,20 @@ NodeInput *Node::AcceleratedCodeIterativeInput() const
return nullptr;
}
bool Node::ProcessesSamples() const
{
return false;
}
void Node::ProcessSamples(const NodeValueDatabase &values, const AudioRenderingParams &params, const float *input, float *output, int index) const
{
Q_UNUSED(values)
Q_UNUSED(params)
Q_UNUSED(input)
Q_UNUSED(output)
Q_UNUSED(index)
}
NodeParam *Node::GetParameterWithID(const QString &id) const
{
foreach (NodeParam* param, params_) {
+11
View File
@@ -32,6 +32,7 @@
#include "node/inputarray.h"
#include "node/output.h"
#include "node/value.h"
#include "render/audioparams.h"
/**
* @brief A single processing unit that can be connected with others to create intricate processing systems
@@ -156,6 +157,16 @@ public:
*/
virtual NodeInput* AcceleratedCodeIterativeInput() const;
/**
* @brief Return whether this node processes samples or not
*/
virtual bool ProcessesSamples() const;
/**
* @brief If ProcessesSamples() is true, this is the function that will process them.
*/
virtual void ProcessSamples(const NodeValueDatabase& values, const AudioRenderingParams& params, const float* input, float* output, int index) const;
/**
* @brief Returns the parameter with the specified ID (or nullptr if it doesn't exist)
*/
+1 -1
View File
@@ -145,7 +145,7 @@ void Exporter::FrameRendered(const rational &time, QVariant value)
} while (cached_frames_.contains(waiting_for_frame_));
if (waiting_for_frame_ >= viewer_node_->Length()) {
S ExportSucceeded();
ExportSucceeded();
}
} else {
cached_frames_.insert(time, value);