mirror of
https://github.com/overte-org/overte.git
synced 2025-08-06 17:00:13 +02:00
AudioRingBuffer is a shared class (between mixer and interface)
This commit is contained in:
parent
63070b4d3c
commit
fb31765024
5 changed files with 5 additions and 85 deletions
|
@ -1,51 +0,0 @@
|
||||||
//
|
|
||||||
// AudioRingBuffer.cpp
|
|
||||||
// interface
|
|
||||||
//
|
|
||||||
// Created by Stephen Birarda on 2/1/13.
|
|
||||||
// Copyright (c) 2013 HighFidelity, Inc. All rights reserved.
|
|
||||||
//
|
|
||||||
|
|
||||||
#include "AudioRingBuffer.h"
|
|
||||||
|
|
||||||
AudioRingBuffer::AudioRingBuffer(short ringBufferSamples) {
|
|
||||||
ringBufferLengthSamples = ringBufferSamples;
|
|
||||||
|
|
||||||
started = false;
|
|
||||||
transmitted = false;
|
|
||||||
|
|
||||||
endOfLastWrite = NULL;
|
|
||||||
|
|
||||||
buffer = new int16_t[ringBufferLengthSamples];
|
|
||||||
nextOutput = buffer;
|
|
||||||
};
|
|
||||||
|
|
||||||
AudioRingBuffer::~AudioRingBuffer() {
|
|
||||||
delete[] buffer;
|
|
||||||
};
|
|
||||||
|
|
||||||
short AudioRingBuffer::diffLastWriteNextOutput()
|
|
||||||
{
|
|
||||||
if (endOfLastWrite == NULL) {
|
|
||||||
return 0;
|
|
||||||
} else {
|
|
||||||
short sampleDifference = endOfLastWrite - nextOutput;
|
|
||||||
|
|
||||||
if (sampleDifference < 0) {
|
|
||||||
sampleDifference += ringBufferLengthSamples;
|
|
||||||
}
|
|
||||||
|
|
||||||
return sampleDifference;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
short AudioRingBuffer::bufferOverlap(int16_t *pointer, short addedDistance)
|
|
||||||
{
|
|
||||||
short samplesLeft = (buffer + ringBufferLengthSamples) - pointer;
|
|
||||||
|
|
||||||
if (samplesLeft < addedDistance) {
|
|
||||||
return addedDistance - samplesLeft;
|
|
||||||
} else {
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,31 +0,0 @@
|
||||||
//
|
|
||||||
// AudioRingBuffer.h
|
|
||||||
// interface
|
|
||||||
//
|
|
||||||
// Created by Stephen Birarda on 2/1/13.
|
|
||||||
// Copyright (c) 2013 HighFidelity, Inc. All rights reserved.
|
|
||||||
//
|
|
||||||
|
|
||||||
#ifndef __interface__AudioRingBuffer__
|
|
||||||
#define __interface__AudioRingBuffer__
|
|
||||||
|
|
||||||
#include <iostream>
|
|
||||||
#include <stdint.h>
|
|
||||||
|
|
||||||
class AudioRingBuffer {
|
|
||||||
public:
|
|
||||||
int16_t *nextOutput;
|
|
||||||
int16_t *endOfLastWrite;
|
|
||||||
int16_t *buffer;
|
|
||||||
short ringBufferLengthSamples;
|
|
||||||
bool started;
|
|
||||||
bool transmitted;
|
|
||||||
|
|
||||||
short diffLastWriteNextOutput();
|
|
||||||
short bufferOverlap(int16_t *pointer, short addedDistance);
|
|
||||||
|
|
||||||
AudioRingBuffer(short ringBufferSamples);
|
|
||||||
~AudioRingBuffer();
|
|
||||||
};
|
|
||||||
|
|
||||||
#endif /* defined(__interface__AudioRingBuffer__) */
|
|
|
@ -44,6 +44,7 @@ struct AgentList {
|
||||||
unsigned short port;
|
unsigned short port;
|
||||||
bool active;
|
bool active;
|
||||||
timeval time;
|
timeval time;
|
||||||
|
bool bufferTransmitted;
|
||||||
} agents[MAX_AGENTS];
|
} agents[MAX_AGENTS];
|
||||||
|
|
||||||
int numAgents = 0;
|
int numAgents = 0;
|
||||||
|
@ -75,6 +76,7 @@ int addAgent(sockaddr_in agentAddress, void *audioData) {
|
||||||
|
|
||||||
if ((i == numAgents) || (agents[i].active == false)) {
|
if ((i == numAgents) || (agents[i].active == false)) {
|
||||||
is_new = 1;
|
is_new = 1;
|
||||||
|
agents[i].bufferTransmitted = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
agents[i].address = inet_ntoa(agentAddress.sin_addr);
|
agents[i].address = inet_ntoa(agentAddress.sin_addr);
|
||||||
|
@ -143,7 +145,7 @@ void *sendBufferThread(void *args)
|
||||||
sourceBuffers[b]->started = false;
|
sourceBuffers[b]->started = false;
|
||||||
} else {
|
} else {
|
||||||
sourceBuffers[b]->started = true;
|
sourceBuffers[b]->started = true;
|
||||||
sourceBuffers[b]->transmitted = true;
|
agents[b].bufferTransmitted = true;
|
||||||
|
|
||||||
for (int s = 0; s < BUFFER_LENGTH_SAMPLES; s++) {
|
for (int s = 0; s < BUFFER_LENGTH_SAMPLES; s++) {
|
||||||
masterMix[s] += sourceBuffers[b]->nextOutput[s];
|
masterMix[s] += sourceBuffers[b]->nextOutput[s];
|
||||||
|
@ -162,11 +164,11 @@ void *sendBufferThread(void *args)
|
||||||
if (diffclock(&agents[a].time, &sendTime) <= LOGOFF_CHECK_INTERVAL) {
|
if (diffclock(&agents[a].time, &sendTime) <= LOGOFF_CHECK_INTERVAL) {
|
||||||
|
|
||||||
int16_t *previousOutput = NULL;
|
int16_t *previousOutput = NULL;
|
||||||
if (sourceBuffers[a]->transmitted) {
|
if (agents[a].bufferTransmitted) {
|
||||||
previousOutput = (sourceBuffers[a]->nextOutput == sourceBuffers[a]->buffer)
|
previousOutput = (sourceBuffers[a]->nextOutput == sourceBuffers[a]->buffer)
|
||||||
? sourceBuffers[a]->buffer + RING_BUFFER_SAMPLES - BUFFER_LENGTH_SAMPLES
|
? sourceBuffers[a]->buffer + RING_BUFFER_SAMPLES - BUFFER_LENGTH_SAMPLES
|
||||||
: sourceBuffers[a]->nextOutput - BUFFER_LENGTH_SAMPLES;
|
: sourceBuffers[a]->nextOutput - BUFFER_LENGTH_SAMPLES;
|
||||||
sourceBuffers[a]->transmitted = false;
|
agents[a].bufferTransmitted = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
for(int as = 0; as < BUFFER_LENGTH_SAMPLES; as++) {
|
for(int as = 0; as < BUFFER_LENGTH_SAMPLES; as++) {
|
||||||
|
|
Loading…
Reference in a new issue