Skip to content

Commit e119b15

Browse files
authored
Extension - Handle stereo audio from TeamSpeak (cherry pick) (#1240)
1 parent 342f25b commit e119b15

File tree

5 files changed

+15
-7
lines changed

5 files changed

+15
-7
lines changed

extensions/src/ACRE2Core/FilterPosition.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88

99
#include <cmath>
1010
#pragma comment(lib, "x3daudio.lib")
11+
#pragma comment(lib, "xaudio2.lib")
1112

1213
#define MAX_FALLOFF_DISTANCE 75
1314
#define MAX_FALLOFF_RANGE 150

extensions/src/ACRE2Core/SoundEngine.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ acre::Result CSoundEngine::onEditPlaybackVoiceDataEvent(acre::id_t id, short* sa
3737
for (size_t i = 0; i < player->channels.size(); ++i) {
3838
if (player->channels[i]) {
3939
player->channels[i]->lock();
40-
player->channels[i]->In(samples, sampleCount);
40+
player->channels[i]->In(samples, sampleCount, channels);
4141
player->channels[i]->unlock();
4242
}
4343
}

extensions/src/ACRE2Core/SoundMonoChannel.cpp

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -44,10 +44,17 @@ CSoundChannelMono::~CSoundChannelMono() {
4444
}
4545
}
4646

47-
int CSoundChannelMono::In(short *samples, int sampleCount) {
47+
int CSoundChannelMono::In(short *samples, int sampleCount, const int channels) {
4848
//memset(samples, 0x00, sampleCount*sizeof(short));
49-
if (this->bufferLength+sampleCount <= this->bufferMaxSize) {
50-
memcpy(this->buffer+this->bufferLength, samples, sampleCount*sizeof(short));
49+
if (this->bufferLength + sampleCount <= this->bufferMaxSize) {
50+
if (channels == 1) {
51+
memcpy(this->buffer + this->bufferLength, samples, sampleCount * sizeof(short));
52+
} else {
53+
// rare but for multi channel input just capture mono, samples[channels*sampleCount]={Left,Right,Left,...}
54+
for (int i = 0; i < sampleCount; i++) {
55+
this->buffer[this->bufferLength + i] = samples[channels * i];
56+
}
57+
}
5158
this->bufferLength += sampleCount;
5259
}
5360
return this->bufferLength;
@@ -113,4 +120,4 @@ CSoundMixdownEffect * CSoundChannelMono::getMixdownEffectInsert(int index) {
113120
if (index > 7)
114121
return NULL;
115122
return this->mixdownEffects[index];
116-
}
123+
}

extensions/src/ACRE2Core/SoundMonoChannel.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ class CSoundChannelMono : public CLockable {
2727
CSoundChannelMono( int length, bool singleShot );
2828

2929
~CSoundChannelMono();
30-
int In(short *samples, int sampleCount);
30+
int In(short *samples, int sampleCount, const int channels);
3131
int Out(short *samples, int sampleCount);
3232
int GetCurrentBufferSize() { return this->bufferLength-this->bufferPos; };
3333
bool IsOneShot() { return this->oneShot; };

extensions/src/ACRE2Core/SoundPlayback.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ acre::Result CSoundPlayback::playSound(std::string id, acre::vec3_fp32_t positio
7878
tempChannel->getMixdownEffectInsert(0)->setParam("isWorld", 0x00000000);
7979
}
8080

81-
tempChannel->In((short *)waveFile.GetData(), waveFile.GetSize()/sizeof(short));
81+
tempChannel->In((short *)waveFile.GetData(), waveFile.GetSize()/sizeof(short), 1);
8282
CEngine::getInstance()->getSoundEngine()->getSoundMixer()->unlock();
8383
return acre::Result::ok;
8484
}

0 commit comments

Comments
 (0)