📄 pesqmain.c
字号:
{800., 12},
{1000., 12},
{1300., 12},
{1600., 12},
{2000., 12},
{2500., 12},
{3000., 12},
{3250., 12},
{3500., 4},
{4000., -200},
{5000., -200},
{6300., -200},
{8000., -200}};
#define TARGET_AVG_POWER 1E7
void fix_power_level (SIGNAL_INFO *info, char *name, long maxNsamples)
{
long n = info-> Nsamples;
long i;
float *align_filtered = (float *) safe_malloc ((n + DATAPADDING_MSECS * (Fs / 1000)) * sizeof (float));
float global_scale;
float power_above_300Hz;
for (i = 0; i < n + DATAPADDING_MSECS * (Fs / 1000); i++) {
align_filtered [i] = info-> data [i];
}
apply_filter (align_filtered, info-> Nsamples, 26, align_filter_dB);
power_above_300Hz = (float) pow_of (align_filtered,
SEARCHBUFFER * Downsample,
n - SEARCHBUFFER * Downsample + DATAPADDING_MSECS * (Fs / 1000),
maxNsamples - 2 * SEARCHBUFFER * Downsample + DATAPADDING_MSECS * (Fs / 1000));
global_scale = (float) sqrt (TARGET_AVG_POWER / power_above_300Hz);
for (i = 0; i < n; i++) {
info-> data [i] *= global_scale;
}
safe_free (align_filtered);
}
void pesq_measure (SIGNAL_INFO * ref_info, SIGNAL_INFO * deg_info,
ERROR_INFO * err_info, long * Error_Flag, char ** Error_Type)
{
float * ftmp = NULL;
ref_info-> data = NULL;
ref_info-> VAD = NULL;
ref_info-> logVAD = NULL;
deg_info-> data = NULL;
deg_info-> VAD = NULL;
deg_info-> logVAD = NULL;
if ((*Error_Flag) == 0)
{
printf ("Reading reference file %s...", ref_info-> path_name);
load_src (Error_Flag, Error_Type, ref_info);
if ((*Error_Flag) == 0)
printf ("done.\n");
}
if ((*Error_Flag) == 0)
{
printf ("Reading degraded file %s...", deg_info-> path_name);
load_src (Error_Flag, Error_Type, deg_info);
if ((*Error_Flag) == 0)
printf ("done.\n");
}
if (((ref_info-> Nsamples - 2 * SEARCHBUFFER * Downsample < Fs / 4) ||
(deg_info-> Nsamples - 2 * SEARCHBUFFER * Downsample < Fs / 4)) &&
((*Error_Flag) == 0))
{
(*Error_Flag) = 2;
(*Error_Type) = "Reference or Degraded below 1/4 second - processing stopped ";
}
if ((*Error_Flag) == 0)
{
alloc_other (ref_info, deg_info, Error_Flag, Error_Type, &ftmp);
}
if ((*Error_Flag) == 0)
{
int maxNsamples = max (ref_info-> Nsamples, deg_info-> Nsamples);
float * model_ref;
float * model_deg;
long i;
FILE *resultsFile;
printf (" Level normalization...\n");
fix_power_level (ref_info, "reference", maxNsamples);
fix_power_level (deg_info, "degraded", maxNsamples);
printf (" IRS filtering...\n");
apply_filter (ref_info-> data, ref_info-> Nsamples, 26, standard_IRS_filter_dB);
apply_filter (deg_info-> data, deg_info-> Nsamples, 26, standard_IRS_filter_dB);
model_ref = (float *) safe_malloc ((ref_info-> Nsamples + DATAPADDING_MSECS * (Fs / 1000)) * sizeof (float));
model_deg = (float *) safe_malloc ((deg_info-> Nsamples + DATAPADDING_MSECS * (Fs / 1000)) * sizeof (float));
for (i = 0; i < ref_info-> Nsamples + DATAPADDING_MSECS * (Fs / 1000); i++) {
model_ref [i] = ref_info-> data [i];
}
for (i = 0; i < deg_info-> Nsamples + DATAPADDING_MSECS * (Fs / 1000); i++) {
model_deg [i] = deg_info-> data [i];
}
input_filter( ref_info, deg_info, ftmp );
printf (" Variable delay compensation...\n");
calc_VAD (ref_info);
calc_VAD (deg_info);
crude_align (ref_info, deg_info, err_info, WHOLE_SIGNAL, ftmp);
utterance_locate (ref_info, deg_info, err_info, ftmp);
for (i = 0; i < ref_info-> Nsamples + DATAPADDING_MSECS * (Fs / 1000); i++) {
ref_info-> data [i] = model_ref [i];
}
for (i = 0; i < deg_info-> Nsamples + DATAPADDING_MSECS * (Fs / 1000); i++) {
deg_info-> data [i] = model_deg [i];
}
safe_free (model_ref);
safe_free (model_deg);
if ((*Error_Flag) == 0) {
if (ref_info-> Nsamples < deg_info-> Nsamples) {
float *new_ref = (float *) safe_malloc((deg_info-> Nsamples + DATAPADDING_MSECS * (Fs / 1000)) * sizeof(float));
long i;
for (i = 0; i < ref_info-> Nsamples + DATAPADDING_MSECS * (Fs / 1000); i++) {
new_ref [i] = ref_info-> data [i];
}
for (i = ref_info-> Nsamples + DATAPADDING_MSECS * (Fs / 1000);
i < deg_info-> Nsamples + DATAPADDING_MSECS * (Fs / 1000); i++) {
new_ref [i] = 0.0f;
}
safe_free (ref_info-> data);
ref_info-> data = new_ref;
new_ref = NULL;
} else {
if (ref_info-> Nsamples > deg_info-> Nsamples) {
float *new_deg = (float *) safe_malloc((ref_info-> Nsamples + DATAPADDING_MSECS * (Fs / 1000)) * sizeof(float));
long i;
for (i = 0; i < deg_info-> Nsamples + DATAPADDING_MSECS * (Fs / 1000); i++) {
new_deg [i] = deg_info-> data [i];
}
for (i = deg_info-> Nsamples + DATAPADDING_MSECS * (Fs / 1000);
i < ref_info-> Nsamples + DATAPADDING_MSECS * (Fs / 1000); i++) {
new_deg [i] = 0.0f;
}
safe_free (deg_info-> data);
deg_info-> data = new_deg;
new_deg = NULL;
}
}
}
printf (" Acoustic model processing...\n");
pesq_psychoacoustic_model (ref_info, deg_info, err_info, ftmp);
safe_free (ref_info-> data);
safe_free (ref_info-> VAD);
safe_free (ref_info-> logVAD);
safe_free (deg_info-> data);
safe_free (deg_info-> VAD);
safe_free (deg_info-> logVAD);
safe_free (ftmp);
resultsFile = fopen (ITU_RESULTS_FILE, "at");
if (resultsFile != NULL) {
long start, end;
if (0 != fseek (resultsFile, 0, SEEK_SET)) {
printf ("Could not move to start of results file %s!\n", ITU_RESULTS_FILE);
exit (1);
}
start = ftell (resultsFile);
if (0 != fseek (resultsFile, 0, SEEK_END)) {
printf ("Could not move to end of results file %s!\n", ITU_RESULTS_FILE);
exit (1);
}
end = ftell (resultsFile);
if (start == end) {
fprintf (resultsFile, "REFERENCE\t DEGRADED\t PESQMOS\t PESQMOS\t SUBJMOS\t COND\t SAMPLE_FREQ\t CRUDE_DELAY\n");
fflush (resultsFile);
}
fprintf (resultsFile, "%s\t ", ref_info-> path_name);
fprintf (resultsFile, "%s\t ", deg_info-> path_name);
fprintf (resultsFile, "SQValue=%.3f\t ", err_info->pesq_mos);
fprintf (resultsFile, "%.3f\t ", err_info->pesq_mos);
fprintf (resultsFile, "%.3f\t ", err_info->subj_mos);
fprintf (resultsFile, "%d\t ", err_info->cond_nr);
fprintf (resultsFile, "%d\t", Fs);
fprintf (resultsFile, "%.4f\n ", (float) err_info-> Crude_DelayEst / (float) Fs);
fclose (resultsFile);
}
resultsFile = fopen (SIMPLE_RESULTS_FILE, "at");
if (resultsFile != NULL) {
long start, end;
if (0 != fseek (resultsFile, 0, SEEK_SET)) {
printf ("Could not move to start of results file %s!\n", SIMPLE_RESULTS_FILE);
exit (1);
}
start = ftell (resultsFile);
if (0 != fseek (resultsFile, 0, SEEK_END)) {
printf ("Could not move to end of results file %s!\n", SIMPLE_RESULTS_FILE);
exit (1);
}
end = ftell (resultsFile);
if (start == end) {
fprintf (resultsFile, "DEGRADED\t PESQMOS\t SUBJMOS\t COND\t SAMPLE_FREQ\t CRUDE_DELAY\n");
fflush (resultsFile);
}
fprintf (resultsFile, "%s\t ", deg_info-> file_name);
fprintf (resultsFile, "%.3f\t ", err_info->pesq_mos);
fprintf (resultsFile, "%.3f\t ", err_info->subj_mos);
fprintf (resultsFile, "%d\t ", err_info->cond_nr);
fprintf (resultsFile, "%d\t", Fs);
fprintf (resultsFile, "%.4f\n ", (float) err_info-> Crude_DelayEst / (float) Fs);
fclose (resultsFile);
}
}
return;
}
/* END OF FILE */
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -