mirror of
https://github.com/overte-org/overte.git
synced 2025-04-20 04:44:11 +02:00
Merge remote-tracking branch 'origin'
This commit is contained in:
commit
f8cd82bd82
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;
|
||||
bool active;
|
||||
timeval time;
|
||||
bool bufferTransmitted;
|
||||
} agents[MAX_AGENTS];
|
||||
|
||||
int numAgents = 0;
|
||||
|
@ -75,6 +76,7 @@ int addAgent(sockaddr_in agentAddress, void *audioData) {
|
|||
|
||||
if ((i == numAgents) || (agents[i].active == false)) {
|
||||
is_new = 1;
|
||||
agents[i].bufferTransmitted = false;
|
||||
}
|
||||
|
||||
agents[i].address = inet_ntoa(agentAddress.sin_addr);
|
||||
|
@ -143,7 +145,7 @@ void *sendBufferThread(void *args)
|
|||
sourceBuffers[b]->started = false;
|
||||
} else {
|
||||
sourceBuffers[b]->started = true;
|
||||
sourceBuffers[b]->transmitted = true;
|
||||
agents[b].bufferTransmitted = true;
|
||||
|
||||
for (int s = 0; s < BUFFER_LENGTH_SAMPLES; s++) {
|
||||
masterMix[s] += sourceBuffers[b]->nextOutput[s];
|
||||
|
@ -162,11 +164,11 @@ void *sendBufferThread(void *args)
|
|||
if (diffclock(&agents[a].time, &sendTime) <= LOGOFF_CHECK_INTERVAL) {
|
||||
|
||||
int16_t *previousOutput = NULL;
|
||||
if (sourceBuffers[a]->transmitted) {
|
||||
if (agents[a].bufferTransmitted) {
|
||||
previousOutput = (sourceBuffers[a]->nextOutput == sourceBuffers[a]->buffer)
|
||||
? sourceBuffers[a]->buffer + RING_BUFFER_SAMPLES - 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++) {
|
||||
|
|
Loading…
Reference in a new issue