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