media/libsoundtouch/src/FIFOSamplePipe.h

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/media/libsoundtouch/src/FIFOSamplePipe.h	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,234 @@
     1.4 +////////////////////////////////////////////////////////////////////////////////
     1.5 +///
     1.6 +/// 'FIFOSamplePipe' : An abstract base class for classes that manipulate sound
     1.7 +/// samples by operating like a first-in-first-out pipe: New samples are fed
     1.8 +/// into one end of the pipe with the 'putSamples' function, and the processed
     1.9 +/// samples are received from the other end with the 'receiveSamples' function.
    1.10 +///
    1.11 +/// 'FIFOProcessor' : A base class for classes the do signal processing with 
    1.12 +/// the samples while operating like a first-in-first-out pipe. When samples
    1.13 +/// are input with the 'putSamples' function, the class processes them
    1.14 +/// and moves the processed samples to the given 'output' pipe object, which
    1.15 +/// may be either another processing stage, or a fifo sample buffer object.
    1.16 +///
    1.17 +/// Author        : Copyright (c) Olli Parviainen
    1.18 +/// Author e-mail : oparviai 'at' iki.fi
    1.19 +/// SoundTouch WWW: http://www.surina.net/soundtouch
    1.20 +///
    1.21 +////////////////////////////////////////////////////////////////////////////////
    1.22 +//
    1.23 +// Last changed  : $Date: 2012-06-13 14:29:53 -0500 (Wed, 13 Jun 2012) $
    1.24 +// File revision : $Revision: 4 $
    1.25 +//
    1.26 +// $Id: FIFOSamplePipe.h 143 2012-06-13 19:29:53Z oparviai $
    1.27 +//
    1.28 +////////////////////////////////////////////////////////////////////////////////
    1.29 +//
    1.30 +// License :
    1.31 +//
    1.32 +//  SoundTouch audio processing library
    1.33 +//  Copyright (c) Olli Parviainen
    1.34 +//
    1.35 +//  This library is free software; you can redistribute it and/or
    1.36 +//  modify it under the terms of the GNU Lesser General Public
    1.37 +//  License as published by the Free Software Foundation; either
    1.38 +//  version 2.1 of the License, or (at your option) any later version.
    1.39 +//
    1.40 +//  This library is distributed in the hope that it will be useful,
    1.41 +//  but WITHOUT ANY WARRANTY; without even the implied warranty of
    1.42 +//  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
    1.43 +//  Lesser General Public License for more details.
    1.44 +//
    1.45 +//  You should have received a copy of the GNU Lesser General Public
    1.46 +//  License along with this library; if not, write to the Free Software
    1.47 +//  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
    1.48 +//
    1.49 +////////////////////////////////////////////////////////////////////////////////
    1.50 +
    1.51 +#ifndef FIFOSamplePipe_H
    1.52 +#define FIFOSamplePipe_H
    1.53 +
    1.54 +#include <assert.h>
    1.55 +#include <stdlib.h>
    1.56 +#include "STTypes.h"
    1.57 +
    1.58 +namespace soundtouch
    1.59 +{
    1.60 +
    1.61 +/// Abstract base class for FIFO (first-in-first-out) sample processing classes.
    1.62 +class FIFOSamplePipe
    1.63 +{
    1.64 +public:
    1.65 +    // virtual default destructor
    1.66 +    virtual ~FIFOSamplePipe() {}
    1.67 +
    1.68 +
    1.69 +    /// Returns a pointer to the beginning of the output samples. 
    1.70 +    /// This function is provided for accessing the output samples directly. 
    1.71 +    /// Please be careful for not to corrupt the book-keeping!
    1.72 +    ///
    1.73 +    /// When using this function to output samples, also remember to 'remove' the
    1.74 +    /// output samples from the buffer by calling the 
    1.75 +    /// 'receiveSamples(numSamples)' function
    1.76 +    virtual SAMPLETYPE *ptrBegin() = 0;
    1.77 +
    1.78 +    /// Adds 'numSamples' pcs of samples from the 'samples' memory position to
    1.79 +    /// the sample buffer.
    1.80 +    virtual void putSamples(const SAMPLETYPE *samples,  ///< Pointer to samples.
    1.81 +                            uint numSamples             ///< Number of samples to insert.
    1.82 +                            ) = 0;
    1.83 +
    1.84 +
    1.85 +    // Moves samples from the 'other' pipe instance to this instance.
    1.86 +    void moveSamples(FIFOSamplePipe &other  ///< Other pipe instance where from the receive the data.
    1.87 +         )
    1.88 +    {
    1.89 +        int oNumSamples = other.numSamples();
    1.90 +
    1.91 +        putSamples(other.ptrBegin(), oNumSamples);
    1.92 +        other.receiveSamples(oNumSamples);
    1.93 +    };
    1.94 +
    1.95 +    /// Output samples from beginning of the sample buffer. Copies requested samples to 
    1.96 +    /// output buffer and removes them from the sample buffer. If there are less than 
    1.97 +    /// 'numsample' samples in the buffer, returns all that available.
    1.98 +    ///
    1.99 +    /// \return Number of samples returned.
   1.100 +    virtual uint receiveSamples(SAMPLETYPE *output, ///< Buffer where to copy output samples.
   1.101 +                                uint maxSamples                 ///< How many samples to receive at max.
   1.102 +                                ) = 0;
   1.103 +
   1.104 +    /// Adjusts book-keeping so that given number of samples are removed from beginning of the 
   1.105 +    /// sample buffer without copying them anywhere. 
   1.106 +    ///
   1.107 +    /// Used to reduce the number of samples in the buffer when accessing the sample buffer directly
   1.108 +    /// with 'ptrBegin' function.
   1.109 +    virtual uint receiveSamples(uint maxSamples   ///< Remove this many samples from the beginning of pipe.
   1.110 +                                ) = 0;
   1.111 +
   1.112 +    /// Returns number of samples currently available.
   1.113 +    virtual uint numSamples() const = 0;
   1.114 +
   1.115 +    // Returns nonzero if there aren't any samples available for outputting.
   1.116 +    virtual int isEmpty() const = 0;
   1.117 +
   1.118 +    /// Clears all the samples.
   1.119 +    virtual void clear() = 0;
   1.120 +
   1.121 +    /// allow trimming (downwards) amount of samples in pipeline.
   1.122 +    /// Returns adjusted amount of samples
   1.123 +    virtual uint adjustAmountOfSamples(uint numSamples) = 0;
   1.124 +
   1.125 +};
   1.126 +
   1.127 +
   1.128 +
   1.129 +/// Base-class for sound processing routines working in FIFO principle. With this base 
   1.130 +/// class it's easy to implement sound processing stages that can be chained together,
   1.131 +/// so that samples that are fed into beginning of the pipe automatically go through 
   1.132 +/// all the processing stages.
   1.133 +///
   1.134 +/// When samples are input to this class, they're first processed and then put to 
   1.135 +/// the FIFO pipe that's defined as output of this class. This output pipe can be
   1.136 +/// either other processing stage or a FIFO sample buffer.
   1.137 +class FIFOProcessor :public FIFOSamplePipe
   1.138 +{
   1.139 +protected:
   1.140 +    /// Internal pipe where processed samples are put.
   1.141 +    FIFOSamplePipe *output;
   1.142 +
   1.143 +    /// Sets output pipe.
   1.144 +    void setOutPipe(FIFOSamplePipe *pOutput)
   1.145 +    {
   1.146 +        assert(output == NULL);
   1.147 +        assert(pOutput != NULL);
   1.148 +        output = pOutput;
   1.149 +    }
   1.150 +
   1.151 +
   1.152 +    /// Constructor. Doesn't define output pipe; it has to be set be 
   1.153 +    /// 'setOutPipe' function.
   1.154 +    FIFOProcessor()
   1.155 +    {
   1.156 +        output = NULL;
   1.157 +    }
   1.158 +
   1.159 +
   1.160 +    /// Constructor. Configures output pipe.
   1.161 +    FIFOProcessor(FIFOSamplePipe *pOutput   ///< Output pipe.
   1.162 +                 )
   1.163 +    {
   1.164 +        output = pOutput;
   1.165 +    }
   1.166 +
   1.167 +
   1.168 +    /// Destructor.
   1.169 +    virtual ~FIFOProcessor()
   1.170 +    {
   1.171 +    }
   1.172 +
   1.173 +
   1.174 +    /// Returns a pointer to the beginning of the output samples. 
   1.175 +    /// This function is provided for accessing the output samples directly. 
   1.176 +    /// Please be careful for not to corrupt the book-keeping!
   1.177 +    ///
   1.178 +    /// When using this function to output samples, also remember to 'remove' the
   1.179 +    /// output samples from the buffer by calling the 
   1.180 +    /// 'receiveSamples(numSamples)' function
   1.181 +    virtual SAMPLETYPE *ptrBegin()
   1.182 +    {
   1.183 +        return output->ptrBegin();
   1.184 +    }
   1.185 +
   1.186 +public:
   1.187 +
   1.188 +    /// Output samples from beginning of the sample buffer. Copies requested samples to 
   1.189 +    /// output buffer and removes them from the sample buffer. If there are less than 
   1.190 +    /// 'numsample' samples in the buffer, returns all that available.
   1.191 +    ///
   1.192 +    /// \return Number of samples returned.
   1.193 +    virtual uint receiveSamples(SAMPLETYPE *outBuffer, ///< Buffer where to copy output samples.
   1.194 +                                uint maxSamples                    ///< How many samples to receive at max.
   1.195 +                                )
   1.196 +    {
   1.197 +        return output->receiveSamples(outBuffer, maxSamples);
   1.198 +    }
   1.199 +
   1.200 +
   1.201 +    /// Adjusts book-keeping so that given number of samples are removed from beginning of the 
   1.202 +    /// sample buffer without copying them anywhere. 
   1.203 +    ///
   1.204 +    /// Used to reduce the number of samples in the buffer when accessing the sample buffer directly
   1.205 +    /// with 'ptrBegin' function.
   1.206 +    virtual uint receiveSamples(uint maxSamples   ///< Remove this many samples from the beginning of pipe.
   1.207 +                                )
   1.208 +    {
   1.209 +        return output->receiveSamples(maxSamples);
   1.210 +    }
   1.211 +
   1.212 +
   1.213 +    /// Returns number of samples currently available.
   1.214 +    virtual uint numSamples() const
   1.215 +    {
   1.216 +        return output->numSamples();
   1.217 +    }
   1.218 +
   1.219 +
   1.220 +    /// Returns nonzero if there aren't any samples available for outputting.
   1.221 +    virtual int isEmpty() const
   1.222 +    {
   1.223 +        return output->isEmpty();
   1.224 +    }
   1.225 +
   1.226 +    /// allow trimming (downwards) amount of samples in pipeline.
   1.227 +    /// Returns adjusted amount of samples
   1.228 +    virtual uint adjustAmountOfSamples(uint numSamples)
   1.229 +    {
   1.230 +        return output->adjustAmountOfSamples(numSamples);
   1.231 +    }
   1.232 +
   1.233 +};
   1.234 +
   1.235 +}
   1.236 +
   1.237 +#endif

mercurial