changeset 11:977f541d6683

GPL and cosmetic changes
author Wen X <xue.wen@elec.qmul.ac.uk>
date Wed, 10 Aug 2011 12:33:35 +0100
parents c6528c38b23c
children 4b35f8ac5113
files align8.cpp align8.h arrayalloc.h fft.cpp fft.h hs.cpp hs.h hsedit.cpp hsedit.h hssf.cpp hssf.h main.cpp matrix.cpp matrix.h multires.cpp multires.h opt.cpp opt.h procedures.cpp procedures.h quickspec.cpp quickspec.h sinest.cpp sinest.h sinsyn.cpp sinsyn.h splines.cpp splines.h tstream.h vibrato.cpp vibrato.h wavelet.cpp wavelet.h windowfunctions.cpp windowfunctions.h xcomplex.h
diffstat 36 files changed, 494 insertions(+), 42 deletions(-) [+]
line wrap: on
line diff
--- a/align8.cpp	Thu Jul 28 10:36:57 2011 +0100
+++ b/align8.cpp	Wed Aug 10 12:33:35 2011 +0100
@@ -1,3 +1,15 @@
+/*
+    Harmonic sinusoidal modelling and tools
+
+    C++ code package for harmonic sinusoidal modelling and relevant signal processing.
+    Centre for Digital Music, Queen Mary, University of London.
+    This file copyright 2011 Wen Xue.
+
+    This program is free software; you can redistribute it and/or
+    modify it under the terms of the GNU General Public License as
+    published by the Free Software Foundation; either version 2 of the
+    License, or (at your option) any later version.
+*/
 //---------------------------------------------------------------------------
 
 
--- a/align8.h	Thu Jul 28 10:36:57 2011 +0100
+++ b/align8.h	Wed Aug 10 12:33:35 2011 +0100
@@ -1,3 +1,15 @@
+/*
+    Harmonic sinusoidal modelling and tools
+
+    C++ code package for harmonic sinusoidal modelling and relevant signal processing.
+    Centre for Digital Music, Queen Mary, University of London.
+    This file copyright 2011 Wen Xue.
+
+    This program is free software; you can redistribute it and/or
+    modify it under the terms of the GNU General Public License as
+    published by the Free Software Foundation; either version 2 of the
+    License, or (at your option) any later version.
+*/
 //---------------------------------------------------------------------------
 
 #ifndef align8H
--- a/arrayalloc.h	Thu Jul 28 10:36:57 2011 +0100
+++ b/arrayalloc.h	Wed Aug 10 12:33:35 2011 +0100
@@ -1,3 +1,15 @@
+/*
+    Harmonic sinusoidal modelling and tools
+
+    C++ code package for harmonic sinusoidal modelling and relevant signal processing.
+    Centre for Digital Music, Queen Mary, University of London.
+    This file copyright 2011 Wen Xue.
+
+    This program is free software; you can redistribute it and/or
+    modify it under the terms of the GNU General Public License as
+    published by the Free Software Foundation; either version 2 of the
+    License, or (at your option) any later version.
+*/
 #ifndef ARRAYALLOC
 #define ARRAYALLOC
 
--- a/fft.cpp	Thu Jul 28 10:36:57 2011 +0100
+++ b/fft.cpp	Wed Aug 10 12:33:35 2011 +0100
@@ -1,3 +1,15 @@
+/*
+    Harmonic sinusoidal modelling and tools
+
+    C++ code package for harmonic sinusoidal modelling and relevant signal processing.
+    Centre for Digital Music, Queen Mary, University of London.
+    This file copyright 2011 Wen Xue.
+
+    This program is free software; you can redistribute it and/or
+    modify it under the terms of the GNU General Public License as
+    published by the Free Software Foundation; either version 2 of the
+    License, or (at your option) any later version.
+*/
 //---------------------------------------------------------------------------
 
 #include <string.h>
@@ -19,6 +31,16 @@
 }//Atan2
 
 /**
+  function Log2: Log2
+
+  Returns x for Log2(2^x) if x is integer.
+*/
+int Log2(int x)
+{
+  return floor(log(x)/log(2)+0.5);
+}//Log2
+
+/**
   function BitInv: inverse bit order of Value within an $Order-bit expression.
 
   In: integer Value smaller than 2^Order
--- a/fft.h	Thu Jul 28 10:36:57 2011 +0100
+++ b/fft.h	Wed Aug 10 12:33:35 2011 +0100
@@ -1,3 +1,15 @@
+/*
+    Harmonic sinusoidal modelling and tools
+
+    C++ code package for harmonic sinusoidal modelling and relevant signal processing.
+    Centre for Digital Music, Queen Mary, University of London.
+    This file copyright 2011 Wen Xue.
+
+    This program is free software; you can redistribute it and/or
+    modify it under the terms of the GNU General Public License as
+    published by the Free Software Foundation; either version 2 of the
+    License, or (at your option) any later version.
+*/
 #ifndef fftH
 #define fftH
 
@@ -75,6 +87,7 @@
 
 //--tools--------------------------------------------------------------------
 double Atan2(double, double);
+int Log2(int);
 int* CreateBitInvTable(int Order);  //creates table of bit-inversed integers
 void SetTwiddleFactors(int N, cdouble* w);  //set twiddle factors
 
--- a/hs.cpp	Thu Jul 28 10:36:57 2011 +0100
+++ b/hs.cpp	Wed Aug 10 12:33:35 2011 +0100
@@ -1,3 +1,15 @@
+/*
+    Harmonic sinusoidal modelling and tools
+
+    C++ code package for harmonic sinusoidal modelling and relevant signal processing.
+    Centre for Digital Music, Queen Mary, University of London.
+    This file copyright 2011 Wen Xue.
+
+    This program is free software; you can redistribute it and/or
+    modify it under the terms of the GNU General Public License as
+    published by the Free Software Foundation; either version 2 of the
+    License, or (at your option) any later version.
+*/
 //---------------------------------------------------------------------------
 #include <math.h>
 #include "hs.h"
@@ -4608,6 +4620,7 @@
     atom* part=partials[m]; bool fzero=false;
     for (int fr=0; fr<Fr; fr++)
     {
+      if (terminatetag && *terminatetag) {free8(xrec); free8(as); return 0;}
       if (part[fr].f<=0){fzero=true; break;}
       ixs[fr]=part[fr].t;
       xs[fr]=part[fr].t;
@@ -4616,25 +4629,29 @@
       if (part[fr].type==atMuted) as[fr]=0;
 		}
     if (fzero) break;
-    if (terminatetag && *terminatetag) {free8(xrec); free8(as); return 0;}
 
     CubicSpline(Fr-1, f3, f2, f1, f0, xs, fs, 1, 1);
     CubicSpline(Fr-1, a3, a2, a1, a0, xs, as, 1, 1);
     double ph=0, ph0=0;
     for (int fr=0; fr<Fr-1; fr++)
     {
+      if (terminatetag && *terminatetag) {free8(xrec); free8(as); return 0;}
       part[fr].p=ph;
       ALIGN8(Sinusoid(&xrec[ixs[fr]-dst], 0, ixs[fr+1]-ixs[fr], a3[fr], a2[fr], a1[fr], a0[fr], f3[fr], f2[fr], f1[fr], f0[fr], ph, true);)
-      if (terminatetag && *terminatetag) {free8(xrec); free8(as); return 0;}
     }
-    part[Fr-1].p=ph;
-    ALIGN8(Sinusoid(&xrec[ixs[Fr-2]-dst], ixs[Fr-1]-ixs[Fr-2], den-ixs[Fr-2], a3[Fr-2], a2[Fr-2], a1[Fr-2], a0[Fr-2], f3[Fr-2], f2[Fr-2], f1[Fr-2], f0[Fr-2], ph, true);
-           Sinusoid(&xrec[ixs[0]-dst], dst-ixs[0], 0, a3[0], a2[0], a1[0], a0[0], f3[0], f2[0], f1[0], f0[0], ph0, true);)
+    part[Fr-1].p=ph; ph=part[Fr-2].p;
+    ALIGN8(Sinusoid(&xrec[ixs[Fr-2]-dst], ixs[Fr-1]-ixs[Fr-2], den-ixs[Fr-2], a3[Fr-2], a2[Fr-2], a1[Fr-2], a0[Fr-2], f3[Fr-2], f2[Fr-2], f1[Fr-2], f0[Fr-2], ph, true);)
+    ALIGN8(Sinusoid(&xrec[ixs[0]-dst], dst-ixs[0], 0, a3[0], a2[0], a1[0], a0[0], f3[0], f2[0], f1[0], f0[0], ph0, true);)
   }
   free8(as);
   return xrec;
 }//SynthesisHS
 
+double* SynthesisHS(THS* HS, int& dst, int& den, bool* terminatetag)
+{
+  return SynthesisHS(HS->M, HS->Fr, HS->Partials, dst, den, terminatetag);
+}//SynthesisHS
+
 /**
   function SynthesisHS2: synthesizes a perfectly harmonic sinusoid without aligning the phases.
   Frequencies of partials above the fundamental are not used in this synthesis process.
--- a/hs.h	Thu Jul 28 10:36:57 2011 +0100
+++ b/hs.h	Wed Aug 10 12:33:35 2011 +0100
@@ -1,3 +1,15 @@
+/*
+    Harmonic sinusoidal modelling and tools
+
+    C++ code package for harmonic sinusoidal modelling and relevant signal processing.
+    Centre for Digital Music, Queen Mary, University of London.
+    This file copyright 2011 Wen Xue.
+
+    This program is free software; you can redistribute it and/or
+    modify it under the terms of the GNU General Public License as
+    published by the Free Software Foundation; either version 2 of the
+    License, or (at your option) any later version.
+*/
 #ifndef hsH
 #define hsH
 
@@ -13,7 +25,12 @@
 #include "align8.h"
 #include "fft.h"
 #include "quickspec.h"
+
+#ifndef __BORLANDC__
 #include "tstream.h"
+#else
+#include <Classes.hpp>
+#endif
 
 #define ATOM_LOCALANCHOR 1
 #define HS_CONSTF 1
@@ -127,7 +144,6 @@
   THS is the data structure hosting a harmonic sinusoid representation. Its key members include the number
   of partials, number of frames, and all its atoms (sinusoid parameters of all partials at measurement points).
 */
-
 class THS
 {
 public:
@@ -239,6 +255,7 @@
 void InitializeR(TPolygon* R, int apind, double af, double ef, double maxB);
 
 //--internal structure conversion routines-----------------------------------
+void AtomsToPartials(int k, atom* part, int& M, int& Fr, atom**& partials, int offst);
 int NMResultToAtoms(int M, atom* HP, int t, int wid, NMResults results);
 int NMResultToPartials(int M, int fr, atom** Partials, int t, int wid, NMResults results);
 
@@ -263,6 +280,7 @@
 
 //--harmonic sinusoid synthesis routines-------------------------------------
 double* SynthesisHS(int pm, int pfr, atom** partials, int& dst, int& den, bool* terminatetag=0);
+double* SynthesisHS(THS* HS, int& dst, int& den, bool* terminatetag=0);
 double* SynthesisHS2(int M, int Fr, atom** partials, int& dst, int& den, bool* terminatetag=0);
 double* SynthesisHSp(int pm, int pfr, atom** partials, int& dst, int& den, double** startamp=0, int st_start=0, int st_offst=0, int st_count=0);
 double* SynthesisHSp(THS* HS, int& dst, int& den);
--- a/hsedit.cpp	Thu Jul 28 10:36:57 2011 +0100
+++ b/hsedit.cpp	Wed Aug 10 12:33:35 2011 +0100
@@ -1,3 +1,15 @@
+/*
+    Harmonic sinusoidal modelling and tools
+
+    C++ code package for harmonic sinusoidal modelling and relevant signal processing.
+    Centre for Digital Music, Queen Mary, University of London.
+    This file copyright 2011 Wen Xue.
+
+    This program is free software; you can redistribute it and/or
+    modify it under the terms of the GNU General Public License as
+    published by the Free Software Foundation; either version 2 of the
+    License, or (at your option) any later version.
+*/
 //---------------------------------------------------------------------------
 
 #include "hsedit.h"
--- a/hsedit.h	Thu Jul 28 10:36:57 2011 +0100
+++ b/hsedit.h	Wed Aug 10 12:33:35 2011 +0100
@@ -1,3 +1,15 @@
+/*
+    Harmonic sinusoidal modelling and tools
+
+    C++ code package for harmonic sinusoidal modelling and relevant signal processing.
+    Centre for Digital Music, Queen Mary, University of London.
+    This file copyright 2011 Wen Xue.
+
+    This program is free software; you can redistribute it and/or
+    modify it under the terms of the GNU General Public License as
+    published by the Free Software Foundation; either version 2 of the
+    License, or (at your option) any later version.
+*/
 #ifndef hseditH
 #define hseditH
 
--- a/hssf.cpp	Thu Jul 28 10:36:57 2011 +0100
+++ b/hssf.cpp	Wed Aug 10 12:33:35 2011 +0100
@@ -1,3 +1,15 @@
+/*
+    Harmonic sinusoidal modelling and tools
+
+    C++ code package for harmonic sinusoidal modelling and relevant signal processing.
+    Centre for Digital Music, Queen Mary, University of London.
+    This file copyright 2011 Wen Xue.
+
+    This program is free software; you can redistribute it and/or
+    modify it under the terms of the GNU General Public License as
+    published by the Free Software Foundation; either version 2 of the
+    License, or (at your option) any later version.
+*/
 //---------------------------------------------------------------------------
 
 #include <math.h>
@@ -65,6 +77,7 @@
 */
 void TSF::Duplicate(TSF& SF)
 {
+	TSF::~TSF();
   memcpy(this, &SF, sizeof(TSF)); lp=F0=avgh=avgb=0, h=b=0;
   AllocateL(L); memcpy(F0, SF.F0, sizeof(double)*(L+2)*6);
   AllocateP(); memcpy(lp, SF.lp, sizeof(double)*(P+2));
--- a/hssf.h	Thu Jul 28 10:36:57 2011 +0100
+++ b/hssf.h	Wed Aug 10 12:33:35 2011 +0100
@@ -1,3 +1,15 @@
+/*
+    Harmonic sinusoidal modelling and tools
+
+    C++ code package for harmonic sinusoidal modelling and relevant signal processing.
+    Centre for Digital Music, Queen Mary, University of London.
+    This file copyright 2011 Wen Xue.
+
+    This program is free software; you can redistribute it and/or
+    modify it under the terms of the GNU General Public License as
+    published by the Free Software Foundation; either version 2 of the
+    License, or (at your option) any later version.
+*/
 #ifndef hssfH
 #define hssfH
 
--- a/main.cpp	Thu Jul 28 10:36:57 2011 +0100
+++ b/main.cpp	Wed Aug 10 12:33:35 2011 +0100
@@ -1,3 +1,4 @@
+
 /*
   Sample program: analysis of harmonic sinusoid in low-noise monophonic context.
 
--- a/matrix.cpp	Thu Jul 28 10:36:57 2011 +0100
+++ b/matrix.cpp	Wed Aug 10 12:33:35 2011 +0100
@@ -1,3 +1,15 @@
+/*
+    Harmonic sinusoidal modelling and tools
+
+    C++ code package for harmonic sinusoidal modelling and relevant signal processing.
+    Centre for Digital Music, Queen Mary, University of London.
+    This file copyright 2011 Wen Xue.
+
+    This program is free software; you can redistribute it and/or
+    modify it under the terms of the GNU General Public License as
+    published by the Free Software Foundation; either version 2 of the
+    License, or (at your option) any later version.
+*/
 //---------------------------------------------------------------------------
 #include <math.h>
 #include <memory.h>
--- a/matrix.h	Thu Jul 28 10:36:57 2011 +0100
+++ b/matrix.h	Wed Aug 10 12:33:35 2011 +0100
@@ -1,3 +1,15 @@
+/*
+    Harmonic sinusoidal modelling and tools
+
+    C++ code package for harmonic sinusoidal modelling and relevant signal processing.
+    Centre for Digital Music, Queen Mary, University of London.
+    This file copyright 2011 Wen Xue.
+
+    This program is free software; you can redistribute it and/or
+    modify it under the terms of the GNU General Public License as
+    published by the Free Software Foundation; either version 2 of the
+    License, or (at your option) any later version.
+*/
 #ifndef MatrixH
 #define MatrixH
 
--- a/multires.cpp	Thu Jul 28 10:36:57 2011 +0100
+++ b/multires.cpp	Wed Aug 10 12:33:35 2011 +0100
@@ -1,3 +1,15 @@
+/*
+    Harmonic sinusoidal modelling and tools
+
+    C++ code package for harmonic sinusoidal modelling and relevant signal processing.
+    Centre for Digital Music, Queen Mary, University of London.
+    This file copyright 2011 Wen Xue.
+
+    This program is free software; you can redistribute it and/or
+    modify it under the terms of the GNU General Public License as
+    published by the Free Software Foundation; either version 2 of the
+    License, or (at your option) any later version.
+*/
 //---------------------------------------------------------------------------
 
 #include <math.h>
--- a/multires.h	Thu Jul 28 10:36:57 2011 +0100
+++ b/multires.h	Wed Aug 10 12:33:35 2011 +0100
@@ -1,3 +1,15 @@
+/*
+    Harmonic sinusoidal modelling and tools
+
+    C++ code package for harmonic sinusoidal modelling and relevant signal processing.
+    Centre for Digital Music, Queen Mary, University of London.
+    This file copyright 2011 Wen Xue.
+
+    This program is free software; you can redistribute it and/or
+    modify it under the terms of the GNU General Public License as
+    published by the Free Software Foundation; either version 2 of the
+    License, or (at your option) any later version.
+*/
 #ifndef multiresH
 #define multiresH
 
--- a/opt.cpp	Thu Jul 28 10:36:57 2011 +0100
+++ b/opt.cpp	Wed Aug 10 12:33:35 2011 +0100
@@ -1,3 +1,15 @@
+/*
+    Harmonic sinusoidal modelling and tools
+
+    C++ code package for harmonic sinusoidal modelling and relevant signal processing.
+    Centre for Digital Music, Queen Mary, University of London.
+    This file copyright 2011 Wen Xue.
+
+    This program is free software; you can redistribute it and/or
+    modify it under the terms of the GNU General Public License as
+    published by the Free Software Foundation; either version 2 of the
+    License, or (at your option) any later version.
+*/
 //---------------------------------------------------------------------------
 
 #include <math.h>
--- a/opt.h	Thu Jul 28 10:36:57 2011 +0100
+++ b/opt.h	Wed Aug 10 12:33:35 2011 +0100
@@ -1,3 +1,15 @@
+/*
+    Harmonic sinusoidal modelling and tools
+
+    C++ code package for harmonic sinusoidal modelling and relevant signal processing.
+    Centre for Digital Music, Queen Mary, University of London.
+    This file copyright 2011 Wen Xue.
+
+    This program is free software; you can redistribute it and/or
+    modify it under the terms of the GNU General Public License as
+    published by the Free Software Foundation; either version 2 of the
+    License, or (at your option) any later version.
+*/
 #ifndef optH
 #define optH
 
--- a/procedures.cpp	Thu Jul 28 10:36:57 2011 +0100
+++ b/procedures.cpp	Wed Aug 10 12:33:35 2011 +0100
@@ -1,3 +1,15 @@
+/*
+    Harmonic sinusoidal modelling and tools
+
+    C++ code package for harmonic sinusoidal modelling and relevant signal processing.
+    Centre for Digital Music, Queen Mary, University of London.
+    This file copyright 2011 Wen Xue.
+
+    This program is free software; you can redistribute it and/or
+    modify it under the terms of the GNU General Public License as
+    published by the Free Software Foundation; either version 2 of the
+    License, or (at your option) any later version.
+*/
 //---------------------------------------------------------------------------
 
 #include <math.h>
@@ -318,7 +330,7 @@
 
   for (int i=0; i<Fr; i++)
   {
-    RFFTCW(&data[i*Offst+start], Window, 0, 0, log2(Wid), w, x);
+    RFFTCW(&data[i*Offst+start], Window, 0, 0, Log2(Wid), w, x);
 
     if (Spec)
     {
@@ -658,7 +670,7 @@
 */
 void FFTConv(double* dest, double* source1, int size1, double* source2, int size2, int zero, double* pre_buffer, double* post_buffer)
 {
-  int order=log2(size2-1)+1+1;
+  int order=Log2(size2-1)+1+1;
   int Wid=1<<order;
   int HWid=Wid/2;
   int Fr=size1/HWid;
@@ -799,7 +811,7 @@
 void FFTConv(double* dest, double* source1, int size1, double* source2, int HWid, double* pre_buffer)
 {
   int Wid=HWid*2;
-  int order=log2(Wid);
+  int order=Log2(Wid);
   int Fr=size1/HWid;
   int res=size1-HWid*Fr;
 
@@ -900,7 +912,7 @@
 */
 void FFTConv(unsigned char* dest, unsigned char* source1, int bps, int size1, double* source2, int size2, int zero, unsigned char* pre_buffer, unsigned char* post_buffer)
 {
-  int order=log2(size2-1)+1+1;
+  int order=Log2(size2-1)+1+1;
   int Wid=1<<order;
   int HWid=Wid/2;
   int Fr=size1/HWid;
@@ -1038,7 +1050,7 @@
 */
 void FFTFilter(double* dataout, double* data, int Count, int Wid, int On, int Off)
 {
-  int Order=log2(Wid);
+  int Order=Log2(Wid);
   int HWid=Wid/2;
   int Fr=(Count-Wid)/HWid+1;
   AllocateFFTBuffer(Wid, ldata, w, x);
@@ -1110,7 +1122,7 @@
   AllocateFFTBuffer(Wid, spec, w, x);
   memset(x, 0, sizeof(cdouble)*Wid);
   for (int i=On+1; i<Off; i++) x[i].x=x[Wid-i].x=1-2*(i%2);
-  CIFFTR(x, log2(Wid), w, spec);
+  CIFFTR(x, Log2(Wid), w, spec);
   FFTConv(dataout, data, Count, spec, Wid, -Wid, pre_buffer, NULL);
   FreeFFTBuffer(spec);
 }//FFTFilterOLA
@@ -1120,7 +1132,7 @@
   AllocateFFTBuffer(Wid, spec, w, x);
   memset(x, 0, sizeof(cdouble)*Wid);
   for (int i=On+1; i<Off; i++) x[i].x=x[Wid-i].x=1-2*(i%2);
-  CIFFTR(x, log2(Wid), w, spec);
+  CIFFTR(x, Log2(Wid), w, spec);
   FFTConv(dataout, data, BytesPerSample, Count, spec, Wid, -Wid, pre_buffer, NULL);
   FreeFFTBuffer(spec);
 }//FFTFilterOLA
@@ -1149,7 +1161,7 @@
     x[Wid-i].y=-x[i].y;
   }
   x[HWid].x=amp[HWid], x[HWid].y=0;
-  CIFFTR(x, log2(Wid), w, spec);
+  CIFFTR(x, Log2(Wid), w, spec);
   FFTConv(dataout, data, Count, spec, Wid, -Wid, pre_buffer, NULL);
   FreeFFTBuffer(spec);
 }//FFTFilterOLA
@@ -1167,7 +1179,7 @@
 */
 double FFTMask(double* dataout, double* data, int Count, int Wid, double DigiOn, double DigiOff, double maskcoef)
 {
-  int Order=log2(Wid);
+  int Order=Log2(Wid);
   int HWid=Wid/2;
   int Fr=(Count-Wid)/HWid+1;
   int On=Wid*DigiOn, Off=Wid*DigiOff;
@@ -2037,7 +2049,7 @@
 {
   double tmp, b2s, b2c, b2e;
 
-  RFFTC(Data, 0, 0, log2(FrameWidth), W, X, 0);
+  RFFTC(Data, 0, 0, Log2(FrameWidth), W, X, 0);
   for (int i=0; i<=FrameWidth/2; i++) Amps[i]=X[i].x*X[i].x+X[i].y*X[i].y;
   
   for (int i=0; i<NumBands; i++)
@@ -2306,7 +2318,7 @@
   memset(Amp, 0, sizeof(double)*Count*Pad);
   memcpy(&Amp[Count*(Pad-1)/2], data, sizeof(double)*Count);
   ApplyWindow(Amp, Amp, params->Amp, Count);
-  RFFTC(Amp, Amp, Arg, log2(Count*Pad), w, x, 0);
+  RFFTC(Amp, Amp, Arg, Log2(Count*Pad), w, x, 0);
 
   SmoothPhase(Arg, Count*Pad/2+1);
   double result=Arg[Count*Pad/2]-Arg[0];
@@ -2622,7 +2634,7 @@
 {
   int HWid=Wid/2;
   int Fr=Count/HWid-1;
-  int Order=log2(Wid);
+  int Order=Log2(Wid);
 
   int** lspan=new int*[Fr];
   double* lxspan=new double[Fr];
@@ -2742,7 +2754,7 @@
 {
   int HWid=Wid/2;
   int Fr=Count/HWid-1;
-  int Order=log2(Wid);
+  int Order=Log2(Wid);
 
   int** lspan=new int*[Fr];
   double* lxspan=new double[Fr];
--- a/procedures.h	Thu Jul 28 10:36:57 2011 +0100
+++ b/procedures.h	Wed Aug 10 12:33:35 2011 +0100
@@ -1,3 +1,15 @@
+/*
+    Harmonic sinusoidal modelling and tools
+
+    C++ code package for harmonic sinusoidal modelling and relevant signal processing.
+    Centre for Digital Music, Queen Mary, University of London.
+    This file copyright 2011 Wen Xue.
+
+    This program is free software; you can redistribute it and/or
+    modify it under the terms of the GNU General Public License as
+    published by the Free Software Foundation; either version 2 of the
+    License, or (at your option) any later version.
+*/
 #ifndef proceduresH
 #define proceduresH
 
--- a/quickspec.cpp	Thu Jul 28 10:36:57 2011 +0100
+++ b/quickspec.cpp	Wed Aug 10 12:33:35 2011 +0100
@@ -1,3 +1,15 @@
+/*
+    Harmonic sinusoidal modelling and tools
+
+    C++ code package for harmonic sinusoidal modelling and relevant signal processing.
+    Centre for Digital Music, Queen Mary, University of London.
+    This file copyright 2011 Wen Xue.
+
+    This program is free software; you can redistribute it and/or
+    modify it under the terms of the GNU General Public License as
+    published by the Free Software Foundation; either version 2 of the
+    License, or (at your option) any later version.
+*/
 //---------------------------------------------------------------------------
 #include <math.h>
 #include <memory.h>
@@ -123,8 +135,8 @@
 */
 void CalculateSpectrum(void* Data, int BytesPerSample, double* win, QSPEC_FORMAT* Amp, QSPEC_FORMAT* Arg, int Wid, cdouble* w, cdouble* x, int* hbi)
 {
-  if (BytesPerSample==2) RFFTCW((__int16*)Data, win, 0, 0, log2(Wid), w, x, hbi);
-  else {IntToDouble((double*)x, Data, BytesPerSample, Wid); RFFTCW((double*)x, win, 0, 0, log2(Wid), w, x, hbi);}
+  if (BytesPerSample==2) RFFTCW((__int16*)Data, win, 0, 0, Log2(Wid), w, x, hbi);
+  else {IntToDouble((double*)x, Data, BytesPerSample, Wid); RFFTCW((double*)x, win, 0, 0, Log2(Wid), w, x, hbi);}
   for (int j=0; j<=Wid/2; j++)
   {
     Amp[j]=sqrt(x[j].x*x[j].x+x[j].y*x[j].y);
@@ -157,7 +169,7 @@
   {
     double* doublex=(double*)x;
     IntToDouble(doublex, Data, BytesPerSample, eff); memset(&doublex[eff], 0, sizeof(double)*(Wid-eff));
-    RFFTCW(doublex, win, 0, 0, log2(Wid), w, x, hbi);
+    RFFTCW(doublex, win, 0, 0, Log2(Wid), w, x, hbi);
     for (int j=0; j<=Wid/2; j++)
     {
       Amp[j]=sqrt(x[j].x*x[j].x+x[j].y*x[j].y);
@@ -190,7 +202,7 @@
       free8(fw); free(fhbi);
       fw=(cdouble*)malloc8(sizeof(cdouble)*Wid*1.5); SetTwiddleFactors(Wid, fw);
       fx=&fw[Wid/2];
-      fhbi=CreateBitInvTable(log2(Wid)-1);
+      fhbi=CreateBitInvTable(Log2(Wid)-1);
     }
     if (Wid!=fWid || WinType!=fwt || WinParam!=fwdp)
     { //then update internal window function to the new window type
--- a/quickspec.h	Thu Jul 28 10:36:57 2011 +0100
+++ b/quickspec.h	Wed Aug 10 12:33:35 2011 +0100
@@ -1,3 +1,15 @@
+/*
+    Harmonic sinusoidal modelling and tools
+
+    C++ code package for harmonic sinusoidal modelling and relevant signal processing.
+    Centre for Digital Music, Queen Mary, University of London.
+    This file copyright 2011 Wen Xue.
+
+    This program is free software; you can redistribute it and/or
+    modify it under the terms of the GNU General Public License as
+    published by the Free Software Foundation; either version 2 of the
+    License, or (at your option) any later version.
+*/
 #ifndef QuickSpecH
 #define QuickSpecH
 
@@ -123,7 +135,6 @@
   void AddBuffer();
   void AddBuffer(int AddFrCount);
   void __fastcall CalculateSpectrum(int fr);
-  void SetFrCapacity(int AnFrCapacity);
 
 public:
   //if specified, Parent is responsible to supply FFT buffers through GetFFTBuffers (optional)
@@ -153,6 +164,7 @@
   void FreeBuffers();                           ///< discards all computed frames and free memory
   int Invalidate(int From, int To);             ///< discards computed frames
   QSPEC_FORMAT* __fastcall Ph(int fr);          ///< accesses phase spectrogram at frame fr
+  void SetFrCapacity(int AnFrCapacity);
   cmplx<QSPEC_FORMAT>* __fastcall Spec(int fr); ///< accesses complex spectrogram at frame fr
 };
 #endif
--- a/sinest.cpp	Thu Jul 28 10:36:57 2011 +0100
+++ b/sinest.cpp	Wed Aug 10 12:33:35 2011 +0100
@@ -1,3 +1,15 @@
+/*
+    Harmonic sinusoidal modelling and tools
+
+    C++ code package for harmonic sinusoidal modelling and relevant signal processing.
+    Centre for Digital Music, Queen Mary, University of London.
+    This file copyright 2011 Wen Xue.
+
+    This program is free software; you can redistribute it and/or
+    modify it under the terms of the GNU General Public License as
+    published by the Free Software Foundation; either version 2 of the
+    License, or (at your option) any later version.
+*/
 //---------------------------------------------------------------------------
 
 #include <stddef.h>
@@ -1798,7 +1810,7 @@
     __int16* lx=&x[Offst*fr];
     double* lph=&ph[Offst*(fr-frst)];
     for (int i=0; i<Wid; i++) y[i]=cdouble(lx[i]).rotate(-lph[i]+i*0.15*2*M_PI);
-    CFFTCW(y, win, Amp, 0, log2(Wid), W, X);
+    CFFTCW(y, win, Amp, 0, Log2(Wid), W, X);
     int pf=0.15*Wid, mpf=pf;
     for (int k=pf-4; k<=pf+4; k++) if (Amp[k]>Amp[mpf]) mpf=k;
     if (mpf>pf-4 && mpf<pf+4) pf=mpf;
@@ -1897,7 +1909,7 @@
       SetTwiddleFactors(lWid, w);
       double *lwin=NewWindow(wtHann, lWid), lc[4], liH2;
       windowspec(wtHann, lWid, &lM, lc, &liH2);
-      CFFTCW(&xs[hWid-lhWid], lwin, NULL, NULL, log2(lWid), w, xc);
+      CFFTCW(&xs[hWid-lhWid], lwin, NULL, NULL, Log2(lWid), w, xc);
       delete[] lwin;
       double lf=fbuf[fr]*lWid, la, lp;
       LSESinusoid(lf, lf-3, lf+3, xc, lWid, 3, lM, lc, liH2, la, lp, 1e-3);
@@ -1905,7 +1917,7 @@
     }
     else
     {
-      CFFTCW(xs, win, NULL, NULL, log2(Wid), w, xc);
+      CFFTCW(xs, win, NULL, NULL, Log2(Wid), w, xc);
       double lf=fbuf[fr]*Wid, la, lp;
       LSESinusoid(lf, lf-3, lf+3, xc, Wid, 3, M, c, iH2, la, lp, 1e-3);
       if (la*2>abuf[fr])
@@ -1985,7 +1997,7 @@
       for (int i=hWid; i<Wid; i++) xs[i].x=ldata[i]*lrefcos[i], xs[i].y=-ldata[i]*lrefsin[i];
     }
 
-    CFFTCW(xs, win, NULL, NULL, log2(Wid), w, xc);
+    CFFTCW(xs, win, NULL, NULL, Log2(Wid), w, xc);
     double lf=fbuf[fr]*Wid, la, lp;
     LSESinusoid(lf, lf-3, lf+3, xc, Wid, 3, M, c, iH2, la, lp, 1e-3);
     if (la*2>abuf[fr])
@@ -2089,7 +2101,7 @@
       SetTwiddleFactors(lWid, w);
       double *lwin=NewWindow(wtHann, lWid), lc[4], liH2;
       windowspec(wtHann, lWid, &lM, lc, &liH2);
-      CFFTCW(&xs[hWid-lhWid], lwin, NULL, NULL, log2(lWid), w, xc);
+      CFFTCW(&xs[hWid-lhWid], lwin, NULL, NULL, Log2(lWid), w, xc);
       delete[] lwin;
       double lf=fbuf[fr]*lWid, la, lp;
       LSESinusoid(lf, lf-3, lf+3, xc, lWid, 3, lM, lc, liH2, la, lp, 1e-3);
@@ -2097,7 +2109,7 @@
     }
     else
     {
-      CFFTCW(xs, win, NULL, NULL, log2(Wid), w, xc);
+      CFFTCW(xs, win, NULL, NULL, Log2(Wid), w, xc);
       double lf=fbuf[fr]*Wid, la, lp;
       LSESinusoid(lf, lf-3, lf+3, xc, Wid, 3, M, c, iH2, la, lp, 1e-3);
       if (la*2>abuf[fr]) fbuf[fr]=lf/Wid, abuf[fr]=la*2, pbuf[fr]=lp;
@@ -2209,7 +2221,7 @@
 void Derivative(int Wid, double* win, cdouble* x, cdouble* dx, cdouble* ddx, double& f0, double* f1, double* a0, double* a1, double* ph)
 {
   AllocateFFTBuffer(Wid, fft, W, X);
-  CFFTCW(x, win, fft, NULL, log2(Wid), W, X);
+  CFFTCW(x, win, fft, NULL, Log2(Wid), W, X);
   int m=f0*Wid, m0=m-10, m1=m+10, hWid=Wid/2;
   if (m0<0) m0=0; if (m1>hWid) m1=hWid;
   for (int n=m0; n<=m1; n++) if (fft[n]>fft[m]) m=n;
--- a/sinest.h	Thu Jul 28 10:36:57 2011 +0100
+++ b/sinest.h	Wed Aug 10 12:33:35 2011 +0100
@@ -1,3 +1,15 @@
+/*
+    Harmonic sinusoidal modelling and tools
+
+    C++ code package for harmonic sinusoidal modelling and relevant signal processing.
+    Centre for Digital Music, Queen Mary, University of London.
+    This file copyright 2011 Wen Xue.
+
+    This program is free software; you can redistribute it and/or
+    modify it under the terms of the GNU General Public License as
+    published by the Free Software Foundation; either version 2 of the
+    License, or (at your option) any later version.
+*/
 #ifndef SinEstH
 #define SinEstH
 
--- a/sinsyn.cpp	Thu Jul 28 10:36:57 2011 +0100
+++ b/sinsyn.cpp	Wed Aug 10 12:33:35 2011 +0100
@@ -1,3 +1,15 @@
+/*
+    Harmonic sinusoidal modelling and tools
+
+    C++ code package for harmonic sinusoidal modelling and relevant signal processing.
+    Centre for Digital Music, Queen Mary, University of London.
+    This file copyright 2011 Wen Xue.
+
+    This program is free software; you can redistribute it and/or
+    modify it under the terms of the GNU General Public License as
+    published by the Free Software Foundation; either version 2 of the
+    License, or (at your option) any later version.
+*/
 //---------------------------------------------------------------------------
 
 #include "align8.h"
@@ -788,7 +800,7 @@
     ALIGN8(Sinusoid(&xrec[(int)xs[fr]-dst], 0, xs[fr+1]-xs[fr], a3[fr], a2[fr], a1[fr], a0[fr], f3[fr], f2[fr], f1[fr], f0[fr], ph, add);)
     if (terminatetag && *terminatetag) {delete[] f3; return 0;}
   }
-  phs[Fr-1]=ph;
+  phs[Fr-1]=ph; ph=phs[Fr-2];
   ALIGN8(Sinusoid(&xrec[(int)xs[Fr-2]-dst], xs[Fr-1]-xs[Fr-2], den-xs[Fr-2], a3[Fr-2], a2[Fr-2], a1[Fr-2], a0[Fr-2], f3[Fr-2], f2[Fr-2], f1[Fr-2], f0[Fr-2], ph, add);
          Sinusoid(&xrec[(int)xs[0]-dst], dst-xs[0], 0, a3[0], a2[0], a1[0], a0[0], f3[0], f2[0], f1[0], f0[0], phs[0], add);)
   delete[] f3;
--- a/sinsyn.h	Thu Jul 28 10:36:57 2011 +0100
+++ b/sinsyn.h	Wed Aug 10 12:33:35 2011 +0100
@@ -1,3 +1,15 @@
+/*
+    Harmonic sinusoidal modelling and tools
+
+    C++ code package for harmonic sinusoidal modelling and relevant signal processing.
+    Centre for Digital Music, Queen Mary, University of London.
+    This file copyright 2011 Wen Xue.
+
+    This program is free software; you can redistribute it and/or
+    modify it under the terms of the GNU General Public License as
+    published by the Free Software Foundation; either version 2 of the
+    License, or (at your option) any later version.
+*/
 #ifndef SinSynH
 #define SinSynH
 
--- a/splines.cpp	Thu Jul 28 10:36:57 2011 +0100
+++ b/splines.cpp	Wed Aug 10 12:33:35 2011 +0100
@@ -1,3 +1,15 @@
+/*
+    Harmonic sinusoidal modelling and tools
+
+    C++ code package for harmonic sinusoidal modelling and relevant signal processing.
+    Centre for Digital Music, Queen Mary, University of London.
+    This file copyright 2011 Wen Xue.
+
+    This program is free software; you can redistribute it and/or
+    modify it under the terms of the GNU General Public License as
+    published by the Free Software Foundation; either version 2 of the
+    License, or (at your option) any later version.
+*/
 //---------------------------------------------------------------------------
 
 #include "splines.h"
--- a/splines.h	Thu Jul 28 10:36:57 2011 +0100
+++ b/splines.h	Wed Aug 10 12:33:35 2011 +0100
@@ -1,3 +1,15 @@
+/*
+    Harmonic sinusoidal modelling and tools
+
+    C++ code package for harmonic sinusoidal modelling and relevant signal processing.
+    Centre for Digital Music, Queen Mary, University of London.
+    This file copyright 2011 Wen Xue.
+
+    This program is free software; you can redistribute it and/or
+    modify it under the terms of the GNU General Public License as
+    published by the Free Software Foundation; either version 2 of the
+    License, or (at your option) any later version.
+*/
 #ifndef splinesH
 #define splinesH
 
--- a/tstream.h	Thu Jul 28 10:36:57 2011 +0100
+++ b/tstream.h	Wed Aug 10 12:33:35 2011 +0100
@@ -1,3 +1,15 @@
+/*
+    Harmonic sinusoidal modelling and tools
+
+    C++ code package for harmonic sinusoidal modelling and relevant signal processing.
+    Centre for Digital Music, Queen Mary, University of London.
+    This file copyright 2011 Wen Xue.
+
+    This program is free software; you can redistribute it and/or
+    modify it under the terms of the GNU General Public License as
+    published by the Free Software Foundation; either version 2 of the
+    License, or (at your option) any later version.
+*/
 #ifndef TSTREAM_H
 #define TSTREAM_H
 
--- a/vibrato.cpp	Thu Jul 28 10:36:57 2011 +0100
+++ b/vibrato.cpp	Wed Aug 10 12:33:35 2011 +0100
@@ -1,3 +1,15 @@
+/*
+    Harmonic sinusoidal modelling and tools
+
+    C++ code package for harmonic sinusoidal modelling and relevant signal processing.
+    Centre for Digital Music, Queen Mary, University of London.
+    This file copyright 2011 Wen Xue.
+
+    This program is free software; you can redistribute it and/or
+    modify it under the terms of the GNU General Public License as
+    published by the Free Software Foundation; either version 2 of the
+    License, or (at your option) any later version.
+*/
 //---------------------------------------------------------------------------
 
 #include <math.h>
@@ -462,10 +474,10 @@
 */
 void DeAM(double* A2, double* A1, int npfr, double* lp, int Fr)
 {
-  int* peakfr=new int[npfr];
+  int* peakfr=(int*)malloc(sizeof(int)*npfr);
   for (int i=0; i<npfr; i++) peakfr[i]=ceil(lp[i]);
   DeAM(A2, A1, npfr, peakfr, Fr);
-  delete[] peakfr;
+  free(peakfr);
 }//DeAM
 
 /**
@@ -557,10 +569,10 @@
 */
 void DeFM(double* f2, double* f1, double* AA, int npfr, double* lp, int Fr, double& fct, int& fcount, double* &frs, double* &f, bool furthersmoothing)
 {
-  int* peakfr=new int[npfr];
+  int* peakfr=(int*)malloc(sizeof(int)*npfr);
   for (int i=0; i<npfr; i++) peakfr[i]=ceil(lp[i]);
   DeFM(f2, f1, AA, npfr, peakfr, Fr, fct, fcount, frs, f, furthersmoothing);
-  delete[] peakfr;
+  free(peakfr);
 }//DeFM
 
 /**
@@ -832,7 +844,7 @@
   int inewP=ceil(newP+Pst);
   newV->P=inewP;
 
-  newV->peakfr=new int[inewP];
+  newV->peakfr=(int*)malloc(sizeof(int)*inewP);
   newV->AllocateP(); newV->AllocatePK();
 
   newV->lp[0]=V.lp[0]/rate;
@@ -907,7 +919,7 @@
 {
   rate=0; regularity=0;
   //find the section used for calculating regularity and rate
-  int frlen=fren-frst+1, frlenp=1<<(int(log2(fren))+2), frlenpp=frlenp*padrate;
+  int frlen=fren-frst+1, frlenp=1<<(int(Log2(fren))+2), frlenpp=frlenp*padrate;
   double *lf=new double[frlenpp*4];
   cdouble *w=(cdouble*)&lf[frlenpp];
   cdouble *x=(cdouble*)&lf[frlenpp*2];
@@ -924,13 +936,13 @@
     }
 
 
-  RFFTC(lf, NULL, NULL, log2(frlenp), w, x, 0);
+  RFFTC(lf, NULL, NULL, Log2(frlenp), w, x, 0);
 //  xr[0]=0;
   for (int i=0; i<frlenp/2; i++) {x[i].x=x[i].x*x[i].x+x[i].y*x[i].y; x[i].y=0;}
   memset(&x[frlenp/2], 0, sizeof(cdouble)*(frlenpp-frlenp/2));
 
   SetTwiddleFactors(frlenpp, w);
-  CIFFTR(x, log2(frlenpp), w, lf);
+  CIFFTR(x, Log2(frlenpp), w, lf);
 
   delete[] rdata;
 
@@ -1082,6 +1094,12 @@
       bandsendinc[nbands++]=i++;
     }
 
+  if (nbands==0)
+  {
+    memset(LogAF, 0, sizeof(double)*afres/2);
+  }
+  else
+  {
     //integrate DAF over the fundamental band, with AF(F0Overall)=1
     i=F0Overall*afres;
     double theta=F0Overall*afres-i;
@@ -1112,7 +1130,8 @@
         cshift=cshift+log(Partials[band][fr].a*(band+1)/(Partials[band-1][fr].a*band))+logaflast-logafthis;
         ccount++;
       }
-      cshift/=ccount;
+      if (ccount!=0) cshift/=ccount;
+      else cshift=0;
       //apply the shift
       for (int i=bandsstart[band]; i<=bandsendinc[band]; i++) LogAF[i]+=cshift;
       //make up the blank band
@@ -1120,10 +1139,11 @@
       for (int i=lastend+1; i<thisstart; i++) LogAF[i]=LogAF[lastend]+cshift*(i-lastend)/(thisstart-lastend);
       band++;
     }
-    delete[] DAF;
 
     int tmpband=bandsstart[0]; for (int i=0; i<tmpband; i++) LogAF[i]=LogAF[tmpband];
     tmpband=bandsendinc[nbands-1]; for (int i=tmpband; i<afres/2; i++) LogAF[i]=LogAF[tmpband];
+  }
+  delete[] DAF;
 
     //Here LogAF contains the filter model, new get the source model
     memset(LogAS, 0, sizeof(double)*100);
--- a/vibrato.h	Thu Jul 28 10:36:57 2011 +0100
+++ b/vibrato.h	Wed Aug 10 12:33:35 2011 +0100
@@ -1,3 +1,15 @@
+/*
+    Harmonic sinusoidal modelling and tools
+
+    C++ code package for harmonic sinusoidal modelling and relevant signal processing.
+    Centre for Digital Music, Queen Mary, University of London.
+    This file copyright 2011 Wen Xue.
+
+    This program is free software; you can redistribute it and/or
+    modify it under the terms of the GNU General Public License as
+    published by the Free Software Foundation; either version 2 of the
+    License, or (at your option) any later version.
+*/
 #ifndef vibratoH
 #define vibratoH
 
--- a/wavelet.cpp	Thu Jul 28 10:36:57 2011 +0100
+++ b/wavelet.cpp	Wed Aug 10 12:33:35 2011 +0100
@@ -1,3 +1,15 @@
+/*
+    Harmonic sinusoidal modelling and tools
+
+    C++ code package for harmonic sinusoidal modelling and relevant signal processing.
+    Centre for Digital Music, Queen Mary, University of London.
+    This file copyright 2011 Wen Xue.
+
+    This program is free software; you can redistribute it and/or
+    modify it under the terms of the GNU General Public License as
+    published by the Free Software Foundation; either version 2 of the
+    License, or (at your option) any later version.
+*/
 //---------------------------------------------------------------------------
 
 #include <math.h>
--- a/wavelet.h	Thu Jul 28 10:36:57 2011 +0100
+++ b/wavelet.h	Wed Aug 10 12:33:35 2011 +0100
@@ -1,3 +1,15 @@
+/*
+    Harmonic sinusoidal modelling and tools
+
+    C++ code package for harmonic sinusoidal modelling and relevant signal processing.
+    Centre for Digital Music, Queen Mary, University of London.
+    This file copyright 2011 Wen Xue.
+
+    This program is free software; you can redistribute it and/or
+    modify it under the terms of the GNU General Public License as
+    published by the Free Software Foundation; either version 2 of the
+    License, or (at your option) any later version.
+*/
 #ifndef waveletH
 #define waveletH
 
--- a/windowfunctions.cpp	Thu Jul 28 10:36:57 2011 +0100
+++ b/windowfunctions.cpp	Wed Aug 10 12:33:35 2011 +0100
@@ -1,3 +1,15 @@
+/*
+    Harmonic sinusoidal modelling and tools
+
+    C++ code package for harmonic sinusoidal modelling and relevant signal processing.
+    Centre for Digital Music, Queen Mary, University of London.
+    This file copyright 2011 Wen Xue.
+
+    This program is free software; you can redistribute it and/or
+    modify it under the terms of the GNU General Public License as
+    published by the Free Software Foundation; either version 2 of the
+    License, or (at your option) any later version.
+*/
 //---------------------------------------------------------------------------
 #include <math.h>
 #include <string.h>
--- a/windowfunctions.h	Thu Jul 28 10:36:57 2011 +0100
+++ b/windowfunctions.h	Wed Aug 10 12:33:35 2011 +0100
@@ -1,3 +1,15 @@
+/*
+    Harmonic sinusoidal modelling and tools
+
+    C++ code package for harmonic sinusoidal modelling and relevant signal processing.
+    Centre for Digital Music, Queen Mary, University of London.
+    This file copyright 2011 Wen Xue.
+
+    This program is free software; you can redistribute it and/or
+    modify it under the terms of the GNU General Public License as
+    published by the Free Software Foundation; either version 2 of the
+    License, or (at your option) any later version.
+*/
 #ifndef WindowFunctionsH
 #define WindowFunctionsH
 
--- a/xcomplex.h	Thu Jul 28 10:36:57 2011 +0100
+++ b/xcomplex.h	Wed Aug 10 12:33:35 2011 +0100
@@ -1,3 +1,15 @@
+/*
+    Harmonic sinusoidal modelling and tools
+
+    C++ code package for harmonic sinusoidal modelling and relevant signal processing.
+    Centre for Digital Music, Queen Mary, University of London.
+    This file copyright 2011 Wen Xue.
+
+    This program is free software; you can redistribute it and/or
+    modify it under the terms of the GNU General Public License as
+    published by the Free Software Foundation; either version 2 of the
+    License, or (at your option) any later version.
+*/
 #ifndef XCOMPLEX
 #define XCOMPLEX