package com.dowse.base.audio;

import java.util.Arrays;

/* loaded from: ds_base_2.0.9_23030112.aar:classes.jar:com/dowse/base/audio/DSCircleQueue.class */
public class DSCircleQueue {
    private static final String TAG = "DSCircleQueue";
    private final int DEFAULT_SIZE = 100;
    public int head_offset = 0;
    public int capacity = 0;
    public DSAudioFrame[] elementData = new DSAudioFrame[100];

    public synchronized void add(DSAudioFrame element) {
        int offset = this.head_offset % 100;
        element.setNo(this.head_offset);
        this.elementData[offset] = element;
        this.head_offset++;
        this.capacity++;
        if (this.capacity > 100) {
            this.capacity = 100;
        }
    }

    public synchronized void clear() {
        Arrays.fill(this.elementData, (Object) null);
        this.head_offset = 0;
        this.capacity = 0;
    }

    public synchronized DSElement get(int index) {
        int offset;
        DSElement element = new DSElement();
        int need_position = 0;
        if (this.capacity <= 0) {
            element.setRet(-1);
            return element;
        }
        if (index < 0) {
            need_position = 1;
        } else if (index >= this.head_offset) {
            element.setRet(-2);
            return element;
        } else if (index < this.head_offset - 100) {
            element.setRet(-1);
            return element;
        }
        element.setRet(0);
        if (need_position == 1) {
            offset = (this.head_offset - 1) % 100;
        } else {
            offset = index % 100;
        }
        element.setData(this.elementData[offset]);
        return element;
    }
}
