Ejemplo n.º 1
0
int main(int argc, char** argv) {
  cbuf *cb1 = cbuf_alloc();

  // make sure the cbuf grows and shrinks appropriately
  int capacity = cbuf_capacity(cb1);
  check(capacity > 0, "Initial capacity > 0");
  check(cbuf_size(cb1) == 0, "Initial size == 0");

  for(int i = 0; i < capacity; i++) {
    cbuf_update(cb1, 60, 1.291);
  }

  check(cbuf_size(cb1) == cbuf_capacity(cb1), "Size is allowed to grow to capacity");

  cbuf_update(cb1, 60, 1.291);

  // inserting one more than what the original structure could contain
  int new_capacity = cbuf_capacity(cb1);
  check(new_capacity > capacity, "Capacity grows when necessary");

  // inserting an update that's > 5 minutes older than all of the data
  // in the structure
  cbuf_update(cb1, 60 + 6 * 60, 1.291);
  check(cbuf_capacity(cb1) < new_capacity, "Capacity shrinks when able");
  check(cbuf_size(cb1) == 1, "Aged out records are removed correctly");

  cbuf_free(cb1);

  return 0;
}
static void aud_ftm_play_tone( void * pCtxt )
{
  int32  size, capacity;
    Aud_FTM_DrvCtxt_T * pDrvCtxt = (Aud_FTM_DrvCtxt_T *)pCtxt;

  do
      {
          aud_ftm_cbuf_read(&(pDrvCtxt->fifo_data_buf),(uint8 *)pAud_ftm_rx_buf,
                             (pDrvCtxt->nRx_blk_convey_samples)*sizeof(int16) );

          audio_ftm_hw_write( pDrvCtxt->pDevCtxt,(void *)pAud_ftm_rx_buf,
            (uint32)pDrvCtxt->nRx_blk_convey_samples);

          /* determine if needing fillful new data */
          size=cbuf_data_size(&(pDrvCtxt->fifo_data_buf));
          capacity=cbuf_capacity(&(pDrvCtxt->fifo_data_buf));

      if( pDrvCtxt->bStart != TRUE ) break;

          if(size <= (capacity/2))
          {
            DALSYS_EventCtrl(pDrvCtxt->hReq_Data_Event, 0,0,NULL,0);
          }

      }while(1);

    pthread_exit(0);
}
static void aud_ftm_tone_generator(void *pCtxt)
{
  int32  size, capacity;
  uint16  i, channels;
    int16   sample;
    Aud_FTM_DrvCtxt_T * pDrvCtxt = (Aud_FTM_DrvCtxt_T *)pCtxt;

    channels=pDrvCtxt->client_param.channel;

  do
      {
          DALSYS_EventWaitTimeout(pDrvCtxt->hReq_Data_Event, 500);   /* 500ms timeout */
          if( pDrvCtxt->bStart != TRUE ) break;

          /* determine if needing fillful new data */
          size=cbuf_data_size(&(pDrvCtxt->fifo_data_buf));
          capacity=cbuf_capacity(&(pDrvCtxt->fifo_data_buf));

        /* generate data */
        DALSYS_memset(pTmpBuf,0,capacity-size-4);

        for(i=0; i<((capacity-size-4)/sizeof(int16)); i++)
        {
          sample=audio_ftm_dtmf_tone_sample_gen(&(pDrvCtxt->dtmfGen) ,pDrvCtxt->nDTMF_Gain);
          *(pTmpBuf+i)=sample;
                if(channels == AUDIO_FTM_CHN_2)
                {
                   i++;
                   *(pTmpBuf+i)=sample;
                }
        }

        aud_ftm_cbuf_write (&(pDrvCtxt->fifo_data_buf),(uint8 *)pTmpBuf,(int32)(capacity-size-4));

      }while(1);

    pthread_exit(0);
}