LMMS
Loading...
Searching...
No Matches
FifoBuffer.h
Go to the documentation of this file.
1/*
2 * FifoBuffer.h - FIFO fixed-size buffer
3 *
4 * Copyright (c) 2007 Javier Serrano Polo <jasp00/at/users.sourceforge.net>
5 *
6 * This file is part of LMMS - https://lmms.io
7 *
8 * This program is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU General Public
10 * License as published by the Free Software Foundation; either
11 * version 2 of the License, or (at your option) any later version.
12 *
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public
19 * License along with this program (see COPYING); if not, write to the
20 * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
21 * Boston, MA 02110-1301 USA.
22 *
23 */
24
25#ifndef LMMS_FIFO_BUFFER_H
26#define LMMS_FIFO_BUFFER_H
27
28#include <QSemaphore>
29
30
31namespace lmms
32{
33
34
35template<typename T>
37{
38public:
42 m_readIndex(0),
43 m_writeIndex(0),
45 {
46 m_buffer = new T[size];
47 m_readSem.acquire(size);
48 }
49
51 {
52 delete[] m_buffer;
53 m_readSem.release(m_size);
54 }
55
56 void write(T element)
57 {
58 m_writeSem.acquire();
59 m_buffer[m_writeIndex++] = element;
61 m_readSem.release();
62 }
63
64 T read()
65 {
66 m_readSem.acquire();
67 T element = m_buffer[m_readIndex++];
69 m_writeSem.release();
70 return element;
71 }
72
74 {
75 m_writeSem.acquire(m_size);
76 m_writeSem.release(m_size);
77 }
78
79 bool available()
80 {
81 return m_readSem.available();
82 }
83
84
85private:
86 QSemaphore m_readSem;
87 QSemaphore m_writeSem;
90 int m_size;
92} ;
93
94
95} // namespace lmms
96
97#endif // LMMS_FIFO_BUFFER_H
void write(T element)
Definition FifoBuffer.h:56
void waitUntilRead()
Definition FifoBuffer.h:73
T read()
Definition FifoBuffer.h:64
int m_writeIndex
Definition FifoBuffer.h:89
int m_readIndex
Definition FifoBuffer.h:88
QSemaphore m_writeSem
Definition FifoBuffer.h:87
bool available()
Definition FifoBuffer.h:79
int m_size
Definition FifoBuffer.h:90
~FifoBuffer()
Definition FifoBuffer.h:50
QSemaphore m_readSem
Definition FifoBuffer.h:86
SampleFrame ** m_buffer
Definition FifoBuffer.h:91
FifoBuffer(int size)
Definition FifoBuffer.h:39
Definition AudioAlsa.cpp:35
ulg size
Definition extract.c:2350