/* first attempt at main program */ #include #include #include #include "Xgraphics.h" #include "/u1/metzler/sound/prog/AFsp-V2R2/include/libtsp.h" /*-----------------------------------------------------------------*/ /* declarations */ /*-----------------------------------------------------------------*/ /* GUI windows and worlds */ Window mainwindow, freqwindow, ampwindow,filtwindow; World mainworld; World fvalues, feg, avalues, aeg, ivalues, ieg; XEvent mainmenu; /* functions for envelopes etc. */ float env(float lvl0, float lvl1,float lvl2, float lvl3, float lvl4, float time1, float time2, float time3, float time4, float time); float lfo(int form, float offset,float pos,float amp, float freq, float time); /* subroutines for editing parameters */ void mainrenew(); void freqpage(); void frenew(char menu, float ftmpfloat); void freqwrite(); void amppage(); void arenew(char amenu, float atmpfloat); void awrite(); void filtpage(); void irenew(char menu, float tmpfloat); void iwrite(); void drawenv(World w, float lvl0, float lvl1, float lvl2, float lvl3, float lvl4, float tm1, float tm2, float tm3, float tm4); /* subroutines for calculating modified wave file */ void recalculate(); float timestretch(float time, float pos); float lint(float y[], float x); /* some flags */ int done = 0; int stop = 0; /* names for input and output files */ char infile[30]; /* = "in.wav"; */ char tempfile[30] = "tmp.wav"; char outfile[30]= "out.wav"; AFILE *inptr; AFILE *tmpptr; AFILE *outptr; /* counters for old and new sample */ long int channels; long int length1,length2; /* sample rate */ float samplerate; /* parameters */ float flvl0 = 0.5, flvl1=0.5,flvl2=0.5,flvl3=0.5,flvl4=0.5; float ftime1=0.25,ftime2=0.5,ftime3=0.75,ftime4=1.0; float flforate=0.5,flfooffset=0.2,flfoamp= 0.05; int flfoform= 2; float alvl0=0,alvl1=1.0, alvl2=0.8, alvl3=0.7,alvl4=0.0; float atime1=0.05,atime2=0.15,atime3=.75,atime4=1.0; float alforate= 0.5,alfooffset=0.2, alfoamp = 0.1; int alfoform=1; float ilvl0=0,ilvl1=1,ilvl2=0.8,ilvl3=0.7,ilvl4=0.0; float itime1=0.1, itime2=0.25, itime3=0.75, itime4=1.0; float resonance=0; /*-----------------------------------------------------------------*/ /* main menu */ /*-----------------------------------------------------------------*/ void main(int argc, char* argv[2]) { int j; InitX(); mainwindow = CreateWindow(500,400,"Main Menu"); freqwindow = CreateWindow(600, 530, "Frequency menu"); ampwindow = CreateWindow(600, 530, "Amplitude menu"); filtwindow = CreateWindow(600, 465, "Filter menu"); strcpy(infile, argv[1]); InitButtons(mainwindow, "b,load file, l,b,output file,o,b, recalculate,r,b,frequency page,f,b,amplitude page,a,b,filter page,i,b, exit,x",200); ShowWindow(mainwindow); while(done == 0) { if (GetEvent(&mainmenu,1)){ switch(mainmenu.type) { case KeyPress: switch(ExtractChar(mainmenu)){ case 'r': recalculate(); break; case 'f': freqpage(); break; case 'a': amppage(); break; case 'i': filtpage(); break; case 'x': done = 1; break; } /*switch*/ } /*switch */ } /*if*/ InitButtons(mainwindow, "b,load file, l,b,output file,o,b,recalculate,r ,b,frequency page,f,b,amplitude page,a,b,filter page,i,b,exit,x",200); } /*while*/ ExitX(); } /* end of main*/ /*----------------------------------------------------------------*/ /* mainwrite */ /*----------------------------------------------------------------*/ /* subroutines for calculating new wave file */ /*----------------------------------------------------------------*/ void recalculate() { float pos,time; int i,j,l,m; int nsamp; int blocksize; float x, xtemp[9]; int xnr, xcount=0; float y[2050], y2a[2050]; float sampbuff[4100]; float yout[8200]; float sampout[16400]; /*---- -----------*/ inptr= AFopenRead(infile, &length1, &channels, &samplerate, NULL); tmpptr = AFopenWrite(tempfile, 261, channels, samplerate, NULL); for(i = 0; 2048*channels*i2048) { return (2048-x)*y[2047]+ (x-2047)*y[2048];} else {return (xround+1.0-x)*y[xint] + (x - xround)*y[xint+1];} } /*---------------------------------------------------------------*/ /* subroutines for editing frequency parameters */ /*---------------------------------------------------------------*/ /* getting parameters for frequency page */ void freqpage() { World envelope; XEvent freqevent; int leave = 0; int temp = 1; float tempfloat=0; char fmenu; feg = CreateWorld(freqwindow, 5, 5, 350, 350, 0, 1,1 , 0, 0, 0); drawenv(feg,flvl0,flvl1, flvl2,flvl3, flvl4, ftime1,ftime2, ftime3, ftime4); fvalues = CreateWorld(freqwindow, 365, 0, 65, 420, 0,0,1,12,0, 0); freqwrite(); InitButtons(freqwindow, "b, Level 1,a,b,Level 2,b,b,Level 3,c,b,Level 4,d,b,Time 1,e,b,Time 2,f,b,Time 3,g,b,Time 4,h,b, Lfo Form,i,b, Lfo Rate,j,b, Lfo Offset,k,b, Lfo Amplitude,l,b,Decrease(-),-,b, Increase(+),+,b,exit,x", 150); ShowWindow(freqwindow); ClearArea(freqwindow,0,0, 355,355); while(leave == 0) { if (GetEvent(&mainmenu,1)){ switch(mainmenu.type) { case KeyPress: switch(ExtractChar(mainmenu)){ case 'a': fmenu = 'a'; tempfloat = flvl1;break; case 'b': fmenu = 'b';tempfloat = flvl2;break; case 'c': fmenu = 'c';tempfloat = flvl3;break; case 'd': fmenu = 'd';tempfloat = flvl4;break; case 'e': fmenu = 'e';tempfloat = ftime1;break; case 'f': fmenu = 'f';tempfloat = ftime2;break; case 'g': fmenu = 'g';tempfloat = ftime3;break; case 'h': fmenu = 'h';tempfloat = ftime4;break; case 'i': flfoform = flfoform + 1; if (flfoform == 5) flfoform = 1; freqwrite(); break; case 'j': fmenu = 'j'; tempfloat = flforate;break; case 'k': fmenu = 'k'; tempfloat = flfooffset; break; case 'l': fmenu = 'l'; tempfloat = flfoamp;break; case '-' : tempfloat = tempfloat -0.01; if(tempfloat<0.0) tempfloat = 0.0; frenew(fmenu, tempfloat); break; case '+': tempfloat = tempfloat + 0.01; if(tempfloat>1.0) tempfloat = 1.0; frenew(fmenu, tempfloat); /* assign tempfloat to corresponding parameter */ break; case 'x': leave =1; HideWindow(freqwindow); break; }; /*switch */ }/*switch*/ }/*if*/ }/*while */ } /*-------------------------------------------------------------------*/ /* frenew updates values of parameters, has them printed */ /* and new envelope drawn */ void frenew(char menu, float tmpfloat) { switch(menu){ case 'a': flvl1 = tmpfloat;break; case 'b': flvl2 = tmpfloat;break; case 'c': flvl3 = tmpfloat;break; case 'd': flvl4 = tmpfloat;break; case 'e': ftime1 = tmpfloat; if (ftime1> ftime2) ftime1= ftime2; break; case 'f': ftime2 = tmpfloat; if(ftime2ftime3) ftime2=ftime3; break; case 'g': ftime3 = tmpfloat; if(ftime3ftime4) ftime3=ftime4; break; case 'h': ftime4 = tmpfloat; if(ftime41.0) tempfloat = 1.0; arenew(amenu, tempfloat); /* assign tempfloat to corresponding parameter */ break; case 'x': leave =1; HideWindow(ampwindow); break; }; /*switch */ }/*switch*/ }/*if*/ }/*while */ } /*-------------------------------------------------------------------*/ /* arenew updates values of parameters, has them printed */ /* and new envelope drawn */ void arenew(char menu, float tmpfloat) { switch(menu){ case 'a': alvl1 = tmpfloat;break; case 'b': alvl2 = tmpfloat;break; case 'c': alvl3 = tmpfloat;break; case 'd': alvl4 = tmpfloat;break; case 'e': atime1 = tmpfloat; if (atime1>atime2) atime1= atime2; break; case 'f': atime2 = tmpfloat; if(atime2atime3) atime2=atime3; break; case 'g': atime3 = tmpfloat; if(atime3atime4) atime3=atime4; break; case 'h': atime4 = tmpfloat; if(atime41.0) tempfloat = 1.0; irenew(imenu, tempfloat); /* assign tempfloat to corresponding parameter */ break; case 'x': leave =1; HideWindow(filtwindow); break; }; /*switch */ }/*switch*/ }/*if*/ }/*while */ } /*-------------------------------------------------------------------*/ /* irenew updates values of parameters, has them printed */ /* and new envelope drawn */ void irenew(char menu, float tmpfloat) { switch(menu){ case 'a': ilvl1 = tmpfloat;break; case 'b': ilvl2 = tmpfloat;break; case 'c': ilvl3 = tmpfloat;break; case 'd': ilvl4 = tmpfloat;break; case 'e': itime1 = tmpfloat; if (itime1>itime2) itime1= itime2; break; case 'f': itime2 = tmpfloat; if(itime2itime3) itime2=itime3; break; case 'g': itime3 = tmpfloat; if(itime3itime4) itime3=itime4; break; case 'h': itime4 = tmpfloat; if(itime4