迪文科技论坛

 找回密码
 立即注册
搜索
查看: 52|回复: 0

【开源】FFT 音频 频谱显示

[复制链接]

15

主题

15

回帖

1571

积分

金牌会员

Rank: 6Rank: 6

积分
1571
QQ
发表于 4 天前 | 显示全部楼层 |阅读模式
下面是效果,大家先看下



通信音频板,把计算好的条形柱数据,上传迪文屏幕,再通过屏幕显示出当前的音频,频谱的 ,不同频率的能量大小
看音频代码,以下代码,可以获取频谱的能量大小

void FFT_GET_DATA(void)
{
#ifdef FFT_OPEN
    static TickType_tlast_print_tick = 0;
    TickType_t current_tick =xTaskGetTickCount();

    fre_send_flag=0;
    if(!AudioSpectrumGet(freq_values))
        return;
    fre_send_flag=1;

    {
        int i;
        for (i = 0; i< 64; i++)
        {
           int32_t v = freq_values;
           if (v <= 0)
            {
               spectrum_levels = 0;
            }
           else
            {
               int log_int = 0;
               int32_t tmp = v;
               int frac, level;
               while (tmp > 1) { tmp >>= 1; log_int++; }
               if (log_int <= 4)
                   frac = (v & ((1 << log_int) - 1))<< (4 - log_int);
               else
                   frac = (v >> (log_int - 4)) & 0x0F;
               level = ((log_int << 4) | frac) * 64 / 336;
               if (level > 64) level = 64;
               spectrum_levels = (unsigned char)level;
            }
        }
    }
    if ((current_tick -last_print_tick) >= 1000)
    {
        last_print_tick= current_tick;
    }
#endif
}
uint8_t AudioSpectrumGet(int32_t*freq_values_out)
{
    if(gAudioSpectrum.spectrum_valid && freq_values_out)
    {
       memcpy(freq_values_out, gAudioSpectrum.freq_values,
              FFT_TARGET_FREQ_COUNT * sizeof(int32_t));
        return 1;
    }
    return 0;
}
以下代码,把数据发送给屏幕
u8 FFT_Send[64+10];
void FFT_SEND_DATA(void)
{
#ifdef FFT_OPEN
    static TickType_tlast_print_tick = 0;
    TickType_t current_tick =xTaskGetTickCount();
    if ((current_tick -last_print_tick) < 100)
        return;
    last_print_tick =current_tick;
    if(fre_send_flag)
    {
       fre_send_flag=0;
       memset(FFT_Send,0,sizeof(FFT_Send));
       FFT_Send[0]=LCD_Addr;
       FFT_Send[1]=0x02;
        static constunsigned char sel_idx[32] = {
           0, 2, 4, 6, 9, 11, 14, 17, 20, 22, 24, 26, 29, 31, 33, 35,
           37, 39, 41, 43, 45, 47, 49, 51, 53, 55, 57, 58, 60, 61, 62, 63
        };
        unsigned charspectrum_32[32];
        int j;
        for (j = 0; j< 32; j++)
        {
           spectrum_32[j] = spectrum_levels[sel_idx[j]];
        }
       memcpy(&FFT_Send[2], spectrum_32, 32);
       Usr_uartSend(FFT_Send, 34);
    }
#endif   
}
看迪文屏幕代码
以下处理接收条FFT 显示代码
void MainMachineHandle(void)
{
       inti=0;
       u8fftVal[2]={0,0};
       if(UartDataHandle)
       {
              switch(Uart4_Rx[1])
              {
                     case1://页面改变
                            ChangePage(Uart4_Rx[2]);
                     break;
                     case2:
                            for(i=0;i<32;i++)
                            {
                                   fftVal[1]=Uart4_Rx[2+i];
                                   Write_Dgusii_Vp_byChar(0x2000+i,fftVal,2);
                            }
                     break;
              }
              CLR_UartMp3();

       }


本帖子中包含更多资源

您需要 登录 才可以下载或查看,没有账号?立即注册

x
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

QQ|Archiver|手机版|小黑屋|迪文科技论坛 ( 京ICP备05033781号-1 )

GMT+8, 2026-7-17 12:41 , Processed in 0.026141 second(s), 25 queries .

Powered by Discuz! X3.4

© 2001-2023 Discuz! Team.

快速回复 返回顶部 返回列表