Permalink
Browse files

add waveshaping and tweak roundoff

  • Loading branch information...
1 parent f0b121c commit ce0a29d18a7ded8deaa315d7ce1c889049413f51 alex committed Dec 28, 2012
Showing with 34 additions and 23 deletions.
  1. +24 −17 audio.c
  2. +6 −4 audio.h
  3. +4 −2 server.c
View
41 audio.c
@@ -52,10 +52,12 @@ int queue_size(t_sound *queue) {
void queue_add(t_sound **queue, t_sound *new) {
//printf("queuing %s @ %lld\n", new->samplename, new->start);
int s = queue_size(*queue);
+ if (s >= MAXSOUNDS) {
+ printf("hit max sounds (%d)\n", MAXSOUNDS);
+ }
int added = 0;
if (*queue == NULL) {
*queue = new;
- assert(s == (queue_size(*queue) - 1));
added++;
}
else {
@@ -76,9 +78,6 @@ void queue_add(t_sound **queue, t_sound *new) {
}
tmp->prev = new;
- if (s != (queue_size(*queue) - 1)) {
- assert(s == (queue_size(*queue) - 1));
- }
added++;
break;
}
@@ -88,23 +87,18 @@ void queue_add(t_sound **queue, t_sound *new) {
tmp->next = new;
new->prev = tmp;
added++;
- assert(s == (queue_size(*queue) - 1));
break;
}
++i;
tmp = tmp->next;
}
}
- if (s != (queue_size(*queue) - added)) {
- assert(s == (queue_size(*queue) - added));
- }
assert(added == 1);
}
void queue_remove(t_sound **queue, t_sound *old) {
- int s = queue_size(*queue);
if (old->prev == NULL) {
*queue = old->next;
if (*queue != NULL) {
@@ -118,7 +112,6 @@ void queue_remove(t_sound **queue, t_sound *old) {
old->next->prev = old->prev;
}
}
- assert(s == (queue_size(*queue) + 1));
free(old);
}
@@ -211,7 +204,7 @@ float effect_vcf(float in, t_sound *sound, int channel) {
return vcf->y4;
}
-extern int audio_play(double when, char *samplename, float offset, float start, float end, float speed, float pan, float velocity, int vowelnum, float cutoff, float resonance, float accellerate) {
+extern int audio_play(double when, char *samplename, float offset, float start, float end, float speed, float pan, float velocity, int vowelnum, float cutoff, float resonance, float accellerate, float shape) {
struct timeval tv;
#ifdef FEEDBACK
int is_loop = 0;
@@ -241,7 +234,7 @@ extern int audio_play(double when, char *samplename, float offset, float start,
#endif
new = (t_sound *) calloc(1, sizeof(t_sound));
- printf("samplename: %s when: %f\n", samplename, when - (float) tv.tv_sec);
+ //printf("samplename: %s when: %f\n", samplename, when);
strncpy(new->samplename, samplename, MAXPATHSIZE);
#ifdef FEEDBACK
@@ -278,11 +271,17 @@ extern int audio_play(double when, char *samplename, float offset, float start,
new->cutoff = cutoff;
new->resonance = resonance;
+
+ if (shape != 0) {
+ new->shape = 1;
+ new->shape_k = (2.0f * shape) / (1.0f - shape);
+ }
+
init_vcf(new);
new->accellerate = accellerate;
- printf("frames: %f\n", new->end);
+ //printf("frames: %f\n", new->end);
if (start > 0 && start <= 1) {
new->start = start * new->end;
}
@@ -407,16 +406,24 @@ void playback(float **buffers, int frame, jack_nframes_t frametime) {
}
if ((p->end - p->position) < ROUNDOFF) {
- // TODO what end < ROUNDOFF?)
+ // TODO what if end < ROUNDOFF?)
//printf("roundoff: %f\n", (p->end - pos) / (float) ROUNDOFF);
- roundoff = (p->end - pos) / (float) ROUNDOFF;
+ roundoff = (p->end - p->position) / (float) ROUNDOFF;
+ //printf("end roundoff: %f (%f)\n", roundoff, p->end - p->position);
}
else {
- if ((pos - p->start) < ROUNDOFF) {
- roundoff = (pos - p->start) / (float) ROUNDOFF;
+ if ((p->position - p->start) < ROUNDOFF) {
+ roundoff = (p->position - p->start) / (float) ROUNDOFF;
+ //printf("start roundoff: %f (%f / %d)\n", roundoff, p->position - p->start, ROUNDOFF);
}
}
+
+ if (p->shape) {
+ value = (1+p->shape_k)*value/(1+p->shape_k*fabs(value));
+ }
+
value *= roundoff;
+ value *= 0.5;
float c = (float) channel + p->pan;
float d = c - floor(c);
View
10 audio.h
@@ -4,8 +4,8 @@
#define MAXDELAYS 16
#define MAXDELAY 44100
-
-#define ROUNDOFF 8
+#define MAXSOUNDS 64
+#define ROUNDOFF 128
typedef struct {
float cutoff;
@@ -51,9 +51,11 @@ typedef struct t_node {
float cutoff;
float resonance;
t_vcf vcf[CHANNELS];
- float accellerate;
+ float accellerate;
+ int shape;
+ float shape_k;
} t_sound;
extern int audio_callback(int frames, float *input, float **outputs);
extern void audio_init(void);
-extern int audio_play(double when, char *samplename, float offset, float start, float end, float speed, float pan, float velocity, int vowelnum, float cutoff, float resonance, float accellerate);
+extern int audio_play(double when, char *samplename, float offset, float start, float end, float speed, float pan, float velocity, int vowelnum, float cutoff, float resonance, float accellerate, float shape);
View
@@ -59,6 +59,7 @@ int play_handler(const char *path, const char *types, lo_arg **argv,
float cutoff = argv[10]->f;
float resonance = argv[11]->f;
float accellerate = argv[12]->f;
+ float shape = argv[13]->f;
int vowelnum = -1;
@@ -82,7 +83,8 @@ int play_handler(const char *path, const char *types, lo_arg **argv,
vowelnum,
cutoff,
resonance,
- accellerate
+ accellerate,
+ shape
);
return 0;
}
@@ -94,7 +96,7 @@ extern int server_init(void) {
//lo_server_thread_add_method(st, NULL, NULL, generic_handler, NULL);
- lo_server_thread_add_method(st, "/play", "iisffffffsfff",
+ lo_server_thread_add_method(st, "/play", "iisffffffsffff",
play_handler,
NULL
);

0 comments on commit ce0a29d

Please sign in to comment.