chenlh
2025-08-29 faba6b022b86f066d95b1cfdf752573724d5fbcd
src/tob.cpp
@@ -16,6 +16,7 @@
#include "../drv/memory.h"
//#define DEBUG
#ifdef DEBUG
#define dbg_printf printf
@@ -95,7 +96,6 @@
   u32 size = sizeof(FlowChartHead);
   u32 nPhyInput =0 ,nPhyOutput=0;
   frames = new Frames(head->dsp_buffer_num[dsp_index]);
   do {
@@ -187,18 +187,57 @@
   if (size != nbytes) {
      dbg_printf("check flowchart some error!\n");
   }
   dbg_printf("Phy InputNum %d, Output Num %d\n",nPhyInput,nPhyOutput);
//   dbg_printf("Phy InputNum %d, Output Num %d\n",nPhyInput,nPhyOutput);
   SetNumOfChannels(IntDataType::TDM , nPhyInput, nPhyOutput);
   return    ErrStatus::SUCCESS;
}
#if 1//DEBUG
   const s8* type_string[ModuleType::PROC_COUNT] = {
         "none"
         ,"input"
         ,"meter"
         ,"peq"
         ,"expander"
         ,"compresser"
         ,"limiter"
         ,"mixer"
         ,"delay"
         ,"crossover"
         ,"output"
         ,"gain"
         ,"nhs"
         ,"gain sharing am"
         ,"agc"
         ,"aec"
         ,"ans"
         ,"sysctrl"
         ,"shelf"
         ,"selector"
         ,"gating am"
         ,"spl"
         ,"gating"
         ,"ducker"
         ,"reverb"
         ,"echo"
         ,"geq"
         ,"fir"
         ,"afc"
         ,"signal gen"
         ,"pitch"
         ,"route"
         ,"dummuy input"
         ,"dummy output"
   };
#endif
ErrStatus ToB::CreateModuleV1(const u8* bin, u32 nbytes)
{
   FlowChartHead* head = (FlowChartHead*)bin;
   u32 size = sizeof(FlowChartHead);
   u16 nPhyInput[IntDataType::COUNT] = { 0,0,0 }, nPhyOutput[IntDataType::COUNT] = { 0,0,0 };
   s32 len =0;
   frames = new Frames(head->dsp_buffer_num[dsp_index]); // C H G
   frames = new Frames(head->dsp_buffer_num[dsp_index]);
   do {
      const Module* pmod = (Module*)(bin+ size);  size += sizeof(Module);
@@ -225,27 +264,33 @@
      if (pmod->mDsp != dsp_index)  continue;
#ifdef DEBUG
      printf("Module ID %d type %d rxnum %d txnum %d tag %d. \n",pmod->mID ,pmod->mType, pmod->mRxNum,pmod->mTxNum,pmod->mTag);
      printf("Module ID %d type %d %s rxnum %d txnum %d tag %d. \n",pmod->mID ,pmod->mType, type_string[pmod->mType], pmod->mRxNum,pmod->mTxNum,pmod->mTag);
#endif
      IModule* m = CreateBaseModule(pmod->mType,pmod->mTag, mRxNum,mTxNum);
      IModule* m = CreateBaseModule(pmod->mType, pmod->mTag, mRxNum, mTxNum);
      if(!m) {
         dbg_printf("Module ID Create fail.\n", pmod->mID);
         continue;
      }
      m->SetModuleInfo(pmod->mID ,pmod->mType,pmod->mTag);
//      int ddr = sram_free_space(SRAM_DDR,mem_any);
//      int ccm = sram_free_space(SRAM_L2,mem_any);
//      int l1 = sram_free_space(SRAM_L1,mem_heap);
//      printf("ddr %d ccm %d l1 %d.\n",ddr, ccm ,l1);
      m->SetModuleInfo(pmod->mID ,pmod->mType, pmod->mTag);
      mList.push_back(m);
      if(pmod->mID >= mModuleIndex.size()) {
         mModuleIndex.resize(pmod->mID + 1, 0);
      }
      mModuleIndex[pmod->mID] = ++mModuleNum  ;
      mModuleIndex[pmod->mID] = ++mModuleNum;
//      printf("Module id:%d, Tx buffer id:", pmod->mID);
      for (size_t i = 0; i < mTxNum && !bOutput; i++){
//         printf("bid %d", mTxbufID[i]);
         printf("bid %d, ", mTxbufID[i]);
         if (mTxbufID[i] > 0) {
            Frame* pcm = frames->GetFrame(mTxbufID[i]-1 );
            Frame* pcm = frames->GetFrame(mTxbufID[i]-1);
            m->SetOutputChannelDataPtr(i, pcm);
            if (bInput && mPhyID[i].mIntType < IntDataType::COUNT) {
@@ -253,7 +298,7 @@
                  nPhyInput[mPhyID[i].mIntType] = mPhyID[i].mPhyID;
               m->SetInputChannelDataPtr(i, pcm);
               SetRxChannelPtr(static_cast<IntDataType>(mPhyID[i].mIntType), mPhyID[i].mPhyID-1, pcm->Data());
//               printf("phy_id %d", mPhyID[i].mPhyID);
               printf("phy_id %d\n", mPhyID[i].mPhyID);
            }
         }
         else {
@@ -284,7 +329,16 @@
//      printf("\n");
      m->Init();
      //paramset->GetParamEntry(m->GetModuleType())(m, (uvoid*)pmod->mParamaddr, len);
//      paramset->GetParamEntry(m->GetModuleType())(m, (uvoid*)pmod->mParamaddr, len);
      // 获取模块类型
      u32 moduleType = m->GetModuleType();
      // 从 paramset 中获取对应的参数控制函数指针
      ParamCtrl_fn paramEntry = paramset->GetParamEntry(moduleType);
      // 获取模块参数地址
      void* paramAddr = (uvoid*)pmod->mParamaddr;
      // 调用参数控制函数
      u32 result = paramEntry(m, paramAddr, len);
   } while (size < nbytes);
   if (size != nbytes) {
@@ -331,13 +385,10 @@
{
   if(processed) {
      for (auto iter = mList.begin(); iter < mList.end(); iter++) {
//         if ((*iter)->GetModuleID() == 166)
//            continue;
         if((*iter)->GetModuleType() <= 5) {
            printf("%d ", (*iter)->GetModuleID());
//         if(((*iter)->GetModuleType() >= 9) && ((*iter)->GetModuleType() <= 9)) {
//            printf("%d ", (*iter)->GetModuleID());
            (*iter)->Proc();
         }
//         }
      }
//      printf("\n");
   }
@@ -417,8 +468,10 @@
   for (std::vector<IModule*>::iterator iter = mList.begin();
      iter != mList.end() ; iter++) {
      size = (*iter)->GetLevel(buffer + n );
//      printf("proc %s level num:%d\n",type_string[(*iter)->GetModuleType()],size);
      n += size;
   }
   return n;
}