Lines Matching defs:er
71 struct echo_reference *er;
77 er = (struct echo_reference *)((char *)buffer_provider -
80 if (er->wr_src_buf == NULL || er->wr_frames_in == 0) {
86 buffer->frame_count = (buffer->frame_count > er->wr_frames_in) ? er->wr_frames_in : buffer->frame_count;
87 // this is er->rd_channel_count here as we resample after stereo to mono conversion if any
88 buffer->i16 = (int16_t *)er->wr_src_buf + (er->wr_curr_frame_size - er->wr_frames_in) * er->rd_channel_count;
96 struct echo_reference *er;
102 er = (struct echo_reference *)((char *)buffer_provider -
105 er->wr_frames_in -= buffer->frame_count;
108 static void echo_reference_reset_l(struct echo_reference *er)
111 free(er->buffer);
112 er->buffer = NULL;
113 er->buf_size = 0;
114 er->frames_in = 0;
115 free(er->wr_buf);
116 er->wr_buf = NULL;
117 er->wr_buf_size = 0;
118 er->wr_render_time.tv_sec = 0;
119 er->wr_render_time.tv_nsec = 0;
120 er->delta_count = 0;
121 er->prev_delta_sign = 0;
132 struct echo_reference *er = (struct echo_reference *)echo_reference;
135 if (er == NULL) {
139 pthread_mutex_lock(&er->lock);
143 er->state &= ~ECHOREF_WRITING;
144 echo_reference_reset_l(er);
149 ALOGV("echo_reference_write() playbackTimestamp:[%d].[%d], er->playback_delay:[%d]",
151 (int)buffer->time_stamp.tv_nsec, er->playback_delay);
157 (er->wr_render_time.tv_sec == 0) && (er->wr_render_time.tv_nsec == 0)) {
161 if ((er->state & ECHOREF_WRITING) == 0) {
163 if (er->resampler != NULL) {
164 er->resampler->reset(er->resampler);
166 er->state |= ECHOREF_WRITING;
169 if ((er->state & ECHOREF_READING) == 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;
179 er->wr_curr_frame_size = buffer->frame_count;
184 if (er->rd_channel_count != er->wr_channel_count ||
185 er->rd_sampling_rate != er->wr_sampling_rate) {
190 if (er->rd_sampling_rate != er->wr_sampling_rate) {
191 inFrames = (buffer->frame_count * er->rd_sampling_rate) / er->wr_sampling_rate +
200 if (er->wr_buf_size < wrBufSize) {
202 er->wr_buf_size, wrBufSize);
203 er->wr_buf_size = wrBufSize;
204 er->wr_buf = realloc(er->wr_buf, er->wr_buf_size * er->rd_frame_size);
207 if (er->rd_channel_count != er->wr_channel_count) {
210 int16_t *dst16 = (int16_t *)er->wr_buf;
217 if (er->wr_sampling_rate != er->rd_sampling_rate) {
218 if (er->resampler == NULL) {
221 er->wr_sampling_rate, er->rd_sampling_rate);
222 er->provider.get_next_buffer = echo_reference_get_next_buffer;
223 er->provider.release_buffer = echo_reference_release_buffer;
224 rc = create_resampler(er->wr_sampling_rate,
225 er->rd_sampling_rate,
226 er->rd_channel_count,
228 &er->provider,
229 &er->resampler);
231 er->resampler = NULL;
237 // er->wr_src_buf and er->wr_frames_in are used by getNexBuffer() called by the resampler
239 if (er->rd_channel_count != er->wr_channel_count) {
240 er->wr_src_buf = er->wr_buf;
242 er->wr_src_buf = buffer->raw;
244 er->wr_frames_in = buffer->frame_count;
248 er->wr_sampling_rate, er->rd_sampling_rate);
249 er->resampler->resample_from_provider(er->resampler,
250 (int16_t *)er->wr_buf, &inFrames);
251 ALOGV_IF(er->wr_frames_in != 0,
252 "echo_reference_write() er->wr_frames_in not 0 (%d) after resampler",
253 er->wr_frames_in);
255 srcBuf = er->wr_buf;
261 if (er->frames_in + inFrames > er->buf_size) {
263 er->buf_size, er->frames_in + inFrames);
264 er->buf_size = er->frames_in + inFrames;
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,
269 inFrames * er->rd_frame_size);
270 er->frames_in += inFrames;
273 " er->wr_render_time:[%d].[%d], er->playback_delay:[%d]",
274 inFrames, er->frames_in, er->buf_size,
275 (int)er->wr_render_time.tv_sec, (int)er->wr_render_time.tv_nsec, er->playback_delay);
277 pthread_cond_signal(&er->cond);
279 pthread_mutex_unlock(&er->lock);
294 struct echo_reference *er = (struct echo_reference *)echo_reference;
296 if (er == NULL) {
300 pthread_mutex_lock(&er->lock);
304 er->state &= ~ECHOREF_READING;
309 "er->frames_in:[%d],buffer->frame_count:[%d]",
310 buffer->delay_ns, er->frames_in, buffer->frame_count);
312 if ((er->state & ECHOREF_READING) == 0) {
314 echo_reference_reset_l(er);
315 er->state |= ECHOREF_READING;
318 if ((er->state & ECHOREF_WRITING) == 0) {
319 memset(buffer->raw, 0, er->rd_frame_size * 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);
333 pthread_cond_timedwait_relative_np(&er->cond, &er->lock, &ts);
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);
344 if ((er->wr_render_time.tv_sec == 0 && er->wr_render_time.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;
361 if (er->resampler != NULL) {
363 int32_t rsmp_delay = er->resampler->delay_ns(er->resampler);
368 "er->playback_delay[%d] + delayCapture[%d] - timeDiff[%lld]",
369 expectedDelayNs, er->playback_delay, buffer->delay_ns, timeDiff);
372 int64_t delayNs = ((int64_t)er->frames_in * 1000000000) / er->rd_sampling_rate;
382 if (delay_sign == er->prev_delta_sign) {
383 er->delta_count++;
385 er->delta_count = 1;
387 er->prev_delta_sign = delay_sign;
389 if (er->delta_count > MIN_DELTA_NUM) {
390 size_t previousFrameIn = er->frames_in;
391 er->frames_in = (size_t)((expectedDelayNs * er->rd_sampling_rate)/1000000000);
392 int offset = er->frames_in - previousFrameIn;
395 "er->frames_in: %d, previousFrameIn = %d",
396 delay_sign ? "positive" : "negative", er->frames_in, previousFrameIn);
400 if (er->frames_in > er->buf_size) {
401 er->buf_size = er->frames_in;
402 er->buffer = realloc(er->buffer, er->buf_size * er->rd_frame_size);
404 er->buf_size);
408 memset((char *)er->buffer + previousFrameIn * er->rd_frame_size,
409 0, offset * er->rd_frame_size);
416 memcpy(er->buffer, (char *)er->buffer + (offset * er->rd_frame_size),
417 er->frames_in * er->rd_frame_size);
419 er->frames_in);
424 er->delta_count = 0;
425 er->prev_delta_sign = 0;
431 "er->playback_delay[%d] + delayCapture[%d] - timeDiff[%lld]",
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);
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;
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,
455 er->frames_in * er->rd_frame_size);
461 buffer->frame_count, er->frames_in);
463 pthread_cond_signal(&er->cond);
466 pthread_mutex_unlock(&er->lock);
479 struct echo_reference *er;
500 er = (struct echo_reference *)calloc(1, sizeof(struct echo_reference));
502 er->itfe.read = echo_reference_read;
503 er->itfe.write = echo_reference_write;
505 er->state = ECHOREF_IDLE;
506 er->rd_format = rdFormat;
507 er->rd_channel_count = rdChannelCount;
508 er->rd_sampling_rate = rdSamplingRate;
509 er->wr_format = wrFormat;
510 er->wr_channel_count = wrChannelCount;
511 er->wr_sampling_rate = wrSamplingRate;
512 er->rd_frame_size = audio_bytes_per_sample(rdFormat) * rdChannelCount;
513 er->wr_frame_size = audio_bytes_per_sample(wrFormat) * wrChannelCount;
514 *echo_reference = &er->itfe;
519 struct echo_reference *er = (struct echo_reference *)echo_reference;
521 if (er == NULL) {
526 echo_reference_reset_l(er);
527 if (er->resampler != NULL) {
528 release_resampler(er->resampler);
530 free(er);