LCOV - code coverage report
Current view: top level - media/libsoundtouch/src - FIFOSamplePipe.h (source / functions) Hit Total Coverage
Test: output.info Lines: 0 35 0.0 %
Date: 2017-07-14 16:53:18 Functions: 0 15 0.0 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : ////////////////////////////////////////////////////////////////////////////////
       2             : ///
       3             : /// 'FIFOSamplePipe' : An abstract base class for classes that manipulate sound
       4             : /// samples by operating like a first-in-first-out pipe: New samples are fed
       5             : /// into one end of the pipe with the 'putSamples' function, and the processed
       6             : /// samples are received from the other end with the 'receiveSamples' function.
       7             : ///
       8             : /// 'FIFOProcessor' : A base class for classes the do signal processing with 
       9             : /// the samples while operating like a first-in-first-out pipe. When samples
      10             : /// are input with the 'putSamples' function, the class processes them
      11             : /// and moves the processed samples to the given 'output' pipe object, which
      12             : /// may be either another processing stage, or a fifo sample buffer object.
      13             : ///
      14             : /// Author        : Copyright (c) Olli Parviainen
      15             : /// Author e-mail : oparviai 'at' iki.fi
      16             : /// SoundTouch WWW: http://www.surina.net/soundtouch
      17             : ///
      18             : ////////////////////////////////////////////////////////////////////////////////
      19             : //
      20             : // Last changed  : $Date: 2012-06-13 19:29:53 +0000 (Wed, 13 Jun 2012) $
      21             : // File revision : $Revision: 4 $
      22             : //
      23             : // $Id: FIFOSamplePipe.h 143 2012-06-13 19:29:53Z oparviai $
      24             : //
      25             : ////////////////////////////////////////////////////////////////////////////////
      26             : //
      27             : // License :
      28             : //
      29             : //  SoundTouch audio processing library
      30             : //  Copyright (c) Olli Parviainen
      31             : //
      32             : //  This library is free software; you can redistribute it and/or
      33             : //  modify it under the terms of the GNU Lesser General Public
      34             : //  License as published by the Free Software Foundation; either
      35             : //  version 2.1 of the License, or (at your option) any later version.
      36             : //
      37             : //  This library is distributed in the hope that it will be useful,
      38             : //  but WITHOUT ANY WARRANTY; without even the implied warranty of
      39             : //  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
      40             : //  Lesser General Public License for more details.
      41             : //
      42             : //  You should have received a copy of the GNU Lesser General Public
      43             : //  License along with this library; if not, write to the Free Software
      44             : //  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
      45             : //
      46             : ////////////////////////////////////////////////////////////////////////////////
      47             : 
      48             : #ifndef FIFOSamplePipe_H
      49             : #define FIFOSamplePipe_H
      50             : 
      51             : #include <assert.h>
      52             : #include <stdlib.h>
      53             : #include "STTypes.h"
      54             : 
      55             : namespace soundtouch
      56             : {
      57             : 
      58             : /// Abstract base class for FIFO (first-in-first-out) sample processing classes.
      59           0 : class FIFOSamplePipe
      60             : {
      61             : public:
      62             :     // virtual default destructor
      63           0 :     virtual ~FIFOSamplePipe() {}
      64             : 
      65             : 
      66             :     /// Returns a pointer to the beginning of the output samples. 
      67             :     /// This function is provided for accessing the output samples directly. 
      68             :     /// Please be careful for not to corrupt the book-keeping!
      69             :     ///
      70             :     /// When using this function to output samples, also remember to 'remove' the
      71             :     /// output samples from the buffer by calling the 
      72             :     /// 'receiveSamples(numSamples)' function
      73             :     virtual SAMPLETYPE *ptrBegin() = 0;
      74             : 
      75             :     /// Adds 'numSamples' pcs of samples from the 'samples' memory position to
      76             :     /// the sample buffer.
      77             :     virtual void putSamples(const SAMPLETYPE *samples,  ///< Pointer to samples.
      78             :                             uint numSamples             ///< Number of samples to insert.
      79             :                             ) = 0;
      80             : 
      81             : 
      82             :     // Moves samples from the 'other' pipe instance to this instance.
      83           0 :     void moveSamples(FIFOSamplePipe &other  ///< Other pipe instance where from the receive the data.
      84             :          )
      85             :     {
      86           0 :         int oNumSamples = other.numSamples();
      87             : 
      88           0 :         putSamples(other.ptrBegin(), oNumSamples);
      89           0 :         other.receiveSamples(oNumSamples);
      90           0 :     };
      91             : 
      92             :     /// Output samples from beginning of the sample buffer. Copies requested samples to 
      93             :     /// output buffer and removes them from the sample buffer. If there are less than 
      94             :     /// 'numsample' samples in the buffer, returns all that available.
      95             :     ///
      96             :     /// \return Number of samples returned.
      97             :     virtual uint receiveSamples(SAMPLETYPE *output, ///< Buffer where to copy output samples.
      98             :                                 uint maxSamples                 ///< How many samples to receive at max.
      99             :                                 ) = 0;
     100             : 
     101             :     /// Adjusts book-keeping so that given number of samples are removed from beginning of the 
     102             :     /// sample buffer without copying them anywhere. 
     103             :     ///
     104             :     /// Used to reduce the number of samples in the buffer when accessing the sample buffer directly
     105             :     /// with 'ptrBegin' function.
     106             :     virtual uint receiveSamples(uint maxSamples   ///< Remove this many samples from the beginning of pipe.
     107             :                                 ) = 0;
     108             : 
     109             :     /// Returns number of samples currently available.
     110             :     virtual uint numSamples() const = 0;
     111             : 
     112             :     // Returns nonzero if there aren't any samples available for outputting.
     113             :     virtual int isEmpty() const = 0;
     114             : 
     115             :     /// Clears all the samples.
     116             :     virtual void clear() = 0;
     117             : 
     118             :     /// allow trimming (downwards) amount of samples in pipeline.
     119             :     /// Returns adjusted amount of samples
     120             :     virtual uint adjustAmountOfSamples(uint numSamples) = 0;
     121             : 
     122             : };
     123             : 
     124             : 
     125             : 
     126             : /// Base-class for sound processing routines working in FIFO principle. With this base 
     127             : /// class it's easy to implement sound processing stages that can be chained together,
     128             : /// so that samples that are fed into beginning of the pipe automatically go through 
     129             : /// all the processing stages.
     130             : ///
     131             : /// When samples are input to this class, they're first processed and then put to 
     132             : /// the FIFO pipe that's defined as output of this class. This output pipe can be
     133             : /// either other processing stage or a FIFO sample buffer.
     134             : class FIFOProcessor :public FIFOSamplePipe
     135             : {
     136             : protected:
     137             :     /// Internal pipe where processed samples are put.
     138             :     FIFOSamplePipe *output;
     139             : 
     140             :     /// Sets output pipe.
     141           0 :     void setOutPipe(FIFOSamplePipe *pOutput)
     142             :     {
     143           0 :         assert(output == NULL);
     144           0 :         assert(pOutput != NULL);
     145           0 :         output = pOutput;
     146           0 :     }
     147             : 
     148             : 
     149             :     /// Constructor. Doesn't define output pipe; it has to be set be 
     150             :     /// 'setOutPipe' function.
     151           0 :     FIFOProcessor()
     152           0 :     {
     153           0 :         output = NULL;
     154           0 :     }
     155             : 
     156             : 
     157             :     /// Constructor. Configures output pipe.
     158           0 :     FIFOProcessor(FIFOSamplePipe *pOutput   ///< Output pipe.
     159             :                  )
     160           0 :     {
     161           0 :         output = pOutput;
     162           0 :     }
     163             : 
     164             : 
     165             :     /// Destructor.
     166           0 :     virtual ~FIFOProcessor()
     167           0 :     {
     168           0 :     }
     169             : 
     170             : 
     171             :     /// Returns a pointer to the beginning of the output samples. 
     172             :     /// This function is provided for accessing the output samples directly. 
     173             :     /// Please be careful for not to corrupt the book-keeping!
     174             :     ///
     175             :     /// When using this function to output samples, also remember to 'remove' the
     176             :     /// output samples from the buffer by calling the 
     177             :     /// 'receiveSamples(numSamples)' function
     178           0 :     virtual SAMPLETYPE *ptrBegin()
     179             :     {
     180           0 :         return output->ptrBegin();
     181             :     }
     182             : 
     183             : public:
     184             : 
     185             :     /// Output samples from beginning of the sample buffer. Copies requested samples to 
     186             :     /// output buffer and removes them from the sample buffer. If there are less than 
     187             :     /// 'numsample' samples in the buffer, returns all that available.
     188             :     ///
     189             :     /// \return Number of samples returned.
     190           0 :     virtual uint receiveSamples(SAMPLETYPE *outBuffer, ///< Buffer where to copy output samples.
     191             :                                 uint maxSamples                    ///< How many samples to receive at max.
     192             :                                 )
     193             :     {
     194           0 :         return output->receiveSamples(outBuffer, maxSamples);
     195             :     }
     196             : 
     197             : 
     198             :     /// Adjusts book-keeping so that given number of samples are removed from beginning of the 
     199             :     /// sample buffer without copying them anywhere. 
     200             :     ///
     201             :     /// Used to reduce the number of samples in the buffer when accessing the sample buffer directly
     202             :     /// with 'ptrBegin' function.
     203           0 :     virtual uint receiveSamples(uint maxSamples   ///< Remove this many samples from the beginning of pipe.
     204             :                                 )
     205             :     {
     206           0 :         return output->receiveSamples(maxSamples);
     207             :     }
     208             : 
     209             : 
     210             :     /// Returns number of samples currently available.
     211           0 :     virtual uint numSamples() const
     212             :     {
     213           0 :         return output->numSamples();
     214             :     }
     215             : 
     216             : 
     217             :     /// Returns nonzero if there aren't any samples available for outputting.
     218           0 :     virtual int isEmpty() const
     219             :     {
     220           0 :         return output->isEmpty();
     221             :     }
     222             : 
     223             :     /// allow trimming (downwards) amount of samples in pipeline.
     224             :     /// Returns adjusted amount of samples
     225           0 :     virtual uint adjustAmountOfSamples(uint numSamples)
     226             :     {
     227           0 :         return output->adjustAmountOfSamples(numSamples);
     228             :     }
     229             : 
     230             : };
     231             : 
     232             : }
     233             : 
     234             : #endif

Generated by: LCOV version 1.13