void AsyncAudioDecoder::DecodingTask::notifyComplete()
{
    if (audioBuffer() && successCallback())
        successCallback()->handleEvent(audioBuffer());
    else if (errorCallback())
        errorCallback()->handleEvent(audioBuffer());

    // Our ownership was given up in AsyncAudioDecoder::runLoop()
    // Make sure to clean up here.
    delete this;
}
Esempio n. 2
0
void Connection::processBuffer() {
    Buffer* buffer;
    char* nextHeader;
    char* nextBuffer;

    while (!queue.isEmpty() ){
        buffer=queue.dequeue();
        nextHeader=buffer->getHeader();
        nextBuffer=buffer->getBuffer();

        //qDebug() << "processBuffer " << nextHeader[0];
        // emit a signal to show what buffer we have
        if(nextHeader[0]==SPECTRUM_BUFFER){
            emit spectrumBuffer(nextHeader,nextBuffer);
        }
        else if(nextHeader[0]==AUDIO_BUFFER) {
            emit audioBuffer(nextHeader,nextBuffer);
        } else if(nextHeader[0]==BANDSCOPE_BUFFER) {
            //qDebug() << "socketData: bandscope";
            emit bandscopeBuffer(nextHeader,nextBuffer);
        } else {
            qDebug() << "Connection::socketData: invalid header: " << nextHeader[0];
        }
    }
}
Esempio n. 3
0
void LAudioAppComponent::getNextAudioBlock( const AudioSourceChannelInfo& bufferToFill ) {
    if(stopped
            || !audioOpen
            || !hasCallback("getNextAudioBlock") 
            || (audioOpen && audioSourcePlayer.getCurrentSource()==nullptr) )
    {
        bufferToFill.clearActiveBufferRegion();
        return;
    }
    if(hasCallback("getNextAudioBlock")) {
        MessageManagerLock mml (Thread::getCurrentThread());
            if (! mml.lockWasGained()) {
                DBG("CAN'T GET LOCK");
                return; // another thread is trying to kill us!
            }
        LAudioSampleBuffer audioBuffer(Ls, *bufferToFill.buffer);
        callback("getNextAudioBlock", 0, {
                bufferToFill.startSample,
                bufferToFill.numSamples,
                bufferToFill.buffer->getNumChannels(),
                new LRefBase("AudioSampleBuffer", &audioBuffer)
        });
        if(volume>-1) {
            if(volume) bufferToFill.buffer->applyGain(volume);
            else bufferToFill.clearActiveBufferRegion();
        }
    }
}
void Connection::processBuffer() {
    Buffer* buffer;
    char* nextHeader;
    char* nextBuffer;

// We only want to mute the audio (actually not for full duplex)
// the spectrum display should show the microphone waveform
/*
    if(muted) { // If Rx muted, clear queue and don't process buffer - gvj
        queue.clear();
    }
*/
    while (!queue.isEmpty()){
        buffer=queue.dequeue();
        nextHeader=buffer->getHeader();
        nextBuffer=buffer->getBuffer();
        // emit a signal to show what buffer we have
        //qDebug() << "processBuffer " << nextHeader[0];
        if(nextHeader[0]==SPECTRUM_BUFFER){
            emit spectrumBuffer(nextHeader,nextBuffer);
        }
        else if(nextHeader[0]==AUDIO_BUFFER) {
            // need to add a duplex state
            if(!muted) emit audioBuffer(nextHeader,nextBuffer);
        } else if(nextHeader[0]==BANDSCOPE_BUFFER) {
            //qDebug() << "socketData: bandscope";
            emit bandscopeBuffer(nextHeader,nextBuffer);
        } else {
            qDebug() << "Connection::socketData: invalid header: " << nextHeader[0];
            queue.clear();
        }
    }
}
void KeyAnalysisThread::analyzeSingleKey()
{
	DBG("Thread: " << this->getThreadName() << " analyzing single key of: " << fileToAnalyze->getUUID());
	//skip already-analyzed files
	if (fileToAnalyze->isFileAnalyzed() == "Yes")
	{
		DBG("Skipping analysis of " << fileToAnalyze->getFileName() << " : Already analyzed.");
		return;
	}
	//DBG("File being analyzed: " << fileToAnalyze.getFileToBeAnalyzed().getFileName());
//	r> audioFormatReader = audioFormatManager.createReaderFor(fileToAnalyze.getFileToBeAnalyzed());

	size_t numSamples = audioFormatReader->lengthInSamples;
	size_t numChannels = audioFormatReader->numChannels;
	size_t sampleRate = audioFormatReader->sampleRate;
	//size_t numFrames = numSamples / numChannels;
	//DBG("Samples:" + String(numSamples) + " Channels:" + String(numChannels) + " Frames:" + String(numFrames));
	audioData.addToSampleCount(numSamples*numChannels);
	audioData.setChannels(numChannels);
	audioData.setFrameRate(sampleRate);

	AudioBuffer<float> audioBuffer(numChannels, numSamples);

	// #TODO(Casey): Fix either audiobuffer or audioData to allow direct move of sample array (Performance)
	// #TODO(Casey): integrate libsndfile as primary choice

	//DBG("Reading wav to buffer");
	audioFormatReader->read(&audioBuffer, 0, numSamples, 0, true, true);


	//DBG("Copying buffer samples to audioData");
	for (size_t i = 0; i < numSamples; ++i)
	{
		//DBG("On sample " + String(i) + " of " + String(numSamples));
		for (size_t currChannel = 0; currChannel < numChannels; ++currChannel)
		{
			audioData.setSampleByFrame(i, currChannel, audioBuffer.getSample(currChannel, i));
		}
		//audioData.setSampleByFrame(i, 1, audioBuffer.getSample(1, i));
	}

	//DBG("Detecting key...");

	static KeyFinder::KeyFinder keyFinder;

	KeyFinder::key_t key = keyFinder.keyOfAudio(audioData);

	//KeyFinder::key_t key = KeyFinder::key_t::C_MAJOR;

	fileToAnalyze->setDetectedKey(key);

	String foundKey(fileToAnalyze->getDetectedKeyAsString());

	DBG("Detected key in analyzeAudioFiles: " + foundKey);
}
    // ////////////////////////////////////////////////////////////////////
    //
    // ////////////////////////////////////////////////////////////////////
    boost::shared_ptr<IAudioBuffer> DirectSound8Audio::VInitAudioBuffer(shared_ptr<SoundResHandle> soundResource)//const
    {
        boost::shared_ptr<IAudioBuffer> null;
        const char *fileExtension = FindExtFromSoundType(soundResource->GetSoundType());

        if(m_pDS == NULL) {
            return (null);
        }

        switch(soundResource->GetSoundType()) {
            case SOUND_TYPE_OGG:
            case SOUND_TYPE_WAVE:
                // We support WAVs and OGGs
                break;

            case SOUND_TYPE_MP3:
            case SOUND_TYPE_MIDI:   //If it's a midi file, then do nothin at this time... maybe we will support this in the future
                GF_LOG_TRACE_ERR("DirectSound8Audio::VInitAudioBuffer()", "MP3s and MIDI are not supported");
                return (null);
                break;

            default:
                GF_LOG_TRACE_ERR("DirectSound8Audio::VInitAudioBuffer()", "Unknown sound file");
                return (null);
                break;
        }//end switch

        LPDIRECTSOUNDBUFFER sampleHandle;

        // Create the direct sound buffer, and only request the flags needed
        // since each requires some overhead and limits if the buffer can
        // be hardware accelerated
        DSBUFFERDESC dsbd;
        ZeroMemory(&dsbd, sizeof(DSBUFFERDESC));
        dsbd.dwSize          = sizeof(DSBUFFERDESC);
        dsbd.dwFlags         = DSBCAPS_CTRLVOLUME;
        dsbd.dwBufferBytes   = soundResource->GetPCMBufferSize();
        dsbd.guid3DAlgorithm = GUID_NULL;
        dsbd.lpwfxFormat     = const_cast<WAVEFORMATEX *>(soundResource->GetFormat());

        HRESULT hr;
        if(FAILED(hr = m_pDS->CreateSoundBuffer(&dsbd, &sampleHandle, NULL))) {
            GF_LOG_TRACE_ERR("DirectSound8Audio::VInitAudioBuffer()", "");
            return (null);
        }

        // Add handle to the list
        boost::shared_ptr<IAudioBuffer> audioBuffer(GCC_NEW DirectSound8AudioBuffer(sampleHandle, soundResource));
        if(audioBuffer) {
            m_AllSamples.insert(m_AllSamples.begin(), audioBuffer);
        }

        return (audioBuffer);
    }
status_t FMA2DPWriter::allocateBufferPool()
{
    Mutex::Autolock lock(mFreeQLock);

    for (int i = 0; i < BUFFER_POOL_SIZE; ++i) {
        int *buffer = (int*)malloc(mBufferSize);
        if(buffer){
            audioBufferstruct audioBuffer(buffer,mBufferSize);
            mFreeQ.push_back(audioBuffer);
        }
        else{
            ALOGE("fatal:failed to alloate buffer pool");
            return  NO_INIT;
        }
    }
    return OK;
}