void AudioScriptingInterface::playSound(Sound* sound, const AudioInjectorOptions* injectorOptions) { AudioInjector* injector = new AudioInjector(sound, *injectorOptions); QThread* injectorThread = new QThread(); injector->moveToThread(injectorThread); // start injecting when the injector thread starts connect(injectorThread, SIGNAL(started()), injector, SLOT(injectAudio())); // connect the right slots and signals so that the AudioInjector is killed once the injection is complete connect(injector, SIGNAL(finished()), injector, SLOT(deleteLater())); connect(injector, SIGNAL(finished()), injectorThread, SLOT(quit())); connect(injectorThread, SIGNAL(finished()), injectorThread, SLOT(deleteLater())); injectorThread->start(); }
AudioInjector* AudioInjector::playSound(const QByteArray& buffer, const AudioInjectorOptions options, AbstractAudioInterface* localInterface) { QThread* injectorThread = new QThread(); injectorThread->setObjectName("Audio Injector Thread"); AudioInjector* injector = new AudioInjector(buffer, options); injector->setLocalAudioInterface(localInterface); injector->moveToThread(injectorThread); // start injecting when the injector thread starts connect(injectorThread, &QThread::started, injector, &AudioInjector::injectAudio); // connect the right slots and signals for AudioInjector and thread cleanup connect(injector, &AudioInjector::destroyed, injectorThread, &QThread::quit); connect(injectorThread, &QThread::finished, injectorThread, &QThread::deleteLater); injectorThread->start(); return injector; }
void AudioScriptingInterface::startDrumSound(float volume, float frequency, float duration, float decay, const AudioInjectorOptions* injectorOptions) { Sound* sound = new Sound(volume, frequency, duration, decay); AudioInjector* injector = new AudioInjector(sound, *injectorOptions); sound->setParent(injector); QThread* injectorThread = new QThread(); injector->moveToThread(injectorThread); // start injecting when the injector thread starts connect(injectorThread, SIGNAL(started()), injector, SLOT(injectAudio())); // connect the right slots and signals so that the AudioInjector is killed once the injection is complete connect(injector, SIGNAL(finished()), injector, SLOT(deleteLater())); connect(injector, SIGNAL(finished()), injectorThread, SLOT(quit())); connect(injectorThread, SIGNAL(finished()), injectorThread, SLOT(deleteLater())); injectorThread->start(); }