From 5ddb9db0d940e6084920224fc3319eb57662c6ea Mon Sep 17 00:00:00 2001 From: slmdev Date: Thu, 25 Jul 2024 21:44:18 +0200 Subject: [PATCH] v0.7.7 --- src/cmdline.cpp | 105 ++------------ src/cmdline.h | 1 - src/file/sac.cpp | 7 +- src/file/sac.h | 1 - src/libsac/cost.h | 32 +++++ src/libsac/libsac.cpp | 304 ++++++++++++++++++----------------------- src/libsac/libsac.h | 6 +- src/libsac/pred.h | 1 - src/libsac/profile.cpp | 52 +------ src/libsac/profile.h | 15 +- src/main.cpp | 2 +- src/opt/dds.h | 2 +- src/pred/bias.h | 2 +- src/pred/lms_cascade.h | 10 +- 14 files changed, 205 insertions(+), 335 deletions(-) diff --git a/src/cmdline.cpp b/src/cmdline.cpp index 8449fcd..672a82c 100644 --- a/src/cmdline.cpp +++ b/src/cmdline.cpp @@ -7,14 +7,12 @@ CmdLine::CmdLine() :mode(ENCODE) { - opt.profile=0; opt.optimize=0; - opt.sparse_pcm=0; + opt.sparse_pcm=1; opt.reset_profile=0; opt.zero_mean=1; opt.max_framelen=8; - opt.dds_search_radius=0.15; opt.optimize_cost=opt.SearchCost::Entropy; opt.optimize_search=opt.SearchMethod::DDS; } @@ -33,8 +31,6 @@ void CmdLine::PrintWav(const AudioFile &myWav) void CmdLine::PrintMode() { std::cout << " Profile: "; - if (opt.profile==0) std::cout << "normal"; - else if (opt.profile==1) std::cout << "high"; std::cout << " " << opt.max_framelen << "s"; if (opt.zero_mean) std::cout << " zero-mean"; if (opt.sparse_pcm) std::cout << " sparse-pcm"; @@ -59,72 +55,6 @@ void CmdLine::Split(const std::string &str,std::string &key,std::string &val,con } -int CmdLine::ReadConfig(const std::string &fname) -{ - struct profile { - std::vector ols_lambda; - std::vector ols_nu; - std::vector lms_mu0; - std::vector lms_mu1; - std::vector lms_mu2; - std::vector lms_mu_decay; - std::vector lms_pow_decay; - std::vector lms_mu_mix; - } myprofile; - const std::string whites=" \t\n"; - std::ifstream ifile(fname); - - if (ifile.is_open()) { - std::string line,s; - while (std::getline(ifile,line)) { - s=line; - auto firstPos = s.find_first_of("#"); // remove comment - if (firstPos!=std::string::npos) { - s=s.substr(0,firstPos); - } - StrUtils::RemoveWhite(s,whites); - if (s.length()) { - - StrUtils::StrUpper(s); - auto splitPos=s.find_first_of("="); - if (splitPos!=std::string::npos) { - //process key=val pair - std::string key,val; - key=s.substr(0,splitPos); - val=s.substr(splitPos+1); - StrUtils::RemoveWhite(val,whites); - StrUtils::RemoveWhite(key,whites); - if (key=="OLS_LAMBDA") StrUtils::SplitFloat(val,myprofile.ols_lambda); - else if (key=="OLS_NU") StrUtils::SplitFloat(val,myprofile.ols_nu); - else if (key=="LMS_MU0") StrUtils::SplitFloat(val,myprofile.lms_mu0); - else if (key=="LMS_MU1") StrUtils::SplitFloat(val,myprofile.lms_mu1); - else if (key=="LMS_MU2") StrUtils::SplitFloat(val,myprofile.lms_mu2); - else if (key=="LMS_MU_DECAY") StrUtils::SplitFloat(val,myprofile.lms_mu_decay); - else if (key=="LMS_POW_DECAY") StrUtils::SplitFloat(val,myprofile.lms_pow_decay); - else if (key=="LMS_MU_MIX") StrUtils::SplitFloat(val,myprofile.lms_mu_mix); - else std::cerr << " warning: unknown option: '" << line << "'\n"; - //std::cout << "'" << s << "'\n"; - } else std::cerr << " warning: unknown option: '" << line << "'\n"; - } - } - for (auto &x:myprofile.ols_lambda) std::cout << x << ' '; - - opt.profiledata.Init(12,0); - if (myprofile.ols_lambda.size()) opt.profiledata.Set(0,myprofile.ols_lambda); - if (myprofile.ols_nu.size()) opt.profiledata.Set(1,myprofile.ols_nu); - - std::cout << '\n';for (auto &x:myprofile.ols_nu) std::cout << x << ' '; - std::cout << '\n';for (auto &x:myprofile.lms_mu0) std::cout << x << ' '; - std::cout << '\n';for (auto &x:myprofile.lms_mu1) std::cout << x << ' '; - std::cout << '\n';for (auto &x:myprofile.lms_mu2) std::cout << x << ' '; - std::cout << '\n';for (auto &x:myprofile.lms_mu_decay) std::cout << x << ' '; - std::cout << '\n';for (auto &x:myprofile.lms_pow_decay) std::cout << x << ' '; - std::cout << '\n';for (auto &x:myprofile.lms_mu_mix) std::cout << x << ' '; - //std::cout << "'" << val << "' '" << key << "'\n"; - return 0; - } else return 1; -} - int CmdLine::Parse(int argc,char *argv[]) { if (argc < 2) { @@ -151,25 +81,20 @@ int CmdLine::Parse(int argc,char *argv[]) if (val.length()) opt.verbose_level=stoi(val); else opt.verbose_level=1; } - else if (key=="--NORMAL") opt.profile=0; - else if (key=="--HIGH") { - opt.profile=1; + else if (key=="--NORMAL") { + opt.optimize=0; + } else if (key=="--HIGH") { opt.optimize=1; - opt.optimize_fraction=0.20; - opt.optimize_maxnfunc=150; - opt.sparse_pcm=0; + opt.optimize_fraction=0.05; + opt.optimize_maxnfunc=100; } else if (key=="--VERYHIGH") { - opt.profile=1; opt.optimize=1; - opt.optimize_fraction=0.50; - opt.optimize_maxnfunc=1000; - opt.sparse_pcm=1; + opt.optimize_fraction=0.20; + opt.optimize_maxnfunc=250; } else if (key=="--BEST") { - opt.profile=1; opt.optimize=1; - opt.optimize_maxnfunc=1500; - opt.optimize_fraction=0.80; - opt.sparse_pcm=1; + opt.optimize_fraction=0.50; + opt.optimize_maxnfunc=1000; } else if (key=="--RESET-OPT") { opt.reset_profile=1; } else if (key=="--OPTIMIZE") { @@ -188,13 +113,13 @@ int CmdLine::Parse(int argc,char *argv[]) if (val.length()) opt.max_framelen=stoi(val); } else if (key=="--SPARSE-PCM") { - if (val.length()) opt.sparse_pcm=stoi(val); + if (val=="NO" || val=="0") opt.sparse_pcm=0; else opt.sparse_pcm=1; } else if (key=="--STEREO-MS") { opt.stereo_ms=1; } else if (key=="--ZERO-MEAN") { - if (val.length()==0) opt.zero_mean=1; - else if (val=="NO" || val=="0") opt.zero_mean=0; + if (val=="NO" || val=="0") opt.zero_mean=0; + else opt.zero_mean=1; } else std::cout << "warning: unknown option '" << param << "'\n"; } else { if (first) {sinputfile=param;first=false;} @@ -271,10 +196,6 @@ int CmdLine::Process() mySac.setKBPS(kbps); PrintWav(mySac); std::cout << " Profile: "; - switch (mySac.mcfg.profile) { - case 0:std::cout << "Normal";break; - case 1:std::cout << "High";break; - } std::cout << " " << static_cast(mySac.mcfg.max_framelen) << "s"; std::cout << std::endl; std::cout << " Ratio: " << std::fixed << std::setprecision(3) << bps << " bits per sample\n\n"; diff --git a/src/cmdline.h b/src/cmdline.h index 551380b..09da193 100644 --- a/src/cmdline.h +++ b/src/cmdline.h @@ -29,7 +29,6 @@ class CmdLine { public: CmdLine(); int Parse(int argc,char *argv[]); - int ReadConfig(const std::string &fname); int Process(); private: void PrintMode(); diff --git a/src/file/sac.cpp b/src/file/sac.cpp index 50b9e90..06a25dd 100644 --- a/src/file/sac.cpp +++ b/src/file/sac.cpp @@ -27,8 +27,8 @@ int Sac::WriteSACHeader(Wav &myWav) BitUtils::put32LH(buf+6,samplerate); BitUtils::put16LH(buf+10,bitspersample); BitUtils::put32LH(buf+12,numsamples); - buf[16] = mcfg.profile; - buf[17] = mcfg.max_framelen; + buf[16] = mcfg.max_framelen; + buf[17] = 0; // write wav meta data const uint32_t metadatasize=myChunks.GetMetaDataSize(); @@ -55,8 +55,7 @@ int Sac::ReadSACHeader() samplerate=BitUtils::get32LH(buf+6); bitspersample=BitUtils::get16LH(buf+10); numsamples=BitUtils::get32LH(buf+12); - mcfg.profile=buf[16]; - mcfg.max_framelen=buf[17]; + mcfg.max_framelen=buf[16]; mcfg.metadatasize=BitUtils::get32LH(buf+18); ReadData(metadata,mcfg.metadatasize); mcfg.max_framesize=samplerate*static_cast(mcfg.max_framelen); diff --git a/src/file/sac.h b/src/file/sac.h index 3b623c7..29aafbe 100644 --- a/src/file/sac.h +++ b/src/file/sac.h @@ -13,7 +13,6 @@ class Sac : public AudioFile public: struct sac_cfg { - uint8_t profile=0; uint8_t max_framelen=0; uint32_t max_framesize=0; diff --git a/src/libsac/cost.h b/src/libsac/cost.h index 718d51a..43dd79c 100644 --- a/src/libsac/cost.h +++ b/src/libsac/cost.h @@ -80,6 +80,38 @@ class CostEntropyO0 : public CostFunction { } }; +// entropy using order-0 markov model +class CostEntropyO0b : public CostFunction { + public: + CostEntropyO0b(){}; + double Calc(const int32_t *buf,int numsamples) + { + if (numsamples<=0) return 0.0; + int32_t minval = std::numeric_limits::max(); + int32_t maxval = std::numeric_limits::min(); + for (int i=0;imaxval) maxval=val; + if (val counts(maxval-minval+1); + + for (int i=0;iemax_map) emax_map=map_ue; - } - framestats[ch].maxbpn_map=MathUtils::iLog2(emax_map); + param.vn0={(int)round(profile.Get(28)),(int)round(profile.Get(29)),(int)round(profile.Get(30)),(int)round(profile.Get(37))}; + param.vn1={(int)round(profile.Get(31)),(int)round(profile.Get(32)),(int)round(profile.Get(33)),(int)round(profile.Get(38))}; + + param.vmu0={profile.Get(2)/double(param.vn0[0]),profile.Get(3)/double(param.vn0[1]),profile.Get(4)/double(param.vn0[2]),profile.Get(5)/double(param.vn0[3])}; + param.vmudecay0={profile.Get(6),profile.Get(39),profile.Get(46),profile.Get(47)}; + param.vpowdecay0={profile.Get(7),profile.Get(8),profile.Get(50),profile.Get(51)}; + param.mu_mix0=profile.Get(10); + param.mu_mix_beta0=profile.Get(11); + + param.lambda1=profile.Get(12); + param.ols_nu1=profile.Get(13); + param.vmu1={profile.Get(14)/double(param.vn1[0]),profile.Get(15)/double(param.vn1[1]),profile.Get(16)/double(param.vn1[2]),profile.Get(17)/double(param.vn1[3])}; + param.vmudecay1={profile.Get(18),profile.Get(40),profile.Get(48),profile.Get(49)}; + param.vpowdecay1={profile.Get(19),profile.Get(20),profile.Get(21),profile.Get(52)}; + param.mu_mix1=profile.Get(22); + param.mu_mix_beta1=profile.Get(23); + + param.nA=round(profile.Get(24)); + param.nB=round(profile.Get(25)); + param.nS0=round(profile.Get(26)); + param.nS1=round(profile.Get(27)); + + param.beta_sum0=profile.Get(34); + param.beta_pow0=profile.Get(35); + param.beta_add0=profile.Get(36); + + param.beta_sum1=profile.Get(34); + param.beta_pow1=profile.Get(35); + param.beta_add1=profile.Get(36); + + param.mix_nu0=profile.Get(41); + param.mix_nu1=profile.Get(42); + + param.bias_mu0=profile.Get(43); + param.bias_mu1=profile.Get(44); + + param.bias_scale=std::round(profile.Get(45)); } void FrameCoder::PredictFrame(const SacProfile &profile,int from,int numsamples,bool optimize) @@ -144,10 +95,12 @@ void FrameCoder::PredictFrame(const SacProfile &profile,int from,int numsamples, // predict master channel const auto *src0=&samples[0][from]; + int32_t minval = framestats[0].minval; + int32_t maxval = framestats[0].maxval; for (int i=0;iemap(numsamples); + int32_t emax_map=0; + for (int i=0;iemax_map) emax_map=map_ue; + } + framestats[ch].maxbpn_map=MathUtils::iLog2(emax_map); + + CostEntropyO0b cost; + double ent1 = cost.Calc(&error[ch][0],numsamples); + double ent2 = cost.Calc(&emap[0],numsamples); + double r=1.0; + if (ent1!=0.0) r=ent2/ent1; + if (opt.verbose_level>0) std::cout << "entropy: " << ent1 << ' ' << ent2 << ' ' << r << '\n'; + return r; +} + void FrameCoder::EncodeMonoFrame(int ch,int numsamples) { if (opt.sparse_pcm==0) { @@ -252,19 +231,21 @@ void FrameCoder::EncodeMonoFrame(int ch,int numsamples) framestats[ch].enc_mapped=false; encoded[ch]=enc_temp1[ch]; } else { - CalcRemapError(ch,numsamples); + double r = CalcRemapError(ch,numsamples); int size_normal=EncodeMonoFrame_Normal(ch,numsamples,enc_temp1[ch]); - int size_mapped=EncodeMonoFrame_Mapped(ch,numsamples,enc_temp2[ch]); - if (size_normal0) { - std::cout << "sparse frame " << size_normal << " -> " << size_mapped << '\n'; + framestats[ch].enc_mapped=false; + encoded[ch]=enc_temp1[ch]; + + if (r > 1.01) { + int size_mapped=EncodeMonoFrame_Mapped(ch,numsamples,enc_temp2[ch]); + if (size_mapped0) { + std::cout << "sparse frame " << size_normal << " -> " << size_mapped << '\n'; + } + framestats[ch].enc_mapped=true; + encoded[ch]=enc_temp2[ch]; } - framestats[ch].enc_mapped=true; - encoded[ch]=enc_temp2[ch]; } } } @@ -299,37 +280,36 @@ double FrameCoder::GetCost(SacProfile &profile,CostFunction *func,int start_samp return cost; } -void PrintProfile(int iprofile, SacProfile &profile) +void PrintProfile(SacProfile &profile) { Predictor::tparam param; SetParam(param,profile); - if (iprofile==0) { - std::cout << "lpc "; - std::cout << "nA " << std::round(profile.Get(26)) << ' ' << "nB " << std::round(profile.Get(27)) << ' '; - std::cout << "nS0 " << std::round(profile.Get(28)) << ' ' << "nS1 " << std::round(profile.Get(29)) << '\n'; - } else if (iprofile==1) { - std::cout << '\n'; - std::cout << "lpc "; - std::cout << "nA " << std::round(profile.Get(24)) << ' ' << "nB " << std::round(profile.Get(25)) << ' '; - std::cout << "nS0 " << std::round(profile.Get(26)) << ' ' << "nS1 " << std::round(profile.Get(27)) << '\n'; - std::cout << "lms0 "; - for (int i=28;i<=30;i++) std::cout << std::round(profile.Get(i)) << ' '; - std::cout << std::round(profile.Get(37)); - std::cout << '\n'; - std::cout << "lms1 "; - for (int i=31;i<=33;i++) std::cout << std::round(profile.Get(i)) << ' '; - std::cout << std::round(profile.Get(38)); - std::cout << '\n'; - std::cout << "mu_decay "; - for (auto &x : param.vmudecay0) - std::cout << x << ' '; - std::cout << '\n'; - std::cout << "pow_decay "; - for (auto &x : param.vpowdecay0) - std::cout << x << ' '; - std::cout << '\n'; - } + std::cout << '\n'; + std::cout << "lpc "; + std::cout << "nA " << std::round(profile.Get(24)) << ' ' << "nB " << std::round(profile.Get(25)) << ' '; + std::cout << "nS0 " << std::round(profile.Get(26)) << ' ' << "nS1 " << std::round(profile.Get(27)) << '\n'; + std::cout << "lms0 "; + for (int i=28;i<=30;i++) std::cout << std::round(profile.Get(i)) << ' '; + std::cout << std::round(profile.Get(37)); + std::cout << '\n'; + std::cout << "lms1 "; + for (int i=31;i<=33;i++) std::cout << std::round(profile.Get(i)) << ' '; + std::cout << std::round(profile.Get(38)); + std::cout << '\n'; + std::cout << "mu "; + for (std::size_t i=0;i¶ms_to_o switch (opt.optimize_cost) { case opt.SearchCost::L1:CostFunc=new CostMeanRMS();break; case opt.SearchCost::Golomb:CostFunc=new CostGolomb();break; - case opt.SearchCost::Entropy:CostFunc=new CostEntropyO0();break; + case opt.SearchCost::Entropy:CostFunc=new CostEntropyO0b();break; case opt.SearchCost::Bitplane:CostFunc=new CostBitplane();break; default:std::cerr << " error: unknown FramerCoder::CostFunction\n";return; } @@ -378,7 +358,7 @@ void FrameCoder::Optimize(SacProfile &profile,const std::vector¶ms_to_o DDS dds(pb); if (opt.verbose_level>0) std::cout << "\nDDS " << opt.optimize_maxnfunc << "= "; - auto ret = dds.run(cost_func,xstart,opt.optimize_maxnfunc,opt.dds_search_radius); + auto ret = dds.run(cost_func,xstart,opt.optimize_maxnfunc); if (opt.verbose_level>0) std::cout << ret.first << "\n"; const vec1D x_p = ret.second; @@ -386,7 +366,7 @@ void FrameCoder::Optimize(SacProfile &profile,const std::vector¶ms_to_o } if (opt.verbose_level>0) { - PrintProfile(opt.profile, profile); + PrintProfile(profile); } delete CostFunc; } @@ -439,7 +419,7 @@ void FrameCoder::AnalyseMonoChannel(int ch, int numsamples) for (int i=0;imaxval) maxval=val; - else if (val + void FrameCoder::AnalyseShift(int ch,int numsamples) { if (numsamples) { @@ -457,6 +439,8 @@ void FrameCoder::AnalyseShift(int ch,int numsamples) uint32_t ordata=0,xordata=0,anddata=~0; for (int i=0;iy(src[i]); + //std::cout << y << ' '; xordata |= src[i] ^ -(src[i] & 1); anddata &= src[i]; ordata |= src[i]; @@ -482,7 +466,6 @@ void FrameCoder::AnalyseShift(int ch,int numsamples) } } - void FrameCoder::Predict() { for (int ch=0;chlparam(base_profile.coefs.size()); std::iota(std::begin(lparam),std::end(lparam),0); Optimize(base_profile,lparam); - - /*if (opt.profile==0) { - std::vectorlparam(base_profile.coefs.size()); - std::iota(std::begin(lparam),std::end(lparam),0); - Optimize(base_profile,lparam); - } else if (opt.profile==1) { - std::vectorlparam(base_profile.coefs.size()); - std::iota(std::begin(lparam),std::end(lparam),0); - Optimize(base_profile,lparam); - }*/ } PredictFrame(base_profile,0,numsamples_,false); } @@ -561,13 +535,13 @@ void FrameCoder::DecodeProfile(SacProfile &profile,const std::vector &b } } -int FrameCoder::WriteBlockHeader(std::fstream &file, std::vector &framestats,int ch) +int FrameCoder::WriteBlockHeader(std::fstream &file, const std::vector &framestats,int ch) { - uint8_t buf[12]; + uint8_t buf[32]; BitUtils::put32LH(buf,framestats[ch].blocksize); - BitUtils::put16LH(buf+4,framestats[ch].mean); - BitUtils::put16LH(buf+6,framestats[ch].minval); - BitUtils::put16LH(buf+8,framestats[ch].maxval); + BitUtils::put32LH(buf+4,static_cast(framestats[ch].mean)); + BitUtils::put32LH(buf+8,static_cast(framestats[ch].minval)); + BitUtils::put32LH(buf+12,static_cast(framestats[ch].maxval)); uint16_t flag=0; if (framestats[ch].enc_mapped) { flag|=(1<<9); @@ -575,25 +549,25 @@ int FrameCoder::WriteBlockHeader(std::fstream &file, std::vector(buf),12); + BitUtils::put16LH(buf+16,flag); + file.write(reinterpret_cast(buf),18); return 12; } int FrameCoder::ReadBlockHeader(std::fstream &file, std::vector &framestats,int ch) { - uint8_t buf[12]; - file.read(reinterpret_cast(buf),12); + uint8_t buf[32]; + file.read(reinterpret_cast(buf),18); framestats[ch].blocksize=BitUtils::get32LH(buf); - framestats[ch].mean=static_cast(BitUtils::get16LH(buf+4)); - framestats[ch].minval=static_cast(BitUtils::get16LH(buf+6)); - framestats[ch].maxval=static_cast(BitUtils::get16LH(buf+8)); - uint16_t flag=BitUtils::get16LH(buf+10); + framestats[ch].mean=static_cast(BitUtils::get32LH(buf+4)); + framestats[ch].minval=static_cast(BitUtils::get32LH(buf+8)); + framestats[ch].maxval=static_cast(BitUtils::get32LH(buf+12)); + uint16_t flag=BitUtils::get16LH(buf+16); if (flag>>9) framestats[ch].enc_mapped=true; else framestats[ch].enc_mapped=false; framestats[ch].maxbpn=flag&0xff; - return 12; + return 18; } void FrameCoder::WriteEncoded(AudioFile &fout) @@ -638,11 +612,7 @@ void Codec::ScanFrames(Sac &mySac) std::streampos fsize=mySac.getFileSize(); SacProfile profile_tmp; //create dummy profile - switch (mySac.mcfg.profile) - { - case 0:LoadProfileNormal(profile_tmp);break; - case 1:LoadProfileHigh(profile_tmp);break; - } + LoadProfileHigh(profile_tmp); const int size_profile_bytes=profile_tmp.coefs.size()*4; int frame_num=1; @@ -679,7 +649,6 @@ void Codec::EncodeFile(Wav &myWav,Sac &mySac,FrameCoder::coder_ctx &opt) const int numchannels=myWav.getNumChannels(); FrameCoder myFrame(numchannels,max_framesize,opt); - mySac.mcfg.profile = opt.profile; mySac.mcfg.max_framelen = opt.max_framelen; mySac.WriteSACHeader(myWav); @@ -733,7 +702,6 @@ void Codec::DecodeFile(Sac &mySac,Wav &myWav) myWav.WriteHeader(); FrameCoder::coder_ctx opt; - opt.profile=cfg.profile; opt.max_framelen=cfg.max_framelen; FrameCoder myFrame(mySac.getNumChannels(),cfg.max_framesize,opt); diff --git a/src/libsac/libsac.h b/src/libsac/libsac.h index 24e4225..20efc59 100644 --- a/src/libsac/libsac.h +++ b/src/libsac/libsac.h @@ -11,7 +11,6 @@ class FrameCoder { struct coder_ctx { enum SearchCost {L1,Entropy,Golomb,Bitplane}; enum SearchMethod {CMA,DDS}; - int profile=0; int optimize=0; int sparse_pcm=0; int optimize_maxnfunc=0; @@ -23,7 +22,6 @@ class FrameCoder { SearchMethod optimize_search=DDS; SearchCost optimize_cost=L1; double optimize_fraction=0; - double dds_search_radius=0; SacProfile profiledata; }; FrameCoder(int numchannels,int framesize,const coder_ctx &opt); @@ -39,7 +37,7 @@ class FrameCoder { std::vector encoded,enc_temp1,enc_temp2; std::vector framestats; - static int WriteBlockHeader(std::fstream &file, std::vector &framestats, int ch); + static int WriteBlockHeader(std::fstream &file, const std::vector &framestats, int ch); static int ReadBlockHeader(std::fstream &file, std::vector &framestats, int ch); private: void EncodeProfile(const SacProfile &profile,std::vector &buf); @@ -56,7 +54,7 @@ class FrameCoder { void PredictFrame(const SacProfile &profile,int from,int numsamples,bool optimize=false); void UnpredictFrame(const SacProfile &profile,int numsamples); - void CalcRemapError(int ch, int numsamples); + double CalcRemapError(int ch, int numsamples); void EncodeMonoFrame(int ch,int numsamples); void DecodeMonoFrame(int ch,int numsamples); int numchannels_,framesize_,numsamples_; diff --git a/src/libsac/pred.h b/src/libsac/pred.h index c99c447..3002dce 100644 --- a/src/libsac/pred.h +++ b/src/libsac/pred.h @@ -20,7 +20,6 @@ class Predictor { double mix_nu0,mix_nu1; double bias_mu0,bias_mu1; int bias_scale; - }; Predictor(const tparam &p); diff --git a/src/libsac/profile.cpp b/src/libsac/profile.cpp index d53e7cc..8c017de 100644 --- a/src/libsac/profile.cpp +++ b/src/libsac/profile.cpp @@ -1,56 +1,10 @@ #include "profile.h" -void LoadProfileNormal(SacProfile &profile) -{ - const int mo_lpc=32; // maximum ols order - profile.Init(35,0); - profile.Set(0,0.99,0.9999,0.998); // ols-lambda - profile.Set(1,0.0001,10.0,0.001);//ols-nu - profile.Set(2,0.00001,0.008,0.0008);//mu0 - profile.Set(3,0.00008,0.008,0.002);//mu1 - profile.Set(4,0.0001,0.05,0.008);//mu2 - profile.Set(5,0.0,1.0,0.8); // pow-decay0 - profile.Set(6,0.0,1.0,0.8); // pow-decay1 - profile.Set(7,0.0,1.0,0.8); // pow-decay2 - profile.Set(8,0.98,1,1.0); // mu-decay0 - profile.Set(9,0.98,1,1.0); // mu-decay1 - profile.Set(10,0.98,1,1.0); // mu-decay2 - profile.Set(11,0.0001,0.008,0.002);//mu-mix - profile.Set(12,0.8,0.9999,0.95); //mu-mix-beta - - profile.Set(13,0.99,0.9999,0.998); // ols-lambda - profile.Set(14,0.001,10.0,0.001);//ols-nu - profile.Set(15,0.00001,0.008,0.0008);//mu0 - profile.Set(16,0.00008,0.008,0.002);//mu1 - profile.Set(17,0.0001,0.05,0.008);//mu2 - profile.Set(18,0.0,1.0,0.8); // pow-decay0 - profile.Set(19,0.0,1.0,0.8); // pow-decay1 - profile.Set(20,0.0,1.0,0.8); // pow-decay2 - profile.Set(21,0.98,1,1.0); // mu-decay0 - profile.Set(22,0.98,1,1.0); // mu-decay1 - profile.Set(23,0.98,1,1.0); // mu-decay2 - profile.Set(24,0.0001,0.008,0.002);//mu-mix - profile.Set(25,0.8,0.9999,0.95); //mu-mix-beta - - profile.Set(26,4,mo_lpc,16);//ols-order - profile.Set(27,4,mo_lpc,16);//ols-order - profile.Set(28,0,mo_lpc,8);//ols-order - profile.Set(29,0,mo_lpc,8);//ols-order - - profile.Set(30,0,1,0.6);//ols-order - profile.Set(31,0.8,2,0.8);//ols-order - profile.Set(32,0,10,2);//ols-order - - profile.Set(33,1,8,5);//bias_scale - - profile.Set(34,0.1,1.0,1.0);//mix_nu -} - -void LoadProfileHigh(SacProfile &profile) +int LoadProfileHigh(SacProfile &profile) { const int mo_lpc=32; // maximum ols order - profile.Init(53,1); + profile.Init(53); profile.Set(0,0.99,0.9999,0.998); profile.Set(1,0.001,10.0,0.001); @@ -122,4 +76,6 @@ void LoadProfileHigh(SacProfile &profile) profile.Set(51,0.0,1.0,0.8); //pow_decay profile.Set(52,0.0,1.0,0.8); //pow_decay + return profile.coefs.size(); + //profile.Set(53,0.0,1.0,1.0); } diff --git a/src/libsac/profile.h b/src/libsac/profile.h index 9b003aa..1d2ff93 100644 --- a/src/libsac/profile.h +++ b/src/libsac/profile.h @@ -64,17 +64,18 @@ class SacProfile { int32_t blocksize,minval,maxval,mean; Remap mymap; }; + struct coef { float vmin,vmax,vdef; }; - SacProfile():type(0){}; - void Init(int numcoefs,int ptype) + + SacProfile(){}; + void Init(int numcoefs) { coefs.resize(numcoefs); - type=ptype; } - SacProfile(int numcoefs,int type) - :type(type),coefs(numcoefs) + SacProfile(int numcoefs) + :coefs(numcoefs) { } @@ -99,11 +100,9 @@ class SacProfile { return coefs[num].vdef; } else return 0.; } - int type; std::vector coefs; }; -void LoadProfileNormal(SacProfile &profile); -void LoadProfileHigh(SacProfile &profile); +int LoadProfileHigh(SacProfile &profile); #endif // PROFILE_H diff --git a/src/main.cpp b/src/main.cpp index 3ceb496..adbcffe 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -1,7 +1,7 @@ #include "cmdline.h" #include -#define SAC_VERSION "0.7.6" +#define SAC_VERSION "0.7.7" int main(int argc,char *argv[]) { diff --git a/src/opt/dds.h b/src/opt/dds.h index e405304..019bee7 100644 --- a/src/opt/dds.h +++ b/src/opt/dds.h @@ -19,7 +19,7 @@ class DDS : public Opt { double dy = rmin-rmax; return n*(dy/dx)+rmax; } - opt_ret run(opt_func func,const vec1D &xstart,int nfunc_max,double radius=0.1) + opt_ret run(opt_func func,const vec1D &xstart,int nfunc_max) { assert(pb.size()==xstart.size()); diff --git a/src/pred/bias.h b/src/pred/bias.h index e1f15e6..0ad387b 100644 --- a/src/pred/bias.h +++ b/src/pred/bias.h @@ -71,7 +71,7 @@ class BiasEstimator { } public: - BiasEstimator(double lms_mu=0.003,int cnt_scale=32,double nd_sigma=1.5,double nd_lambda=0.998) + BiasEstimator(double lms_mu=0.003,int cnt_scale=5,double nd_sigma=1.5,double nd_lambda=0.998) : mix_ada(32,SSLMS(4,lms_mu)), hist_input(8),hist_delta(8), diff --git a/src/pred/lms_cascade.h b/src/pred/lms_cascade.h index 4402155..61a2848 100644 --- a/src/pred/lms_cascade.h +++ b/src/pred/lms_cascade.h @@ -23,13 +23,13 @@ class LMSCascade { } void Update(double input, double ols_pred) { - double pr=input-ols_pred; + double target=input-ols_pred; + lms_mix.Update(target); + for (int i=0;iUpdate(pr); - pr-=nu*p[i]; - //pr*=nu; + clms[i]->Update(target); + target-=nu*p[i]; } - lms_mix.Update(input-ols_pred); } ~LMSCascade() {