mirror of
https://github.com/overte-org/overte.git
synced 2025-04-20 04:44:11 +02:00
fix QIODevice fail in AudioInjector by passing explicit size
This commit is contained in:
parent
cd3877b584
commit
83529c1fed
4 changed files with 23 additions and 16 deletions
|
@ -1334,11 +1334,13 @@ void Audio::startDrumSound(float volume, float frequency, float duration, float
|
|||
_drumSoundSample = 0;
|
||||
}
|
||||
|
||||
QIODevice* Audio::newLocalOutputDevice(bool isStereo) {
|
||||
QIODevice* Audio::newLocalOutputDevice(bool isStereo, int numBytes, QObject* injector) {
|
||||
QAudioFormat localFormat = _desiredOutputFormat;
|
||||
localFormat.setChannelCount(isStereo ? 2 : 1);
|
||||
|
||||
QAudioOutput* localOutput = new QAudioOutput(getNamedAudioDeviceForMode(QAudio::AudioOutput, _outputAudioDeviceName),
|
||||
localFormat);
|
||||
localFormat, this);
|
||||
localOutput->setBufferSize(numBytes);
|
||||
|
||||
return localOutput->start();
|
||||
}
|
||||
|
|
|
@ -155,7 +155,7 @@ public slots:
|
|||
void selectAudioFilterBassCut();
|
||||
void selectAudioFilterSmiley();
|
||||
|
||||
virtual QIODevice* newLocalOutputDevice(bool isStereo);
|
||||
virtual QIODevice* newLocalOutputDevice(bool isStereo, int numBytes, QObject* injector);
|
||||
|
||||
void sendDownstreamAudioStatsPacket();
|
||||
|
||||
|
@ -256,10 +256,6 @@ private:
|
|||
float _iconColor;
|
||||
qint64 _iconPulseTimeReference;
|
||||
|
||||
/// Audio callback in class context.
|
||||
inline void performIO(int16_t* inputLeft, int16_t* outputLeft, int16_t* outputRight);
|
||||
|
||||
|
||||
bool _processSpatialAudio; /// Process received audio by spatial audio hooks
|
||||
unsigned int _spatialAudioStart; /// Start of spatial audio interval (in sample rate time base)
|
||||
unsigned int _spatialAudioFinish; /// End of spatial audio interval (in sample rate time base)
|
||||
|
|
|
@ -25,7 +25,7 @@ public:
|
|||
virtual void startCollisionSound(float magnitude, float frequency, float noise, float duration, bool flashScreen) = 0;
|
||||
virtual void startDrumSound(float volume, float frequency, float duration, float decay) = 0;
|
||||
public slots:
|
||||
virtual QIODevice* newLocalOutputDevice(bool isStereo) = 0;
|
||||
virtual QIODevice* newLocalOutputDevice(bool isStereo, int numBytes, QObject* injector) = 0;
|
||||
};
|
||||
|
||||
Q_DECLARE_METATYPE(AbstractAudioInterface*)
|
||||
|
|
|
@ -71,18 +71,27 @@ void AudioInjector::injectLocally() {
|
|||
|
||||
QIODevice* localBuffer = NULL;
|
||||
|
||||
QMetaObject::invokeMethod(_localAudioInterface, "newLocalOutputDevice", Qt::BlockingQueuedConnection,
|
||||
Q_RETURN_ARG(QIODevice*, localBuffer),
|
||||
Q_ARG(bool, _options.stereo));
|
||||
const QByteArray& soundByteArray = _sound->getByteArray();
|
||||
|
||||
if (localBuffer) {
|
||||
// immediately write the byte array to the local device
|
||||
localBuffer->write(_sound->getByteArray());
|
||||
if (soundByteArray.size() > 0) {
|
||||
QMetaObject::invokeMethod(_localAudioInterface, "newLocalOutputDevice", Qt::BlockingQueuedConnection,
|
||||
Q_RETURN_ARG(QIODevice*, localBuffer),
|
||||
Q_ARG(bool, _options.stereo),
|
||||
Q_ARG(int, soundByteArray.size()),
|
||||
Q_ARG(QObject*, this));
|
||||
|
||||
if (localBuffer) {
|
||||
// immediately write the byte array to the local device
|
||||
qDebug() << "Writing" << localBuffer->write(soundByteArray) << "bytes to local audio device";
|
||||
} else {
|
||||
qDebug() << "AudioInjector::injectLocally did not get a valid QIODevice from _localAudioInterface";
|
||||
}
|
||||
} else {
|
||||
qDebug() << "AudioInject::injectLocally did not get a valid QIODevice from _localAudioInterface";
|
||||
qDebug() << "AudioInjector::injectLocally called without any data in Sound QByteArray";
|
||||
}
|
||||
|
||||
} else {
|
||||
qDebug() << "AudioInject::injectLocally cannot inject locally with no local audio interface present.";
|
||||
qDebug() << "AudioInjector::injectLocally cannot inject locally with no local audio interface present.";
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue