History

make sure talkbox order does not exceed ORD_MAX

Matthew Wang committed 6 years ago

Commit a3ef3e01 parent 1c558171 file · +31 −24Browse files

Unified · Split

leaf/Src/leaf-effects.c+31−24
@@ -89,14 +89,18 @@ void tTalkbox_update(tTalkbox* const voc) ///update internal parameters... · 88 unmodified lines
89 LEAF* leaf = v->mempool->leaf;89 LEAF* leaf = v->mempool->leaf;
90 90
91 float fs = leaf->sampleRate;91 float fs = leaf->sampleRate;
92 if(fs < 8000.0f) fs = 8000.0f;92// if(fs < 8000.0f) fs = 8000.0f;
93 if(fs > 96000.0f) fs = 96000.0f;93// if(fs > 96000.0f) fs = 96000.0f;
94 94
95 int32_t n = (int32_t)(0.01633f * fs); //this sets the window time to 16ms if the buffer is large enough. Buffer needs to be at least 784 samples at 4800095 int32_t n = (int32_t)(0.01633f * fs); //this sets the window time to 16ms if the buffer is large enough. Buffer needs to be at least 784 samples at 48000
96 if(n > v->bufsize) n = v->bufsize;96 if(n > v->bufsize) n = v->bufsize;
97 97
98 //O = (VstInt32)(0.0005f * fs);98 //O = (VstInt32)(0.0005f * fs);
99 v->O = (int32_t)((0.0001f + 0.0004f * v->param[3]) * fs);99 v->O = (int32_t)((0.0001f + 0.0004f * v->param[3]) * fs);
100 if (v->O >= ORD_MAX)
101 {
102 v->O = ORD_MAX-1;
103 }
100 104
101 if(n != v->N) //recalc hanning window105 if(n != v->N) //recalc hanning window
102 {106 {
@@ -261,7 +265,6 @@ void tTalkbox_lpc(float *buf, float *car, double* dl, double* Rt, int32_t n, int · 158 unmodified lines
261 float z[ORD_MAX], r[ORD_MAX], x;265 float z[ORD_MAX], r[ORD_MAX], x;
262 int32_t i, j, nn=n;266 int32_t i, j, nn=n;
263 267
264
265 if (warpOn == 0)268 if (warpOn == 0)
266 {269 {
267 for(j=0; j<=o; j++, nn--) //buf[] is already emphasized and windowed270 for(j=0; j<=o; j++, nn--) //buf[] is already emphasized and windowed
@@ -286,11 +289,11 @@ void tTalkbox_lpc(float *buf, float *car, double* dl, double* Rt, int32_t n, int · 18 unmodified lines
286 {289 {
287 if(r[0] < min)290 if(r[0] < min)
288 {291 {
289// for(i=0; i<n; i++)292 for(i=0; i<n; i++)
290// {293 {
291 buf[0] = 0.0f;294 buf[i] = 0.0f;
292 return;295 }
293// }296 return;
294 }297 }
295 298
296 tTalkbox_lpcDurbin(r, o, k, G); //calc reflection coeffs299 tTalkbox_lpcDurbin(r, o, k, G); //calc reflection coeffs
@@ -418,14 +421,18 @@ void tTalkboxFloat_update(tTalkboxFloat* const voc) ///update internal parameter · 121 unmodified lines
418 LEAF* leaf = v->mempool->leaf;421 LEAF* leaf = v->mempool->leaf;
419 422
420 float fs = leaf->sampleRate;423 float fs = leaf->sampleRate;
421 if(fs < 8000.0f) fs = 8000.0f;424// if(fs < 8000.0f) fs = 8000.0f;
422 if(fs > 96000.0f) fs = 96000.0f;425// if(fs > 96000.0f) fs = 96000.0f;
423 426
424 int32_t n = (int32_t)(0.01633f * fs); //this sets the window time to 16ms if the buffer is large enough. Buffer needs to be at least 784 samples at 48000427 int32_t n = (int32_t)(0.01633f * fs); //this sets the window time to 16ms if the buffer is large enough. Buffer needs to be at least 784 samples at 48000
425 if(n > v->bufsize) n = v->bufsize;428 if(n > v->bufsize) n = v->bufsize;
426 429
427 //O = (VstInt32)(0.0005f * fs);430 //O = (VstInt32)(0.0005f * fs);
428 v->O = (int32_t)((0.0001f + 0.0004f * v->param[3]) * fs);431 v->O = (int32_t)((0.0001f + 0.0004f * v->param[3]) * fs);
432 if (v->O >= ORD_MAX)
433 {
434 v->O = ORD_MAX-1;
435 }
429 436
430 if(n != v->N) //recalc hanning window437 if(n != v->N) //recalc hanning window
431 {438 {
@@ -589,20 +596,20 @@ float tTalkboxFloat_tick(tTalkboxFloat* const voc, float synth, float voice) · 157 unmodified lines
589void tTalkboxFloat_lpc(float *buf, float *car, float* dl, float* Rt, int32_t n, int32_t o, float warp, int warpOn, float *k, int freeze, float *G)596void tTalkboxFloat_lpc(float *buf, float *car, float* dl, float* Rt, int32_t n, int32_t o, float warp, int warpOn, float *k, int freeze, float *G)
590{597{
591 float z[ORD_MAX], r[ORD_MAX], x;598 float z[ORD_MAX], r[ORD_MAX], x;
592 int32_t i, j, nn=n;599
593
594
595 if (warpOn == 0)600 if (warpOn == 0)
596 {601 {
597 for(j=0; j<=o; j++, nn--) //buf[] is already emphasized and windowed602 int nn = n;
603 for(int j = 0; j <= o; j++, nn--) //buf[] is already emphasized and windowed
598 {604 {
599 z[j] = r[j] = 0.0f;605 z[j] = r[j] = 0.0f;
600 for(i=0; i<nn; i++) r[j] += buf[i] * buf[i+j]; //autocorrelation606 for(int i = 0; i < nn; i++) r[j] += buf[i] * buf[i+j]; //autocorrelation
601 }607 }
602 }608 }
603 else609 else
604 {610 {
605 for(j=0; j<=o; j++, nn--) //buf[] is already emphasized and windowed611 int nn = n;
612 for(int j = 0; j <= o; j++, nn--) //buf[] is already emphasized and windowed
606 {613 {
607 z[j] = r[j] = 0.0f;614 z[j] = r[j] = 0.0f;
608 }615 }
@@ -616,26 +623,26 @@ void tTalkboxFloat_lpc(float *buf, float *car, float* dl, float* Rt, int32_t n, · 7 unmodified lines
616 {623 {
617 if(r[0] < min)624 if(r[0] < min)
618 {625 {
619// for(i=0; i<n; i++)626 for(int i = 0; i < n; i++)
620// {627 {
621 buf[0] = 0.0f;628 buf[i] = 0.0f;
622 return;629 }
623// }630 return;
624 }631 }
625 632
626 tTalkbox_lpcDurbin(r, o, k, G); //calc reflection coeffs633 tTalkbox_lpcDurbin(r, o, k, G); //calc reflection coeffs
627 634
628 //this is for stability to keep reflection coefficients inside the unit circle635 //this is for stability to keep reflection coefficients inside the unit circle
629 //but in Harma's papers I've seen 0.998. just needs to be less than 1 it seems but maybe some wiggle room to avoid instability from floating point precision -JS636 //but in Harma's papers I've seen 0.998. just needs to be less than 1 it seems but maybe some wiggle room to avoid instability from floating point precision -JS
630 for(i=0; i<=o; i++)637 for(int i = 0; i <= o; i++)
631 {638 {
632 if(k[i] > 0.998f) k[i] = 0.998f; else if(k[i] < -0.998f) k[i] = -.998f;639 if(k[i] > 0.998f) k[i] = 0.998f; else if(k[i] < -0.998f) k[i] = -.998f;
633 }640 }
634 }641 }
635 for(i=0; i<n; i++)642 for(int i = 0; i < n; i++)
636 {643 {
637 x = G[0] * car[i];644 x = G[0] * car[i];
638 for(j=o; j>0; j--) //lattice filter645 for(int j = o; j > 0; j--) //lattice filter
639 {646 {
640 x -= k[j] * z[j-1];647 x -= k[j] * z[j-1];
641 z[j] = z[j-1] + k[j] * x;648 z[j] = z[j-1] + k[j] * x;

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t