Lines Matching refs:buffer

47     void *buffer;                   // main buffer
48 size_t buf_size; // main buffer size in frames
49 size_t frames_in; // number of frames in main buffer
50 void *wr_buf; // buffer for input conversions
51 size_t wr_buf_size; // size of conversion buffer in frames
52 size_t wr_frames_in; // number of frames in conversion buffer
54 void *wr_src_buf; // resampler input buf (either wr_buf or buffer used by write())
57 int32_t playback_delay; // playback buffer delay indicated by last write()
64 struct resampler_buffer_provider provider; // resampler buffer provider
69 struct resampler_buffer* buffer)
81 buffer->raw = NULL;
82 buffer->frame_count = 0;
86 buffer->frame_count = (buffer->frame_count > er->wr_frames_in) ? er->wr_frames_in : buffer->frame_count;
88 buffer->i16 = (int16_t *)er->wr_src_buf + (er->wr_curr_frame_size - er->wr_frames_in) * er->rd_channel_count;
94 struct resampler_buffer* buffer)
105 er->wr_frames_in -= buffer->frame_count;
111 free(er->buffer);
112 er->buffer = NULL;
124 /* additional space in resampler buffer allowing for extra samples to be returned
130 struct echo_reference_buffer *buffer)
141 if (buffer == NULL) {
148 ALOGV("echo_reference_write() START trying to write %d frames", buffer->frame_count);
150 (int)buffer->time_stamp.tv_sec,
151 (int)buffer->time_stamp.tv_nsec, er->playback_delay);
153 //ALOGV("echo_reference_write() %d frames", buffer->frame_count);
156 if ((buffer->time_stamp.tv_sec == 0) && (buffer->time_stamp.tv_nsec == 0) &&
173 er->wr_render_time.tv_sec = buffer->time_stamp.tv_sec;
174 er->wr_render_time.tv_nsec = buffer->time_stamp.tv_nsec;
176 er->playback_delay = buffer->delay_ns;
178 // this will be used in the get_next_buffer, to support variable input buffer sizes
179 er->wr_curr_frame_size = buffer->frame_count;
186 size_t wrBufSize = buffer->frame_count;
188 inFrames = buffer->frame_count;
191 inFrames = (buffer->frame_count * er->rd_sampling_rate) / er->wr_sampling_rate +
194 // output so buffer size is driven by both write and read sample rates
201 ALOGV("echo_reference_write() increasing write buffer size from %d to %d",
209 int16_t *src16 = (int16_t *)buffer->raw;
211 size_t frames = buffer->frame_count;
242 er->wr_src_buf = buffer->raw;
244 er->wr_frames_in = buffer->frame_count;
257 inFrames = buffer->frame_count;
258 srcBuf = buffer->raw;
262 ALOGV("echo_reference_write() increasing buffer size from %d to %d",
265 er->buffer = realloc(er->buffer, er->buf_size * er->rd_frame_size);
267 memcpy((char *)er->buffer + er->frames_in * er->rd_frame_size,
272 ALOGV("echo_reference_write() frames written:[%d], frames total:[%d] buffer size:[%d]\n"
284 // delay jump threshold to update ref buffer: 6 samples at 8kHz in nsecs
287 // the buffer
292 struct echo_reference_buffer *buffer)
302 if (buffer == NULL) {
309 "er->frames_in:[%d],buffer->frame_count:[%d]",
310 buffer->delay_ns, er->frames_in, buffer->frame_count);
319 memset(buffer->raw, 0, er->rd_frame_size * buffer->frame_count);
320 buffer->delay_ns = 0;
324 // ALOGV("echo_reference_read() %d frames", buffer->frame_count);
327 if (er->frames_in < buffer->frame_count) {
328 uint32_t timeoutMs = (uint32_t)((1000 * buffer->frame_count) / er->rd_sampling_rate / 2);
335 ALOGV_IF((er->frames_in < buffer->frame_count),
337 " er->frames_in: %d, buffer->frame_count = %d",
338 timeoutMs, er->frames_in, buffer->frame_count);
345 (buffer->time_stamp.tv_sec == 0 && buffer->time_stamp.tv_nsec == 0)) {
350 if (buffer->time_stamp.tv_nsec < er->wr_render_time.tv_nsec) {
351 tmp.tv_sec = buffer->time_stamp.tv_sec - er->wr_render_time.tv_sec - 1;
352 tmp.tv_nsec = 1000000000 + buffer->time_stamp.tv_nsec - er->wr_render_time.tv_nsec;
354 tmp.tv_sec = buffer->time_stamp.tv_sec - er->wr_render_time.tv_sec;
355 tmp.tv_nsec = buffer->time_stamp.tv_nsec - er->wr_render_time.tv_nsec;
359 int64_t expectedDelayNs = er->playback_delay + buffer->delay_ns - timeDiff;
369 expectedDelayNs, er->playback_delay, buffer->delay_ns, timeDiff);
378 // smooth the variation and update the reference buffer only
399 // Less data available in the reference buffer than expected
402 er->buffer = realloc(er->buffer, er->buf_size * er->rd_frame_size);
403 ALOGV("echo_reference_read(): increasing buffer size to %d",
408 memset((char *)er->buffer + previousFrameIn * er->rd_frame_size,
410 ALOGV("echo_reference_read(): pushing ref buffer by [%d]", offset);
413 // More data available in the reference buffer than expected
416 memcpy(er->buffer, (char *)er->buffer + (offset * er->rd_frame_size),
418 ALOGV("echo_reference_read(): shifting ref buffer by [%d]",
432 expectedDelayNs, er->playback_delay, buffer->delay_ns, timeDiff);
436 if (er->frames_in < buffer->frame_count) {
437 if (buffer->frame_count > er->buf_size) {
438 er->buf_size = buffer->frame_count;
439 er->buffer = realloc(er->buffer, er->buf_size * er->rd_frame_size);
440 ALOGV("echo_reference_read(): increasing buffer size to %d", er->buf_size);
442 // filling up the reference buffer with 0s to match the expected delay.
443 memset((char *)er->buffer + er->frames_in * er->rd_frame_size,
444 0, (buffer->frame_count - er->frames_in) * er->rd_frame_size);
445 er->frames_in = buffer->frame_count;
448 memcpy(buffer->raw,
449 (char *)er->buffer,
450 buffer->frame_count * er->rd_frame_size);
452 er->frames_in -= buffer->frame_count;
453 memcpy(er->buffer,
454 (char *)er->buffer + buffer->frame_count * er->rd_frame_size,
457 // As the reference buffer is now time aligned to the microphone signal there is a zero delay
458 buffer->delay_ns = 0;
461 buffer->frame_count, er->frames_in);