BlockResizer0.h

Go to the documentation of this file.
00001 //
00002 //  BlockResizer.h -- Regularizes the amount of data called for
00003 //  See the copyright notice and acknowledgment of authors in the file COPYRIGHT
00004 //
00005 //  This is useful for time-frequency transformations which only work with certain buffer sizes
00006 //
00007 //  To use, implement an overridden next_buffer method that:
00008 //      - checks if it needs to buffer
00009 //      - if so
00010 //          -- buffers input
00011 //          -- calls next_buffer if it has enough input buffered
00012 //          -- retrieves output
00013 //
00014 //  E.g., 
00015 //  status next_buffer(Buffer & inputBuffer, Buffer & outputBuffer) {
00016 //      unsigned numFrames = outputBuffer.mNumFrames;
00017 //      unsigned dimension = _fftSize;
00018 //      
00019 //      // if I don't need to do any buffering
00020 //      while (numFrames == dimension && 
00021 //      0 == _blockResizer._numAvailableInput && 
00022 //      0 == _blockResizer._numAvailableFrames)
00023 //          return FrameStream::next_buffer(inputBuffer, outputBuffer);
00024 //  
00025 //      _blockResizer.buffer_input(inputBuffer);
00026 //      if (_blockResizer._numAvailableInput >= (int) dimension)
00027 //      {
00028 //          _blockResizer.read_input();
00029 //          FrameStream::next_buffer(_blockResizer._inputBuffer, _blockResizer.mOutputBuffer);
00030 //          _blockResizer.buffer_output();
00031 //      }
00032 //      
00033 //      _blockResizer.read_output(outputBuffer);
00034 //      return cslOk;
00035 //  }
00036 
00037 #ifndef CSL_BlockResizer_H
00038 #define CSL_BlockResizer_H
00039 
00040 #include "CSL_Core.h"
00041 #include "RingBuffer.h"
00042 
00043 namespace csl {
00044 
00045 // Regularizes the amount of data called for
00046 // This is useful for time-frequency transformations which
00047 // only work with certain buffer sizes
00048 
00049 class BlockResizer : public Effect {
00050 
00051 public:
00052                     // ctor / dtor
00053     BlockResizer();
00054     BlockResizer(unsigned quantum);
00055     BlockResizer(UnitGenerator &input, unsigned quantum);
00056     ~BlockResizer();
00057                     // state
00058     unsigned    mFrameQuantum;      // how many frames need to be available
00059     
00060 // IT SHOULD GET THE NUMBER OF CHANNELS FROM THE UGEN BEING FED.
00061     int         mNumAvailableInput;     // how much input do I have buffered?
00062     int         mNumAvailableFrames;    // how many frames are available?   
00063     
00064     Buffer      mInputBuffer;           // buffer used to pull input
00065     Buffer      mOutputBuffer;          // buffer used to pull output   
00066     
00067     RingBuffer  mInputRingBuffer;       // buffer used to store input
00068     RingBuffer  mOutputRingBuffer;      // ring buffer used to store frames
00069     
00070                     // methods
00071     void setBlockSize(unsigned quantum);
00072     void resizeInternalBuffers();
00073     
00074     void bufferInput(Buffer & inputBuffer);
00075     void readInput();           // fills an internal buffer
00076     void bufferOutput();        // reads from an internal buffer
00077     void readOutput(Buffer & outputBuffer);
00078     
00079                                                                 // THIS SHOULD BE A SUBCLASS SPECIAL FOR OVERLAPP ADD
00080     void readInputAdvancing(unsigned numFramesToAdvance);       // fills an internal buffer -- used in overlap-add
00081                                                                 // THIS SHOULD BE A SUBCLASS SPECIAL FOR OVERLAPP ADD
00082     void sumIntoOutputAdvancing(unsigned numFramesToAdvance);   // reads from an internal buffer -- used in overlap-add
00083                                                                 // ??? BLOCK RESIZER SHOULD ONLY RESIZE.
00084     void readOutputAndZero(Buffer& outputBuffer);
00085     
00086     void nextBuffer(Buffer & outputBuffer) throw(CException);
00087     
00088 protected:
00089     void initBuffers();
00090     void freeBuffers(); 
00091     void zeroBuffer(Buffer & outputBuffer);
00092 
00093 };
00094 
00095 }
00096 
00097 #endif

Generated on Sat Oct 17 14:12:32 2009 for CSL by  doxygen 1.4.5-20051010