Skip to content

Commit

Permalink
Extension - Handle stereo audio from TeamSpeak (cherry pick) (#1240)
Browse files Browse the repository at this point in the history
  • Loading branch information
PabstMirror authored Apr 13, 2023
1 parent 342f25b commit e119b15
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 7 deletions.
1 change: 1 addition & 0 deletions extensions/src/ACRE2Core/FilterPosition.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

#include <cmath>
#pragma comment(lib, "x3daudio.lib")
#pragma comment(lib, "xaudio2.lib")

#define MAX_FALLOFF_DISTANCE 75
#define MAX_FALLOFF_RANGE 150
Expand Down
2 changes: 1 addition & 1 deletion extensions/src/ACRE2Core/SoundEngine.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ acre::Result CSoundEngine::onEditPlaybackVoiceDataEvent(acre::id_t id, short* sa
for (size_t i = 0; i < player->channels.size(); ++i) {
if (player->channels[i]) {
player->channels[i]->lock();
player->channels[i]->In(samples, sampleCount);
player->channels[i]->In(samples, sampleCount, channels);
player->channels[i]->unlock();
}
}
Expand Down
15 changes: 11 additions & 4 deletions extensions/src/ACRE2Core/SoundMonoChannel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,10 +44,17 @@ CSoundChannelMono::~CSoundChannelMono() {
}
}

int CSoundChannelMono::In(short *samples, int sampleCount) {
int CSoundChannelMono::In(short *samples, int sampleCount, const int channels) {
//memset(samples, 0x00, sampleCount*sizeof(short));
if (this->bufferLength+sampleCount <= this->bufferMaxSize) {
memcpy(this->buffer+this->bufferLength, samples, sampleCount*sizeof(short));
if (this->bufferLength + sampleCount <= this->bufferMaxSize) {
if (channels == 1) {
memcpy(this->buffer + this->bufferLength, samples, sampleCount * sizeof(short));
} else {
// rare but for multi channel input just capture mono, samples[channels*sampleCount]={Left,Right,Left,...}
for (int i = 0; i < sampleCount; i++) {
this->buffer[this->bufferLength + i] = samples[channels * i];
}
}
this->bufferLength += sampleCount;
}
return this->bufferLength;
Expand Down Expand Up @@ -113,4 +120,4 @@ CSoundMixdownEffect * CSoundChannelMono::getMixdownEffectInsert(int index) {
if (index > 7)
return NULL;
return this->mixdownEffects[index];
}
}
2 changes: 1 addition & 1 deletion extensions/src/ACRE2Core/SoundMonoChannel.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ class CSoundChannelMono : public CLockable {
CSoundChannelMono( int length, bool singleShot );

~CSoundChannelMono();
int In(short *samples, int sampleCount);
int In(short *samples, int sampleCount, const int channels);
int Out(short *samples, int sampleCount);
int GetCurrentBufferSize() { return this->bufferLength-this->bufferPos; };
bool IsOneShot() { return this->oneShot; };
Expand Down
2 changes: 1 addition & 1 deletion extensions/src/ACRE2Core/SoundPlayback.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ acre::Result CSoundPlayback::playSound(std::string id, acre::vec3_fp32_t positio
tempChannel->getMixdownEffectInsert(0)->setParam("isWorld", 0x00000000);
}

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

0 comments on commit e119b15

Please sign in to comment.