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

« back to all changes in this revision

Viewing changes to Opcodes/sndloop.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:
652
652
}
653
653
 
654
654
 
655
 
 
 
655
/*
656
656
static int flooper3_init(CSOUND *csound, flooper3 *p)
657
657
{
658
658
    int len,i,p2s,lomod;
659
 
    p->sfunc = csound->FTnp2Find(csound, p->ifn);  /* function table */
 
659
    p->sfunc = csound->FTnp2Find(csound, p->ifn);
660
660
    if (UNLIKELY(p->sfunc==NULL)) {
661
661
      return csound->InitError(csound,Str("function table not found\n"));
662
662
    }
703
703
    int *firsttime = &p->firsttime, elen, init = p->init;
704
704
    uint32 tndx0, tndx1;
705
705
 
706
 
    /* loop parameters & check */
 
706
 
707
707
    if (pitch < FL(0.0)) pitch = FL(0.0);
708
708
    if (*firsttime) {
709
709
      int loopsize;
832
832
      }
833
833
      else if (mode == 2){
834
834
        out[i] = 0;
835
 
        /* this is the forward reader */
 
835
 
836
836
        tndx0 = ndx[0]>>lobits;
837
837
        frac0 = (ndx[0] & lomask)*lodiv;
838
838
        if (init && tndx0 < loop_start + crossfade) {
870
870
          count  += ei;
871
871
        }
872
872
 
873
 
        /* this is the backward reader */
 
873
 
874
874
        tndx1 = ndx[1]>>lobits;
875
875
        frac1 = (ndx[1] & lomask)*lodiv;
876
876
        if (tndx1 > loop_end - crossfade) {
923
923
    p->init = init;
924
924
    return OK;
925
925
}
926
 
 
 
926
*/
927
927
 
928
928
static int pvsarp_init(CSOUND *csound, pvsarp *p)
929
929
{
996
996
                                   "or amp-freq.\n"));
997
997
    }
998
998
   if (p->ceps.auxp == NULL ||
999
 
      p->ceps.size < sizeof(MYFLT) * (N+2)) 
 
999
      p->ceps.size < sizeof(MYFLT) * (N+2))
1000
1000
    csound->AuxAlloc(csound, sizeof(MYFLT) * (N + 2), &p->ceps);
1001
 
  memset(p->ceps.auxp, 0, sizeof(MYFLT)*(N+2));
1002
 
  if (p->fenv.auxp == NULL ||
1003
 
      p->fenv.size < sizeof(MYFLT) * (N+2)) 
1004
 
    csound->AuxAlloc(csound, sizeof(MYFLT) * (N + 2), &p->fenv);
1005
 
  if (p->fexc.auxp == NULL ||
1006
 
      p->fexc.size < sizeof(MYFLT) * (N+2)) 
1007
 
    csound->AuxAlloc(csound, sizeof(MYFLT) * (N + 2), &p->fexc);
 
1001
   else
 
1002
     memset(p->ceps.auxp, 0, sizeof(MYFLT)*(N+2));
 
1003
   if (p->fenv.auxp == NULL ||
 
1004
       p->fenv.size < sizeof(MYFLT) * (N+2))
 
1005
     csound->AuxAlloc(csound, sizeof(MYFLT) * (N + 2), &p->fenv);
 
1006
   if (p->fexc.auxp == NULL ||
 
1007
       p->fexc.size < sizeof(MYFLT) * (N+2))
 
1008
     csound->AuxAlloc(csound, sizeof(MYFLT) * (N + 2), &p->fexc);
1008
1009
 
1009
 
    return OK;
 
1010
   return OK;
1010
1011
}
1011
1012
 
1012
1013
static int pvsvoc_process(CSOUND *csound, pvsvoc *p)
1021
1022
    int coefs = (int) *(p->kcoefs), j;
1022
1023
    MYFLT   *fenv = (MYFLT *) p->fenv.auxp;
1023
1024
    MYFLT   *ceps = (MYFLT *) p->ceps.auxp;
1024
 
    float sr = csound->esr;
1025
1025
    float maxe=0.f, maxa=0.f;
1026
 
   
 
1026
 
1027
1027
    if (UNLIKELY(fout==NULL)) goto err1;
1028
1028
 
1029
1029
    if (p->lastframe < p->fin->framecount) {
1030
 
      for(j=0; j < 2; j++) {    
1031
 
        MYFLT a;
1032
 
        maxe = 0.f;
 
1030
      for(j=0; j < 2; j++) {
 
1031
        MYFLT a;
 
1032
        maxe = 0.f;
1033
1033
        maxa = 0.f;
1034
1034
      for(i=0; i < N; i+=2) {
1035
1035
        a  = (j ? fin[i] : (fexc[i] = ffr[i]));
1036
1036
        maxa = maxa < a ? a : maxa;
1037
 
        if (a <= 0) a = 1e-20;
 
1037
        if (a <= 0) a = 1e-20;
1038
1038
        fenv[i/2] = log(a);
1039
1039
      }
1040
1040
      if (coefs < 1) coefs = 80;
1041
 
        for(i=0; i < N; i+=2){
1042
 
          ceps[i] = fenv[i/2];
 
1041
        for(i=0; i < N; i+=2){
 
1042
          ceps[i] = fenv[i/2];
1043
1043
          ceps[i+1] = 0.0;
1044
 
        } 
1045
 
        csound->InverseComplexFFT(csound, ceps, N/2);
1046
 
        for(i=coefs; i < N-coefs; i++) ceps[i] = 0.0;   
 
1044
        }
 
1045
        csound->InverseComplexFFT(csound, ceps, N/2);
 
1046
        for(i=coefs; i < N-coefs; i++) ceps[i] = 0.0;
1047
1047
        csound->ComplexFFT(csound, ceps, N/2);
1048
 
        for(i=0; i < N; i+=2) {    
1049
 
          fenv[i/2] = exp(ceps[i]);
1050
 
           maxe = maxe < fenv[i/2] ? fenv[i/2] : maxe;
1051
 
        }      
1052
 
        if (maxe)
1053
 
        for(i=0; i<N; i+=2){
1054
 
          if (j) fenv[i/2] *= maxa/maxe;   
1055
 
          if (fenv[i/2] && !j) {
 
1048
        for(i=0; i < N; i+=2) {
 
1049
          fenv[i/2] = exp(ceps[i]);
 
1050
           maxe = maxe < fenv[i/2] ? fenv[i/2] : maxe;
 
1051
        }
 
1052
        if (maxe)
 
1053
        for(i=0; i<N; i+=2){
 
1054
          if (j) fenv[i/2] *= maxa/maxe;
 
1055
          if (fenv[i/2] && !j) {
1056
1056
             fenv[i/2] /= maxe;
1057
 
             fexc[i] /= fenv[i/2];
1058
 
          }        
1059
 
          }        
 
1057
             fexc[i] /= fenv[i/2];
 
1058
          }
 
1059
          }
1060
1060
      }
1061
 
     
 
1061
 
1062
1062
      kdepth = kdepth >= 0 ? (kdepth <= 1 ? kdepth : FL(1.0)): FL(0.0);
1063
1063
      for(i=0;i < N+2;i+=2) {
1064
1064
        fout[i] = fenv[i/2]*(fexc[i]*kdepth + fin[i]*(FL(1.0)-kdepth))*gain;
1066
1066
      }
1067
1067
      p->fout->framecount = p->lastframe = p->fin->framecount;
1068
1068
    }
1069
 
    
 
1069
 
1070
1070
    return OK;
1071
1071
 err1:
1072
1072
    return csound->PerfError(csound,Str("pvsvoc: not initialised\n"));
1126
1126
static OENTRY localops[] = {
1127
1127
  {"sndloop", sizeof(sndloop), 5,
1128
1128
   "ak", "akkii", (SUBR)sndloop_init, NULL, (SUBR)sndloop_process},
1129
 
  {"flooper", sizeof(flooper), 5,
 
1129
  {"flooper", sizeof(flooper), TR|5,
1130
1130
   "a", "kkiiii", (SUBR)flooper_init, NULL, (SUBR)flooper_process},
1131
1131
  {"pvsarp", sizeof(pvsarp), 3,
1132
1132
   "f", "fkkk", (SUBR)pvsarp_init, (SUBR)pvsarp_process},
1133
1133
  {"pvsvoc", sizeof(pvsvoc), 3,
1134
1134
   "f", "ffkkO", (SUBR)pvsvoc_init, (SUBR)pvsvoc_process},
1135
 
  {"flooper2", sizeof(flooper2), 5,
 
1135
  {"flooper2", sizeof(flooper2), TR|5,
1136
1136
   "a", "kkkkkiooooO", (SUBR)flooper2_init, NULL, (SUBR)flooper2_process},
1137
 
 {"flooper3", sizeof(flooper3), 5,
1138
 
  "a", "kkkkkioooo", (SUBR)flooper3_init, NULL, (SUBR)flooper3_process},
 
1137
  /* {"flooper3", sizeof(flooper3), TR|5,
 
1138
     "a", "kkkkkioooo", (SUBR)flooper3_init, NULL, (SUBR)flooper3_process},*/
1139
1139
 {"pvsmorph", sizeof(pvsvoc), 3,
1140
1140
   "f", "ffkk", (SUBR)pvsmorph_init, (SUBR)pvsmorph_process}
1141
1141
};
1145
1145
  return csound->AppendOpcodes(csound, &(localops[0]),
1146
1146
                               (int) (sizeof(localops) / sizeof(OENTRY)));
1147
1147
}
1148