Mercurial > hg > x
comparison sinest.cpp @ 3:42c078b19e9a
* Replace null-pointer hack with use of standard macro offsetof(struct,member)
author | Chris Cannam |
---|---|
date | Tue, 05 Oct 2010 16:18:52 +0100 |
parents | fc19d45615d1 |
children | 5f3c32dc6e17 |
comparison
equal
deleted
inserted
replaced
2:fc19d45615d1 | 3:42c078b19e9a |
---|---|
669 Returns the frequency estimate, in bins. | 669 Returns the frequency estimate, in bins. |
670 */ | 670 */ |
671 double LSESinusoid(cdouble* x, int N, double B, int M, double* c, double iH2, double& a, double& pp, double epf) | 671 double LSESinusoid(cdouble* x, int N, double B, int M, double* c, double iH2, double& a, double& pp, double epf) |
672 { | 672 { |
673 struct l_hx {int N; int k1; int k2; int M; double* c; double iH2; cdouble* x; double dhxpeak; double hxpeak;} p={N, 0, 0, M, c, iH2, x, 0, 0}; //(l_hx *)¶ms; | 673 struct l_hx {int N; int k1; int k2; int M; double* c; double iH2; cdouble* x; double dhxpeak; double hxpeak;} p={N, 0, 0, M, c, iH2, x, 0, 0}; //(l_hx *)¶ms; |
674 int dfshift=int(&((l_hx*)0)->dhxpeak); | 674 int dfshift=offsetof(l_hx, dhxpeak); |
675 | 675 |
676 int inp; | 676 int inp; |
677 double minp=0; | 677 double minp=0; |
678 for (int i=0; i<N; i++) | 678 for (int i=0; i<N; i++) |
679 { | 679 { |
710 No return value. | 710 No return value. |
711 */ | 711 */ |
712 void LSESinusoid(double& f, cdouble* x, int N, double B, int M, double* c, double iH2, double& a, double& pp, double epf) | 712 void LSESinusoid(double& f, cdouble* x, int N, double B, int M, double* c, double iH2, double& a, double& pp, double epf) |
713 { | 713 { |
714 struct l_hx {int N; int k1; int k2; int M; double* c; double iH2; cdouble* x; double dhxpeak; double hxpeak;} p={N, 0, 0, M, c, iH2, x, 0, 0}; | 714 struct l_hx {int N; int k1; int k2; int M; double* c; double iH2; cdouble* x; double dhxpeak; double hxpeak;} p={N, 0, 0, M, c, iH2, x, 0, 0}; |
715 int dfshift=int(&((l_hx*)0)->dhxpeak); | 715 int dfshift=offsetof(l_hx, dhxpeak); |
716 | 716 |
717 double inp=f; | 717 double inp=f; |
718 p.k1=ceil(inp-B); if (p.k1<0) p.k1=0; | 718 p.k1=ceil(inp-B); if (p.k1<0) p.k1=0; |
719 p.k2=floor(inp+B); if (p.k2>=p.N/2) p.k2=p.N/2-1; | 719 p.k2=floor(inp+B); if (p.k2>=p.N/2) p.k2=p.N/2-1; |
720 double tmp=Newton(f, ddIPWindow, &p, dfshift, epf); | 720 double tmp=Newton(f, ddIPWindow, &p, dfshift, epf); |
740 Returns the frequency estimate, in bins. | 740 Returns the frequency estimate, in bins. |
741 */ | 741 */ |
742 double LSESinusoid(int f1, int f2, cdouble* x, int N, double B, int M, double* c, double iH2, double& a, double& pp, double epf) | 742 double LSESinusoid(int f1, int f2, cdouble* x, int N, double B, int M, double* c, double iH2, double& a, double& pp, double epf) |
743 { | 743 { |
744 struct l_hx {int N; int k1; int k2; int M; double* c; double iH2; cdouble* x; double dhxpeak; double hxpeak;} p={N, 0, 0, M, c, iH2, x, 0, 0}; | 744 struct l_hx {int N; int k1; int k2; int M; double* c; double iH2; cdouble* x; double dhxpeak; double hxpeak;} p={N, 0, 0, M, c, iH2, x, 0, 0}; |
745 int dfshift=int(&((l_hx*)0)->dhxpeak); | 745 int dfshift=offsetof(l_hx, dhxpeak); |
746 | 746 |
747 int inp; | 747 int inp; |
748 double minp=0; | 748 double minp=0; |
749 for (int i=f1; i<f2; i++) | 749 for (int i=f1; i<f2; i++) |
750 { | 750 { |
785 f. | 785 f. |
786 */ | 786 */ |
787 int LSESinusoid(double& f, double f1, double f2, cdouble* x, int N, double B, int M, double* c, double iH2, double& a, double& pp, double epf) | 787 int LSESinusoid(double& f, double f1, double f2, cdouble* x, int N, double B, int M, double* c, double iH2, double& a, double& pp, double epf) |
788 { | 788 { |
789 struct l_hx {int N; int k1; int k2; int M; double* c; double iH2; cdouble* x; double dhxpeak; double hxpeak;} p={N, 0, 0, M, c, iH2, x, 0, 0};//(l_hx *)¶ms; | 789 struct l_hx {int N; int k1; int k2; int M; double* c; double iH2; cdouble* x; double dhxpeak; double hxpeak;} p={N, 0, 0, M, c, iH2, x, 0, 0};//(l_hx *)¶ms; |
790 int dfshift=int(&((l_hx*)0)->dhxpeak); | 790 int dfshift=offsetof(l_hx, dhxpeak); |
791 | 791 |
792 int result=0; | 792 int result=0; |
793 double inp=f; | 793 double inp=f; |
794 p.k1=ceil(inp-B); if (p.k1<0) p.k1=0; | 794 p.k1=ceil(inp-B); if (p.k1<0) p.k1=0; |
795 p.k2=floor(inp+B); if (p.k2>=p.N/2) p.k2=p.N/2-1; | 795 p.k2=floor(inp+B); if (p.k2>=p.N/2) p.k2=p.N/2-1; |
834 Returns an error bound of the frequency estimate. | 834 Returns an error bound of the frequency estimate. |
835 */ | 835 */ |
836 double LSESinusoidMP(double& f, double f1, double f2, cdouble** x, int Fr, int N, double B, int M, double* c, double iH2, double* a, double* ph, double epf) | 836 double LSESinusoidMP(double& f, double f1, double f2, cdouble** x, int Fr, int N, double B, int M, double* c, double iH2, double* a, double* ph, double epf) |
837 { | 837 { |
838 struct l_ip1 {int N; int k1; int k2; int M; double* c; double iH2; int L; cdouble** x; double dsip; double sip; cdouble* lmd;} p={N, 0, 0, M, c,iH2, Fr, x, 0, 0, 0}; | 838 struct l_ip1 {int N; int k1; int k2; int M; double* c; double iH2; int L; cdouble** x; double dsip; double sip; cdouble* lmd;} p={N, 0, 0, M, c,iH2, Fr, x, 0, 0, 0}; |
839 int dfshift=int(&((l_ip1*)0)->dsip), fshift=int(&((l_ip1*)0)->sip); | 839 int dfshift=offsetof(l_ip1, dsip), fshift=offsetof(l_ip1, sip); |
840 | 840 |
841 double inp=f; | 841 double inp=f; |
842 p.k1=ceil(inp-B); if (p.k1<0) p.k1=0; | 842 p.k1=ceil(inp-B); if (p.k1<0) p.k1=0; |
843 p.k2=floor(inp+B); if (p.k2>=p.N/2) p.k2=p.N/2-1; | 843 p.k2=floor(inp+B); if (p.k2>=p.N/2) p.k2=p.N/2-1; |
844 double errf=Newton1dmax(f, f1, f2, ddsIPWindow, &p, dfshift, fshift, dsIPWindow, dfshift, epf); | 844 double errf=Newton1dmax(f, f1, f2, ddsIPWindow, &p, dfshift, fshift, dsIPWindow, dfshift, epf); |
873 */ | 873 */ |
874 double LSESinusoidMPC(double& f, double f1, double f2, cdouble** x, int Fr, int N, int Offst, double B, int M, double* c, double iH2, double* a, double* ph, double epf) | 874 double LSESinusoidMPC(double& f, double f1, double f2, cdouble** x, int Fr, int N, int Offst, double B, int M, double* c, double iH2, double* a, double* ph, double epf) |
875 { | 875 { |
876 struct l_ip {int N; int k1; int k2; int M; double* c; double iH2; int L; double offst_rel; cdouble** x; double sdip; double sip;} | 876 struct l_ip {int N; int k1; int k2; int M; double* c; double iH2; int L; double offst_rel; cdouble** x; double sdip; double sip;} |
877 p={N, 0, 0, M, c,iH2, Fr, Offst*1.0/N, x, 0, 0}; | 877 p={N, 0, 0, M, c,iH2, Fr, Offst*1.0/N, x, 0, 0}; |
878 int dfshift=int(&((l_ip*)0)->sdip), fshift=int(&((l_ip*)0)->sip); | 878 int dfshift=offsetof(l_ip, sdip), fshift=offsetof(l_ip, sip); |
879 | 879 |
880 double inp=f; | 880 double inp=f; |
881 p.k1=ceil(inp-B); if (p.k1<0) p.k1=0; | 881 p.k1=ceil(inp-B); if (p.k1<0) p.k1=0; |
882 p.k2=floor(inp+B); if (p.k2>=p.N/2) p.k2=p.N/2-1; | 882 p.k2=floor(inp+B); if (p.k2>=p.N/2) p.k2=p.N/2-1; |
883 double errf=Newton1dmax(f, f1, f2, ddsIPWindowC, &p, dfshift, fshift, dsIPWindowC, dfshift, epf); | 883 double errf=Newton1dmax(f, f1, f2, ddsIPWindowC, &p, dfshift, fshift, dsIPWindowC, dfshift, epf); |
1403 int result=0; | 1403 int result=0; |
1404 double inp=f2; | 1404 double inp=f2; |
1405 int k1=ceil(inp-B); if (k1<0) k1=0; | 1405 int k1=ceil(inp-B); if (k1<0) k1=0; |
1406 int k2=floor(inp+B); if (k2>=N/2) k2=N/2-1; | 1406 int k2=floor(inp+B); if (k2>=N/2) k2=N/2-1; |
1407 struct l_hx {int N; int k1; int k2; double* c; double* d; int M; double iH2; cdouble* x; double f1; double dipwindow; double ipwindow;} p={N, k1, k2, c, d, M, iH2, x, f1, 0, 0}; | 1407 struct l_hx {int N; int k1; int k2; double* c; double* d; int M; double iH2; cdouble* x; double f1; double dipwindow; double ipwindow;} p={N, k1, k2, c, d, M, iH2, x, f1, 0, 0}; |
1408 int dfshift=int(&((l_hx*)0)->dipwindow);// fshift=int(&((l_hx*)0)->ipwindow); | 1408 int dfshift=offsetof(l_hx, dipwindow);// fshift=int(&((l_hx*)0)->ipwindow); |
1409 | 1409 |
1410 double tmp=Newton(f2, ddsIPWindowDuo, &p, dfshift, epf, 100, 1e-256, fmin, fmax); | 1410 double tmp=Newton(f2, ddsIPWindowDuo, &p, dfshift, epf, 100, 1e-256, fmin, fmax); |
1411 if (tmp!=-1 && f2>fmin && f2<fmax) result=1; | 1411 if (tmp!=-1 && f2>fmin && f2<fmax) result=1; |
1412 else | 1412 else |
1413 { | 1413 { |