Merge pull request #3499 from Atlante45/radio_js

Stereo fix
This commit is contained in:
Andrzej Kapolka 2014-09-26 20:04:55 -07:00
commit 533d59becc
4 changed files with 22 additions and 9 deletions

View file

@ -89,10 +89,13 @@ int AudioMixerClientData::parseData(const QByteArray& packet) {
// grab the stream identifier for this injected audio // grab the stream identifier for this injected audio
int bytesBeforeStreamIdentifier = numBytesForPacketHeader(packet) + sizeof(quint16); int bytesBeforeStreamIdentifier = numBytesForPacketHeader(packet) + sizeof(quint16);
QUuid streamIdentifier = QUuid::fromRfc4122(packet.mid(bytesBeforeStreamIdentifier, NUM_BYTES_RFC4122_UUID)); QUuid streamIdentifier = QUuid::fromRfc4122(packet.mid(bytesBeforeStreamIdentifier, NUM_BYTES_RFC4122_UUID));
int bytesBeforeStereoIdentifier = bytesBeforeStreamIdentifier + NUM_BYTES_RFC4122_UUID;
bool isStereo;
QDataStream(packet.mid(bytesBeforeStereoIdentifier)) >> isStereo;
if (!_audioStreams.contains(streamIdentifier)) { if (!_audioStreams.contains(streamIdentifier)) {
// we don't have this injected stream yet, so add it // we don't have this injected stream yet, so add it
_audioStreams.insert(streamIdentifier, matchingStream = new InjectedAudioStream(streamIdentifier, AudioMixer::getStreamSettings())); _audioStreams.insert(streamIdentifier, matchingStream = new InjectedAudioStream(streamIdentifier, isStereo, AudioMixer::getStreamSettings()));
} else { } else {
matchingStream = _audioStreams.value(streamIdentifier); matchingStream = _audioStreams.value(streamIdentifier);
} }

View file

@ -33,7 +33,8 @@ AudioInjector::AudioInjector(QObject* parent) :
AudioInjector::AudioInjector(Sound* sound, const AudioInjectorOptions& injectorOptions) : AudioInjector::AudioInjector(Sound* sound, const AudioInjectorOptions& injectorOptions) :
_sound(sound), _sound(sound),
_options(injectorOptions), _options(injectorOptions),
_shouldStop(false) _shouldStop(false),
_currentSendPosition(0)
{ {
} }
@ -44,9 +45,13 @@ void AudioInjector::setOptions(AudioInjectorOptions& options) {
const uchar MAX_INJECTOR_VOLUME = 0xFF; const uchar MAX_INJECTOR_VOLUME = 0xFF;
void AudioInjector::injectAudio() { void AudioInjector::injectAudio() {
QByteArray soundByteArray = _sound->getByteArray(); QByteArray soundByteArray = _sound->getByteArray();
if (_currentSendPosition < 0 ||
_currentSendPosition >= soundByteArray.size()) {
_currentSendPosition = 0;
}
// make sure we actually have samples downloaded to inject // make sure we actually have samples downloaded to inject
if (soundByteArray.size()) { if (soundByteArray.size()) {
// give our sample byte array to the local audio interface, if we have it, so it can be handled locally // give our sample byte array to the local audio interface, if we have it, so it can be handled locally

View file

@ -19,8 +19,8 @@
#include "InjectedAudioStream.h" #include "InjectedAudioStream.h"
InjectedAudioStream::InjectedAudioStream(const QUuid& streamIdentifier, const InboundAudioStream::Settings& settings) : InjectedAudioStream::InjectedAudioStream(const QUuid& streamIdentifier, const bool isStereo, const InboundAudioStream::Settings& settings) :
PositionalAudioStream(PositionalAudioStream::Injector, false, settings), PositionalAudioStream(PositionalAudioStream::Injector, isStereo, settings),
_streamIdentifier(streamIdentifier), _streamIdentifier(streamIdentifier),
_radius(0.0f), _radius(0.0f),
_attenuationRatio(0) _attenuationRatio(0)
@ -39,9 +39,14 @@ int InjectedAudioStream::parseStreamProperties(PacketType type,
// skip the stream identifier // skip the stream identifier
packetStream.skipRawData(NUM_BYTES_RFC4122_UUID); packetStream.skipRawData(NUM_BYTES_RFC4122_UUID);
packetStream >> _isStereo; // read the channel flag
if (isStereo()) { bool isStereo;
_ringBuffer.resizeForFrameSize(NETWORK_BUFFER_LENGTH_SAMPLES_STEREO); packetStream >> isStereo;
// if isStereo value has changed, restart the ring buffer with new frame size
if (isStereo != _isStereo) {
_ringBuffer.resizeForFrameSize(isStereo ? NETWORK_BUFFER_LENGTH_SAMPLES_STEREO : NETWORK_BUFFER_LENGTH_SAMPLES_PER_CHANNEL);
_isStereo = isStereo;
} }
// pull the loopback flag and set our boolean // pull the loopback flag and set our boolean

View file

@ -18,7 +18,7 @@
class InjectedAudioStream : public PositionalAudioStream { class InjectedAudioStream : public PositionalAudioStream {
public: public:
InjectedAudioStream(const QUuid& streamIdentifier, const InboundAudioStream::Settings& settings); InjectedAudioStream(const QUuid& streamIdentifier, const bool isStereo, const InboundAudioStream::Settings& settings);
float getRadius() const { return _radius; } float getRadius() const { return _radius; }
float getAttenuationRatio() const { return _attenuationRatio; } float getAttenuationRatio() const { return _attenuationRatio; }