mirror of
https://github.com/HifiExperiments/overte.git
synced 2025-08-09 20:32:21 +02:00
provide old ASI APIs in AudioInjector
This commit is contained in:
parent
7b485829c4
commit
0498c5c708
2 changed files with 35 additions and 40 deletions
|
@ -34,35 +34,20 @@ void injectorFromScriptValue(const QScriptValue& object, AudioInjector*& out) {
|
||||||
}
|
}
|
||||||
|
|
||||||
AudioInjector::AudioInjector(QObject* parent) :
|
AudioInjector::AudioInjector(QObject* parent) :
|
||||||
QObject(parent),
|
QObject(parent)
|
||||||
_options(),
|
|
||||||
_shouldStop(false),
|
|
||||||
_loudness(0.0f),
|
|
||||||
_isFinished(false),
|
|
||||||
_currentSendPosition(0),
|
|
||||||
_localBuffer(NULL)
|
|
||||||
{
|
{
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
AudioInjector::AudioInjector(Sound* sound, const AudioInjectorOptions& injectorOptions) :
|
AudioInjector::AudioInjector(Sound* sound, const AudioInjectorOptions& injectorOptions) :
|
||||||
_audioData(sound->getByteArray()),
|
_audioData(sound->getByteArray()),
|
||||||
_options(injectorOptions),
|
_options(injectorOptions)
|
||||||
_shouldStop(false),
|
|
||||||
_loudness(0.0f),
|
|
||||||
_isFinished(false),
|
|
||||||
_currentSendPosition(0),
|
|
||||||
_localBuffer(NULL)
|
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
AudioInjector::AudioInjector(const QByteArray& audioData, const AudioInjectorOptions& injectorOptions) :
|
AudioInjector::AudioInjector(const QByteArray& audioData, const AudioInjectorOptions& injectorOptions) :
|
||||||
_audioData(audioData),
|
_audioData(audioData),
|
||||||
_options(injectorOptions),
|
_options(injectorOptions)
|
||||||
_shouldStop(false),
|
|
||||||
_loudness(0.0f),
|
|
||||||
_isFinished(false),
|
|
||||||
_currentSendPosition(0),
|
|
||||||
_localBuffer(NULL)
|
|
||||||
{
|
{
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -83,21 +68,25 @@ float AudioInjector::getLoudness() {
|
||||||
|
|
||||||
void AudioInjector::injectAudio() {
|
void AudioInjector::injectAudio() {
|
||||||
|
|
||||||
// check if we need to offset the sound by some number of seconds
|
if (!_isStarted) {
|
||||||
if (_options.secondOffset > 0.0f) {
|
// check if we need to offset the sound by some number of seconds
|
||||||
|
if (_options.secondOffset > 0.0f) {
|
||||||
|
|
||||||
|
// convert the offset into a number of bytes
|
||||||
|
int byteOffset = (int) floorf(AudioConstants::SAMPLE_RATE * _options.secondOffset * (_options.stereo ? 2.0f : 1.0f));
|
||||||
|
byteOffset *= sizeof(int16_t);
|
||||||
|
|
||||||
|
_currentSendPosition = byteOffset;
|
||||||
|
}
|
||||||
|
|
||||||
// convert the offset into a number of bytes
|
if (_options.localOnly) {
|
||||||
int byteOffset = (int) floorf(AudioConstants::SAMPLE_RATE * _options.secondOffset * (_options.stereo ? 2.0f : 1.0f));
|
injectLocally();
|
||||||
byteOffset *= sizeof(int16_t);
|
} else {
|
||||||
|
injectToMixer();
|
||||||
_currentSendPosition = byteOffset;
|
}
|
||||||
}
|
|
||||||
|
|
||||||
if (_options.localOnly) {
|
|
||||||
injectLocally();
|
|
||||||
} else {
|
} else {
|
||||||
injectToMixer();
|
qDebug() << "AudioInjector::injectAudio called but already started.";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void AudioInjector::injectLocally() {
|
void AudioInjector::injectLocally() {
|
||||||
|
|
|
@ -43,25 +43,31 @@ public:
|
||||||
public slots:
|
public slots:
|
||||||
void injectAudio();
|
void injectAudio();
|
||||||
void stop();
|
void stop();
|
||||||
void stopAndDeleteLater();
|
|
||||||
void setOptions(AudioInjectorOptions& options);
|
void setOptions(AudioInjectorOptions& options);
|
||||||
void setCurrentSendPosition(int currentSendPosition) { _currentSendPosition = currentSendPosition; }
|
void setCurrentSendPosition(int currentSendPosition) { _currentSendPosition = currentSendPosition; }
|
||||||
float getLoudness();
|
float getLoudness() const;
|
||||||
|
bool isPlaying() const { return !_isFinished; }
|
||||||
|
|
||||||
signals:
|
signals:
|
||||||
void finished();
|
void finished();
|
||||||
|
|
||||||
|
private slots:
|
||||||
|
void stopAndDeleteLater();
|
||||||
private:
|
private:
|
||||||
void injectToMixer();
|
void injectToMixer();
|
||||||
void injectLocally();
|
void injectLocally();
|
||||||
|
|
||||||
QByteArray _audioData;
|
QByteArray _audioData;
|
||||||
AudioInjectorOptions _options;
|
AudioInjectorOptions _options;
|
||||||
bool _shouldStop;
|
bool _shouldStop = false;
|
||||||
float _loudness;
|
float _loudness = 0.0f;
|
||||||
bool _isFinished;
|
bool _isStarted = false;
|
||||||
int _currentSendPosition;
|
bool _isFinished = false;
|
||||||
AbstractAudioInterface* _localAudioInterface;
|
int _currentSendPosition = 0;
|
||||||
AudioInjectorLocalBuffer* _localBuffer;
|
AbstractAudioInterface* _localAudioInterface = NULL;
|
||||||
|
AudioInjectorLocalBuffer* _localBuffer = NULL;
|
||||||
|
|
||||||
|
friend QScriptValue injectorToScriptValue(QScriptEngine* engine, AudioInjector* const& in);
|
||||||
};
|
};
|
||||||
|
|
||||||
Q_DECLARE_METATYPE(AudioInjector*)
|
Q_DECLARE_METATYPE(AudioInjector*)
|
||||||
|
|
Loading…
Reference in a new issue