예제 #1
0
void RingBufferPut(tRingBuffer *rb, unsigned char c, int block)
{
    if (block)
    {
        while (RingBufferFillLevel(rb) + 1 == RingBufferSize(rb))
        {
            // wait
        }
    }
    else
    {
        if (RingBufferFillLevel(rb) + 1 == RingBufferSize(rb))
        {
            rb->Overrun++;
            return;
        }
    }

    rb->Buffer[rb->Write] = c;

    if (rb->Write + 1 == RingBufferSize(rb))
    {
        rb->Write = 0;
    }
    else
    {
        rb->Write++;
    }

    if (rb->CallBack)
    {
        rb->CallBack();
    }
}
예제 #2
0
void RingBufferPutBlock(tRingBuffer *rb, unsigned char *data, int dataLen, int block)
{
    if (block)
    {
        while (RingBufferFillLevel(rb) + dataLen >= RingBufferSize(rb))
        {
            // wait
        }
    }
    else
    {
        if (RingBufferFillLevel(rb) + dataLen >= RingBufferSize(rb))
        {
            rb->Overrun += dataLen;

            if (rb->CallBack)
            {
                rb->CallBack();
            }

            return;
        }
    }

    int free1 = RingBufferSize(rb) - rb->Write;

    if (dataLen <= free1)
    {
        memcpy(rb->Buffer + rb->Write, data, dataLen);

        if (rb->Write + dataLen == RingBufferSize(rb))
        {
            rb->Write = 0;
        }
        else
        {
            rb->Write += dataLen;
        }
    }
    else
    {
        memcpy(rb->Buffer + rb->Write, data, free1);
        int len2 = dataLen - free1;
        memcpy(rb->Buffer, data + free1, len2);
        rb->Write = len2;
    }

    if (rb->CallBack)
    {
        rb->CallBack();
    }
}
예제 #3
0
void UART4_IRQHandler(void) //UART4 Interrupt handler implementation
{
    int sr = UART4->SR;
    IrqCntUart4++;

    if (sr & USART_FLAG_TXE)
    {
        tRingBuffer *rb = &RingBufferUART4TX;

        if (rb->Read != rb->Write)
        {
            UART4->DR = rb->Buffer[rb->Read];

            if (rb->Read + 1 == RingBufferSize(rb))
            {
                rb->Read = 0;
            }
            else
            {
                rb->Read++;
            }
        }
        else
        {
            USART_ITConfig(UART4, USART_IT_TXE, DISABLE);
            asm volatile("nop");
            asm volatile("nop");
        }
    }
예제 #4
0
static ALCuint pulse_available_samples(ALCdevice *device) //{{{
{
    pulse_data *data = device->ExtraData;
    size_t samples;

    pa_threaded_mainloop_lock(data->loop);
    /* Capture is done in fragment-sized chunks, so we loop until we get all
     * that's available */
    samples = (device->Connected ? pa_stream_readable_size(data->stream) : 0);
    while(samples > 0)
    {
        const void *buf;
        size_t length;

        if(pa_stream_peek(data->stream, &buf, &length) < 0)
        {
            ERR("pa_stream_peek() failed: %s\n",
                pa_strerror(pa_context_errno(data->context)));
            break;
        }

        WriteRingBuffer(data->ring, buf, length/data->frame_size);
        samples -= length;

        pa_stream_drop(data->stream);
    }
    pa_threaded_mainloop_unlock(data->loop);

    return RingBufferSize(data->ring);
} //}}}
예제 #5
0
파일: alsa.c 프로젝트: 9heart/DT3
static ALCuint alsa_available_samples(ALCdevice *Device)
{
    alsa_data *data = (alsa_data*)Device->ExtraData;
    snd_pcm_sframes_t avail;

    avail = (Device->Connected ? snd_pcm_avail_update(data->pcmHandle) : 0);
    if(avail < 0)
    {
        ERR("avail update failed: %s\n", snd_strerror(avail));

        if((avail=snd_pcm_recover(data->pcmHandle, avail, 1)) >= 0)
        {
            if(data->doCapture)
                avail = snd_pcm_start(data->pcmHandle);
            if(avail >= 0)
                avail = snd_pcm_avail_update(data->pcmHandle);
        }
        if(avail < 0)
        {
            ERR("restore error: %s\n", snd_strerror(avail));
            aluHandleDisconnect(Device);
        }
    }
    while(avail > 0)
    {
        snd_pcm_sframes_t amt;

        amt = snd_pcm_bytes_to_frames(data->pcmHandle, data->size);
        if(avail < amt) amt = avail;

        amt = snd_pcm_readi(data->pcmHandle, data->buffer, amt);
        if(amt < 0)
        {
            ERR("read error: %s\n", snd_strerror(amt));

            if(amt == -EAGAIN)
                continue;
            if((amt=snd_pcm_recover(data->pcmHandle, amt, 1)) >= 0)
            {
                if(data->doCapture)
                    amt = snd_pcm_start(data->pcmHandle);
                if(amt >= 0)
                    amt = snd_pcm_avail_update(data->pcmHandle);
            }
            if(amt < 0)
            {
                ERR("restore error: %s\n", snd_strerror(amt));
                aluHandleDisconnect(Device);
                break;
            }
            avail = amt;
            continue;
        }

        WriteRingBuffer(data->ring, data->buffer, amt);
        avail -= amt;
    }

    return RingBufferSize(data->ring);
}
예제 #6
0
파일: oss.c 프로젝트: ghoulsblade/vegaogre
static void oss_capture_samples(ALCdevice *pDevice, ALCvoid *pBuffer, ALCuint lSamples)
{
    oss_data *data = (oss_data*)pDevice->ExtraData;
    if(lSamples <= (ALCuint)RingBufferSize(data->ring))
        ReadRingBuffer(data->ring, pBuffer, lSamples);
    else
        SetALCError(ALC_INVALID_VALUE);
}
예제 #7
0
파일: portaudio.c 프로젝트: 3dseals/furseal
static void pa_capture_samples(ALCdevice *device, ALCvoid *buffer, ALCuint samples)
{
    pa_data *data = device->ExtraData;
    if(samples <= (ALCuint)RingBufferSize(data->ring))
        ReadRingBuffer(data->ring, buffer, samples);
    else
        alcSetError(device, ALC_INVALID_VALUE);
}
예제 #8
0
/** \brief a initialized packet
 *
 *  \warning Use *only* at init, not at packet runtime
 */
void PacketPoolStorePacket(Packet *p) {
    if (RingBufferIsFull(ringbuffer)) {
        exit(1);
    }

    RingBufferMrMwPut(ringbuffer, (void *)p);
    SCLogDebug("buffersize %u", RingBufferSize(ringbuffer));
}
예제 #9
0
static void pulse_capture_samples(ALCdevice *device, ALCvoid *buffer, ALCuint samples) //{{{
{
    pulse_data *data = device->ExtraData;
    ALCuint available = RingBufferSize(data->ring);
    const void *buf;
    size_t length;

    available *= data->frame_size;
    samples *= data->frame_size;

    ppa_threaded_mainloop_lock(data->loop);
    if(available+ppa_stream_readable_size(data->stream) < samples)
    {
        ppa_threaded_mainloop_unlock(data->loop);
        alcSetError(device, ALC_INVALID_VALUE);
        return;
    }

    available = min(available, samples);
    if(available > 0)
    {
        ReadRingBuffer(data->ring, buffer, available/data->frame_size);
        buffer = (ALubyte*)buffer + available;
        samples -= available;
    }

    /* Capture is done in fragment-sized chunks, so we loop until we get all
     * that's requested */
    while(samples > 0)
    {
        if(ppa_stream_peek(data->stream, &buf, &length) < 0)
        {
            AL_PRINT("pa_stream_peek() failed: %s\n",
                     ppa_strerror(ppa_context_errno(data->context)));
            break;
        }
        available = min(length, samples);

        memcpy(buffer, buf, available);
        buffer = (ALubyte*)buffer + available;
        buf = (const ALubyte*)buf + available;
        samples -= available;
        length -= available;

        /* Any unread data in the fragment will be lost, so save it */
        length /= data->frame_size;
        if(length > 0)
        {
            if(length > data->samples)
                length = data->samples;
            WriteRingBuffer(data->ring, buf, length);
        }

        ppa_stream_drop(data->stream);
    }
    ppa_threaded_mainloop_unlock(data->loop);
} //}}}
예제 #10
0
static void pulse_capture_samples(ALCdevice *device, ALCvoid *buffer, ALCuint samples) //{{{
{
    pulse_data *data = device->ExtraData;
    ALCuint available = RingBufferSize(data->ring);

    if(available < samples)
        SetALCError(ALC_INVALID_VALUE);
    else
        ReadRingBuffer(data->ring, buffer, samples);
} //}}}
예제 #11
0
void CommunicationCheckWrite(CommunicationState *com) {
    char ch;
    while(RingBufferPeek(&com->uart_out_ringbuffer, &ch)) {
        if(CommunicationTrySendChar(ch))
            RingBufferPop(&com->uart_out_ringbuffer, 0);
    }

    if(RingBufferSize(&com->uart_out_ringbuffer) > 0)
        CommunicationIntDisableWrite();
}
예제 #12
0
static ALCuint pulse_available_samples(ALCdevice *device) //{{{
{
    pulse_data *data = device->ExtraData;
    ALCuint ret;

    ppa_threaded_mainloop_lock(data->loop);
    ret  = RingBufferSize(data->ring);
    ret += ppa_stream_readable_size(data->stream)/data->frame_size;
    ppa_threaded_mainloop_unlock(data->loop);

    return ret;
} //}}}
예제 #13
0
/** \brief a initialized packet
 *
 *  \warning Use *only* at init, not at packet runtime
 */
void PacketPoolStorePacket(Packet *p) {
    if (RingBufferIsFull(ringbuffer)) {
        exit(1);
    }

    /* Clear the PKT_ALLOC flag, since that indicates to push back
     * onto the ring buffer. */
    p->flags &= ~PKT_ALLOC;
    p->ReleasePacket = PacketPoolReturnPacket;
    PacketPoolReturnPacket(p);

    SCLogDebug("buffersize %u", RingBufferSize(ringbuffer));
}
예제 #14
0
static ALCuint DSoundAvailableSamples(ALCdevice *pDevice)
{
    DSoundCaptureData *pData = pDevice->ExtraData;
    DWORD dwRead, dwCursor, dwBufferBytes, dwNumBytes;
    void *pvAudio1, *pvAudio2;
    DWORD dwAudioBytes1, dwAudioBytes2;
    DWORD FrameSize;
    HRESULT hr;

    if(!pDevice->Connected)
        goto done;

    FrameSize = FrameSizeFromDevFmt(pDevice->FmtChans, pDevice->FmtType);
    dwBufferBytes = pData->dwBufferBytes;
    dwCursor = pData->dwCursor;

    hr = IDirectSoundCaptureBuffer_GetCurrentPosition(pData->DSCbuffer, NULL, &dwRead);
    if(SUCCEEDED(hr))
    {
        dwNumBytes = (dwBufferBytes + dwRead - dwCursor) % dwBufferBytes;
        if(dwNumBytes == 0)
            goto done;
        hr = IDirectSoundCaptureBuffer_Lock(pData->DSCbuffer,
                                            dwCursor, dwNumBytes,
                                            &pvAudio1, &dwAudioBytes1,
                                            &pvAudio2, &dwAudioBytes2, 0);
    }
    if(SUCCEEDED(hr))
    {
        WriteRingBuffer(pData->pRing, pvAudio1, dwAudioBytes1/FrameSize);
        if(pvAudio2 != NULL)
            WriteRingBuffer(pData->pRing, pvAudio2, dwAudioBytes2/FrameSize);
        hr = IDirectSoundCaptureBuffer_Unlock(pData->DSCbuffer,
                                              pvAudio1, dwAudioBytes1,
                                              pvAudio2, dwAudioBytes2);
        pData->dwCursor = (dwCursor + dwAudioBytes1 + dwAudioBytes2) % dwBufferBytes;
    }

    if(FAILED(hr))
    {
        ERR("update failed: 0x%08lx\n", hr);
        aluHandleDisconnect(pDevice);
    }

done:
    return RingBufferSize(pData->pRing);
}
예제 #15
0
static ALCuint DSoundAvailableSamples(ALCdevice *Device)
{
    DSoundCaptureData *data = Device->ExtraData;
    DWORD ReadCursor, LastCursor, BufferBytes, NumBytes;
    VOID *ReadPtr1, *ReadPtr2;
    DWORD ReadCnt1,  ReadCnt2;
    DWORD FrameSize;
    HRESULT hr;

    if(!Device->Connected)
        goto done;

    FrameSize = FrameSizeFromDevFmt(Device->FmtChans, Device->FmtType);
    BufferBytes = data->BufferBytes;
    LastCursor = data->Cursor;

    hr = IDirectSoundCaptureBuffer_GetCurrentPosition(data->DSCbuffer, NULL, &ReadCursor);
    if(SUCCEEDED(hr))
    {
        NumBytes = (ReadCursor-LastCursor + BufferBytes) % BufferBytes;
        if(NumBytes == 0)
            goto done;
        hr = IDirectSoundCaptureBuffer_Lock(data->DSCbuffer, LastCursor, NumBytes,
                                            &ReadPtr1, &ReadCnt1,
                                            &ReadPtr2, &ReadCnt2, 0);
    }
    if(SUCCEEDED(hr))
    {
        WriteRingBuffer(data->Ring, ReadPtr1, ReadCnt1/FrameSize);
        if(ReadPtr2 != NULL)
            WriteRingBuffer(data->Ring, ReadPtr2, ReadCnt2/FrameSize);
        hr = IDirectSoundCaptureBuffer_Unlock(data->DSCbuffer,
                                              ReadPtr1, ReadCnt1,
                                              ReadPtr2, ReadCnt2);
        data->Cursor = (LastCursor+ReadCnt1+ReadCnt2) % BufferBytes;
    }

    if(FAILED(hr))
    {
        ERR("update failed: 0x%08lx\n", hr);
        aluHandleDisconnect(Device);
    }

done:
    return RingBufferSize(data->Ring);
}
예제 #16
0
int RingBufferGet(tRingBuffer *rb)
{
    if (rb->Read == rb->Write)
    {
        return -1;
    }
    else
    {
        int c = rb->Buffer[rb->Read];

        if (rb->Read + 1 == RingBufferSize(rb))
        {
            rb->Read = 0;
        }
        else
        {
            rb->Read++;
        }

        return c;
    }
}
예제 #17
0
static ALCuint ca_available_samples(ALCdevice *device)
{
    ca_data *data = device->ExtraData;
    return RingBufferSize(data->ring) / data->sampleRateRatio;
}
예제 #18
0
static ALCuint pa_available_samples(ALCdevice *device)
{
    pa_data *data = device->ExtraData;
    return RingBufferSize(data->ring);
}
예제 #19
0
파일: oss.c 프로젝트: LighFusion/surreal
static ALCuint oss_available_samples(ALCdevice *Device)
{
    oss_data *data = (oss_data*)Device->ExtraData;
    return RingBufferSize(data->ring);
}
예제 #20
0
static ALCuint pulse_available_samples(ALCdevice *device) //{{{
{
    pulse_data *data = device->ExtraData;
    return RingBufferSize(data->ring);
} //}}}
예제 #21
0
static ALCuint WinMMAvailableSamples(ALCdevice *Device)
{
    WinMMData *data = (WinMMData*)Device->ExtraData;
    return RingBufferSize(data->Ring);
}
예제 #22
0
uint16_t PacketPoolSize(void) {
    return RingBufferSize(ringbuffer);
}
예제 #23
0
static ALCuint alsa_available_samples(ALCdevice *pDevice)
{
    alsa_data *data = (alsa_data*)pDevice->ExtraData;
    return RingBufferSize(data->ring);
}
예제 #24
0
int RingBufferFillLevel(tRingBuffer *rb)
{
    return (rb->Write - rb->Read + RingBufferSize(rb)) % RingBufferSize(rb);
}