INNER CODE UNIT · C

ring_init

Cateners/tiny_container · app/src/main/cpp/tiny_audio_jni.c:67

static void ring_init(ring_t *r)     { atomic_init(&r->write_idx,0); atomic_init(&r->read_idx,0); }

static uint32_t ring_write(ring_t *r, const uint8_t *src, uint32_t n)
{
    uint32_t w  = atomic_load_explicit(&r->write_idx, memory_order_relaxed);
    uint32_t rd = atomic_load_explicit(&r->read_idx,  memory_order_acquire);
    uint32_t used = w - rd;

    /*
     * Latency guard: if the ringbuffer has accumulated too much data,
     * the consumer (AAudio) has fallen behind.  Skip old frames so the
     * listener doesn't experience growing end-to-end delay.
     */
    if (used > RING_LATENCY_LIMIT) {
        uint32_t new_rd = w - RING_LATENCY_LIMIT;
        LOGI("ring: latency guard skip %u bytes", new_rd - rd);
        atomic_store_explicit(&r->read_idx, new_rd, memory_order_release);
        rd  = new_rd;

View source record →

📰 Research Paper
Loading…
⏳ Fetching content…