Exemple #1
0
void
OpenSLLayer::playback(SLAndroidSimpleBufferQueueItf queue)
{
    assert(nullptr != queue);
    notifyIncomingCall();

    AudioBuffer &buffer = getNextPlaybackBuffer();
    size_t urgentSamplesToGet = urgentRingBuffer_.availableForGet(RingBufferPool::DEFAULT_ID);

    bufferIsFilled_ = false;
    if (urgentSamplesToGet > 0) {
        bufferIsFilled_ = audioPlaybackFillWithUrgent(buffer, std::min(urgentSamplesToGet, hardwareBuffSize_));
    } else {
        auto& main_buffer = Manager::instance().getRingBufferPool();
        buffer.resize(hardwareBuffSize_);
        size_t samplesToGet = audioPlaybackFillWithVoice(buffer);
        if (samplesToGet == 0) {
            bufferIsFilled_ = audioPlaybackFillWithToneOrRingtone(buffer);
        } else {
            bufferIsFilled_ = true;
        }
    }

    if (bufferIsFilled_) {
        SLresult result = (*queue)->Enqueue(queue, buffer.getChannel(0)->data(), buffer.frames()*sizeof(SFLAudioSample));
        if (SL_RESULT_SUCCESS != result) {
            DEBUG("Error could not enqueue buffers in playback callback\n");
        }
        incrementPlaybackIndex();
    } else {
        DEBUG("Error buffer not filled in audio playback\n");
    }
}
Exemple #2
0
void AlsaLayer::audioCallback()
{
    if (!playbackHandle_ or !captureHandle_)
        return;

    notifyIncomingCall();

    snd_pcm_wait(playbackHandle_, 20);

    int playbackAvailFrames = 0;

    if (not safeUpdate(playbackHandle_, playbackAvailFrames))
        return;

    unsigned framesToGet = urgentRingBuffer_.availableForGet(MainBuffer::DEFAULT_ID);

    if (framesToGet > 0) {
        // Urgent data (dtmf, incoming call signal) come first.
        framesToGet = std::min(framesToGet, (unsigned)playbackAvailFrames);
        playbackBuff_.setFormat(audioFormat_);
        playbackBuff_.resize(framesToGet);
        urgentRingBuffer_.get(playbackBuff_, MainBuffer::DEFAULT_ID);
        playbackBuff_.applyGain(isPlaybackMuted_ ? 0.0 : playbackGain_);
        playbackBuff_.interleave(playbackIBuff_);
        write(playbackIBuff_.data(), framesToGet, playbackHandle_);
        // Consume the regular one as well (same amount of frames)
        Manager::instance().getMainBuffer().discard(framesToGet, MainBuffer::DEFAULT_ID);
    } else {
        // regular audio data
        playback(playbackAvailFrames);
    }

    if (ringtoneHandle_) {
        AudioLoop *file_tone = Manager::instance().getTelephoneFile();
        int ringtoneAvailFrames = 0;

        if (not safeUpdate(ringtoneHandle_, ringtoneAvailFrames))
            return;

        playbackBuff_.setFormat(audioFormat_);
        playbackBuff_.resize(ringtoneAvailFrames);

        if (file_tone) {
            DEBUG("playback gain %d", playbackGain_);
            file_tone->getNext(playbackBuff_, playbackGain_);
        }

        playbackBuff_.interleave(playbackIBuff_);
        write(playbackIBuff_.data(), ringtoneAvailFrames, ringtoneHandle_);
    }

    // Additionally handle the mic's audio stream
    if (is_capture_running_)
        capture();
}
Exemple #3
0
void
JackLayer::playback()
{
    notifyIncomingCall();

    const size_t samplesToGet = Manager::instance().getRingBufferPool().availableForGet(RingBufferPool::DEFAULT_ID);
    const size_t urgentSamplesToGet = urgentRingBuffer_.availableForGet(RingBufferPool::DEFAULT_ID);

    if (urgentSamplesToGet > 0) {
        fillWithUrgent(playbackBuffer_, urgentSamplesToGet);
    } else {
        if (samplesToGet > 0) {
            fillWithVoice(playbackBuffer_, samplesToGet);
        } else {
            fillWithToneOrRingtone(playbackBuffer_);
        }
    }

    playbackFloatBuffer_.resize(playbackBuffer_.frames());
    write(playbackBuffer_, playbackFloatBuffer_);
}