PASDK-218:Update CB PCM OVR detection logic.
authorFrank Livingston <frank-livingston@ti.com>
Sun, 23 Jul 2017 19:35:22 +0000 (14:35 -0500)
committerFrank Livingston <frank-livingston@ti.com>
Sun, 23 Jul 2017 19:56:45 +0000 (14:56 -0500)
NOTE: CB write currently allocates max channels worth of data in PCM
buffer for each write. However, writer only writes active channels as
determined by AF CC stream. For THD 192 kHz, max channel count is 6, but
CB write will allocate space for 32 channels. This is gross
overallocation of memory for CB.

pasdk/common/aspDecOpCircBuf_common.h
pasdk/shared/config.bld
pasdk/test_arm/framework/aspDecOpCircBuf_slave.c
pasdk/test_dsp/framework/itopo/patchs.c

index fc6c9f186da918ac85dd54a06ca07498b9440b50..ac7a366cd774f664bc590cdbb87c7b5acca1ba45 100644 (file)
@@ -73,10 +73,12 @@ All rights reserved.
 #define ASP_DECOP_CB_MAX_NUM_PCM_CH_MAT         ( 32 )      // decoder output circular buffer maximum number audio PCM channels for MAT
 #define ASP_DECOP_CB_MAX_PCM_FRAME_LEN_48kMAT   ( 4*256 )   // decoder output circular buffer maximum PCM frame length at 48kHz sampling rate
 
-// (***) !!! REVISIT!!! FL: THD 192 kHz "fudge factor" for CB PCM buffer size.
+// (***) FL: !!! REVISIT!!! THD 192 kHz "fudge factor" for CB PCM buffer size.
 // Using this factor in PCM buffer size definition, buffer large enough to execute 192 kHz w/o CB OVR/UND.
 // Need to define CB size in different terms than existing macros.
-#define THD_HSR_FUDGE_FACTOR                    ( 488640 )  
+// (***) FL: !!! REVISIT!!! Allocating memory for max # channels (e.g. 32 for THD).
+// GROSS over allocation for THD 192 kHz, 6ch max.
+#define THD_HSR_FUDGE_FACTOR                    ( 368640 + 240000 )  
 #define ASP_DECOP_CB_PCM_BUF_SZ                 ( ASP_DECOP_CB_MAX_NUM_PCM_CH * ASP_DECOP_CB_MAX_NUM_PCM_FRAMES * ASP_DECOP_CB_MAX_PCM_FRAME_LEN + THD_HSR_FUDGE_FACTOR)
 // FL: unused
 //#define ASP_DECOP_CB_PCM_BUF_SZ_32CH48kMAT      ( ASP_DECOP_CB_MAX_NUM_PCM_CH_MAT * ASP_DECOP_CB_MAX_NUM_PCM_FRAMES * ASP_DECOP_CB_MAX_PCM_FRAME_LEN_48kMAT )
index 480aad2614658f753ab93f22bfdbfe52fb48b7e0..90c148118f777f9fed027798c69ed52cdec42c47 100644 (file)
@@ -45,14 +45,14 @@ var Build = xdc.useModule('xdc.bld.BuildEnvironment');
  *  -------------------------------------------------------------
  *    0C00_0000   0008_0000  ( 512 KB)  SR_MSMC     (ipc:data)
  *    0C08_0000   0004_0000  ( 256 KB)  HOST_MSMC   (code, data)
- *    0C0C_0000   0004_0000  ( 256 KB)  CORE_MSMC   (code, data)
+ *    0C0C_0000   0004_0000  ( 256 KB)  CORE0_MSMC  (code, data)
  *    8000_0000   0020_0000  (   2 MB)  SR_0        (ipc)
- *    8020_0000   00E0_0000  (  14 MB)  SR_DDR3     (ipc:data)
+ *    8020_0000   0060_0000  (   6 MB)  COMMON_DDR3 (data)
  *    8100_0000   0100_0000  (  16 MB)  COMMON2_DDR3(code, data)      // aligned to MAR memory region  
- *    8200_0000   0060_0000  (   6 MB)  COMMON_DDR3 (data)
- *    8260_0000   0320_0000  (  50 MB)  HOST_DDR3   (code, data)
- *    8580_0000   0400_0000  (  64 MB)  CORE0_DDR3  (code, data)
- *    8980_0000   7680_0000  (1896 MB)  DDR3        (code, data)
+ *    8200_0000   0100_0000  (  16 MB)  SR_DDR3     (ipc:data)
+ *    8300_0000   0300_0000  (  48 MB)  HOST_DDR3   (code, data)
+ *    8600_0000   0400_0000  (  64 MB)  CORE0_DDR3  (code, data)
+ *    8A00_0000   7600_0000  (1888 MB)  DDR3        (code, data)
  */
 
 var SR_MSMC = {
@@ -69,13 +69,13 @@ var SR_0 = {
 
 var SR_DDR3 = {
         name: "SR_DDR3", space: "data", access: "RW",
-        base: 0x80200000, len: 0x00E00000,
+        base: 0x82000000, len: 0x01000000,
         comment: "SR DDR3 Memory"
     };
 
 var COMMON_DDR3 = {
         name: "COMMON_DDR3", space: "data", access: "RW",
-        base: 0x82000000, len: 0x00600000,
+        base: 0x80200000, len: 0x00600000,
         comment: "COMMON DDR3 Memory"
     };
     
@@ -87,7 +87,7 @@ var COMMON2_DDR3 = {  // Common Structure for shared data, Non cacheable
 
 var DDR3 = {
         name: "DDR3", space: "code/data", access: "RW",
-        base: 0x89800000, len: 0x76800000,
+        base: 0x8A000000, len: 0x76000000,
         comment: "DDR3 Memory"
     };
 
@@ -112,7 +112,7 @@ Build.platformTable["ti.platforms.evmTCI66AK2G02:host"] = {
         
         [ "HOST_DDR3",  {
             name: "HOST_DDR3", space: "code/data", access: "RWX",
-            base: 0x82600000, len: 0x03200000,
+            base: 0x83000000, len: 0x03000000,
             comment: "HOST DDR3"
         }], 
         
@@ -172,7 +172,7 @@ Build.platformTable["ti.platforms.evmTCI66AK2G02:core0"] = {
         
         [ "CORE0_DDR3",  {
             name: "CORE0_DDR3", space: "code/data", access: "RWX",
-            base: 0x85800000, len: 0x04000000,
+            base: 0x86000000, len: 0x04000000,
             comment: "CORE0 DDR3"
         }], 
         
index 79c645bf5bf92f409e311f979c3ef236091ad078..f82709b398c6b8e3d8c485615df90ca31c39e6b3 100644 (file)
@@ -444,6 +444,7 @@ Int cbWriteAf(
     PAF_AudioData *pPcmBuf; UInt8 *pMetaBuf; int nextWrtIdx;PAF_AudioFrame *pAfCbNextAf; 
     PAF_AudioFrame *pAfCbRd;
     PAF_AudioData *pPcmBufRd, *pPcmBufWrt;
+    Int8 pcmOvr;
     
     // Get gate handle
     gateHandle = pCbCtl->gateHandle;
@@ -513,33 +514,68 @@ Int cbWriteAf(
             //    return ASP_DECOP_CB_PCM_WRITE_OVERFLOW;
             //}
 
-            pAfCb = &pCb->afCb[pCb->afWrtIdx]; // get CB AF to be written
+            // get CB AF write info
+            pAfCb = &pCb->afCb[pCb->afWrtIdx];                      // get CB AF to be written
+            pPcmBufWrt = pAfCb->data.sample[0];                     // get current location in PCM buffer to be written
+            // (***) FL: currently no metadata buffer overflow detection
+            pMetaBuf = pAfCb->pafPrivateMetadata[0].pMdBuf;         // get current location in MD buffer to be written
             
-            // Get reader current PCM buffer location for PCM buffer overflow check
-            pAfCbRd = &pCb->afCb[pCb->afRdIdx];
+            // get CB AF read info
+            pAfCbRd = &pCb->afCb[pCb->afRdIdx];                     // get CB AF being read
             //pPcmBufRd = pAfCbRd->data.sample[0];                    // FL: starting location of PCM samples for AF being read
             pPcmBufRd = pAfCbRd->data.sample[0] + pCb->pcmRdIdx;    // FL: current location of PCM samples for AF being read
             
-            pPcmBufWrt = pAfCb->data.sample[0];             // get current location in PCM buffer to be written
-            // (***) FL: currently no metadata buffer overflow detection
-            pMetaBuf = pAfCb->pafPrivateMetadata[0].pMdBuf; // get current location in MD buffer to be written
-            
-            // check PCM buffer overflow
+            // Check PCM buffer overflow
             pPcmBuf = pPcmBufWrt;
+            pcmOvr = 0;
             for (i = 0; i < pCb->maxAFChanNum; i++)
             {
-                // check PCM buffer wrap
+                //
+                // Writes of PCM to PCM CB use CC stream, but this isn't considered here.
+                // For each channel which *can* be written, check the current reader location won't be overwritten.
+                // The current reader location is the earliest channel which *could have been* written for that CB AF.
+                //
                 if ((pPcmBuf + pAfWrt->sampleCount) >= pCb->pcmBufEnd)
                 {
-                    pPcmBuf = pCb->pcmBuf;
+                    // this write will wrap
+                    
+                    // check OVR before wrap
+                    if ((pPcmBuf < pPcmBufRd) && 
+                        ((pPcmBuf + pAfWrt->sampleCount) >= pPcmBufRd))
+                    {
+                        pCb->errPcmOvrCnt++;
+                        pcmOvr = 1;
+                    }
+                    
+                    if (pcmOvr == 0)
+                    {
+                        // wrap pointer
+                        pPcmBuf = pCb->pcmBuf;   
+                        // check OVR after wrap
+                        if ((pPcmBuf < pPcmBufRd) && 
+                            ((pPcmBuf + pAfWrt->sampleCount) >= pPcmBufRd))
+                        {
+                            pCb->errPcmOvrCnt++;
+                            pcmOvr = 1;
+                        }                                                                
+                    }
                 }
-                
-                // check PCM buffer overflow
-                if ((pPcmBuf < pPcmBufRd) && 
+                else if ((pPcmBuf < pPcmBufRd) && 
                     ((pPcmBuf + pAfWrt->sampleCount) >= pPcmBufRd))
                 {
-                    pCb->errPcmOvrCnt++;;
+                    // this write won't wrap
                     
+                    pCb->errPcmOvrCnt++;
+                    pcmOvr = 1;
+                }
+                else
+                {
+                    // update pointer
+                    pPcmBuf += pAfWrt->sampleCount;                                        
+                }
+                
+                if (pcmOvr == 1)
+                {
                     Log_info2("cbWriteAf: ERROR: PCM CB overflow, sampleCount=%d, numPcmSampsPerCh=%d", 
                          pAfWrt->sampleCount, pCb->numPcmSampsPerCh);
             
@@ -554,10 +590,11 @@ Int cbWriteAf(
             
                     return ASP_DECOP_CB_PCM_WRITE_OVERFLOW;
                 }
-                
-                pPcmBuf += pAfWrt->sampleCount;
             }
             
+            // (***) FL: !!! REVISIT!!! 
+            //           Allocating memory for max # channels (e.g. 32 for THD).
+            //           GROSS over allocation for THD 192 kHz, 6ch max.
             // configure AF sample pointers
             pPcmBuf = pPcmBufWrt;
             for (i = 0; i < pCb->maxAFChanNum; i++)
@@ -584,6 +621,7 @@ Int cbWriteAf(
                 pMetaBuf += PAF_MAX_PRIVATE_MD_SZ;
             }
 
+#if 0 // FL: unused
             nextWrtIdx = 0;
             if ((pCb->afWrtIdx + 1) >= pCb->maxNumAfCb)
             {
@@ -596,10 +634,11 @@ Int cbWriteAf(
                 // next audio frame will be current audio frame + 1
                 nextWrtIdx = pCb->afWrtIdx + 1;
             }
-
+            
             pAfCbNextAf = &pCb->afCb[nextWrtIdx]; // +1 or last AF if overflow
-            pAfCbNextAf->data.sample[0] = &pAfCb->data.sample[pCb->maxAFChanNum - 1][pAfWrt->sampleCount];// pAfCb->data.sample[15] + (pAfCb->sampleCount * sizeof(PAF_AudioData));
-
+            pAfCbNextAf->data.sample[0] = &pAfCb->data.sample[pCb->maxAFChanNum - 1][pAfWrt->sampleCount]; // pAfCb->data.sample[15] + (pAfCb->sampleCount * sizeof(PAF_AudioData));
+#endif
+            
             // write audio frame information updated by decoder
             pAfCb->sampleDecode = pAfWrt->sampleDecode;
             PAF_PROCESS_COPY(pAfCb->sampleProcess, pAfWrt->sampleProcess);
@@ -612,6 +651,7 @@ Int cbWriteAf(
             pAfCb->pafBsMetadataUpdate = pAfWrt->pafBsMetadataUpdate;    /* indicates whether bit-stream metadata update */
             pAfCb->numPrivateMetadata  = pAfWrt->numPrivateMetadata;     /* number of valid private metadata (0 or 1 if metadata filtering enabled) */
             pAfCb->bsMetadata_offset   = pAfWrt->bsMetadata_offset;      /* offset into audio frame for change in bsMetadata_type field */
+            
             // write PCM samples
             streamMask = pAfWrt->fxns->channelMask(pAfWrt, pAfCb->channelConfigurationStream);
             for (i = 0; i < pCb->maxAFChanNum; i++)
@@ -648,18 +688,22 @@ Int cbWriteAf(
             #endif
 
             // prepare metadata buffer pointers according to the metadata and buffer sizes
-            for (i=0; i < pAfWrt->numPrivateMetadata; i++)
+            for (i = 0; i < pAfWrt->numPrivateMetadata; i++)
             {
                 UInt8 *nextMdBuf;
-                if(i == 0)
-                    nextMdBuf = (pAfCb->pafPrivateMetadata[0].pMdBuf + pAfWrt->pafPrivateMetadata[0].size);
+                if (i == 0)
+                {
+                    nextMdBuf = (pAfCb->pafPrivateMetadata[0].pMdBuf + pAfWrt->pafPrivateMetadata[0].size);                    
+                }
                 else
-                    nextMdBuf = (pAfCb->pafPrivateMetadata[i-1].pMdBuf + pAfWrt->pafPrivateMetadata[i-1].size);
-                if(nextMdBuf >= pCb->metaBufEnd) // metadata buffer overflow
+                {
+                    nextMdBuf = (pAfCb->pafPrivateMetadata[i-1].pMdBuf + pAfWrt->pafPrivateMetadata[i-1].size);                    
+                }
+                if (nextMdBuf >= pCb->metaBufEnd) // metadata buffer overflow
                 {
                     pAfCb->pafPrivateMetadata[i].pMdBuf = pCb->metaBuf;
                 }
-                else if(i != 0)
+                else if (i != 0)
                 {
                     pAfCb->pafPrivateMetadata[i].pMdBuf = nextMdBuf;
                 }
@@ -676,7 +720,7 @@ Int cbWriteAf(
 
             Cache_inv(pAfCb->pafPrivateMetadata, pAfWrt->numPrivateMetadata*sizeof(PAF_PrivateMetadata *), Cache_Type_ALLD, 0); // FL: this is write back and invalidate??
             Cache_wait();
-            for (i=0; i<pAfCb->numPrivateMetadata; i++) // only write back numPrivateMetadata
+            for (i = 0; i < pAfCb->numPrivateMetadata; i++) // only write back numPrivateMetadata
             {
                 //Log_info4("cbWriteAf: AF: %d nummd: %d offset: %d size: %d ", pCb->afWrtIdx, pAfCb->numPrivateMetadata, pAfCb->pafPrivateMetadata[i].offset,  pAfCb->pafPrivateMetadata[i].size);
                 Cache_wb(pAfCb->pafPrivateMetadata[i].pMdBuf, pAfCb->pafPrivateMetadata[i].size, Cache_Type_ALLD, 0);
@@ -689,7 +733,7 @@ Int cbWriteAf(
             }
 
             pCb->afCb[pCb->afWrtIdx].data.sample[0] = &pAfCb->data.sample[pCb->maxAFChanNum - 1][pAfWrt->sampleCount];
-            if(pAfWrt->numPrivateMetadata > 0)
+            if (pAfWrt->numPrivateMetadata > 0)
             {
                 pCb->afCb[pCb->afWrtIdx].pafPrivateMetadata[0].pMdBuf = pAfCb->pafPrivateMetadata[pAfWrt->numPrivateMetadata - 1].pMdBuf + pAfWrt->pafPrivateMetadata[pAfWrt->numPrivateMetadata - 1].size;
             }
index 4887b32b55b738b0f5e86a5c1806469f41d04c3f..c0bc563839d0cc8376210f5094cceeb1dcb6fa23 100644 (file)
@@ -53,13 +53,13 @@ All rights reserved.
 // NOT performing PCM high-sampling rate + SRC + CAR benchmarking
 //
 
-////#define _AE0_
+//#define _AE0_
 #define _SRC4_
-//#define _CAR_
-//#define _OAR_
-////#define _DAP_
-//#define _BMDA_
-////#define _ML0_
+#define _CAR_
+#define _OAR_
+//#define _DAP_
+#define _BMDA_
+//#define _ML0_
 
 #else // _ENABLE_BENCHMARK_PCMHSR_SRC_CAR_
 //