Exemplo n.º 1
0
AudioInjector* AudioInjector::playSound(const QByteArray& buffer, const AudioInjectorOptions options, AbstractAudioInterface* localInterface) {
    AudioInjector* injector = new AudioInjector(buffer, options);
    injector->setLocalAudioInterface(localInterface);
    
    // grab the AudioInjectorManager
    auto injectorManager = DependencyManager::get<AudioInjectorManager>();
    
    // setup parameters required for injection
    injector->setupInjection();
    
    if (options.localOnly) {
        if (injector->injectLocally()) {
            // local injection succeeded, return the pointer to injector
            return injector;
        } else {
            // unable to inject locally, return a nullptr
            return nullptr;
        }
    } else {
        // attempt to thread the new injector
        if (injectorManager->threadInjector(injector)) {
            return injector;
        } else {
            // we failed to thread the new injector (we are at the max number of injector threads)
            return nullptr;
        }
    }
}
Exemplo n.º 2
0
void* AudioInjectionManager::injectAudioViaThread(void* args) {
    AudioInjector* injector = (AudioInjector*) args;
    
    // if we don't have an injectorSocket then grab the one from the node list
    if (!_injectorSocket) {
        _injectorSocket = NodeList::getInstance()->getNodeSocket();
    }
    
    // if we don't have an explicit destination socket then pull active socket for current audio mixer from node list
    if (!_isDestinationSocketExplicit) {
        Node* audioMixer = NodeList::getInstance()->soloNodeOfType(NODE_TYPE_AUDIO_MIXER);
        if (audioMixer) {
            _destinationSocket = *audioMixer->getActiveSocket();
        }
    }
    
    injector->injectAudio(_injectorSocket, &_destinationSocket);
    
    // if this an injector inside the injection manager's array we're responsible for deletion
    for (int i = 0; i < MAX_CONCURRENT_INJECTORS; i++) {
        if (_injectors[i] == injector) {
            // pointer matched - delete this injector
            delete injector;
            
            // set the pointer to NULL so we can reuse this spot
            _injectors[i] = NULL;
        }
    }
    
    pthread_exit(0);
	return NULL;
}
Exemplo n.º 3
0
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();
}
Exemplo n.º 4
0
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;
}
Exemplo n.º 5
0
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();
}
Exemplo n.º 6
0
AudioInjector* AudioInjector::playSoundAndDelete(const QByteArray& buffer, const AudioInjectorOptions options, AbstractAudioInterface* localInterface) {
    AudioInjector* sound = playSound(buffer, options, localInterface);
    sound->triggerDeleteAfterFinish();
    return sound;
}