~ubuntu-branches/ubuntu/wily/octave-ltfat/wily

« back to all changes in this revision

Viewing changes to thirdparty/Playrec/pa_dll_playrec.c

  • Committer: Package Import Robot
  • Author(s): Sébastien Villemot, Rafael Laboissiere
  • Date: 2015-07-18 23:36:41 UTC
  • mfrom: (1.1.2)
  • Revision ID: package-import@ubuntu.com-20150718233641-jhuf3f551a3523qc
Tags: 2.1.0+dfsg-1
* Team upload.

[ Rafael Laboissiere ]
* Imported Upstream version 2.1.0+dfsg
* d/rules: Prevent unit testing on armhf and mips.
  This avoids FTBFS on theses architectures (see Bug#765545).
* Unit testing does not need X-window anymore
  + d/rules: Do not use xfvb-run to run the tests.
  + d/control: Drop xauth, xvfb, and gnuplot-nox from Build-Depends.
    Also, the versioned dependency on octave-pkg-dev is relaxed.
* Drop .jar file from upstream tarball, complying with the Debian Policy
  + d/copyright: Exclude file blockproc.jar
  + d/rules: Add get-orig-source target
  + d/watch: Mangle upstream version to cope with "+dfsg" tag
* Build blockproc.jar, which is deleted from the upstream tarball
  + d/rules: Add commands for building blockproc.jar
  + d/control: Build-depend on default-jdk
  + d/p/fix-path-of-included-makefile.patch: New patch
* Bump Standard-Versions to 3.9.6 (no changes needed)
* d/p/autoload-yes.patch: Remove patch (deprecated upstream)
* Bump Build-Depends on octave to >> 4.0.0~rc4-1 (for sndfile support)
* d/check.m: Avoid verbose output of unit tests
* d/watch: Add the repacksuffix option
* d/p/add-hardening-flags.patch: Drop patch (applied upstream)
* d/p/fix-path-of-included-makefile.patch: Drop patch (applied upstream)

Show diffs side-by-side

added added

removed removed

Lines of Context:
506
506
      }
507
507
   },
508
508
   {
 
509
      "getPlayrec",
 
510
      doGetPlayrec,
 
511
      1, 2, 0, 3,
 
512
      "Returns the samples played and recorded in a page",
 
513
 
 
514
      "Returns all the recorded data available for the page identified by pageNumber.  "
 
515
      "If the page specified does not exist, was not specified to record any data, "
 
516
      "or has not yet started to record any data then empty array(s) are returned.  "
 
517
      "If the page is currently being processed, only the recorded data currently "
 
518
      "available is returned.",
 
519
      {
 
520
         {"pageNumber", "used to identifying the page containing the required recorded data"}
 
521
      },
 
522
      {
 
523
         {
 
524
            "playrecBuffer", "a Mx(N+K) matrix where M is the number of samples that have been "
 
525
            "recorded, N is the number of channels of recorded data, K is the number of channels "
 
526
            "of played data."
 
527
         },
 
528
         {
 
529
            "recChanList", "a 1xN vector containing the channel numbers associated with "
 
530
            "each channel in recBuffer.  These channels are in the same order as that "
 
531
            "specified when the page was added."
 
532
         }
 
533
      }
 
534
   },
 
535
   {
509
536
      "delPage",
510
537
      doDelPage,
511
538
      0, 1, 0, 1,
1531
1558
 
1532
1559
                  if (pcbs->pbuffer
1533
1560
                        && (tmpBufPos < pcbs->bufLen)
1534
 
                        && (pcbs->channel >= 0)
 
1561
                        // && (pcbs->channel >= 0) //always true
1535
1562
                        && (pcbs->channel < psis->playChanCount))
1536
1563
                  {
1537
1564
 
1590
1617
 
1591
1618
                  if (pcbs->pbuffer
1592
1619
                        && (tmpBufPos < pcbs->bufLen)
1593
 
                        && (pcbs->channel >= 0)
 
1620
                        // && (pcbs->channel >= 0)// always true
1594
1621
                        && (pcbs->channel < psis->recChanCount))
1595
1622
                  {
1596
1623
 
1822
1849
                * will reduce the number of function calls that just
1823
1850
                * return immediately!
1824
1851
                */
1825
 
               if ((*ppsps)->pfirstPlayChan)
1826
 
                  freeChanBufStructs(&(*ppsps)->pfirstPlayChan);
 
1852
              
 
1853
               // if ((*ppsps)->pfirstPlayChan)
 
1854
              // freeChanBufStructs(&(*ppsps)->pfirstPlayChan);
1827
1855
 
1828
1856
               if ((*ppsps)->pplayChansInUse)
1829
1857
               {
2267
2295
            }
2268
2296
 
2269
2297
            /* This if statement should not be required (included for safety) */
2270
 
            if ((pcbs->channel >= 0) && (pcbs->channel < psps->playChanCount))
 
2298
            if (
 
2299
                  //  (pcbs->channel >= 0) && // always true
 
2300
                    (pcbs->channel < psps->playChanCount))
2271
2301
               psps->pplayChansInUse[pcbs->channel] = true;
2272
2302
 
2273
2303
            chansCopied++;
3323
3353
}
3324
3354
 
3325
3355
/*
 
3356
 * FUNCTION:    doGetPlayrec(int nlhs, mxArray *plhs[],
 
3357
 *                      int nrhs, const mxArray *prhs[])
 
3358
 *
 
3359
 * Inputs:      nlhs - number of mexFunction output arguments
 
3360
 *              plhs - pointer to array of mexFunction output arguments
 
3361
 *              nrhs - number of mexFunction input arguments
 
3362
 *              prhs - pointer to array of mexFunction input arguments
 
3363
 *
 
3364
 *              The first element of plhs is always used and so must be valid
 
3365
 *              (this is not checked).  Additionally, if (nlhs >= 2) then the
 
3366
 *              second element of plhs must also be valid.  The first element
 
3367
 *              of prhs must also be valid and must point to an mxArray (the
 
3368
 *              type of mxArray is checked).
 
3369
 *
 
3370
 * Returns:     true, or aborts with an error if not in full initialisation
 
3371
 *              state.
 
3372
 *
 
3373
 * Description: Returns all recorded samples available for the page specified.
 
3374
 *              The page required is identified by its page number, supplied as
 
3375
 *              the first element of prhs.  An array is always returned in the
 
3376
 *              first element of plhs, and if (nlhs >= 2) then an array is also
 
3377
 *              returned in the second element of plhs.  The first of these
 
3378
 *              contains the recorded data in an MxN array where M is the
 
3379
 *              number of samples that have been recorded (if the page is
 
3380
 *              currently being processed this will be the number of valid
 
3381
 *              samples at the specific point in time) and N is the number
 
3382
 *              of channels of data.  The second array is a 1xN array
 
3383
 *              containing the channel number asssociated with each channel
 
3384
 *              of data in the first array.  If the page requested does not
 
3385
 *              exist, or contains no recorded data (either because there are
 
3386
 *              no channels set to record, or because the page is waiting to be
 
3387
 *              processed) then the array(s) returned are empty.
 
3388
 *
 
3389
 * TODO:
 
3390
 */
 
3391
bool doGetPlayrec(int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[])
 
3392
{
 
3393
   StreamPageStruct *psps;
 
3394
   ChanBufStruct *pcbs;
 
3395
   ChanBufStruct *pcbsBoth[2];
 
3396
 
 
3397
   resample_error rerr = RESAMPLE_OK;
 
3398
   SAMPLE *poutBuf;
 
3399
   mxArray *mxRecChanList;
 
3400
   mxArray *mxPlayChanList;
 
3401
   unsigned int *pChanListBoth[2];
 
3402
   unsigned int recSamples, recSamplesTmp;
 
3403
   unsigned int channels[2];
 
3404
   unsigned int recResPlanId = 0;
 
3405
   unsigned int ii;
 
3406
 
 
3407
   /* SRC_DATA recData;*/
 
3408
 
 
3409
   validateState(BASIC_INIT | FULL_INIT, 0);
 
3410
 
 
3411
   if (!_pstreamInfo)
 
3412
   {
 
3413
      mexErrMsgTxt("An error has occurred - in full initialisation yet "
 
3414
                   "_pstreamInfo is NULL.");
 
3415
   }
 
3416
 
 
3417
   /* Configure return values to defaults, and then change if necessary */
 
3418
   plhs[0] = mxCreateNumericMatrix(0, 0, mxSAMPLE, mxREAL);
 
3419
   if (nlhs > 1) plhs[1] = mxCreateNumericMatrix(0, 0, mxSAMPLE, mxREAL);
 
3420
   if (nlhs > 2) plhs[2] = mxCreateNumericMatrix(0, 0, mxSAMPLE, mxREAL);
 
3421
 
 
3422
   /* No pages */
 
3423
   if (!_pstreamInfo->pfirstStreamPage)
 
3424
   {
 
3425
      return true;
 
3426
   }
 
3427
 
 
3428
   /* There must be one element on rhs before function is called */
 
3429
   if (!mxIsNumeric(prhs[0]) || mxIsComplex(prhs[0])
 
3430
         || (mxGetN(prhs[0]) != 1) || (mxGetM(prhs[0]) != 1)
 
3431
         || (mxGetScalar(prhs[0]) != (int)mxGetScalar(prhs[0])))
 
3432
   {
 
3433
 
 
3434
      return true;
 
3435
   }
 
3436
 
 
3437
   /* Try and find requested stream. */
 
3438
   psps = _pstreamInfo->pfirstStreamPage;
 
3439
 
 
3440
   while (psps)
 
3441
   {
 
3442
      if (psps->pageNum == (int)mxGetScalar(prhs[0]))
 
3443
         break;
 
3444
 
 
3445
      psps = psps->pnextStreamPage;
 
3446
   }
 
3447
 
 
3448
   if (!psps)
 
3449
   {
 
3450
      /* page does not exist, so return immediately */
 
3451
      return true;
 
3452
   }
 
3453
 
 
3454
   /* Found the required page */
 
3455
 
 
3456
   /* Determine the maximum number of samples recorded by finding the longest
 
3457
    * buffer, and then limiting to how far through the page we currently are.
 
3458
    * This allows for different length buffers in the future.
 
3459
    */
 
3460
   recSamples = 0;
 
3461
   recSamplesTmp = 0;
 
3462
   channels[0] = 0;
 
3463
   channels[1] = 0;
 
3464
 
 
3465
   pcbsBoth[0] = psps->pfirstRecChan;
 
3466
   pcbsBoth[1] = psps->pfirstPlayChan;
 
3467
 
 
3468
   pcbs = pcbsBoth[0];
 
3469
 
 
3470
   while (pcbs)
 
3471
   {
 
3472
      /* Check for valid buffer */
 
3473
      if (pcbs->pbuffer && (pcbs->bufLen > 0))
 
3474
      {
 
3475
         recSamplesTmp = max(recSamples, pcbs->bufLen);
 
3476
         channels[0]++;
 
3477
      }
 
3478
      pcbs = pcbs->pnextChanBuf;
 
3479
   }
 
3480
 
 
3481
   pcbs = pcbsBoth[1];
 
3482
 
 
3483
   while (pcbs)
 
3484
   {
 
3485
      /* Check for valid buffer */
 
3486
      if (pcbs->pbuffer && (pcbs->bufLen > 0))
 
3487
      {
 
3488
         channels[1]++;
 
3489
      }
 
3490
      pcbs = pcbs->pnextChanBuf;
 
3491
   }
 
3492
 
 
3493
   if (rec_resplan)
 
3494
   {
 
3495
      /* We will do resampling */
 
3496
      if (psps->pagePos != recSamplesTmp)
 
3497
      {
 
3498
         /* Page was not yet finished, do something harmless. */
 
3499
         recSamples = (unsigned int) ( psps->pageLengthRec * psps->pagePos / ((double)recSamples));
 
3500
      }
 
3501
      else
 
3502
      {
 
3503
         recSamples = psps->pageLengthRec;
 
3504
      }
 
3505
   }
 
3506
   else
 
3507
   {
 
3508
      recSamples = recSamplesTmp;
 
3509
   }
 
3510
 
 
3511
 
 
3512
   /* If there are no samples recorded, no need to continue */
 
3513
   if ((recSamples == 0) || (channels[0] == 0) || (channels[1] == 0))
 
3514
   {
 
3515
      return true;
 
3516
   }
 
3517
 
 
3518
   /* This initialises all elements to zero, so for shorter channels no
 
3519
    * problems should arise. Although on exit MATLAB frees the arrays created
 
3520
    * above, do so here for completeness
 
3521
    */
 
3522
   mxDestroyArray(plhs[0]);
 
3523
 
 
3524
   plhs[0] = mxCreateNumericMatrix(recSamples, channels[0] + channels[1], mxSAMPLE, mxREAL);
 
3525
   poutBuf = (SAMPLE*)mxGetData(plhs[0]);
 
3526
 
 
3527
   /* Create the channel list, but only return it if its required */
 
3528
   mxRecChanList = mxCreateNumericMatrix(1, channels[0], mxUNSIGNED_INT, mxREAL);
 
3529
   mxPlayChanList = mxCreateNumericMatrix(1, channels[0], mxUNSIGNED_INT, mxREAL);
 
3530
   pChanListBoth[0] = (unsigned int*)mxGetData(mxRecChanList);
 
3531
   pChanListBoth[1] = (unsigned int*)mxGetData(mxPlayChanList);
 
3532
 
 
3533
 
 
3534
   if (poutBuf && pChanListBoth[0] && pChanListBoth[1])
 
3535
   {
 
3536
 
 
3537
      for (ii = 0; ii < 2; ii++)
 
3538
      {
 
3539
         pcbs = pcbsBoth[ii];
 
3540
 
 
3541
         /* Copy the data across, decrement recChannels to make sure
 
3542
          * the end of the buffer isn't overwritten
 
3543
          */
 
3544
         while (pcbs && (channels[ii] > 0))
 
3545
         {
 
3546
            if (pcbs->pbuffer && (pcbs->bufLen > 0))
 
3547
            {
 
3548
               if (!rec_resplan)
 
3549
               {
 
3550
                  /* Do just a copy if no resampling should be done*/
 
3551
                  memcpy(poutBuf, pcbs->pbuffer,
 
3552
                         min(recSamples, pcbs->bufLen) * sizeof(SAMPLE));
 
3553
               }
 
3554
               else
 
3555
               {
 
3556
                  rerr = resample_execute(rec_resplan[recResPlanId],
 
3557
                                          pcbs->pbuffer, pcbs->bufLen,
 
3558
                                          poutBuf, recSamples);
 
3559
                  if (rerr != RESAMPLE_OK)
 
3560
                  {
 
3561
                     mexWarnMsgTxt("Resampling returned an error. This should not happen.");
 
3562
                  }
 
3563
 
 
3564
                  recResPlanId++;
 
3565
               }
 
3566
 
 
3567
               poutBuf += recSamples;
 
3568
 
 
3569
               *pChanListBoth[ii]++ = pcbs->channel + 1;   /* Add 1 for base 1 channels */
 
3570
               channels[ii]--;
 
3571
            }
 
3572
            pcbs = pcbs->pnextChanBuf;
 
3573
         }
 
3574
      }
 
3575
   }
 
3576
 
 
3577
   if (nlhs > 1)
 
3578
   {
 
3579
      mxDestroyArray(plhs[1]);
 
3580
      plhs[1] = mxPlayChanList;
 
3581
   }
 
3582
   if (nlhs > 2)
 
3583
   {
 
3584
      mxDestroyArray(plhs[22]);
 
3585
      plhs[2] = mxRecChanList;
 
3586
   }
 
3587
 
 
3588
   return true;
 
3589
}
 
3590
/*
3326
3591
 * FUNCTION:    doGetRec(int nlhs, mxArray *plhs[],
3327
3592
 *                      int nrhs, const mxArray *prhs[])
3328
3593
 *
3366
3631
   resample_error rerr = RESAMPLE_OK;
3367
3632
   SAMPLE *poutBuf;
3368
3633
   mxArray *mxChanList;
3369
 
   unsigned int *pChanList;
 
3634
   unsigned int *pRecChanList;
3370
3635
   unsigned int recSamples, recSamplesTmp;
3371
3636
   unsigned int recChannels;
3372
3637
   unsigned int recResPlanId = 0;
3477
3742
 
3478
3743
   /* Create the channel list, but only return it if its required */
3479
3744
   mxChanList = mxCreateNumericMatrix(1, recChannels, mxUNSIGNED_INT, mxREAL);
3480
 
   pChanList = (unsigned int*)mxGetData(mxChanList);
 
3745
   pRecChanList = (unsigned int*)mxGetData(mxChanList);
3481
3746
 
3482
 
   if (poutBuf && pChanList)
 
3747
   if (poutBuf && pRecChanList)
3483
3748
   {
3484
3749
      pcbs = psps->pfirstRecChan;
3485
3750
 
3501
3766
               rerr = resample_execute(rec_resplan[recResPlanId],
3502
3767
                                       pcbs->pbuffer, pcbs->bufLen,
3503
3768
                                       poutBuf, recSamples);
3504
 
               if(rerr!=RESAMPLE_OK)
 
3769
               if (rerr != RESAMPLE_OK)
3505
3770
               {
3506
3771
                  mexWarnMsgTxt("Resampling returned an error. This should not happen.");
3507
3772
               }
3511
3776
 
3512
3777
            poutBuf += recSamples;
3513
3778
 
3514
 
            *pChanList++ = pcbs->channel + 1;   /* Add 1 for base 1 channels */
 
3779
            *pRecChanList++ = pcbs->channel + 1;   /* Add 1 for base 1 channels */
3515
3780
            recChannels--;
3516
3781
         }
3517
3782
         pcbs = pcbs->pnextChanBuf;