/* See COPYING file for copyright and license details. */#include"ebur128.h"#include<float.h>#include<limits.h>#include<math.h> /* You may have to define _USE_MATH_DEFINES if you use MSVC */#include<stdio.h>#include<stdlib.h>/* This can be replaced by any BSD-like queue implementation. */#include<sys/queue.h>#define CHECK_ERROR(condition, errorcode, goto_point) \ if ((condition)) { \ errcode = (errorcode); \ goto goto_point; \ }STAILQ_HEAD(ebur128_double_queue,ebur128_dq_entry);structebur128_dq_entry{doublez;STAILQ_ENTRY(ebur128_dq_entry)entries;};#define ALMOST_ZERO 0.000001typedefstruct{/* Data structure for polyphase FIR interpolator */unsignedintfactor;/* Interpolation factor of the interpolator */unsignedinttaps;/* Taps (prefer odd to increase zero coeffs) */unsignedintchannels;/* Number of channels */unsignedintdelay;/* Size of delay buffer */struct{unsignedintcount;/* Number of coefficients in this subfilter */unsignedint*index;/* Delay index of corresponding filter coeff */double*coeff;/* List of subfilter coefficients */}*filter;/* List of subfilters (one for each factor) */float**z;/* List of delay buffers (one for each channel) */unsignedintzi;/* Current delay buffer index */}interpolator;structebur128_state_internal{/** Filtered audio data (used as ring buffer). */double*audio_data;/** Size of audio_data array. */size_taudio_data_frames;/** Current index for audio_data. */size_taudio_data_index;/** How many frames are needed for a gating block. Will correspond to 400ms * of audio at initialization, and 100ms after the first block (75% overlap * as specified in the 2011 revision of BS1770). */unsignedlongneeded_frames;/** The channel map. Has as many elements as there are channels. */int*channel_map;/** How many samples fit in 100ms (rounded). */unsignedlongsamples_in_100ms;/** BS.1770 filter coefficients (nominator). */doubleb[5];/** BS.1770 filter coefficients (denominator). */doublea[5];/** BS.1770 filter state. */doublev[5][5];/** Linked list of block energies. */structebur128_double_queueblock_list;unsignedlongblock_list_max;unsignedlongblock_list_size;/** Linked list of 3s-block energies, used to calculate LRA. */structebur128_double_queueshort_term_block_list;unsignedlongst_block_list_max;unsignedlongst_block_list_size;intuse_histogram;unsignedlong