-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
137 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
#include "./AudioNode.hpp" | ||
#include <cstdio> | ||
|
||
namespace Dynamo::Sound { | ||
const std::vector<AudioConnection> &AudioNode::get_output_edges() const { | ||
return _output_edges; | ||
} | ||
|
||
void AudioNode::connect(AudioNode &destination, | ||
u32 input_channel, | ||
u32 output_channel) { | ||
_output_edges.push_back({destination, input_channel, output_channel}); | ||
} | ||
|
||
void AudioNode::disconnect() { _output_edges.clear(); } | ||
|
||
void AudioNode::disconnect(AudioNode &destination, | ||
u32 input_channel, | ||
u32 output_channel) { | ||
auto it = _output_edges.begin(); | ||
while (it != _output_edges.end()) { | ||
AudioConnection &edge = *it; | ||
if (&edge.destination.get() == &destination && | ||
edge.input_channel == input_channel && | ||
edge.output_channel == output_channel) { | ||
it = _output_edges.erase(it); | ||
return; | ||
} else { | ||
it++; | ||
} | ||
} | ||
Log::error("AudioNode - Invalid disconnection."); | ||
} | ||
} // namespace Dynamo::Sound |
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,103 @@ | ||
#pragma once | ||
|
||
#include <functional> | ||
#include <vector> | ||
|
||
#include "../../Types.hpp" | ||
#include "../Sound.hpp" | ||
|
||
namespace Dynamo::Sound { | ||
/** | ||
* @brief Forward declare the AudioNode class. | ||
* | ||
*/ | ||
class AudioNode; | ||
|
||
/** | ||
* @brief Connection between two AudioNodes. | ||
* | ||
*/ | ||
struct AudioConnection { | ||
/** | ||
* @brief Destination node. | ||
* | ||
*/ | ||
std::reference_wrapper<AudioNode> destination; | ||
|
||
/** | ||
* @brief Input channel index. | ||
* | ||
*/ | ||
u32 input_channel; | ||
|
||
/** | ||
* @brief Output channel index. | ||
* | ||
*/ | ||
u32 output_channel; | ||
}; | ||
|
||
/** | ||
* @brief Node in an audio processing graph. | ||
* | ||
*/ | ||
class AudioNode { | ||
std::vector<AudioConnection> _output_edges; | ||
|
||
public: | ||
/** | ||
* @brief Destroy the AudioNode object. | ||
* | ||
*/ | ||
virtual ~AudioNode() = 0; | ||
|
||
/** | ||
* @brief Get the output edges object. | ||
* | ||
* @return const std::vector<AudioConnection>& | ||
*/ | ||
const std::vector<AudioConnection> &get_output_edges() const; | ||
|
||
/** | ||
* @brief Connect another AudioNode. | ||
* | ||
* @param destination | ||
* @param input_channel | ||
* @param output_channel | ||
*/ | ||
void connect(AudioNode &destination, | ||
u32 input_channel = 0, | ||
u32 output_channel = 0); | ||
|
||
/** | ||
* @brief Disconnect all outgoing edges. | ||
* | ||
*/ | ||
void disconnect(); | ||
|
||
/** | ||
* @brief Disconnect an outgoing edge. | ||
* | ||
* @param destination | ||
* @param input_channel | ||
* @param output_channel | ||
*/ | ||
void disconnect(AudioNode &destination, | ||
u32 input_channel = 0, | ||
u32 output_channel = 0); | ||
|
||
/** | ||
* @brief Process a single channel and write it to the output | ||
* channel. | ||
* | ||
* @param src | ||
* @param src_length | ||
* @param dst | ||
* @param dst_length | ||
*/ | ||
virtual void process(WaveSample *src, | ||
u32 src_length, | ||
WaveSample *dst, | ||
u32 dst_length) = 0; | ||
}; | ||
} // namespace Dynamo::Sound |