Some fixes and added an extended lv2-beep as beep2.

pull/1/head
Holger Wirtz 8 years ago
parent f93e2d9a44
commit c4524a7980
  1. 5
      lv2-examples/beep/beep.ttl
  2. 5
      lv2-examples/beep/lv2pftci-beep.lv2/beep.ttl
  3. 23
      lv2-examples/beep2/Makefile
  4. 95
      lv2-examples/beep2/beep.cpp
  5. 39
      lv2-examples/beep2/beep.peg
  6. 69
      lv2-examples/beep2/beep2.ttl
  7. 69
      lv2-examples/beep2/lv2pftci-beep2.lv2/beep2.ttl
  8. 5
      lv2-examples/beep2/lv2pftci-beep2.lv2/manifest.ttl
  9. 5
      lv2-examples/beep2/manifest.ttl
  10. 2
      src/Dexed.ttl
  11. 21
      src/dexed.cpp
  12. 13
      src/dexed.h

@ -5,6 +5,7 @@
@prefix ll: <http://ll-plugins.nongnu.org/lv2/namespace#>. @prefix ll: <http://ll-plugins.nongnu.org/lv2/namespace#>.
@prefix pg: <http://ll-plugins.nongnu.org/lv2/ext/portgroups#>. @prefix pg: <http://ll-plugins.nongnu.org/lv2/ext/portgroups#>.
@prefix ev: <http://lv2plug.in/ns/ext/event#>. @prefix ev: <http://lv2plug.in/ns/ext/event#>.
@prefix atom: <http://lv2plug.in/ns/ext/atom#> .
<http://ll-plugins.nongnu.org/lv2/lv2pftci/beep/out> a pg:StereoGroup. <http://ll-plugins.nongnu.org/lv2/lv2pftci/beep/out> a pg:StereoGroup.
@ -16,7 +17,9 @@
ll:pegName "p"; ll:pegName "p";
lv2:port [ lv2:port [
a ev:EventPort, lv2:InputPort; a lv2:InputPort, atom:AtomPort ;
atom:bufferType atom:Sequence ;
atom:supports <http://lv2plug.in/ns/ext/midi#MidiEvent> ;
lv2:index 0; lv2:index 0;
ev:supportsEvent <http://lv2plug.in/ns/ext/midi#MidiEvent>; ev:supportsEvent <http://lv2plug.in/ns/ext/midi#MidiEvent>;
lv2:symbol "midi"; lv2:symbol "midi";

@ -5,6 +5,7 @@
@prefix ll: <http://ll-plugins.nongnu.org/lv2/namespace#>. @prefix ll: <http://ll-plugins.nongnu.org/lv2/namespace#>.
@prefix pg: <http://ll-plugins.nongnu.org/lv2/ext/portgroups#>. @prefix pg: <http://ll-plugins.nongnu.org/lv2/ext/portgroups#>.
@prefix ev: <http://lv2plug.in/ns/ext/event#>. @prefix ev: <http://lv2plug.in/ns/ext/event#>.
@prefix atom: <http://lv2plug.in/ns/ext/atom#> .
<http://ll-plugins.nongnu.org/lv2/lv2pftci/beep/out> a pg:StereoGroup. <http://ll-plugins.nongnu.org/lv2/lv2pftci/beep/out> a pg:StereoGroup.
@ -16,7 +17,9 @@
ll:pegName "p"; ll:pegName "p";
lv2:port [ lv2:port [
a ev:EventPort, lv2:InputPort; a lv2:InputPort, atom:AtomPort ;
atom:bufferType atom:Sequence ;
atom:supports <http://lv2plug.in/ns/ext/midi#MidiEvent> ;
lv2:index 0; lv2:index 0;
ev:supportsEvent <http://lv2plug.in/ns/ext/midi#MidiEvent>; ev:supportsEvent <http://lv2plug.in/ns/ext/midi#MidiEvent>;
lv2:symbol "midi"; lv2:symbol "midi";

@ -0,0 +1,23 @@
BUNDLE = lv2pftci-beep2.lv2
INSTALL_DIR = /usr/local/lib/lv2
$(BUNDLE): manifest.ttl beep2.ttl beep2.so
rm -rf $(BUNDLE)
mkdir $(BUNDLE)
cp $^ $(BUNDLE)
beep2.so: beep.cpp beep.peg
g++ -shared -fPIC -DPIC beep.cpp `pkg-config --cflags --libs lv2-plugin` -o beep2.so
beep.peg: beep2.ttl
lv2peg beep2.ttl beep.peg
install: $(BUNDLE)
mkdir -p $(INSTALL_DIR)
rm -rf $(INSTALL_DIR)/$(BUNDLE)
cp -R $(BUNDLE) $(INSTALL_DIR)
clean:
rm -rf $(BUNDLE) beep2.so beep.peg

@ -0,0 +1,95 @@
// from: http://ll-plugins.nongnu.org/lv2pftci/#A_synth
#include <lv2synth.hpp>
#include "beep.peg"
#include <cstdlib>
class BeepVoice : public LV2::Voice {
public:
BeepVoice(double rate)
: m_key(LV2::INVALID_KEY), m_rate(rate), m_period(10), m_counter(0) {
}
void on(unsigned char key, unsigned char velocity) {
m_key = key;
m_period = m_rate * 4.0 / LV2::key2hz(m_key);
m_pos = std::rand() / float(RAND_MAX);
m_envelope = velocity / 128.0;
}
void off(unsigned char velocity) {
m_key = LV2::INVALID_KEY;
}
unsigned char get_key() const {
return m_key;
}
void render(uint32_t from, uint32_t to) {
if (m_key == LV2::INVALID_KEY)
return;
for (uint32_t i = from; i < to; ++i) {
float pwm = *p(p_pwm) + (1 - *p(p_pwm)) * m_envelope;
float s = -0.25 + 0.5 * (m_counter > m_period * (1 + pwm) / 2);
m_counter = (m_counter + 1) % m_period;
p(p_left)[i] += (1 - m_pos) * s;
p(p_right)[i] += m_pos * s;
if (m_envelope > 0)
m_envelope -= 0.5 / m_rate;
}
}
protected:
unsigned char m_key;
double m_rate;
uint32_t m_period;
uint32_t m_counter;
float m_pos;
float m_envelope;
};
class Beep : public LV2::Synth<BeepVoice, Beep> {
public:
Beep(double rate)
: LV2::Synth<BeepVoice, Beep>(p_n_ports, p_midi),
m_buf_pos(0), m_delay(rate / 3),
m_l_buffer(new float[m_delay]), m_r_buffer(new float[m_delay]) {
add_voices(new BeepVoice(rate), new BeepVoice(rate), new BeepVoice(rate));
add_audio_outputs(p_left, p_right);
for (unsigned i = 0; i < m_delay; ++i) {
m_l_buffer[i] = 0;
m_r_buffer[i] = 0;
}
}
void post_process(uint32_t from, uint32_t to) {
for (uint32_t i = from; i < to; ++i) {
float mono = (p(p_left)[i] + p(p_right)[i]) / 2;
p(p_left)[i] += m_l_buffer[m_buf_pos];
p(p_right)[i] += m_r_buffer[m_buf_pos];
float tmp = m_l_buffer[m_buf_pos];
m_l_buffer[m_buf_pos] = 0.6 * (mono + m_r_buffer[m_buf_pos]);
m_r_buffer[m_buf_pos] = 0.6 * tmp;
m_buf_pos = (m_buf_pos + 1) % m_delay;
p(p_left)[i] *= *p(p_gain);
p(p_right)[i] *= *p(p_gain);
}
}
protected:
unsigned m_buf_pos;
unsigned m_delay;
float* m_l_buffer;
float* m_r_buffer;
};
static int _ = Beep::register_class(p_uri);

@ -0,0 +1,39 @@
#ifndef beep_peg
#define beep_peg
#ifndef PEG_STRUCT
#define PEG_STRUCT
typedef struct {
float min;
float max;
float default_value;
char toggled;
char integer;
char logarithmic;
} peg_data_t;
#endif
/* <http://ll-plugins.nongnu.org/lv2/lv2pftci/beep2> */
static const char p_uri[] = "http://ll-plugins.nongnu.org/lv2/lv2pftci/beep2";
enum p_port_enum {
p_midi,
p_left,
p_right,
p_pwm,
p_gain,
p_n_ports
};
static const peg_data_t p_ports[] = {
{ -3.40282e+38, 3.40282e+38, -3.40282e+38, 0, 0, 0 },
{ -3.40282e+38, 3.40282e+38, -3.40282e+38, 0, 0, 0 },
{ -3.40282e+38, 3.40282e+38, -3.40282e+38, 0, 0, 0 },
{ 0, 1, 0.5, 0, 0, 0 },
{ 0, 2, 1, 0, 0, 0 },
};
#endif /* beep_peg */

@ -0,0 +1,69 @@
@prefix lv2: <http://lv2plug.in/ns/lv2core#>.
@prefix doap: <http://usefulinc.com/ns/doap#>.
@prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>.
@prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#>.
@prefix ll: <http://ll-plugins.nongnu.org/lv2/namespace#>.
@prefix pg: <http://ll-plugins.nongnu.org/lv2/ext/portgroups#>.
@prefix ev: <http://lv2plug.in/ns/ext/event#>.
@prefix atom: <http://lv2plug.in/ns/ext/atom#> .
<http://ll-plugins.nongnu.org/lv2/lv2pftci/beep2/out> a pg:StereoGroup.
<http://ll-plugins.nongnu.org/lv2/lv2pftci/beep2>
a lv2:Plugin, lv2:InstrumentPlugin;
lv2:binary <beep2.so>;
doap:name "Beep2";
doap:license <http://usefulinc.com/doap/licenses/gpl>;
ll:pegName "p";
lv2:port [
a lv2:InputPort, atom:AtomPort ;
atom:bufferType atom:Sequence ;
atom:supports <http://lv2plug.in/ns/ext/midi#MidiEvent> ;
lv2:index 0;
ev:supportsEvent <http://lv2plug.in/ns/ext/midi#MidiEvent>;
lv2:symbol "midi";
lv2:name "MIDI";
],
[
a lv2:AudioPort, lv2:OutputPort;
lv2:index 1;
lv2:symbol "left";
lv2:name "Left";
pg:membership [
pg:group <http://ll-plugins.nongnu.org/lv2/lv2pftci/beep2/out>;
pg:role pg:leftChannel;
];
],
[
a lv2:AudioPort, lv2:OutputPort;
lv2:index 2;
lv2:symbol "right";
lv2:name "Right";
pg:membership [
pg:group <http://ll-plugins.nongnu.org/lv2/lv2pftci/beep2/out>;
pg:role pg:rightChannel;
];
],
[
a lv2:ControlPort, lv2:InputPort;
lv2:index 3;
lv2:symbol "pwm";
lv2:name "PWM";
lv2:minimum 0;
lv2:maximum 1;
lv2:default 0.5;
],
[
a lv2:ControlPort, lv2:InputPort;
lv2:index 4;
lv2:symbol "gain";
lv2:name "Gain";
lv2:minimum 0;
lv2:maximum 2;
lv2:default 1;
].

@ -0,0 +1,69 @@
@prefix lv2: <http://lv2plug.in/ns/lv2core#>.
@prefix doap: <http://usefulinc.com/ns/doap#>.
@prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>.
@prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#>.
@prefix ll: <http://ll-plugins.nongnu.org/lv2/namespace#>.
@prefix pg: <http://ll-plugins.nongnu.org/lv2/ext/portgroups#>.
@prefix ev: <http://lv2plug.in/ns/ext/event#>.
@prefix atom: <http://lv2plug.in/ns/ext/atom#> .
<http://ll-plugins.nongnu.org/lv2/lv2pftci/beep2/out> a pg:StereoGroup.
<http://ll-plugins.nongnu.org/lv2/lv2pftci/beep2>
a lv2:Plugin, lv2:InstrumentPlugin;
lv2:binary <beep2.so>;
doap:name "Beep2";
doap:license <http://usefulinc.com/doap/licenses/gpl>;
ll:pegName "p";
lv2:port [
a lv2:InputPort, atom:AtomPort ;
atom:bufferType atom:Sequence ;
atom:supports <http://lv2plug.in/ns/ext/midi#MidiEvent> ;
lv2:index 0;
ev:supportsEvent <http://lv2plug.in/ns/ext/midi#MidiEvent>;
lv2:symbol "midi";
lv2:name "MIDI";
],
[
a lv2:AudioPort, lv2:OutputPort;
lv2:index 1;
lv2:symbol "left";
lv2:name "Left";
pg:membership [
pg:group <http://ll-plugins.nongnu.org/lv2/lv2pftci/beep2/out>;
pg:role pg:leftChannel;
];
],
[
a lv2:AudioPort, lv2:OutputPort;
lv2:index 2;
lv2:symbol "right";
lv2:name "Right";
pg:membership [
pg:group <http://ll-plugins.nongnu.org/lv2/lv2pftci/beep2/out>;
pg:role pg:rightChannel;
];
],
[
a lv2:ControlPort, lv2:InputPort;
lv2:index 3;
lv2:symbol "pwm";
lv2:name "PWM";
lv2:minimum 0;
lv2:maximum 1;
lv2:default 0.5;
],
[
a lv2:ControlPort, lv2:InputPort;
lv2:index 4;
lv2:symbol "gain";
lv2:name "Gain";
lv2:minimum 0;
lv2:maximum 2;
lv2:default 1;
].

@ -0,0 +1,5 @@
@prefix lv2: <http://lv2plug.in/ns/lv2core#>.
@prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#>.
<http://ll-plugins.nongnu.org/lv2/lv2pftci/beep2>
a lv2:Plugin;
rdfs:seeAlso <beep2.ttl>.

@ -0,0 +1,5 @@
@prefix lv2: <http://lv2plug.in/ns/lv2core#>.
@prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#>.
<http://ll-plugins.nongnu.org/lv2/lv2pftci/beep2>
a lv2:Plugin;
rdfs:seeAlso <beep2.ttl>.

@ -1527,5 +1527,5 @@
] ; ] ;
doap:name "Dexed" ; doap:name "Dexed" ;
doap:maintainer [ foaf:name "Digital Suburban" ] . doap:maintainer [ foaf:name "dcoredump" ] .

@ -10,9 +10,10 @@
#include "msfa/freqlut.h" #include "msfa/freqlut.h"
#include "msfa/controllers.h" #include "msfa/controllers.h"
DexedVoice::DexedVoice(double rate) : m_key(LV2::INVALID_KEY), m_rate(rate) DexedVoice::DexedVoice(double rate, uint8_t fb) : m_key(LV2::INVALID_KEY), m_rate(rate)
{ {
voice.dx7_note=new Dx7Note; voice.dx7_note=new Dx7Note;
feedback_bitdepth=fb;
} }
void DexedVoice::on(unsigned char key, unsigned char velocity) void DexedVoice::on(unsigned char key, unsigned char velocity)
@ -60,17 +61,29 @@ Dexed::Dexed(double rate) : LV2::Synth<DexedVoice, Dexed>(p_n_ports, p_lv2_event
Controllers controllers; Controllers controllers;
//controllers.engineType=DEXED_ENGINE_MARKI; engineType=DEXED_ENGINE_MARKI;
feedback_bitdepth=11;
controllers.core=&engineMkI; controllers.core=&engineMkI;
for(uint i=0;i<sizeof(init_voice);i++) { for(uint i=0;i<sizeof(init_voice);i++) {
data[i] = init_voice[i]; data[i] = init_voice[i];
} }
add_voices(new DexedVoice(rate),new DexedVoice(rate),new DexedVoice(rate),new DexedVoice(rate),new DexedVoice(rate),new DexedVoice(rate),new DexedVoice(rate),new DexedVoice(rate),new DexedVoice(rate),new DexedVoice(rate),new DexedVoice(rate),new DexedVoice(rate),new DexedVoice(rate),new DexedVoice(rate),new DexedVoice(rate),new DexedVoice(rate) add_voices(new DexedVoice(rate, feedback_bitdepth),new DexedVoice(rate, feedback_bitdepth),new DexedVoice(rate, feedback_bitdepth),new DexedVoice(rate, feedback_bitdepth),new DexedVoice(rate, feedback_bitdepth),new DexedVoice(rate, feedback_bitdepth),new DexedVoice(rate, feedback_bitdepth),new DexedVoice(rate, feedback_bitdepth),new DexedVoice(rate, feedback_bitdepth),new DexedVoice(rate, feedback_bitdepth),new DexedVoice(rate, feedback_bitdepth),new DexedVoice(rate, feedback_bitdepth),new DexedVoice(rate, feedback_bitdepth),new DexedVoice(rate, feedback_bitdepth),new DexedVoice(rate, feedback_bitdepth),new DexedVoice(rate, feedback_bitdepth));
);
add_audio_outputs(p_lv2_audio_out_1); add_audio_outputs(p_lv2_audio_out_1);
} }
uint8_t Dexed::get_feedback_bitdepth(void)
{
return(feedback_bitdepth);
}
uint32_t Dexed::get_engineType(void)
{
return(engineType);
}
static int _ = Dexed::register_class(p_uri); static int _ = Dexed::register_class(p_uri);

@ -49,7 +49,7 @@ enum DexedEngineResolution {
class DexedVoice : public LV2::Voice class DexedVoice : public LV2::Voice
{ {
public: public:
DexedVoice(double rate); DexedVoice(double rate, uint8_t fb);
void on(unsigned char key, unsigned char velocity); void on(unsigned char key, unsigned char velocity);
void off(unsigned char velocity); void off(unsigned char velocity);
unsigned char get_key(void) const; unsigned char get_key(void) const;
@ -58,6 +58,7 @@ class DexedVoice : public LV2::Voice
protected: protected:
unsigned char m_key; unsigned char m_key;
double m_rate; double m_rate;
uint8_t feedback_bitdepth;
ProcessorVoice voice; ProcessorVoice voice;
}; };
@ -68,20 +69,18 @@ class Dexed : public LV2::Synth<DexedVoice, Dexed>
public: public:
Dexed(double rate); Dexed(double rate);
FmCore *core; FmCore *core;
uint8_t get_feedback_bitdepth(void);
uint32_t get_engineType(void);
protected: protected:
// dexed internal // dexed internal
FmCore engineMsfa; FmCore engineMsfa;
EngineMkI engineMkI; EngineMkI engineMkI;
EngineOpl engineOpl; EngineOpl engineOpl;
uint8_t feedback_bitdepth;
uint32_t engineType;
}; };
// Global vars
uint8_t feedback_bitdepth=11;
uint32_t engineType;
const char init_voice[] = const char init_voice[] =
{ 99, 99, 99, 99, 99, 99, 99, 00, 39, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 7, { 99, 99, 99, 99, 99, 99, 99, 00, 39, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 7,
99, 99, 99, 99, 99, 99, 99, 00, 39, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 7, 99, 99, 99, 99, 99, 99, 99, 00, 39, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 7,

Loading…
Cancel
Save