-
Notifications
You must be signed in to change notification settings - Fork 2
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
1 parent
4a7dfa6
commit 4114b17
Showing
7 changed files
with
166 additions
and
3 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
// | ||
// Created by Syl Morrison on 11/09/2024. | ||
// |
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 @@ | ||
// | ||
// Created by Syl Morrison on 11/09/2024. | ||
// | ||
|
||
#ifndef MOSTLYHARMLESS_MOSTLYHARMLESS_TESTHELPERS_H | ||
#define MOSTLYHARMLESS_MOSTLYHARMLESS_TESTHELPERS_H | ||
#include <marvin/library/marvin_Concepts.h> | ||
#include <marvin/library/marvin_Literals.h> | ||
#include <marvin/containers/marvin_BufferView.h> | ||
#include <vector> | ||
namespace mostly_harmless::testing { | ||
template<marvin::FloatType SampleType, size_t N> | ||
requires (N > 0) | ||
[[nodiscard]] std::vector<SampleType> generateImpulse() { | ||
std::vector<SampleType> impulse(N, static_cast<SampleType>(0.0)); | ||
impulse.front() = static_cast<SampleType>(1.0); | ||
return impulse; | ||
} | ||
|
||
template<marvin::FloatType SampleType, size_t NumChannels, size_t BufferSize> | ||
SampleType** generateImpulse() { | ||
using namespace marvin::literals; | ||
SampleType** arr = new SampleType*[2]; | ||
for(auto channel = 0_sz; channel < NumChannels; ++channel) { | ||
arr[channel] = new SampleType[BufferSize]; | ||
std::memset(arr[channel], 0, BufferSize * sizeof(SampleType)); | ||
arr[channel][0] = static_cast<SampleType>(1); | ||
} | ||
return arr; | ||
} | ||
|
||
template<marvin::FloatType SampleType> | ||
bool checkBuffer(marvin::containers::BufferView<SampleType> buffer) { | ||
using namespace marvin::literals; | ||
const auto* const* read = buffer.getArrayOfReadPointers(); | ||
for(auto channel = 0_sz; channel < buffer.getNumChannels(); ++channel) { | ||
for(auto sample = 0_sz; sample < buffer.getNumSamples(); ++sample) { | ||
const auto x = read[channel][sample]; | ||
if(std::isnan(x) || std::isinf(x)) { | ||
return false; | ||
} | ||
} | ||
} | ||
return true; | ||
} | ||
} | ||
#endif // MOSTLYHARMLESS_MOSTLYHARMLESS_TESTHELPERS_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,107 @@ | ||
// | ||
// Created by Syl Morrison on 11/09/2024. | ||
// | ||
#include "mostlyharmless_TestHelpers.h" | ||
#include <mostly_harmless/mostlyharmless_Plugin.h> | ||
#include <mostly_harmless/gui/mostlyharmless_WebviewEditor.h> | ||
#include <marvin/library/marvin_Literals.h> | ||
#include <catch2/catch_test_macros.hpp> | ||
namespace mostly_harmless::testing { | ||
template <marvin::FloatType SampleType> | ||
class GenericPlugin : public mostly_harmless::Plugin<SampleType> { | ||
public: | ||
explicit GenericPlugin(const clap_host* host) : mostly_harmless::Plugin<SampleType>(host, {}) { | ||
} | ||
void initialise(double sampleRate, std::uint32_t minFrame, std::uint32_t maxFrame) noexcept override { | ||
} | ||
|
||
void process(marvin::containers::BufferView<SampleType> buffer, mostly_harmless::events::InputEventContext context) noexcept override { | ||
} | ||
|
||
void flushParams(mostly_harmless::events::InputEventContext context) noexcept override { | ||
} | ||
|
||
void reset() noexcept override { | ||
} | ||
|
||
void loadState(std::string_view data) noexcept override { | ||
} | ||
|
||
void saveState(std::ostringstream& outStream) noexcept override { | ||
} | ||
|
||
std::unique_ptr<mostly_harmless::gui::IEditor> createEditor() noexcept override { | ||
return nullptr; | ||
} | ||
|
||
private: | ||
}; | ||
// ret name arg | ||
|
||
|
||
std::uint32_t size(const struct clap_input_events* list) { | ||
return 0; | ||
} | ||
|
||
template <marvin::FloatType SampleType, size_t NumChannels, size_t BufferSize> void testPlugin() { | ||
using namespace marvin::literals; | ||
auto host = std::make_unique<clap_host>(); | ||
GenericPlugin<SampleType> plugin{ host.get() }; | ||
plugin.activate(44100.0, BufferSize, BufferSize); | ||
clap_audio_buffer in; | ||
SampleType** buffer = generateImpulse<SampleType, NumChannels, BufferSize>(); | ||
if constexpr (std::same_as<float, SampleType>) { | ||
in = { | ||
.data32 = buffer, | ||
.data64 = nullptr, | ||
.channel_count = NumChannels, | ||
.latency = 0, | ||
.constant_mask = 0x0 | ||
}; | ||
} else { | ||
in = { | ||
.data32 = nullptr, | ||
.data64 = buffer, | ||
.channel_count = NumChannels, | ||
.latency = 0, | ||
.constant_mask = 0x0 | ||
}; | ||
} | ||
|
||
auto* ctx = malloc(sizeof(SampleType) * 100); | ||
clap_input_events inputEvents{ | ||
.ctx = ctx, | ||
.size = size | ||
}; | ||
|
||
const clap_process process{ | ||
.steady_time = -1, | ||
.frames_count = BufferSize, | ||
.transport = nullptr, | ||
.audio_inputs = &in, | ||
.audio_outputs = &in, | ||
.audio_inputs_count = NumChannels, | ||
.audio_outputs_count = NumChannels, | ||
.in_events = &inputEvents, | ||
.out_events = nullptr | ||
}; | ||
const auto res = static_cast<mostly_harmless::Plugin<SampleType>*>(&plugin)->process(&process); | ||
marvin::containers::BufferView<SampleType> view{ buffer, NumChannels, BufferSize}; | ||
const auto bufferOk = checkBuffer(view); | ||
REQUIRE(bufferOk); | ||
|
||
|
||
free(ctx); | ||
for (auto i = 0_sz; i < NumChannels; ++i) { | ||
delete[] buffer[i]; | ||
} | ||
delete[] buffer; | ||
} | ||
|
||
TEST_CASE("Test Plugin") { | ||
testPlugin<float, 1, 64>(); | ||
testPlugin<double, 1, 64>(); | ||
testPlugin<float, 2, 128>(); | ||
testPlugin<double, 2, 128>(); | ||
} | ||
} |
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