-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(amplimix): Clip and Clamp nodes.
Signed-off-by: Axel Nana <[email protected]>
- Loading branch information
Showing
8 changed files
with
212 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
// Copyright (c) 2024-present Sparky Studios. All rights reserved. | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
#include <Mixer/Nodes/ClampNode.h> | ||
|
||
namespace SparkyStudios::Audio::Amplitude | ||
{ | ||
ClampNodeInstance::ClampNodeInstance() | ||
: ProcessorNodeInstance(false) | ||
{} | ||
|
||
const AudioBuffer* ClampNodeInstance::Process(const AudioBuffer* input) | ||
{ | ||
_output = *input; | ||
|
||
for (AmSize c = 0; c < _output.GetChannelCount(); c++) | ||
{ | ||
const auto& inChannel = _output[c]; | ||
/* */ auto& outChannel = _output[c]; | ||
|
||
for (AmSize i = 0, l = _output.GetFrameCount(); i < l; i++) | ||
{ | ||
const AmReal32& x = inChannel[i]; | ||
/* */ AmReal32& y = outChannel[i]; | ||
|
||
y = std::max(AM_AUDIO_SAMPLE_MIN, std::min(AM_AUDIO_SAMPLE_MAX, x)); | ||
} | ||
} | ||
|
||
return &_output; | ||
} | ||
|
||
ClampNode::ClampNode() | ||
: Node("Clamp") | ||
{} | ||
} // namespace SparkyStudios::Audio::Amplitude |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
// Copyright (c) 2024-present Sparky Studios. All rights reserved. | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
#pragma once | ||
|
||
#ifndef _AM_IMPLEMENTATION_MIXER_NODES_CLAMP_NODE_H | ||
#define _AM_IMPLEMENTATION_MIXER_NODES_CLAMP_NODE_H | ||
|
||
#include <SparkyStudios/Audio/Amplitude/Core/Memory.h> | ||
#include <SparkyStudios/Audio/Amplitude/Mixer/Node.h> | ||
|
||
namespace SparkyStudios::Audio::Amplitude | ||
{ | ||
class ClampNodeInstance final : public ProcessorNodeInstance | ||
{ | ||
public: | ||
ClampNodeInstance(); | ||
|
||
const AudioBuffer* Process(const AudioBuffer* input) override; | ||
|
||
private: | ||
AudioBuffer _output; | ||
}; | ||
|
||
class ClampNode final : public Node | ||
{ | ||
public: | ||
ClampNode(); | ||
|
||
[[nodiscard]] AM_INLINE NodeInstance* CreateInstance() const override | ||
{ | ||
return ampoolnew(MemoryPoolKind::Amplimix, ClampNodeInstance); | ||
} | ||
|
||
void DestroyInstance(NodeInstance* instance) const override | ||
{ | ||
ampooldelete(MemoryPoolKind::Amplimix, ClampNodeInstance, (ClampNodeInstance*)instance); | ||
} | ||
}; | ||
} // namespace SparkyStudios::Audio::Amplitude | ||
|
||
#endif // _AM_IMPLEMENTATION_MIXER_NODES_CLAMP_NODE_H |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
// Copyright (c) 2024-present Sparky Studios. All rights reserved. | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
#include <Mixer/Nodes/ClipNode.h> | ||
|
||
namespace SparkyStudios::Audio::Amplitude | ||
{ | ||
ClipNodeInstance::ClipNodeInstance() | ||
: ProcessorNodeInstance(false) | ||
{} | ||
|
||
const AudioBuffer* ClipNodeInstance::Process(const AudioBuffer* input) | ||
{ | ||
_output = *input; | ||
|
||
for (AmSize c = 0; c < _output.GetChannelCount(); c++) | ||
{ | ||
const auto& inChannel = _output[c]; | ||
/* */ auto& outChannel = _output[c]; | ||
|
||
for (AmSize i = 0, l = _output.GetFrameCount(); i < l; i++) | ||
{ | ||
const AmReal32& x = inChannel[i]; | ||
/* */ AmReal32& y = outChannel[i]; | ||
|
||
y = x <= -1.65f ? -0.9862875f : x >= 1.65f ? 0.9862875f : 0.87f * x - 0.1f * x * x * x; | ||
} | ||
} | ||
|
||
return &_output; | ||
} | ||
|
||
ClipNode::ClipNode() | ||
: Node("Clip") | ||
{} | ||
} // namespace SparkyStudios::Audio::Amplitude |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
// Copyright (c) 2024-present Sparky Studios. All rights reserved. | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
#pragma once | ||
|
||
#ifndef _AM_IMPLEMENTATION_MIXER_NODES_CLIP_NODE_H | ||
#define _AM_IMPLEMENTATION_MIXER_NODES_CLIP_NODE_H | ||
|
||
#include <SparkyStudios/Audio/Amplitude/Core/Memory.h> | ||
#include <SparkyStudios/Audio/Amplitude/Mixer/Node.h> | ||
|
||
namespace SparkyStudios::Audio::Amplitude | ||
{ | ||
class ClipNodeInstance final : public ProcessorNodeInstance | ||
{ | ||
public: | ||
ClipNodeInstance(); | ||
|
||
const AudioBuffer* Process(const AudioBuffer* input) override; | ||
|
||
private: | ||
AudioBuffer _output; | ||
}; | ||
|
||
class ClipNode final : public Node | ||
{ | ||
public: | ||
ClipNode(); | ||
|
||
[[nodiscard]] AM_INLINE NodeInstance* CreateInstance() const override | ||
{ | ||
return ampoolnew(MemoryPoolKind::Amplimix, ClipNodeInstance); | ||
} | ||
|
||
void DestroyInstance(NodeInstance* instance) const override | ||
{ | ||
ampooldelete(MemoryPoolKind::Amplimix, ClipNodeInstance, (ClipNodeInstance*)instance); | ||
} | ||
}; | ||
} // namespace SparkyStudios::Audio::Amplitude | ||
|
||
#endif // _AM_IMPLEMENTATION_MIXER_NODES_CLIP_NODE_H |