📄 loudness.c
字号:
/******************************************************************** * Project: Tasking-STM32-Stick * File: loudness.c * * System: Cortex ARMv7 32 Bit (STM32FRT) * Compiler: Tasking Altuim VX Toolchain v2.01 * * Date: 2007-08-20 * Author: Application@Hitex.de * * Rights: Hitex Development Tools GmbH * Greschbachstr. 12 * D-76229 Karlsruhe ******************************************************************** * Description: * * This file is part of the Tasking Example chain * The code is based on usage of the STmicro library functions * This is a small implementation of different features * The application runs in ARM mode with high optimization level. * loudness.c - loudness of the signal * * loud() calculates the loudness of the signal, for * each freq point. Result is an integer array, * units are dB (values will be negative). * * All data are fixed-point short integers, in which * -32768 to +32768 represent -1.0 to +1.0. Integer arithmetic * is used for speed, instead of the more natural floating-point. * ******************************************************************** * History: * * Revision 1.0 2007/08/20 Gn * Initial revision ******************************************************************** * This is a preliminary version. * * WARRANTY: HITEX warrants that the media on which the SOFTWARE is * furnished is free from defects in materials and workmanship under * normal use and service for a period of ninety (90) days. HITEX entire * liability and your exclusive remedy shall be the replacement of the * SOFTWARE if the media is defective. This Warranty is void if failure * of the media resulted from unauthorized modification, accident, abuse, * or misapplication. * * DISCLAIMER: OTHER THAN THE ABOVE WARRANTY, THE SOFTWARE IS FURNISHED * "AS IS" WITHOUT WARRANTY OF ANY KIND. HITEX DISCLAIMS ALL OTHER WARRANTIES, * EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO IMPLIED WARRANTIES * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. * * NEITHER HITEX NOR ITS AFFILIATES SHALL BE LIABLE FOR ANY DAMAGES ARISING * OUT OF THE USE OF OR INABILITY TO USE THE SOFTWARE, INCLUDING DAMAGES FOR * LOSS OF PROFITS, BUSINESS INTERRUPTION, OR ANY SPECIAL, INCIDENTAL, INDIRECT * OR CONSEQUENTIAL DAMAGES EVEN IF HITEX HAS BEEN ADVISED OF THE POSSIBILITY * OF SUCH DAMAGES. ********************************************************************/#include "FFTfunc.h"int db_from_ampl(short re, short im);/** loudness() - compute loudness of freq-spectrum components. n should be ntot/2, where ntot was passed to fix_fft(); 6 dB is added to account for the omitted alias components. loud[] is the loudness, in dB wrt 32767; will be +10 to -N_LOUD.*/void loudness(short loud[], short fr[], short fi[]){ int i; for(i=0; i<N_SAMPLE/2; ++i) { loud[i] = db_from_ampl(fr[i],fi[i]) + 6; if(loud[i] > 0) loud[i] = 0; loud[i] = -loud[i]; }}/** db_from_ampl() - find loudness (in dB) from the complex amplitude.*/int db_from_ampl(short re, short im){ long v; int i; v = (long)re * (long)re + (long)im * (long)im; for(i=0; i<N_LOUD; ++i) if(loudness_table[i] <= v) break; return (-i);}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -