Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

v1.1.53 #53

Merged
merged 10 commits into from
Nov 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ set(VERBOSE true)

set(CMAKE_VERBOSE_MAKEFILE ON)

project(ToobAmp VERSION 1.1.51 DESCRIPTION "TooB LV2 Guitar Effects Plugins")
project(ToobAmp VERSION 1.1.53 DESCRIPTION "TooB LV2 Guitar Effects Plugins")

# Semantic Version release type. e.g. "-alpha", "-beta3" or "" for a release.

Expand Down
26 changes: 18 additions & 8 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,26 @@
#
cmake_minimum_required (VERSION 3.18)


execute_process(COMMAND
dpkg-architecture
-qDEB_HOST_ARCH
OUTPUT_VARIABLE
CMAKE_DEB_HOST_ARCH
OUTPUT_STRIP_TRAILING_WHITESPACE
)


set(CMAKE_MODULE_PATH ${PROJECT_BINARY_DIR}/modules/lv2cairo)
#find_package(Lv2c REQUIRED)


# Ubuuntu 21.04 boost static libraries don't have -fPIC, so linking fails.
if (CMAKE_DEB_HOST_ARCH STREQUAL "arm64")
set(Boost_USE_STATIC_LIBS ON)
endif()
find_package(Boost REQUIRED COMPONENTS iostreams )

set (CMAKE_CXX_STANDARD 20)
set(CMAKE_CXX_STANDARD_REQUIRED ON)

Expand All @@ -18,13 +34,6 @@ else()
set(PROFILER 0) # disables google profiler in ConvolutionReverbTest, ProfileNeuralAmpModeler
endif()

execute_process(COMMAND
dpkg-architecture
-qDEB_HOST_ARCH
OUTPUT_VARIABLE
CMAKE_DEB_HOST_ARCH
OUTPUT_STRIP_TRAILING_WHITESPACE
)


set (FLAC_LIBS FLAC++.a FLAC.a ogg.a)
Expand Down Expand Up @@ -125,6 +134,7 @@ set_source_files_properties(NeuralAmpModeler.cpp PROPERTIES COMPILE_FLAGS "-Wno-


add_library(ToobAmp SHARED
DebugPlot.cpp
NeuralAmpModeler.cpp NeuralAmpModeler.h
nam_architecture.hpp

Expand Down Expand Up @@ -268,7 +278,7 @@ target_link_libraries(ToobAmp
RTNeural
namSources
dl pthread
boost_iostreams
${Boost_LIBRARIES}
${FLAC_LIBS}
)

Expand Down
129 changes: 24 additions & 105 deletions src/CircularBuffer.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,11 +39,12 @@ namespace toob {
SetSize(size);
}

bool Overrun() const { return overrun; }
void Overrun(bool value) { overrun = value;}
void Reset() {
overrun = false;
head = 0; count = 0;
for (size_t i = 0; i < buffer.size(); ++i)
{
buffer[i] = 0;
}
head = 0;
}
void SetSize(size_t size)
{
Expand All @@ -52,121 +53,39 @@ namespace toob {
}
void Add(const T &value)
{
if (count == buffer.size())
{
if (locked) {
overrun = true;
return;
}
} else {
++count;
}
buffer[head++] = value;
if (head == buffer.size())
{
head = 0;
}
}
struct LockResult;

class ReadIterator {
public:
ReadIterator(const LockResult*lockResult, T*p)
: lockResult(lockResult),
p(p)
{
}
using iterator_category = std::forward_iterator_tag;
using value_type = T;
using difference_type = std::ptrdiff_t;
using pointer = T*;
using reference = T&;

bool operator==(const ReadIterator&other) const
void CopyTo(std::vector<float> &buffer) const {
size_t count = buffer.size();
if (head >= count)
{
return p == other.p;
}
bool operator!=(const ReadIterator&other) const
{
return p != other.p;
}
const T operator*() const { return *p; }
const T* operator->() const { return p; }



T&operator*() { return *p; }
// pre-increment.
ReadIterator&operator++()
{
++p;
if (p == lockResult->p0+lockResult->count0)
size_t ix = 0;
for (size_t i = head-count; i != head; ++i)
{
p = lockResult->p1;
buffer[ix++] = this->buffer[i];
}
return *this;
}
// post-increment
ReadIterator operator++(int)
{
ReadIterator t(*this);
operator++();
return t;
}

private:
const LockResult *lockResult;
T*p;
};
struct LockResult {
T * p0;
size_t count0;
T* p1;
size_t count1;

ReadIterator begin() const {
return ReadIterator(this,p0);
}
ReadIterator end() const {
return ReadIterator(this,p1+count1);
}
using iterator = ReadIterator;
};
LockResult Lock(size_t count) {
assert(count <= this->count);
locked = true;
LockResult result;
this->count = count;
size_t readTail = this->head;
if (count > readTail)
{
result.count0 = count-readTail;
result.p0 = &(buffer[buffer.size()-result.count0]);
result.p1 = &(buffer[0]);
result.count1 = count-result.count0;
} else {
result.p0 = &buffer[readTail-count];
result.count0 = count;
result.p1 = result.p0+result.count0; // for a useful iterator end()
result.count1 = 0;
}
return result;
}
void Unlock() {
locked = false;
if (overrun)
{
// just start over.
Reset();
size_t ix = 0;
size_t start = this->head + this->buffer.size()-count;
for (size_t i = start; i < buffer.size(); ++i)
{
buffer[ix++] = this->buffer[i];
}
for (size_t i = 0; i < this->head; ++i)
{
buffer[ix++] = this->buffer[i];
}
}

}
size_t Size() const { return count;}
size_t Size() const { return buffer.size();}
private:
bool locked = false;
bool overrun = false;
std::vector<T> buffer;

// TODO: Originally written with volatile. Re-write with appropriate mem barriers.
std::atomic<size_t> head, count;
size_t head = 0;
};
} // namespace
106 changes: 106 additions & 0 deletions src/DebugPlot.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,106 @@
// debug_plot.hpp
#include <vector>
#include <fstream>
#include <string>
#include <cstdlib>
#include <iostream>

class DebugPlotter
{
public:
static void plot(const std::vector<float> &data,
const std::string &title = "Debug Plot",
const std::string &xlabel = "Index",
const std::string &ylabel = "Value")
{
// Write data to temporary file
std::ofstream dataFile("debug_data.tmp");
for (size_t i = 0; i < data.size(); ++i)
{
dataFile << i << " " << data[i] << "\n";
}
dataFile.close();

// Create gnuplot script
std::ofstream scriptFile("plot_script.gnu");
scriptFile << "set title '" << title << "'\n"
<< "set xlabel '" << xlabel << "'\n"
<< "set ylabel '" << ylabel << "'\n"
<< "set grid\n"
<< "plot 'debug_data.tmp' with linespoints title 'Data'\n"
<< "pause mouse close\n"; // Keep window open until clicked
scriptFile.close();

// Launch gnuplot
#ifdef _WIN32
int retval = system("start gnuplot plot_script.gnu");
#else
int retval = system("gnuplot plot_script.gnu &");
#endif
if (retval != EXIT_SUCCESS)
{
std::cerr << "Error: Failed to execut gnuplot." << std::endl;
}
}

// Overload for multiple datasets
static void plot(const std::vector<std::vector<float>> &datasets,
const std::vector<std::string> &labels,
const std::string &title = "Debug Plot",
const std::string &xlabel = "Index",
const std::string &ylabel = "Value")
{
// Write data to separate files
for (size_t d = 0; d < datasets.size(); ++d)
{
std::ofstream dataFile("debug_data_" + std::to_string(d) + ".tmp");
for (size_t i = 0; i < datasets[d].size(); ++i)
{
dataFile << i << " " << datasets[d][i] << "\n";
}
dataFile.close();
}

// Create gnuplot script
std::ofstream scriptFile("plot_script.gnu");
scriptFile << "set title '" << title << "'\n"
<< "set xlabel '" << xlabel << "'\n"
<< "set ylabel '" << ylabel << "'\n"
<< "set grid\n"
<< "plot ";

for (size_t d = 0; d < datasets.size(); ++d)
{
if (d > 0)
scriptFile << ", ";
scriptFile << "'debug_data_" << d << ".tmp' with linespoints title '"
<< (d < labels.size() ? labels[d] : "Dataset " + std::to_string(d)) << "'";
}

scriptFile << "\npause mouse close\n";
scriptFile.close();

// Launch gnuplot
int retval;
#ifdef _WIN32
retval = system("start gnuplot plot_script.gnu");
#else
retval = system("gnuplot plot_script.gnu &");
#endif
if (retval != EXIT_SUCCESS)
{
throw std::runtime_error("Error: Failed to execute gnuplot.");
}
}
};

extern "C" __attribute__((visibility("default"))) void plotArray(float *values, int length)
{
std::vector<float> v;
for (int i = 0; i < length; ++i)
{
v.push_back(values[i]);
}

DebugPlotter::plot(v);
}
Loading
Loading