mirror of
https://github.com/overte-org/overte.git
synced 2025-04-23 00:54:08 +02:00
switched to vector
This commit is contained in:
parent
a162643e1e
commit
9507cd8955
4 changed files with 33 additions and 78 deletions
audio-mixer/src
interface/src
|
@ -19,17 +19,12 @@ PositionalAudioRingBuffer::PositionalAudioRingBuffer() :
|
|||
_orientation(0.0f, 0.0f, 0.0f, 0.0f),
|
||||
_willBeAddedToMix(false),
|
||||
_listenMode(AudioRingBuffer::NORMAL),
|
||||
_listenRadius(0.0f),
|
||||
_listenSourceCount(0),
|
||||
_listenSources(NULL)
|
||||
_listenRadius(0.0f)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
PositionalAudioRingBuffer::~PositionalAudioRingBuffer() {
|
||||
if (_listenSources) {
|
||||
delete[] _listenSources;
|
||||
}
|
||||
}
|
||||
|
||||
bool PositionalAudioRingBuffer::isListeningToNode(Node& other) const {
|
||||
|
@ -46,11 +41,9 @@ bool PositionalAudioRingBuffer::isListeningToNode(Node& other) const {
|
|||
break;
|
||||
}
|
||||
case AudioRingBuffer::SELECTED_SOURCES:
|
||||
if (_listenSources) {
|
||||
for (int i = 0; i < _listenSourceCount; i++) {
|
||||
if (other.getNodeID() == _listenSources[i]) {
|
||||
return true;
|
||||
}
|
||||
for (int i = 0; i < _listenSources.size(); i++) {
|
||||
if (other.getNodeID() == _listenSources[i]) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
|
@ -79,14 +72,15 @@ int PositionalAudioRingBuffer::parseListenModeData(unsigned char* sourceBuffer,
|
|||
memcpy(&_listenRadius, currentBuffer, sizeof(_listenRadius));
|
||||
currentBuffer += sizeof(_listenRadius);
|
||||
} else if (_listenMode == AudioRingBuffer::SELECTED_SOURCES) {
|
||||
memcpy(&_listenSourceCount, currentBuffer, sizeof(_listenSourceCount));
|
||||
currentBuffer += sizeof(_listenSourceCount);
|
||||
if (_listenSources) {
|
||||
delete[] _listenSources;
|
||||
int listenSourcesCount;
|
||||
memcpy(&listenSourcesCount, currentBuffer, sizeof(listenSourcesCount));
|
||||
currentBuffer += sizeof(listenSourcesCount);
|
||||
for (int i = 0; i < listenSourcesCount; i++) {
|
||||
int sourceID;
|
||||
memcpy(&sourceID, currentBuffer, sizeof(sourceID));
|
||||
currentBuffer += sizeof(sourceID);
|
||||
_listenSources.push_back(sourceID);
|
||||
}
|
||||
_listenSources = new int[_listenSourceCount];
|
||||
memcpy(_listenSources, currentBuffer, sizeof(int) * _listenSourceCount);
|
||||
currentBuffer += sizeof(int) * _listenSourceCount;
|
||||
}
|
||||
|
||||
return currentBuffer - sourceBuffer;
|
||||
|
|
|
@ -9,6 +9,7 @@
|
|||
#ifndef __hifi__PositionalAudioRingBuffer__
|
||||
#define __hifi__PositionalAudioRingBuffer__
|
||||
|
||||
#include <vector>
|
||||
#include <glm/gtx/quaternion.hpp>
|
||||
|
||||
#include <AudioRingBuffer.h>
|
||||
|
@ -42,11 +43,9 @@ protected:
|
|||
glm::quat _orientation;
|
||||
bool _willBeAddedToMix;
|
||||
|
||||
ListenMode _listenMode;
|
||||
float _listenRadius;
|
||||
int _listenSourceCount;
|
||||
int* _listenSources;
|
||||
|
||||
ListenMode _listenMode;
|
||||
float _listenRadius;
|
||||
std::vector<int> _listenSources;
|
||||
};
|
||||
|
||||
#endif /* defined(__hifi__PositionalAudioRingBuffer__) */
|
||||
|
|
|
@ -136,13 +136,14 @@ inline void Audio::performIO(int16_t* inputLeft, int16_t* outputLeft, int16_t* o
|
|||
currentPacketPtr += (sizeof(_listenRadius));
|
||||
leadingBytes += (sizeof(_listenRadius));
|
||||
} else if (_listenMode == AudioRingBuffer::SELECTED_SOURCES) {
|
||||
memcpy(currentPacketPtr, &_listenSourceCount, sizeof(_listenSourceCount));
|
||||
currentPacketPtr += (sizeof(_listenSourceCount));
|
||||
leadingBytes += (sizeof(_listenSourceCount));
|
||||
if (_listenSources) {
|
||||
memcpy(currentPacketPtr, _listenSources, sizeof(int) * _listenSourceCount);
|
||||
currentPacketPtr += (sizeof(int) * _listenSourceCount);
|
||||
leadingBytes += (sizeof(int) * _listenSourceCount);
|
||||
int listenSourceCount = _listenSources.size();
|
||||
memcpy(currentPacketPtr, &listenSourceCount, sizeof(listenSourceCount));
|
||||
currentPacketPtr += (sizeof(listenSourceCount));
|
||||
leadingBytes += (sizeof(listenSourceCount));
|
||||
for (int i = 0; i < listenSourceCount; i++) {
|
||||
memcpy(currentPacketPtr, &_listenSources[i], sizeof(_listenSources[i]));
|
||||
currentPacketPtr += sizeof(_listenSources[i]);
|
||||
leadingBytes += sizeof(_listenSources[i]);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -336,49 +337,18 @@ void Audio::reset() {
|
|||
}
|
||||
|
||||
void Audio::addListenSource(int sourceID) {
|
||||
|
||||
// If we don't yet have a list of listen sources, make one
|
||||
if (!_listenSources) {
|
||||
_listenSources = new int[AudioRingBuffer::DEFAULT_LISTEN_LIST_SIZE];
|
||||
}
|
||||
|
||||
// First check to see if the source is already in our list
|
||||
for (int i = 0; i < _listenSourceCount; i++) {
|
||||
if (_listenSources[i] == sourceID) {
|
||||
return; // already in list
|
||||
}
|
||||
}
|
||||
|
||||
// we know it's not in the list, check to see if we have room to add our source
|
||||
if (_listenSourceCount + 1 < _listenSourcesArraySize) {
|
||||
int* newList = new int[_listenSourcesArraySize + AudioRingBuffer::DEFAULT_LISTEN_LIST_SIZE];
|
||||
memmove(newList, _listenSources, _listenSourcesArraySize);
|
||||
delete[] _listenSources;
|
||||
_listenSources = newList;
|
||||
_listenSourcesArraySize += AudioRingBuffer::DEFAULT_LISTEN_LIST_SIZE;
|
||||
}
|
||||
_listenSources[_listenSourceCount] = sourceID;
|
||||
_listenSourceCount++;
|
||||
_listenSources.push_back(sourceID);
|
||||
}
|
||||
|
||||
void Audio::clearListenSources() {
|
||||
delete[] _listenSources;
|
||||
_listenSources = NULL;
|
||||
_listenSourceCount = 0;
|
||||
_listenSources.clear();
|
||||
}
|
||||
|
||||
void Audio::removeListenSource(int sourceID) {
|
||||
// If we don't yet have a list of listen sources, make one
|
||||
if (_listenSources) {
|
||||
// First check to see if the source is already in our list
|
||||
for (int i = 0; i < _listenSourceCount; i++) {
|
||||
if (_listenSources[i] == sourceID) {
|
||||
|
||||
// found it, so, move the items forward in list
|
||||
memmove(&_listenSources[i], &_listenSources[i+1], _listenSourceCount - i);
|
||||
_listenSourceCount--;
|
||||
return;
|
||||
}
|
||||
for (int i = 0; i < _listenSources.size(); i++) {
|
||||
if (_listenSources[i] == sourceID) {
|
||||
_listenSources.erase(_listenSources.begin() + i);
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -415,10 +385,7 @@ Audio::Audio(Oscilloscope* scope, int16_t initialJitterBufferSamples) :
|
|||
_proceduralEffectSample(0),
|
||||
_heartbeatMagnitude(0.0f),
|
||||
_listenMode(AudioRingBuffer::NORMAL),
|
||||
_listenRadius(0.0f),
|
||||
_listenSourceCount(0),
|
||||
_listenSourcesArraySize(0),
|
||||
_listenSources(NULL)
|
||||
_listenRadius(0.0f)
|
||||
{
|
||||
outputPortAudioError(Pa_Initialize());
|
||||
|
||||
|
@ -487,10 +454,6 @@ Audio::~Audio() {
|
|||
outputPortAudioError(Pa_Terminate());
|
||||
}
|
||||
delete[] _echoSamplesLeft;
|
||||
|
||||
if (_listenSources) {
|
||||
delete[] _listenSources;
|
||||
}
|
||||
}
|
||||
|
||||
void Audio::addReceivedAudioToBuffer(unsigned char* receivedData, int receivedBytes) {
|
||||
|
|
|
@ -9,6 +9,7 @@
|
|||
#ifndef __interface__Audio__
|
||||
#define __interface__Audio__
|
||||
|
||||
#include <vector>
|
||||
#include <portaudio.h>
|
||||
#include <AudioRingBuffer.h>
|
||||
#include <StdDev.h>
|
||||
|
@ -98,9 +99,7 @@ private:
|
|||
|
||||
AudioRingBuffer::ListenMode _listenMode;
|
||||
float _listenRadius;
|
||||
int _listenSourceCount;
|
||||
int _listenSourcesArraySize;
|
||||
int* _listenSources;
|
||||
std::vector<int> _listenSources;
|
||||
|
||||
// Audio callback in class context.
|
||||
inline void performIO(int16_t* inputLeft, int16_t* outputLeft, int16_t* outputRight);
|
||||
|
|
Loading…
Reference in a new issue