📄 actlevel.c
字号:
============================================================================*/void print_act_short_summary(out, file, state, al_dB, ratio, gain) FILE *out; SVP56_state state; char *file; double ratio, al_dB, gain;{ double abs_max_dB; /* Calculate peak in dB */ abs_max_dB = 20 * log10(SVP56_get_abs_max(state) + MIN_LOG_OFFSET) - state.refdB; /* Report number of samples */ fprintf(out, "Samples: %5ld ", state.n); /* Skip if filesize is zero */ if (state.n==0) { fprintf(out, "%s%s%s%s", "Min: ------ Max: ----- DC: ------- ", "RMSLev[dB]: ------- ActLev[dB]: ------- %Active: ------ ", "RMSPkF[dB]: ------- ActPkF[dB]: -------", gain>0? "Gain: ------ ":""); } else { fprintf(out, "Min: %5.0f ", ratio * state.maxN); fprintf(out, "Max: %05.0f ", ratio * state.maxP); fprintf(out, "DC: %7.2f ", ratio * state.DClevel); fprintf(out, "RMSLev[dB]: %7.3f ", state.rmsdB); fprintf(out, "ActLev[dB]: %7.3f ", al_dB); fprintf(out, "%%Active: %7.3f ", state.ActivityFactor * 100); fprintf(out, "RMSPkF[dB]: %7.3f ", abs_max_dB - SVP56_get_rms_dB(state)); fprintf(out, "ActPkF[dB]: %7.3f", abs_max_dB - al_dB); if (gain>0) fprintf(out, " Gain[]: %7.3f", gain); } fprintf(out, "\t%s\n", file);}/* ................... End of print_act_short_summary() .................... *//* ************************************************************************** *** *** *** Demo-Program for testing the correct implementation *** *** and to show how to use the programs *** *** *** ***************************************************************************/int main(argc, argv) int argc; char *argv[];{ /* DECLARATIONS */ /* Parameters for operation */ double Overflow; /* Max.positive value for AD_resolution bits */ long N=DEF_BLK_LEN, N1=1, N2=0, N2_ori, i, l; /* Intermediate storage variables for speech voltmeter */ SVP56_state state;#ifdef LOCAL_PRINT double abs_max_dB;#endif /* File-related variables */ char FileIn[150]; FILE *Fi; /* input file pointer */ FILE *out=stdout; /* where to print the statistical results */#ifdef VMS char mrs[15];#endif /* Other variables */ short buffer[4096]; float Buf[4096]; long start_byte, bitno = 16; double sf=16000; /* Hz */ double ActiveLeveldB, level=0, gain=0; static char funny[] = "|/-\\|/-\\", funny_size = sizeof(funny), quiet=0;#ifdef LOCAL_PRINT static char unity[5] = "dBov";#endif char use_active_level = 1; /* ......... GET PARAMETERS ......... */ /* Getting options */ if (argc < 2) display_usage(); else { while (argc > 1 && argv[1][0] == '-') if (strcmp(argv[1], "-sf") == 0) { /* Change default sampling frequency */ sf = atof(argv[2]); /* Update argc/argv to next valid option/argument */ argv+=2; argc-=2; } else if (strcmp(argv[1], "-lev") == 0) { /* Set a desired level */ level = atof(argv[2]); /* Update argc/argv to next valid option/argument */ argv+=2; argc-=2; } else if (strcmp(argv[1], "-rms") == 0) { /* Use the RMS level to normalize instead of the active level */ use_active_level = 0; /* Update argc/argv to next valid option/argument */ argv++; argc--; } else if (strcmp(argv[1], "-bits") == 0) { /* Change default sampling frequency */ bitno = atoi(argv[2]); /* Update argc/argv to next valid option/argument */ argv+=2; argc-=2; } else if (strcmp(argv[1], "-blk") == 0) { /* Change default sampling frequency */ N = atoi(argv[2]); /* Update argc/argv to next valid option/argument */ argv+=2; argc-=2; } else if (strcmp(argv[1], "-start") == 0) { /* Change default sampling frequency */ N1 = atoi(argv[2]); /* Update argc/argv to next valid option/argument */ argv+=2; argc-=2; } else if (strcmp(argv[1], "-n") == 0) { /* Change default sampling frequency */ N2 = atoi(argv[2]); /* Update argc/argv to next valid option/argument */ argv+=2; argc-=2; } else if (strcmp(argv[1], "-end") == 0) { /* Change number of blocks based on the last block */ N2 = atol(argv[2]) - N1 + 1; /* Update argc/argv to next valid option/argument */ argv+=2; argc-=2; } else if (strcmp(argv[1], "-log") == 0) { /* Log statistics into a file */ if ((out=fopen(argv[2], WT)) == NULL) KILL(argv[2], 2); else fprintf(stderr, "Statistics will be logged in %s\n", argv[2]); /* Update argc/argv to next valid option/argument */ argv+=2; argc-=2; } else if (strcmp(argv[1], "-q") == 0) { /* Don't print progress indicator */ quiet = 1; /* Move argv over the option to the next argument */ argv++; argc--; } else if (strcmp(argv[1],"--")==0) { /* No more options: */ /* Move argv over the option to the next argument and quit loop */ argv++; argc--; break; } else if (strcmp(argv[1], "-?") == 0 || strstr(argv[1], "-help")) { /* Print help */ display_usage(); } else { fprintf(stderr, "ERROR! Invalid option \"%s\" in command line\n\n", argv[1]); display_usage(); } } /* ......... SOME INITIALIZATIONS ......... */ /* funny_size = strlen(funny); */ start_byte = --N1; start_byte *= N * sizeof(short); N2_ori = N2; /* Overflow (saturation) point */ Overflow = pow((double)2.0, (double)(bitno-1)); /* REPEAT FOR ALL FILES IN THE COMMAND LINE */ while(argc>1) { /* Get new file name and update argument line pointer/counter */ strncpy(FileIn, argv[1], sizeof(FileIn)); argv++; argc--; /* Reset variables for speech level measurements */ init_speech_voltmeter(&state, sf); /* ......... FILE PREPARATION ......... */ /* Opening input file; abort if there's any problem */#ifdef VMS sprintf(mrs, "mrs=%d", 2 * N);#endif if ((Fi = fopen(FileIn, RB)) == NULL) KILL(FileIn, 2); /* Reinitialize number of blocks as specified initially */ N2 = N2_ori; /* Check if is to process the whole file */ if (N2 == 0) { struct stat st; stat(FileIn, &st); N2 = ceil(st.st_size / (double)(N * sizeof(short))); } /* Move pointer to 1st block of interest */ if (fseek(Fi, start_byte, 0) < 0l) KILL(FileIn, 4); /* ... MEASUREMENT OF ACTIVE SPEECH LEVEL ACCORDING P.56 ... */ /* Read samples ... */ if (!quiet) fprintf(stderr, " Processing \r"); for (i = 0; i < N2; i++) { if ((l = fread(buffer, sizeof(short), N, Fi)) > 0) { /* ... Convert samples to float */ sh2fl((long) l, buffer, Buf, bitno, 1); /* ... Get the active level */ ActiveLeveldB = speech_voltmeter(Buf, (long) l, &state); /* Print progress flag */ if (!quiet) fprintf(stderr, "%c\r", funny[i % funny_size]); } else { KILL(FileIn, 5); } } if (!quiet) fprintf(stderr, "\n");#ifdef LOCAL_PRINT /* Convert absolute maximum sample to dB */ abs_max_dB = 20 * log10(SVP56_get_abs_max(state)) - state.refdB; /* ... PRINT-OUT OF RESULTS ... */ if (!quiet) { fprintf(stderr, "%s%s", " ---------------------------", "----------------------------"); fprintf(stderr, "\n Input file: ................... %s, ", FileIn); fprintf(stderr, "%2ld bits, fs=%5.0f Hz", bitno, sf); fprintf(stderr, "\n Block Length: ................. %7ld [samples]", N); fprintf(stderr, "\n Starting Block: ............... %7ld []", N1 + 1); fprintf(stderr, "\n Number of Blocks: ............. %7ld []", N2); /* Skip if filesize is zero */ if (state.n==0) { fprintf(stderr, "%s%s", "\n -***-----------------------", "----------------------------\n"); continue; } /* If the activity factor is 0, don't report many things */ if (SVP56_get_activity(state) == 0) { fprintf(stderr, "\n Activity factor is ZERO -- the file is silence"); fprintf(stderr, " or idle noise"); fprintf(stderr, "%s%s", "\n ---------------------------", "----------------------------"); fprintf(stderr, "\n DC level: ..................... %7.0f [PCM]", Overflow * SVP56_get_DC_level(state)); fprintf(stderr, "\n Maximum positive value: ....... %7.0f [PCM]", Overflow * SVP56_get_pos_max(state)); fprintf(stderr, "\n Maximum negative value: ....... %7.0f [PCM]", Overflow * SVP56_get_neg_max(state)); fprintf(stderr, "%s%s", "\n ---------------------------", "----------------------------"); fprintf(stderr, "\n Noise/silence energy (rms): ... %7.3f [dB]", SVP56_get_rms_dB(state)); } else { fprintf(stderr, "%s%s", "\n ---------------------------", "----------------------------"); fprintf(stderr, "\n DC level: ..................... %7.0f [PCM]", Overflow * SVP56_get_DC_level(state)); fprintf(stderr, "\n Maximum positive value: ....... %7.0f [PCM]", Overflow * SVP56_get_pos_max(state)); fprintf(stderr, "\n Maximum negative value: ....... %7.0f [PCM]", Overflow * SVP56_get_neg_max(state)); fprintf(stderr, "%s%s", "\n ---------------------------", "----------------------------"); fprintf(stderr, "\n Long term energy (rms): ....... %7.3f [%s]", SVP56_get_rms_dB(state), unity); fprintf(stderr, "\n Active speech level: .......... %7.3f [%s]", ActiveLeveldB, unity); fprintf(stderr, "\n RMS peak-factor found: ........ %7.3f [dB]", abs_max_dB - SVP56_get_rms_dB(state)); fprintf(stderr, "\n Active peak factor found: ..... %7.3f [dB]", abs_max_dB - ActiveLeveldB); fprintf(stderr, "\n Activity factor: .............. %7.3f [%%]", SVP56_get_activity(state)); } fprintf(stderr, "%s%s", "\n ---------------------------", "----------------------------\n"); } else { printf("Samples: %5ld ", state.n); /* Skip if filesize is zero */ if (state.n==0) { printf("%s%s", "Min: ------ Max: ----- DC: ------- ", "RMSLev[dB]: ------- ActLev[dB]: ------- %Active: ------"); } else { printf("Min: %-5.0f ", Overflow * state.maxN); printf("Max: %-5.0f ", Overflow * state.maxP); printf("DC: %-7.2f ", Overflow * state.DClevel); printf("RMSLev[dB]: %7.3f ", state.rmsdB); printf("ActLev[dB]: %7.3f ", ActiveLeveldB); printf("%%Active: %7.3f ", state.ActivityFactor * 100); printf("RMSPkF[dB]: %7.3f ", abs_max_dB - SVP56_get_rms_dB(state)); printf("ActPkF[dB]: %7.3f", abs_max_dB - ActiveLeveldB); } printf("\t%s\n", FileIn); }#else if (level!=0) { /* Computes the equalization factor to be used in the output file */ if (use_active_level) gain = pow(10.0, (level-ActiveLeveldB) / 20.0); else gain = pow(10.0, (level-SVP56_get_rms_dB(state)) / 20.0); } /* ... PRINT-OUT OF RESULTS ... */ if (!quiet) print_act_long_summary(out, FileIn, state, ActiveLeveldB, level, Overflow, gain, N, N1, N2, bitno); else print_act_short_summary(out, FileIn, state, ActiveLeveldB, Overflow, gain);#endif /* LOCAL_PRINT */ /* Close current file */ fclose(Fi); } /* FINALIZATIONS */ /* ... Close log file, if it is the case */ if (out != stdout) fclose(out); /* ... Exit cleanly */#if !defined(VMS) return (0);#endif}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -