1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122
|
/*************************************************************************
SampleFIFO.h - simple FIFO, tuned for sample_t
-------------------
begin : Sun Apr 11 2004
copyright : (C) 2004 by Thomas Eschenbacher
email : Thomas.Eschenbacher@gmx.de
***************************************************************************/
/***************************************************************************
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
* *
***************************************************************************/
#ifndef SAMPLE_FIFO_H
#define SAMPLE_FIFO_H
#include "config.h"
#include "libkwave_export.h"
#include <QtGlobal>
#include <QList>
#include <QQueue>
#include <QRecursiveMutex>
#include "libkwave/SampleArray.h"
namespace Kwave
{
class LIBKWAVE_EXPORT SampleFIFO
{
public:
/** Constructor */
SampleFIFO();
/** copy constructor */
SampleFIFO(const SampleFIFO &other);
/** copy assignment operator */
SampleFIFO& operator=(const SampleFIFO &other);
/** Destructor */
virtual ~SampleFIFO();
/**
* Reset the FIFO. This destroys the content and sets
* all pointers to their initial value.
*/
virtual void flush();
/**
* puts samples into the FIFO
*
* @param source reference to an array of samples to feed in
*/
virtual void put(const Kwave::SampleArray &source);
/**
* gets and removes samples from the FIFO
*
* @param buffer reference to an array of samples to be filled
* @return number of received samples
*/
virtual unsigned int get(Kwave::SampleArray &buffer);
/**
* gets and removes all samples from the FIFO
*
* @return a list of sample arrays
*/
virtual QList<Kwave::SampleArray> getAll();
/**
* Returns the number of samples that can be read out.
* @see m_written
*/
virtual unsigned int length();
/**
* sets the maximum size of the content
*/
virtual void setSize(unsigned int size);
/**
* discards all superfluous content until the size
* condition is met.
*/
virtual void crop();
private:
/** internal version of length(), without locking */
unsigned int unlockedLength();
private:
/** list of buffers with sample data */
QQueue<Kwave::SampleArray> m_buffer;
/** maximum number of samples of the content */
sample_index_t m_size;
/**
* number of samples that have already been read out
* from the first buffer (head, first one to read out)
*/
sample_index_t m_read_offset;
/** mutex for access to the FIFO (recursive) */
QRecursiveMutex m_lock;
};
}
#endif /* SAMPLE_FIFO_H */
//***************************************************************************
//***************************************************************************
|