Browse Source

basic saw working

cache_saws
Alexandros Theodotou 3 years ago
parent
commit
905aad2b65
Signed by: alex
GPG Key ID: 022EAE42313D70F3
  1. 100
      ext/Soundpipe/h/sp_base.h
  2. 48
      plugins/supersaw/supersaw.c

100
ext/Soundpipe/h/sp_base.h

@ -0,0 +1,100 @@ @@ -0,0 +1,100 @@
#ifndef SOUNDPIPE_H
#define SOUNDPIPE_H
#include <stdint.h>
#include <stdio.h>
#define SP_BUFSIZE 4096
#ifndef SPFLOAT
#define SPFLOAT float
#endif
#define SP_OK 1
#define SP_NOT_OK 0
#define SP_RANDMAX 2147483648
typedef unsigned long sp_frame;
typedef struct sp_auxdata {
size_t size;
void *ptr;
} sp_auxdata;
typedef struct sp_data {
SPFLOAT *out;
int sr;
int nchan;
unsigned long len;
unsigned long pos;
char filename[200];
uint32_t rand;
} sp_data;
typedef struct {
char state;
SPFLOAT val;
} sp_param;
int sp_auxdata_alloc(sp_auxdata *aux, size_t size);
int sp_auxdata_free(sp_auxdata *aux);
int sp_create(sp_data **spp);
int sp_createn(sp_data **spp, int nchan);
int sp_destroy(sp_data **spp);
int sp_process(sp_data *sp, void *ud, void (*callback)(sp_data *, void *));
int sp_process_raw(sp_data *sp, void *ud, void (*callback)(sp_data *, void *));
int sp_process_plot(sp_data *sp, void *ud, void (*callback)(sp_data *, void *));
int sp_process_spa(sp_data *sp, void *ud, void (*callback)(sp_data *, void *));
SPFLOAT sp_midi2cps(SPFLOAT nn);
int sp_set(sp_param *p, SPFLOAT val);
int sp_out(sp_data *sp, uint32_t chan, SPFLOAT val);
uint32_t sp_rand(sp_data *sp);
void sp_srand(sp_data *sp, uint32_t val);
typedef struct {
SPFLOAT *utbl;
int16_t *BRLow;
int16_t *BRLowCpx;
} sp_fft;
void sp_fft_init(sp_fft *fft, int M);
void sp_fftr(sp_fft *fft, SPFLOAT *buf, int FFTsize);
void sp_fft_cpx(sp_fft *fft, SPFLOAT *buf, int FFTsize);
void sp_ifftr(sp_fft *fft, SPFLOAT *buf, int FFTsize);
void sp_fft_destroy(sp_fft *fft);
#ifndef kiss_fft_scalar
#define kiss_fft_scalar SPFLOAT
#endif
typedef struct {
kiss_fft_scalar r;
kiss_fft_scalar i;
}kiss_fft_cpx;
typedef struct kiss_fft_state* kiss_fft_cfg;
typedef struct kiss_fftr_state* kiss_fftr_cfg;
/* SPA: Soundpipe Audio */
enum { SPA_READ, SPA_WRITE, SPA_NULL };
typedef struct {
char magic;
char nchan;
uint16_t sr;
uint32_t len;
} spa_header;
typedef struct {
spa_header header;
size_t offset;
int mode;
FILE *fp;
uint32_t pos;
} sp_audio;
#endif

48
plugins/supersaw/supersaw.c

@ -178,17 +178,15 @@ activate ( @@ -178,17 +178,15 @@ activate (
srand (time (NULL));
for (int i = 0; i < 128; i++)
{
MidiKey key = self->keys[i];
sp_create (&key.sp);
sp_blsaw_create (&key.blsaw);
sp_blsaw_init (key.sp, key.blsaw);
sp_adsr_create (&key.adsr);
sp_adsr_init (key.sp, key.adsr);
key.blsaw->freq = (float *) 400;
key.blsaw->amp = (float *) 1;
key.sp->len =
(long unsigned)
self->common.samplerate * 5;
MidiKey * key = &self->keys[i];
sp_create (&key->sp);
sp_blsaw_create (&key->blsaw);
sp_blsaw_init (key->sp, key->blsaw);
sp_adsr_create (&key->adsr);
sp_adsr_init (key->sp, key->adsr);
*key->blsaw->freq =
440.f * powf (2.f, ((float) i - 49.f) / 12.f);
*key->blsaw->amp = 0.3f;
}
}
@ -200,14 +198,18 @@ process ( @@ -200,14 +198,18 @@ process (
SuperSaw * self,
uint32_t * offset)
{
self->stereo_out_l[*offset] = 0.f;
self->stereo_out_r[*offset] = 0.f;
for (int i = 0; i < 128; i++)
{
MidiKey key = self->keys[i];
if (key.phase == PHASE_OFF)
MidiKey * key = &self->keys[i];
/*float val = 0.f;*/
#if 0
if (key->phase == PHASE_OFF)
continue;
float val = 0.f;
switch (key.phase)
switch (key->phase)
{
case PHASE_ATTACK:
case PHASE_DECAY:
@ -217,9 +219,19 @@ process ( @@ -217,9 +219,19 @@ process (
default:
break;
}
#endif
self->stereo_out_l[*offset] += val;
self->stereo_out_r[*offset] += val;
if (key->pressed)
{
key->sp->len = 4800 * 4;
sp_blsaw_compute (
key->sp, key->blsaw, NULL, &key->sp->out[0]);
key->offset =
(key->offset + 1) % (size_t) self->common.samplerate;
self->stereo_out_l[*offset] += key->sp->out[0];
self->stereo_out_r[*offset] += key->sp->out[0];
}
}
(*offset)++;
}
@ -247,10 +259,12 @@ run ( @@ -247,10 +259,12 @@ run (
case LV2_MIDI_MSG_NOTE_ON:
printf ("note on at %ld: %u (vel %u)\n",
ev->time.frames, msg[1], msg[2]);
self->keys[msg[1]].pressed = 1;
break;
case LV2_MIDI_MSG_NOTE_OFF:
printf ("note off at %ld: %u\n",
ev->time.frames, msg[1]);
self->keys[msg[1]].pressed = 0;
break;
default:
printf ("unknown MIDI message\n");

Loading…
Cancel
Save