~ubuntu-branches/ubuntu/precise/csound/precise

« back to all changes in this revision

Viewing changes to Opcodes/pvlock.c

  • Committer: Package Import Robot
  • Author(s): Felipe Sateler
  • Date: 2012-04-19 09:26:46 UTC
  • mfrom: (3.2.19 sid)
  • Revision ID: package-import@ubuntu.com-20120419092646-96xbj1n6atuqosk2
Tags: 1:5.17.6~dfsg-1
* New upstream release
 - Do not build the wiimote opcodes (we need wiiuse).
* Add new API function to symbols file
* Disable lua opcodes, they were broken. Requires OpenMP to be enabled.
* Backport fixes from upstream:
  - Link dssi4cs with dl. Backport
  - Fix building of CsoundAC

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
#include "csdl.h"
 
1
/*
 
2
    crossfm.c:
 
3
 
 
4
    Copyright (C) 2009 V Lazzarini
 
5
 
 
6
    This file is part of Csound.
 
7
 
 
8
    The Csound Library is free software; you can redistribute it
 
9
    and/or modify it under the terms of the GNU Lesser General Public
 
10
    License as published by the Free Software Foundation; either
 
11
    version 2.1 of the License, or (at your option) any later version.
 
12
 
 
13
    Csound is distributed in the hope that it will be useful,
 
14
    but WITHOUT ANY WARRANTY; without even the implied warranty of
 
15
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
16
    GNU Lesser General Public License for more details.
 
17
 
 
18
    You should have received a copy of the GNU Lesser General Public
 
19
    License along with Csound; if not, write to the Free Software
 
20
    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
 
21
    02111-1307 USA
 
22
*/
 
23
 
 
24
#include "csoundCore.h"
 
25
#include "interlocks.h"
2
26
#include "pstream.h"
3
27
#define MAXOUTS 2
4
28
 
46
70
    size = decim*sizeof(int);
47
71
    if (p->framecount[i].auxp == NULL || p->framecount[i].size < size)
48
72
      csound->AuxAlloc(csound, size, &p->framecount[i]);
49
 
    memset(p->framecount[i].auxp,0,size);
 
73
    else
 
74
      memset(p->framecount[i].auxp,0,size);
50
75
    size = decim*sizeof(MYFLT)*N;
51
76
    if (p->outframe[i].auxp == NULL || p->outframe[i].size < size)
52
77
      csound->AuxAlloc(csound, size, &p->outframe[i]);
53
 
    memset(p->outframe[i].auxp,0,size);
 
78
    else
 
79
      memset(p->outframe[i].auxp,0,size);
54
80
    }
55
 
   size = N*sizeof(MYFLT);
 
81
    size = N*sizeof(MYFLT);
56
82
    if (p->win.auxp == NULL || p->win.size < size)
57
83
      csound->AuxAlloc(csound, size, &p->win);
58
84
 
69
95
{
70
96
    MYFLT pitch = *p->kpitch, *time = p->time, lock = *p->klock,
71
97
      *out, amp =*p->kamp;
72
 
    MYFLT *tab, frac,scale;
 
98
    MYFLT *tab, frac;
73
99
    FUNC *ft;
74
100
    int N = p->N, hsize = p->hsize, cnt = p->cnt, nchans = p->nchans;
75
101
    int ksmps = csound->GetKsmps(csound), n;
89
115
        ft = csound->FTnp2Find(csound,p->knum);
90
116
        tab = ft->ftable;
91
117
        size = ft->flen;
92
 
       
 
118
 
93
119
        if (UNLIKELY((int) ft->nchanls != nchans))
94
120
          return csound->PerfError(csound, Str("number of output arguments "
95
121
                                               "inconsistent with number of "
96
122
                                               "sound file channels"));
97
123
 
98
 
       
 
124
 
99
125
 
100
126
        /* spos is the reading position in samples, hsize is hopsize,
101
127
           time[n] is current read position in secs
102
128
           esr is sampling rate
103
129
        */
104
130
        spos  = hsize*(int)((time[n])*csound->esr/hsize);
105
 
        sizefrs = size/nchans;
106
 
        while(spos > sizefrs - N) spos -= sizefrs;
107
 
        while(spos <= hsize)  spos += sizefrs;
 
131
        sizefrs = size/nchans;
 
132
        while(spos > sizefrs - N) spos -= sizefrs;
 
133
        while(spos <= hsize)  spos += sizefrs;
108
134
        pos = spos;
109
135
 
110
 
        for (j = 0; j < nchans; j++) {
 
136
        for (j = 0; j < nchans; j++) {
111
137
 
112
138
          bwin = (MYFLT *) p->bwin[j].auxp;
113
139
          fwin = (MYFLT *) p->fwin[j].auxp;
211
237
          framecnt[curframe] = curframe*N;
212
238
          /* write to overlapped output frames */
213
239
          for (i=0;i<N;i++) outframe[framecnt[curframe]+i] = win[i]*fwin[i];
214
 
        
215
 
        }
 
240
 
 
241
        }
216
242
 
217
243
        cnt=0;
218
244
        curframe++;
219
245
        if (curframe == decim) curframe = 0;
220
246
      }
221
 
      
 
247
 
222
248
      for (j=0; j < nchans; j++) {
223
249
        framecnt  = (int *) p->framecount[j].auxp;
224
250
        outframe  = (MYFLT *) p->outframe[j].auxp;
234
260
      }
235
261
      cnt++;
236
262
    }
237
 
 
 
263
 
238
264
    p->cnt = cnt;
239
265
    p->curframe = curframe;
240
266
    return OK;
259
285
{
260
286
    MYFLT pitch = *p->kpitch, time = *p->time, lock = *p->klock;
261
287
    MYFLT *out, amp =*p->kamp;
262
 
    MYFLT *tab,frac,scale,  dbtresh = *p->dbthresh;
 
288
    MYFLT *tab,frac,  dbtresh = *p->dbthresh;
263
289
    FUNC *ft;
264
290
    int N = p->N, hsize = p->hsize, cnt = p->cnt, sizefrs, nchans = p->nchans;
265
291
    int  ksmps = csound->GetKsmps(csound), n;
274
300
    int decim = p->decim;
275
301
 
276
302
    for (n=0; n < ksmps; n++) {
277
 
      
 
303
 
278
304
      if (cnt == hsize){
279
305
        ft = csound->FTnp2Find(csound,p->knum);
280
306
        tab = ft->ftable;
310
336
          prev = (MYFLT *)p->prev[j].auxp;
311
337
          framecnt  = (int *)p->framecount[j].auxp;
312
338
          outframe= (MYFLT *) p->outframe[j].auxp;
313
 
        
 
339
 
314
340
          for (i=0; i < N; i++) {
315
341
            post = (int) pos;
316
342
            frac = pos  - post;
319
345
            if (post >= 0 && post < size)
320
346
              in = tab[post] + frac*(tab[post+nchans] - tab[post]);
321
347
            else in =  (MYFLT) 0;
322
 
            fwin[i] = in * win[i]; 
323
 
         
 
348
            fwin[i] = in * win[i];
 
349
 
324
350
            post = (int) (pos - hsize*pitch);
325
351
            post *= nchans;
326
352
            post += j;
327
353
            if (post >= 0 && post < size)
328
354
              in =  tab[post] + frac*(tab[post+nchans] - tab[post]);
329
355
            else in =  (MYFLT) 0;
330
 
            bwin[i] = in * win[i];  
 
356
            bwin[i] = in * win[i];
331
357
            post = (int) pos + hsize;
332
358
            post *= nchans;
333
359
            post += j;
336
362
            nwin[i] = in * win[i];
337
363
            pos += pitch;
338
364
          }
339
 
         
 
365
 
340
366
          csound->RealFFT(csound, bwin, N);
341
367
          bwin[N] = bwin[1];
342
368
          bwin[N+1] = FL(0.0);
397
423
 
398
424
            tmp_real =   fwin[i] * ph_real - fwin[i+1] * ph_im;
399
425
            tmp_im =   fwin[i] * ph_im + fwin[i+1] * ph_real;
400
 
          
 
426
 
401
427
            prev[i] = fwin[i] = tmp_real;
402
428
            prev[i+1] = fwin[i+1] = tmp_im;
403
429
          }
408
434
          framecnt[curframe] = curframe*N;
409
435
 
410
436
          for (i=0;i<N;i++) outframe[framecnt[curframe]+i] = win[i]*fwin[i];
411
 
        
 
437
 
412
438
        }
413
439
        cnt=0;
414
440
        curframe++;
415
441
        if (curframe == decim) curframe = 0;
416
442
      }
417
 
           
 
443
 
418
444
      for (j=0; j < nchans; j++) {
419
445
        out = p->out[j];
420
 
        framecnt  = (int *) p->framecount[j].auxp;
421
 
        outframe  = (MYFLT *) p->outframe[j].auxp;
422
 
 
 
446
        framecnt  = (int *) p->framecount[j].auxp;
 
447
        outframe  = (MYFLT *) p->outframe[j].auxp;
 
448
 
423
449
        out[n] = (MYFLT) 0;
424
 
     
 
450
 
425
451
        for (i = 0; i < decim; i++) {
426
452
          out[n] += outframe[framecnt[i]];
427
 
          framecnt[i]++;        
 
453
          framecnt[i]++;
428
454
        }
429
455
        out[n] *= amp*(2./3.);
430
456
      }
431
 
      cnt++;  
 
457
      cnt++;
432
458
    }
433
459
    p->cnt = cnt;
434
460
    p->curframe = curframe;
472
498
 
473
499
static int pvslockproc(CSOUND *csound, PVSLOCK *p)
474
500
{
475
 
    int i,n,k,j, maxmagi;
476
 
    float mag,  maxmag, *fout = (float *) p->fout->frame.auxp, 
 
501
    int i;
 
502
    float *fout = (float *) p->fout->frame.auxp,
477
503
      *fin = (float *) p->fin->frame.auxp;
478
504
    int N = p->fin->N;
479
 
  
 
505
 
480
506
    if (p->lastframe < p->fin->framecount) {
481
507
      memcpy(fout,fin, sizeof(float)*(N+2));
482
 
  
 
508
 
483
509
      if (*p->klock) {
484
 
        for (i=2, n = 0; i < N-4; i+=2){
 
510
        for (i=2; i < N-4; i+=2){
485
511
          float p2 = fin[i];
486
512
          float p3 = fin[i+2];
487
513
          float p1 = fin[i-2];
488
514
          float p4 = fin[i+4];
489
515
          float p5 = fin[i+6];
490
 
          if (p3 > p1 && p3 > p2 && p3 > p4 && p3 > p5) {       
 
516
          if (p3 > p1 && p3 > p2 && p3 > p4 && p3 > p5) {
491
517
            float freq = fin[i+3], d;
492
518
            d = 0.01*freq;
493
519
            if (FABS(fout[i-1] - freq) < d)fout[i-1]  = freq;
503
529
    return OK;
504
530
}
505
531
 
506
 
static OENTRY localops[] = {
 
532
static OENTRY pvlock_localops[] = {
507
533
  {"mincer", sizeof(DATASPACE), 5, "mm", "akkkkoo",
508
534
                                               (SUBR)sinit, NULL,(SUBR)sprocess },
509
535
  {"temposcal", sizeof(DATASPACE), 5, "mm", "kkkkkooPOP",
512
538
         (SUBR) pvslockproc},
513
539
};
514
540
 
515
 
LINKAGE
 
541
LINKAGE1(pvlock_localops)