-
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
15 changed files
with
229 additions
and
205 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 was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
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,61 @@ | ||
#include "./Filter.hpp" | ||
|
||
namespace Dynamo::Sound { | ||
b8 Filter::has_cycles() { | ||
std::unordered_set<Filter *> visited; | ||
std::vector<std::reference_wrapper<Filter>> stack; | ||
|
||
stack.push_back(*this); | ||
while (!stack.empty()) { | ||
Filter &node = stack.back(); | ||
stack.pop_back(); | ||
if (visited.count(&node) > 0) { | ||
return true; | ||
} | ||
for (Filter &child : node._dependencies) { | ||
stack.push_back(child); | ||
} | ||
visited.insert(&node); | ||
} | ||
return false; | ||
} | ||
|
||
void Filter::connect(Filter &destination) { | ||
_dependencies.push_back(destination); | ||
if (has_cycles()) { | ||
Log::error("Jukebox Filter graph disallows cycles."); | ||
} | ||
} | ||
|
||
void Filter::disconnect(Filter &node) { | ||
auto it = _dependencies.begin(); | ||
while (it != _dependencies.end()) { | ||
Filter &curr = *it; | ||
if (&curr == &node) { | ||
it = _dependencies.erase(it); | ||
return; | ||
} else { | ||
it++; | ||
} | ||
} | ||
Log::error("Jukebox Filter graph attempted to disconnect a " | ||
"non-existent node."); | ||
} | ||
|
||
void Filter::disconnect() { _dependencies.clear(); } | ||
|
||
const std::vector<std::reference_wrapper<Filter>> & | ||
Filter::get_dependencies() const { | ||
return _dependencies; | ||
} | ||
|
||
Sound &Filter::get_output() { return _output; } | ||
|
||
Sound &run_filter(Filter &filter, | ||
Sound &src, | ||
u32 offset, | ||
u32 length, | ||
ListenerSet &listeners) { | ||
return src; | ||
} | ||
} // 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,100 @@ | ||
#pragma once | ||
|
||
#include <functional> | ||
#include <unordered_set> | ||
#include <vector> | ||
|
||
#include "../Types.hpp" | ||
#include "./Listener.hpp" | ||
#include "./Sound.hpp" | ||
|
||
namespace Dynamo::Sound { | ||
/** | ||
* @brief Filter node in a signal processing graph. | ||
* | ||
*/ | ||
class Filter { | ||
Sound _output; | ||
std::vector<std::reference_wrapper<Filter>> _dependencies; | ||
|
||
private: | ||
/** | ||
* @brief Test if the graph has cycles. | ||
* | ||
* @return b8 | ||
*/ | ||
b8 has_cycles(); | ||
|
||
public: | ||
/** | ||
* @brief Destroy the Filter object. | ||
* | ||
*/ | ||
virtual ~Filter() = default; | ||
|
||
/** | ||
* @brief Connect a dependency. | ||
* | ||
* The resulting graph must not result in a cycle. | ||
* | ||
* @param node | ||
*/ | ||
void connect(Filter &node); | ||
|
||
/** | ||
* @brief Disconnect all dependencies. | ||
* | ||
*/ | ||
void disconnect(); | ||
|
||
/** | ||
* @brief Disconnect a dependency. | ||
* | ||
* @param node | ||
*/ | ||
void disconnect(Filter &node); | ||
|
||
/** | ||
* @brief Get the immutable list of dependencies. | ||
* | ||
* @return const std::vector<std::reference_wrapper<Filter>>& | ||
*/ | ||
const std::vector<std::reference_wrapper<Filter>> & | ||
get_dependencies() const; | ||
|
||
/** | ||
* @brief Get the output sound buffer. | ||
* | ||
* @return Sound& | ||
*/ | ||
Sound &get_output(); | ||
|
||
/** | ||
* @brief Transform a Sound. | ||
* | ||
* @param src | ||
* @param length | ||
* @param listeners | ||
*/ | ||
virtual void transform(Sound &src, | ||
u32 offset, | ||
u32 length, | ||
ListenerSet &listeners) = 0; | ||
}; | ||
|
||
/** | ||
* @brief Traverse the filter graph and process the sound. | ||
* | ||
* @param filter | ||
* @param src | ||
* @param offset | ||
* @param length | ||
* @param listeners | ||
* @return Sound& | ||
*/ | ||
Sound &run_filter(Filter &root, | ||
Sound &src, | ||
u32 offset, | ||
u32 length, | ||
ListenerSet &listeners); | ||
} // 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
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
Oops, something went wrong.