mirror of
https://github.com/Ardour/ardour.git
synced 2025-12-07 15:25:01 +01:00
remove c99'ness from rsynth.c - should fix #5751
This commit is contained in:
parent
f52cfdd639
commit
e451411719
3 changed files with 21 additions and 16 deletions
|
|
@ -25,7 +25,7 @@
|
||||||
|
|
||||||
/* LV2 */
|
/* LV2 */
|
||||||
#include "lv2/lv2plug.in/ns/lv2core/lv2.h"
|
#include "lv2/lv2plug.in/ns/lv2core/lv2.h"
|
||||||
#include "lv2/lv2plug.in/ns/ext/atom/util.h"
|
#include "lv2/lv2plug.in/ns/ext/atom/atom.h"
|
||||||
#include "lv2/lv2plug.in/ns/ext/urid/urid.h"
|
#include "lv2/lv2plug.in/ns/ext/urid/urid.h"
|
||||||
#include "lv2/lv2plug.in/ns/ext/midi/midi.h"
|
#include "lv2/lv2plug.in/ns/ext/midi/midi.h"
|
||||||
|
|
||||||
|
|
@ -35,7 +35,7 @@
|
||||||
static void * synth_alloc (void);
|
static void * synth_alloc (void);
|
||||||
static void synth_init (void *, double rate);
|
static void synth_init (void *, double rate);
|
||||||
static void synth_free (void *);
|
static void synth_free (void *);
|
||||||
static void synth_parse_midi (void *, uint8_t *data, size_t size);
|
static void synth_parse_midi (void *, const uint8_t *data, const size_t size);
|
||||||
static uint32_t synth_sound (void *, uint32_t written, uint32_t nframes, float **out);
|
static uint32_t synth_sound (void *, uint32_t written, uint32_t nframes, float **out);
|
||||||
|
|
||||||
#include "rsynth.c"
|
#include "rsynth.c"
|
||||||
|
|
@ -131,8 +131,8 @@ run(LV2_Handle handle, uint32_t n_samples)
|
||||||
|
|
||||||
/* Process incoming MIDI events */
|
/* Process incoming MIDI events */
|
||||||
if (self->midiin) {
|
if (self->midiin) {
|
||||||
LV2_Atom_Event* ev = lv2_atom_sequence_begin(&(self->midiin)->body);
|
LV2_Atom_Event const* ev = (LV2_Atom_Event const*) ((&(self->midiin)->body) + 1); // lv2_atom_sequence_begin
|
||||||
while(!lv2_atom_sequence_is_end(&(self->midiin)->body, (self->midiin)->atom.size, ev)) {
|
while( (const uint8_t*)ev < ((const uint8_t*) &(self->midiin)->body + (self->midiin)->atom.size) ) {
|
||||||
if (ev->body.type == self->midi_MidiEvent) {
|
if (ev->body.type == self->midi_MidiEvent) {
|
||||||
if (written + BUFFER_SIZE_SAMPLES < ev->time.frames
|
if (written + BUFFER_SIZE_SAMPLES < ev->time.frames
|
||||||
&& ev->time.frames < n_samples) {
|
&& ev->time.frames < n_samples) {
|
||||||
|
|
@ -140,9 +140,9 @@ run(LV2_Handle handle, uint32_t n_samples)
|
||||||
written = synth_sound(self->synth, written, ev->time.frames, audio);
|
written = synth_sound(self->synth, written, ev->time.frames, audio);
|
||||||
}
|
}
|
||||||
/* send midi message to synth */
|
/* send midi message to synth */
|
||||||
synth_parse_midi(self->synth, (uint8_t*)(ev+1), ev->body.size);
|
synth_parse_midi(self->synth, (const uint8_t*)(ev+1), ev->body.size);
|
||||||
}
|
}
|
||||||
ev = lv2_atom_sequence_next(ev);
|
ev = (LV2_Atom_Event const*)((const uint8_t*)ev + sizeof(LV2_Atom_Event) + ((ev->body.size + 7) & ~7));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -175,9 +175,10 @@ static void synthesize_sineP (RSSynthChannel* sc,
|
||||||
const uint8_t note, const float vol, const float fq,
|
const uint8_t note, const float vol, const float fq,
|
||||||
const size_t n_samples, float* left, float* right) {
|
const size_t n_samples, float* left, float* right) {
|
||||||
|
|
||||||
|
size_t i;
|
||||||
float phase = sc->phase[note];
|
float phase = sc->phase[note];
|
||||||
|
|
||||||
for (size_t i=0; i < n_samples; ++i) {
|
for (i=0; i < n_samples; ++i) {
|
||||||
float env = adsr_env(sc, note);
|
float env = adsr_env(sc, note);
|
||||||
if (sc->adsr_cnt[note] == 0) break;
|
if (sc->adsr_cnt[note] == 0) break;
|
||||||
const float amp = vol * env;
|
const float amp = vol * env;
|
||||||
|
|
@ -272,9 +273,11 @@ static void synth_fragment (void *synth, const size_t n_samples, float *left, fl
|
||||||
memset (left, 0, n_samples * sizeof(float));
|
memset (left, 0, n_samples * sizeof(float));
|
||||||
memset (right, 0, n_samples * sizeof(float));
|
memset (right, 0, n_samples * sizeof(float));
|
||||||
uint8_t keycomp = 0;
|
uint8_t keycomp = 0;
|
||||||
|
int c,k;
|
||||||
|
size_t i;
|
||||||
|
|
||||||
for (int c=0; c < 16; ++c) {
|
for (c=0; c < 16; ++c) {
|
||||||
for (int k=0; k < 128; ++k) {
|
for (k=0; k < 128; ++k) {
|
||||||
if (rs->sc[c].miditable[k] == 0) continue;
|
if (rs->sc[c].miditable[k] == 0) continue;
|
||||||
process_key(synth, c, k, n_samples, left, right);
|
process_key(synth, c, k, n_samples, left, right);
|
||||||
}
|
}
|
||||||
|
|
@ -286,7 +289,7 @@ static void synth_fragment (void *synth, const size_t n_samples, float *left, fl
|
||||||
if (kctgt < .5) kctgt = .5;
|
if (kctgt < .5) kctgt = .5;
|
||||||
if (kctgt > 1.0) kctgt = 1.0;
|
if (kctgt > 1.0) kctgt = 1.0;
|
||||||
const float _w = rs->kcfilt;
|
const float _w = rs->kcfilt;
|
||||||
for (unsigned int i=0; i < n_samples; ++i) {
|
for (i=0; i < n_samples; ++i) {
|
||||||
rs->kcgain += _w * (kctgt - rs->kcgain);
|
rs->kcgain += _w * (kctgt - rs->kcgain);
|
||||||
left[i] *= rs->kcgain;
|
left[i] *= rs->kcgain;
|
||||||
right[i] *= rs->kcgain;
|
right[i] *= rs->kcgain;
|
||||||
|
|
@ -296,7 +299,8 @@ static void synth_fragment (void *synth, const size_t n_samples, float *left, fl
|
||||||
}
|
}
|
||||||
|
|
||||||
static void synth_reset_channel(RSSynthChannel* sc) {
|
static void synth_reset_channel(RSSynthChannel* sc) {
|
||||||
for (int k=0; k < 128; ++k) {
|
int k;
|
||||||
|
for (k=0; k < 128; ++k) {
|
||||||
sc->adsr_cnt[k] = 0;
|
sc->adsr_cnt[k] = 0;
|
||||||
sc->adsr_amp[k] = 0;
|
sc->adsr_amp[k] = 0;
|
||||||
sc->phase[k] = -10;
|
sc->phase[k] = -10;
|
||||||
|
|
@ -307,7 +311,8 @@ static void synth_reset_channel(RSSynthChannel* sc) {
|
||||||
|
|
||||||
static void synth_reset(void *synth) {
|
static void synth_reset(void *synth) {
|
||||||
RSSynthesizer* rs = (RSSynthesizer*)synth;
|
RSSynthesizer* rs = (RSSynthesizer*)synth;
|
||||||
for (int c=0; c < 16; ++c) {
|
int c;
|
||||||
|
for (c=0; c < 16; ++c) {
|
||||||
synth_reset_channel(&(rs->sc[c]));
|
synth_reset_channel(&(rs->sc[c]));
|
||||||
}
|
}
|
||||||
rs->kcgain = 0;
|
rs->kcgain = 0;
|
||||||
|
|
@ -407,7 +412,7 @@ static uint32_t synth_sound (void *synth, uint32_t written, const uint32_t nfram
|
||||||
* @param data 8bit midi message
|
* @param data 8bit midi message
|
||||||
* @param size number of bytes in the midi-message
|
* @param size number of bytes in the midi-message
|
||||||
*/
|
*/
|
||||||
static void synth_parse_midi(void *synth, uint8_t *data, size_t size) {
|
static void synth_parse_midi(void *synth, const uint8_t *data, const size_t size) {
|
||||||
if (size < 2 || size > 3) return;
|
if (size < 2 || size > 3) return;
|
||||||
// All messages need to be 3 bytes; except program-changes: 2bytes.
|
// All messages need to be 3 bytes; except program-changes: 2bytes.
|
||||||
if (size == 2 && (data[0] & 0xf0) != 0xC0) return;
|
if (size == 2 && (data[0] & 0xf0) != 0xC0) return;
|
||||||
|
|
@ -454,14 +459,15 @@ static void synth_init(void *synth, double rate) {
|
||||||
rs->rate = rate;
|
rs->rate = rate;
|
||||||
rs->boffset = BUFFER_SIZE_SAMPLES;
|
rs->boffset = BUFFER_SIZE_SAMPLES;
|
||||||
const float tuning = 440;
|
const float tuning = 440;
|
||||||
for (int k=0; k < 128; k++) {
|
int c,k;
|
||||||
|
for (k=0; k < 128; k++) {
|
||||||
rs->freqs[k] = (2.0 * tuning / 32.0f) * powf(2, (k - 9.0) / 12.0) / rate;
|
rs->freqs[k] = (2.0 * tuning / 32.0f) * powf(2, (k - 9.0) / 12.0) / rate;
|
||||||
assert(rs->freqs[k] < M_PI/2); // otherwise spatialization may phase out..
|
assert(rs->freqs[k] < M_PI/2); // otherwise spatialization may phase out..
|
||||||
}
|
}
|
||||||
rs->kcfilt = 12.0 / rate;
|
rs->kcfilt = 12.0 / rate;
|
||||||
synth_reset(synth);
|
synth_reset(synth);
|
||||||
|
|
||||||
for (int c=0; c < 16; c++) {
|
for (c=0; c < 16; c++) {
|
||||||
synth_load(&rs->sc[c], rate, &synthesize_sineP, &piano_adsr);
|
synth_load(&rs->sc[c], rate, &synthesize_sineP, &piano_adsr);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -15,7 +15,6 @@ def options(opt):
|
||||||
def configure(conf):
|
def configure(conf):
|
||||||
conf.load('compiler_c')
|
conf.load('compiler_c')
|
||||||
autowaf.configure(conf)
|
autowaf.configure(conf)
|
||||||
autowaf.set_c99_mode(conf)
|
|
||||||
if Options.options.lv2:
|
if Options.options.lv2:
|
||||||
autowaf.check_pkg(conf, 'lv2', atleast_version='1.0.0',
|
autowaf.check_pkg(conf, 'lv2', atleast_version='1.0.0',
|
||||||
uselib_store='LV2_1_0_0')
|
uselib_store='LV2_1_0_0')
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue