/** Ring array of pointers is used to hold buffers. In case that asynchronous producer/consumer callbacks do not arrive in a repeated order the ring array stores the buffers and fetch
them in the correct order. */
typedefstruct {
AudioBuffer * buffer_array; /**< Array that hold pointers of the allocated
space for the buffers. */ unsignedint tail; /**< Index of the last element (first to deliver). */ unsignedint count; /**< Number of elements in the array. */ unsignedint capacity; /**< Total length of the array. */
} ring_array;
/** Initialize the ring array. @param ra The ring_array pointer of allocated structure.
@retval 0 on success. */ staticint
ring_array_init(ring_array * ra, uint32_t capacity, uint32_t bytesPerFrame,
uint32_t channelsPerFrame, uint32_t framesPerBuffer)
{
assert(ra); if (capacity == 0 || bytesPerFrame == 0 || channelsPerFrame == 0 ||
framesPerBuffer == 0) { return CUBEB_ERROR_INVALID_PARAMETER;
}
ra->capacity = capacity;
ra->tail = 0;
ra->count = 0;
ra->buffer_array = new AudioBuffer[ra->capacity];
PodZero(ra->buffer_array, ra->capacity); if (ra->buffer_array == NULL) { return CUBEB_ERROR;
}
for (unsignedint i = 0; i < ra->capacity; ++i) { if (single_audiobuffer_init(&ra->buffer_array[i], bytesPerFrame,
channelsPerFrame,
framesPerBuffer) != CUBEB_OK) { return CUBEB_ERROR;
}
}
return CUBEB_OK;
}
/** Destroy the ring array.
@param ra The ring_array pointer.*/ staticvoid
ring_array_destroy(ring_array * ra)
{
assert(ra); if (ra->buffer_array == NULL) { return;
} for (unsignedint i = 0; i < ra->capacity; ++i) { if (ra->buffer_array[i].mData) { operatordelete(ra->buffer_array[i].mData);
}
} delete[] ra->buffer_array;
}
/** Get the allocated buffer to be stored with fresh data. @param ra The ring_array pointer. @retval Pointer of the allocated space to be stored with fresh data or NULL
if full. */ static AudioBuffer *
ring_array_get_free_buffer(ring_array * ra)
{
assert(ra && ra->buffer_array);
assert(ra->buffer_array[0].mData != NULL); if (ra->count == ra->capacity) { return NULL;
}
/** Get the next available buffer with data. @param ra The ring_array pointer.
@retval Pointer of the next in order data buffer or NULL if empty. */ static AudioBuffer *
ring_array_get_data_buffer(ring_array * ra)
{
assert(ra && ra->buffer_array);
assert(ra->buffer_array[0].mData != NULL);
if (ra->count == 0) { return NULL;
}
AudioBuffer * ret = &ra->buffer_array[ra->tail];
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.