Skip to content

Commit

Permalink
0.0.2
Browse files Browse the repository at this point in the history
  • Loading branch information
psemiletov committed Oct 15, 2023
1 parent c607e3d commit 522a1bb
Show file tree
Hide file tree
Showing 7 changed files with 328 additions and 4 deletions.
25 changes: 22 additions & 3 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
cmake_minimum_required(VERSION 3.0)
project (metalluga VERSION 0.0.1 LANGUAGES CXX C)
project (metalluga VERSION 0.0.2 LANGUAGES CXX C)


set(LV2_INSTALL_DIR lib/lv2 CACHE PATH "Specifies where the LV2 libraries should be installed")

SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -g -O3 ")
SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -g -O2 ")


option(USE_CLANG "Build with Clang" OFF)
Expand Down Expand Up @@ -36,12 +36,21 @@ add_library(metalluga SHARED
)


add_library(charm SHARED
./source/dsp.cpp
./source/dsp.h
./source/charm.cpp
)


set_target_properties(metalluga PROPERTIES PREFIX "")
target_link_libraries(metalluga ${LV2_LIBRARIES})

set_target_properties(charm PROPERTIES PREFIX "")
target_link_libraries(charm ${LV2_LIBRARIES})


# config install
# Metalluga install
install(TARGETS metalluga
LIBRARY
DESTINATION ${CMAKE_INSTALL_PREFIX}/${LV2_INSTALL_DIR}/metalluga.lv2
Expand All @@ -51,3 +60,13 @@ install (FILES ./source/ttl-metalluga/metalluga.ttl ./source/ttl-metalluga/manif
DESTINATION ${CMAKE_INSTALL_PREFIX}/${LV2_INSTALL_DIR}/metalluga.lv2
)

# Charm install
install(TARGETS charm
LIBRARY
DESTINATION ${CMAKE_INSTALL_PREFIX}/${LV2_INSTALL_DIR}/charm.lv2
)

install (FILES ./source/ttl-charm/charm.ttl ./source/ttl-charm/manifest.ttl
DESTINATION ${CMAKE_INSTALL_PREFIX}/${LV2_INSTALL_DIR}/charm.lv2
)

3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@ Current plugins list:

**Metalluga** - the distortion effect

**Charm** - the saturation effect, makes sound more "analog"


## Build and install

**Dependencies:** cmake, lv2 library
Expand Down
147 changes: 147 additions & 0 deletions source/charm.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,147 @@
/*
code is Public Domain and written by Peter Semiletov, 2023
*/

#include "lv2/core/lv2.h"


#include <cmath>
#include <stdint.h>
#include <stdlib.h>
#include <iostream>

#include "dsp.h"
#include "fx-resofilter.h"

#define METALLUGA_URI "https://github.com/psemiletov/charm"

typedef enum { PORT_IN_LEFT = 0, PORT_IN_RIGHT = 1, PORT_OUT_LEFT = 2, PORT_OUT_RIGHT = 3, PORT_CHARM = 4} PortIndex;



class CCharm
{
public:

int samplerate;


const float* charm;

const float* input_l;
const float* input_r;

float *output_l;
float *output_r;

//CCharm();
};




static void
activate(LV2_Handle instance)
{}


static LV2_Handle
instantiate(const LV2_Descriptor* descriptor,
double rate,
const char* bundle_path,
const LV2_Feature* const* features)
{
init_db();
CCharm *instance = new CCharm;
instance->samplerate = rate;

return (LV2_Handle)instance;
}


static void
connect_port(LV2_Handle instance, uint32_t port, void* data)
{
CCharm *inst = (CCharm*)instance;

switch ((PortIndex)port)
{
case PORT_IN_LEFT:
inst->input_l = (const float*)data;
break;

case PORT_IN_RIGHT:
inst->input_r = (const float*)data;
break;

case PORT_OUT_LEFT:
inst->output_l = (float*)data;
break;

case PORT_OUT_RIGHT:
inst->output_r = (float*)data;
break;

case PORT_CHARM:
inst->charm = (const float*)data;
break;


}
}


static void
run(LV2_Handle instance, uint32_t n_samples)
{
CCharm *inst = (CCharm*)instance;

//const float* const input = inst->input;
//float* const output = inst->output;

for (uint32_t pos = 0; pos < n_samples; pos++)
{
float fl = inst->input_l[pos];
float fr = inst->input_r[pos];

fl = warmify (fl, *(inst->charm));
fr = warmify (fr, *(inst->charm));

inst->output_l[pos] = fl;
inst->output_r[pos] = fr;
}
}


static void deactivate (LV2_Handle instance)
{
}


static void cleanup(LV2_Handle instance)
{
delete (CCharm*)instance;
}


static const void* extension_data (const char* uri)
{
return NULL;
}


static const LV2_Descriptor descriptor = {METALLUGA_URI,
instantiate,
connect_port,
activate,
run,
deactivate,
cleanup,
extension_data};


LV2_SYMBOL_EXPORT
const LV2_Descriptor* lv2_descriptor (uint32_t index)
{
return index == 0 ? &descriptor : NULL;
}
2 changes: 1 addition & 1 deletion source/dsp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ void init_db()
/*************** SATURATION/DIST/OVERDRIVE *******************/


// Функция для более "хриплого" гитарного искажения
// Функция для "хриплого" гитарного искажения
float gritty_guitar_distortion (float input_sample, float distortion_level)
{
// Шаг 1: Усиление с более высоким коэффициентом
Expand Down
62 changes: 62 additions & 0 deletions source/dsp.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,68 @@ Peter Semiletov, 2023
#endif



#include <cmath>
#include <vector>
#include <cmath>

class ChorusEffect {
public:

float sampleRate;


ChorusEffect(int initialDelayLineLength = 8820) {
sampleRate = 44100.0;
setDelayLineLength(initialDelayLineLength);
index = 0;
rate = 0.25; // Частота "дрожания" (герц)
depth = 0.005; // Сила "дрожания" (максимальное отклонение задержки)
}

// Установка параметров эффекта
void setParameters(float newRate, float newDepth) {
rate = newRate;
depth = newDepth;
}

// Установка длины задержки
void setDelayLineLength(int newLength) {
delayLineLength = newLength;
delayLine.resize(delayLineLength);
}

// Функция для обработки входного сэмпла
float process(float input) {
// Записываем входной сэмпл в задержку
delayLine[index] = input;

// Вычисляем текущую задержку, модулируя глубиной и частотой "дрожания"
float modulatedDelay = static_cast<float>(delayLineLength) / 2 * (1 + depth * sin(2 * M_PI * rate * index / sampleRate));

// Находим два ближайших индекса в задержке для интерполяции
int index1 = static_cast<int>(modulatedDelay);
int index2 = index1 + 1;
float fraction = modulatedDelay - index1;

// Линейная интерполяция между соседними сэмплами в задержке
float output = (1 - fraction) * delayLine[(index1 + delayLineLength) % delayLineLength] +
fraction * delayLine[(index2 + delayLineLength) % delayLineLength];

// Обновляем индекс и возвращаем обработанный сэмпл
index = (index + 1) % delayLineLength;
return output;
}

private:
int delayLineLength;
std::vector<float> delayLine;
int index;
float rate;
float depth;
};


extern float db_scale;

inline float db2lin (float db)
Expand Down
77 changes: 77 additions & 0 deletions source/ttl-charm/charm.ttl
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
# The full description of the plugin is in this file, which is linked to from
# `manifest.ttl`. This is done so the host only needs to scan the relatively
# small `manifest.ttl` files to quickly discover all plugins.

@prefix doap: <http://usefulinc.com/ns/doap#> .
@prefix foaf: <http://xmlns.com/foaf/0.1/> .
@prefix lv2: <http://lv2plug.in/ns/lv2core#> .
@prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> .
@prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#> .
@prefix units: <http://lv2plug.in/ns/extensions/units#> .

<https://github.com/psemiletov/charm>
a lv2:Plugin ,
lv2:DistortionPlugin ;

doap:shortdesc "Warm sound saturator" ;
doap:programming-language "C++" ;
doap:name "Charm",
"Шарм"@ru ,
"Charme"@fr;

doap:maintainer [
foaf:name "Bedroom Studio" ;
foaf:homepage <https://github.com/psemiletov/bedroomstudio> ;
foaf:mbox <[email protected]>
] ;

doap:license <https://creativecommons.org/publicdomain/mark/1.0/> ;

lv2:optionalFeature lv2:hardRTCapable ;

lv2:port [
a lv2:AudioPort ,
lv2:InputPort ;
lv2:index 0 ;
lv2:symbol "in_l" ;
lv2:name "In_Left"
] ,

[
a lv2:AudioPort ,
lv2:InputPort ;
lv2:index 1 ;
lv2:symbol "in_r" ;
lv2:name "In_Right"
] ,

[
a lv2:AudioPort ,
lv2:OutputPort ;
lv2:index 2 ;
lv2:symbol "out_l" ;
lv2:name "Out_Left"
],

[
a lv2:AudioPort ,
lv2:OutputPort ;
lv2:index 3 ;
lv2:symbol "out_r" ;
lv2:name "Out_Right"
],

[
a lv2:InputPort ,
lv2:ControlPort ;
lv2:index 4 ;
lv2:symbol "charm" ;
lv2:name "Charm" ,
"Charme"@fr ,
"Шарм"@ru ;
lv2:default 0.50 ;
lv2:minimum 0.0 ;
lv2:maximum 1.0 ;
units:unit units:coef ;
].

16 changes: 16 additions & 0 deletions source/ttl-charm/manifest.ttl
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
@prefix lv2: <http://lv2plug.in/ns/lv2core#> .
@prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#> .

<https://github.com/psemiletov/charm> a lv2:Plugin .

<https://github.com/psemiletov/charm> lv2:binary <charm.so> .


<https://github.com/psemiletov/charm> rdfs:seeAlso <charm.ttl> .



<https://github.com/psemiletov/charm>
a lv2:Plugin ;
lv2:binary <charm.so> ;
rdfs:seeAlso <charm.ttl> .

0 comments on commit 522a1bb

Please sign in to comment.