mirror of
https://github.com/lubosz/overte.git
synced 2025-08-07 19:01:09 +02:00
use a more consistent method to clock the injector thread
This commit is contained in:
parent
f82db95fee
commit
842ef820ab
1 changed files with 4 additions and 3 deletions
|
@ -90,9 +90,10 @@ void AudioInjector::injectAudio(UDPSocket* injectorSocket, sockaddr* destination
|
||||||
memcpy(currentPacketPtr, &_bearing, sizeof(_bearing));
|
memcpy(currentPacketPtr, &_bearing, sizeof(_bearing));
|
||||||
currentPacketPtr += sizeof(_bearing);
|
currentPacketPtr += sizeof(_bearing);
|
||||||
|
|
||||||
|
gettimeofday(&startTime, NULL);
|
||||||
|
int nextFrame = 0;
|
||||||
|
|
||||||
for (int i = 0; i < _numTotalSamples; i += BUFFER_LENGTH_SAMPLES) {
|
for (int i = 0; i < _numTotalSamples; i += BUFFER_LENGTH_SAMPLES) {
|
||||||
gettimeofday(&startTime, NULL);
|
|
||||||
|
|
||||||
int numSamplesToCopy = BUFFER_LENGTH_SAMPLES;
|
int numSamplesToCopy = BUFFER_LENGTH_SAMPLES;
|
||||||
|
|
||||||
if (_numTotalSamples - i < BUFFER_LENGTH_SAMPLES) {
|
if (_numTotalSamples - i < BUFFER_LENGTH_SAMPLES) {
|
||||||
|
@ -104,7 +105,7 @@ void AudioInjector::injectAudio(UDPSocket* injectorSocket, sockaddr* destination
|
||||||
|
|
||||||
injectorSocket->send(destinationSocket, dataPacket, sizeof(dataPacket));
|
injectorSocket->send(destinationSocket, dataPacket, sizeof(dataPacket));
|
||||||
|
|
||||||
double usecToSleep = BUFFER_SEND_INTERVAL_USECS - (usecTimestampNow() - usecTimestamp(&startTime));
|
double usecToSleep = usecTimestamp(&startTime) + (++nextFrame * BUFFER_SEND_INTERVAL_USECS) - usecTimestampNow();
|
||||||
if (usecToSleep > 0) {
|
if (usecToSleep > 0) {
|
||||||
usleep(usecToSleep);
|
usleep(usecToSleep);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue