Oboe
A library for creating real-time audio apps on Android
Loading...
Searching...
No Matches
FifoBuffer.h
1/*
2 * Copyright 2015 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17#ifndef OBOE_FIFOPROCESSOR_H
18#define OBOE_FIFOPROCESSOR_H
19
20#include <memory>
21#include <stdint.h>
22
23#include "oboe/Definitions.h"
24
25#include "oboe/FifoControllerBase.h"
26
27namespace oboe {
28
30public:
37 FifoBuffer(uint32_t bytesPerFrame, uint32_t capacityInFrames);
38
49 FifoBuffer(uint32_t bytesPerFrame,
50 uint32_t capacityInFrames,
51 std::atomic<uint64_t> *readCounterAddress,
52 std::atomic<uint64_t> *writeCounterAddress,
53 uint8_t *dataStorageAddress);
54
56
62 int32_t convertFramesToBytes(int32_t frames);
63
71 int32_t read(void *destination, int32_t framesToRead);
72
80 int32_t write(const void *source, int32_t framesToWrite);
81
87 uint32_t getBufferCapacityInFrames() const;
88
97 int32_t readNow(void *destination, int32_t numFrames);
98
105 return mFifo->getFullFramesAvailable();
106 }
107
113 uint32_t getBytesPerFrame() const {
114 return mBytesPerFrame;
115 }
116
122 uint64_t getReadCounter() const {
123 return mFifo->getReadCounter();
124 }
125
131 void setReadCounter(uint64_t n) {
132 mFifo->setReadCounter(n);
133 }
134
140 uint64_t getWriteCounter() {
141 return mFifo->getWriteCounter();
142 }
143
149 void setWriteCounter(uint64_t n) {
150 mFifo->setWriteCounter(n);
151 }
152
153private:
154 uint32_t mBytesPerFrame;
155 uint8_t* mStorage;
156 bool mStorageOwned; // did this object allocate the storage?
157 std::unique_ptr<FifoControllerBase> mFifo;
158 uint64_t mFramesReadCount;
159 uint64_t mFramesUnderrunCount;
160};
161
162} // namespace oboe
163
164#endif //OBOE_FIFOPROCESSOR_H
Definition: FifoBuffer.h:29
FifoBuffer(uint32_t bytesPerFrame, uint32_t capacityInFrames, std::atomic< uint64_t > *readCounterAddress, std::atomic< uint64_t > *writeCounterAddress, uint8_t *dataStorageAddress)
uint64_t getReadCounter() const
Definition: FifoBuffer.h:122
int32_t readNow(void *destination, int32_t numFrames)
FifoBuffer(uint32_t bytesPerFrame, uint32_t capacityInFrames)
uint32_t getBufferCapacityInFrames() const
void setWriteCounter(uint64_t n)
Definition: FifoBuffer.h:149
int32_t write(const void *source, int32_t framesToWrite)
uint32_t getBytesPerFrame() const
Definition: FifoBuffer.h:113
int32_t read(void *destination, int32_t framesToRead)
int32_t convertFramesToBytes(int32_t frames)
uint64_t getWriteCounter()
Definition: FifoBuffer.h:140
uint32_t getFullFramesAvailable()
Definition: FifoBuffer.h:104
void setReadCounter(uint64_t n)
Definition: FifoBuffer.h:131
Definition: AudioStream.h:31