Merge pull request #9197 from davidkelly/dk/injectorVolume

No longer applying volume when reading audio injector buffer
This commit is contained in:
David Kelly 2016-12-16 15:11:33 -08:00 committed by GitHub
commit b68a07e930
5 changed files with 7 additions and 21 deletions

View file

@ -1135,8 +1135,9 @@ void AudioClient::mixLocalAudioInjectors(float* mixBuffer) {
} else if (injector->isStereo()) { } else if (injector->isStereo()) {
// stereo gets directly mixed into mixBuffer // stereo gets directly mixed into mixBuffer
float gain = injector->getVolume();
for (int i = 0; i < AudioConstants::NETWORK_FRAME_SAMPLES_STEREO; i++) { for (int i = 0; i < AudioConstants::NETWORK_FRAME_SAMPLES_STEREO; i++) {
mixBuffer[i] += (float)_scratchBuffer[i] * (1/32768.0f); mixBuffer[i] += (float)_scratchBuffer[i] * (1/32768.0f) * gain;
} }
} else { } else {

View file

@ -166,7 +166,6 @@ bool AudioInjector::injectLocally() {
_localBuffer->open(QIODevice::ReadOnly); _localBuffer->open(QIODevice::ReadOnly);
_localBuffer->setShouldLoop(_options.loop); _localBuffer->setShouldLoop(_options.loop);
_localBuffer->setVolume(_options.volume);
// give our current send position to the local buffer // give our current send position to the local buffer
_localBuffer->setCurrentOffset(_currentSendOffset); _localBuffer->setCurrentOffset(_currentSendOffset);

View file

@ -63,7 +63,7 @@ public:
AudioFOA& getLocalFOA() { return _localFOA; } AudioFOA& getLocalFOA() { return _localFOA; }
bool isLocalOnly() const { return _options.localOnly; } bool isLocalOnly() const { return _options.localOnly; }
float getVolume() const { return _options.volume; } float getVolume() const { return glm::clamp(_options.volume, 0.0f, 1.0f); }
glm::vec3 getPosition() const { return _options.position; } glm::vec3 getPosition() const { return _options.position; }
glm::quat getOrientation() const { return _options.orientation; } glm::quat getOrientation() const { return _options.orientation; }
bool isStereo() const { return _options.stereo; } bool isStereo() const { return _options.stereo; }

View file

@ -16,8 +16,7 @@ AudioInjectorLocalBuffer::AudioInjectorLocalBuffer(const QByteArray& rawAudioArr
_rawAudioArray(rawAudioArray), _rawAudioArray(rawAudioArray),
_shouldLoop(false), _shouldLoop(false),
_isStopped(false), _isStopped(false),
_currentOffset(0), _currentOffset(0)
_volume(1.0f)
{ {
} }
@ -36,17 +35,6 @@ bool AudioInjectorLocalBuffer::seek(qint64 pos) {
} }
} }
void copy(char* to, char* from, int size, qreal factor) {
int16_t* toArray = (int16_t*) to;
int16_t* fromArray = (int16_t*) from;
int sampleSize = size / sizeof(int16_t);
for (int i = 0; i < sampleSize; i++) {
*toArray = factor * (*fromArray);
toArray++;
fromArray++;
}
}
qint64 AudioInjectorLocalBuffer::readData(char* data, qint64 maxSize) { qint64 AudioInjectorLocalBuffer::readData(char* data, qint64 maxSize) {
if (!_isStopped) { if (!_isStopped) {
@ -60,7 +48,7 @@ qint64 AudioInjectorLocalBuffer::readData(char* data, qint64 maxSize) {
bytesRead = bytesToEnd; bytesRead = bytesToEnd;
} }
copy(data, _rawAudioArray.data() + _currentOffset, bytesRead, _volume); memcpy(data, _rawAudioArray.data() + _currentOffset, bytesRead);
// now check if we are supposed to loop and if we can copy more from the beginning // now check if we are supposed to loop and if we can copy more from the beginning
if (_shouldLoop && maxSize != bytesRead) { if (_shouldLoop && maxSize != bytesRead) {
@ -88,7 +76,7 @@ qint64 AudioInjectorLocalBuffer::recursiveReadFromFront(char* data, qint64 maxSi
} }
// copy that amount // copy that amount
copy(data, _rawAudioArray.data(), bytesRead, _volume); memcpy(data, _rawAudioArray.data(), bytesRead);
// check if we need to call ourselves again and pull from the front again // check if we need to call ourselves again and pull from the front again
if (bytesRead < maxSize) { if (bytesRead < maxSize) {
@ -97,4 +85,4 @@ qint64 AudioInjectorLocalBuffer::recursiveReadFromFront(char* data, qint64 maxSi
_currentOffset = bytesRead; _currentOffset = bytesRead;
return bytesRead; return bytesRead;
} }
} }

View file

@ -30,7 +30,6 @@ public:
void setShouldLoop(bool shouldLoop) { _shouldLoop = shouldLoop; } void setShouldLoop(bool shouldLoop) { _shouldLoop = shouldLoop; }
void setCurrentOffset(int currentOffset) { _currentOffset = currentOffset; } void setCurrentOffset(int currentOffset) { _currentOffset = currentOffset; }
void setVolume(float volume) { _volume = glm::clamp(volume, 0.0f, 1.0f); }
private: private:
qint64 recursiveReadFromFront(char* data, qint64 maxSize); qint64 recursiveReadFromFront(char* data, qint64 maxSize);
@ -40,7 +39,6 @@ private:
bool _isStopped; bool _isStopped;
int _currentOffset; int _currentOffset;
float _volume;
}; };
#endif // hifi_AudioInjectorLocalBuffer_h #endif // hifi_AudioInjectorLocalBuffer_h