📄 buffer.c
字号:
/* ******************************************************************************** * * This material contains proprietary software of Entropic Speech, Inc. * Any reproduction, distribution, or publication without the the prior * written permission of Entropic Speech, Inc. is strictly prohibited. * Any public distribution of copies of this work authorized in writing * by Entropic Speech, Inc. must bear the notice: * * "Copyright (c) 1987 Entropic Speech, Inc.; all rights reserved" * * Program: buffer * * Written by: Jim Elliott * * Computes buffer statistics for encode program. * ******************************************************************************** *//* * SCCS program and date keywords. */#ifndef lintstatic char *sccs_id = "@(#)buffer.c 1.2 10/6/87 ESI";#endif/* * System include files. */#include <stdio.h>/* * ESPS include files. */#include <esps/esps.h>#include <esps/anafea.h>#include <esps/encode.h>#include <esps/fea.h>/* * Defines. */#define MAX_FRM 120 /* Number of frames in circular buffer *//* ******************************************************************************** * Subroutine to update buffer statistics. ******************************************************************************** */update_buffer( bs, buf_hist, max_delay, samp_freq, chan_rate, anafea_rec )float chan_rate, samp_freq;int buf_hist[], *max_delay;struct anafea *anafea_rec;struct bit_stats *bs;{ static float bits[ MAX_FRM ]; /* Circular buffer for frame bit counts */ static int rd = 0, /* Read pointer for circular buffer */ samp[MAX_FRM], /* Circular buffer for frame samples */ wr = 0; /* Write pointer for circular buffer */ int i, /* Scratch index */ samp_in; /* Samples input to buffer during frame */ float bits_in, /* Bits input to buffer during frame */ bits_out; /* Bits output from buffer during frame */ bits_in = (float) bs->frm_bits; bits_out = (float) *anafea_rec->frame_len / samp_freq * chan_rate; samp_in = *anafea_rec->frame_len;/* * Add input bits to circular buffer and advance write pointer. Check for * wrap-around and abort if it has occurred. */ bits[wr] = bits_in; samp[wr] = samp_in; wr++; if ( wr == MAX_FRM ) wr = 0; spsassert( wr != rd, "crossover in read and write pointers" );/* * Deduct output bits from circular buffer, advancing the read pointer as we * go. If the read pointer catches up with the write pointer, the buffer is * empty, and we are finished. */ while ( bits_out >= bits[rd] ) { bits_out -= bits[rd]; rd++; if ( rd == MAX_FRM ) rd = 0; if ( rd == wr ) break; }/* * Adjust the numbers of bits in the frame addressed by the read pointer, * unless the buffer is empty (pointers equal). */ if ( rd != wr ) bits[rd] -= bits_out;/* * Now, figure out the number of bits and the number of input samples * remaining in the buffer. */ i = rd; bs->buf_bits = 0.0; bs->buf_samp = 0; while ( i != wr ) { bs->buf_bits += bits[i]; bs->buf_samp += samp[i]; i++; if ( i == MAX_FRM ) i = 0; }/* * Update the maximum buffer delay, and the buffer-delay histogram. */ if ( bs->buf_samp > *max_delay ) *max_delay = bs->buf_samp; i = bs->buf_samp / 100; if ( i > 10 ) i = 10; buf_hist[i]++;}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -