• 大小: 1.09MB
    文件类型: .rar
    金币: 1
    下载: 0 次
    发布日期: 2023-08-28
  • 语言: 其他
  • 标签: STM32  MUSIC  PWM  

资源简介

一个将WAV文件转换成代码,直接储存在STM32上并直接播放的程序。亲测在STM32F1系列上直接可用,将你的耳机或者功放+喇叭接在B0,就可以听到美妙的音乐啦。

资源截图

代码片段和文件信息

#include“typedef.h“
#include“sysinit.h“
#include“wav_fmt.h“
#include“driver.h“
#include


extern u8 WaveData[];

struct RIFF_BLOCK RiffBlock; 
struct FMT_BLOCK    FmtBlock;
struct FACT_BLOCK FactBlock;
struct DATA_BLOCK DataBlock;
u32 MusicPosite = 0;


void WavResolve(void);
void SongInfoLCD(void);
int main()
{
RCC_Config();
NVIC_Config();
GPIO_Config();
// LCD1602_Init();

WavResolve();
// SongInfoLCD();
TIMx_Config();
while(1)
{

}
}


void WavResolve(void)
{
/*  RIFF WAVE Chunk 内容解析  */
RiffBlock.szRiffID[0] = WaveData[MusicPosite++]; // ‘R‘
RiffBlock.szRiffID[1] = WaveData[MusicPosite++]; // ‘I‘
RiffBlock.szRiffID[2] = WaveData[MusicPosite++]; // ‘F‘
RiffBlock.szRiffID[3] = WaveData[MusicPosite++]; // ‘F‘

RiffBlock.dwRiffSize = WaveData[MusicPosite++] + (WaveData[MusicPosite++] << 8) +
   (WaveData[MusicPosite++] << 16) + (WaveData[MusicPosite++] << 24);

RiffBlock.szRiffFormat[0] = WaveData[MusicPosite++]; // ‘W‘
RiffBlock.szRiffFormat[1] = WaveData[MusicPosite++]; // ‘A‘
RiffBlock.szRiffFormat[2] = WaveData[MusicPosite++]; // ‘V‘
RiffBlock.szRiffFormat[3] = WaveData[MusicPosite++]; // ‘E‘

/* Format Chunk 内容解析  */
FmtBlock.szFmtID[0] = WaveData[MusicPosite++]; // ‘f‘
FmtBlock.szFmtID[1] = WaveData[MusicPosite++]; // ‘m‘
FmtBlock.szFmtID[2] = WaveData[MusicPosite++]; // ‘t‘
FmtBlock.szFmtID[3] = WaveData[MusicPosite++]; // ‘ ‘

FmtBlock.dwFmtSize = WaveData[MusicPosite++] + (WaveData[MusicPosite++] << 8) +
       (WaveData[MusicPosite++] << 16) + (WaveData[MusicPosite++] << 24);

FmtBlock.wavFormat.wFormatTag = WaveData[MusicPosite++] + (WaveData[MusicPosite++] << 8);
FmtBlock.wavFormat.wChannels = WaveData[MusicPosite++] + (WaveData[MusicPosite++] << 8);
FmtBlock.wavFormat.dwSamplesPerSec = WaveData[MusicPosite++] + (WaveData[MusicPosite++] << 8) +
       (WaveData[MusicPosite++] << 16) + (WaveData[MusicPosite++] << 24);
FmtBlock.wavFormat.dwAvgBytesPerSec = WaveData[MusicPosite++] + (WaveData[MusicPosite++] << 8) +
       (WaveData[MusicPosite++] << 16) + (WaveData[MusicPosite++] << 24);
FmtBlock.wavFormat.wBlockAlign = WaveData[MusicPosite++] + (WaveData[MusicPosite++] << 8);
FmtBlock.wavFormat.wBitsPerSample = WaveData[MusicPosite++] + (WaveData[MusicPosite++] << 8);

if(WaveData[MusicPosite] != ‘f‘)
goto dt;
/* Fact Chunk(optional) 内容解析 */
FactBlock.szFactID[0] = WaveData[MusicPosite++]; // ‘f‘
FactBlock.szFactID[1] = WaveData[MusicPosite++]; // ‘a‘
FactBlock.szFactID[2] = WaveData[MusicPosite++]; // ‘c‘
FactBlock.szFactID[3] = WaveData[MusicPosite++]; // ‘t‘

FactBlock.dwFactSize = WaveData[MusicPosite++] + (WaveData[MusicPosite++] << 8) +
   (WaveData[MusicPosite++] << 16) + (WaveData[MusicPosite++] << 24);

MusicPosite +=FactBlock.dwFactSize;
 
/* Data Chunk 内容解析 */
dt: DataBlock.szDataID[0] = WaveData[MusicPosite++]; // 

 属性            大小     日期    时间   名称
----------- ---------  ---------- -----  ----

     文件      25414  2009-08-02 11:00  PWMMusic\bin\cortexm3_macro.lst

     文件       2348  2009-08-02 11:00  PWMMusic\bin\cortexm3_macro.o

     文件     132093  2009-08-02 11:00  PWMMusic\bin\drv_lcd1602.crf

     文件       1398  2009-08-02 11:00  PWMMusic\bin\drv_lcd1602.d

     文件     138432  2009-08-02 11:00  PWMMusic\bin\drv_lcd1602.o

     文件     126265  2009-08-02 11:00  PWMMusic\bin\drv_tmrx.crf

     文件       1337  2009-08-02 11:00  PWMMusic\bin\drv_tmrx.d

     文件     132392  2009-08-02 11:00  PWMMusic\bin\drv_tmrx.o

     文件       6993  2009-08-02 11:16  PWMMusic\bin\main.crf

     文件        191  2009-08-02 11:16  PWMMusic\bin\main.d

     文件      14908  2009-08-02 11:16  PWMMusic\bin\main.o

     文件     259540  2009-08-02 11:16  PWMMusic\bin\PWMMusic.axf

     文件     295784  2009-08-02 11:16  PWMMusic\bin\PWMMusic.hex

     文件      87973  2009-08-02 11:16  PWMMusic\bin\PWMMusic.htm

     文件        561  2009-08-02 11:16  PWMMusic\bin\PWMMusic.lnp

     文件      75733  2009-08-02 11:16  PWMMusic\bin\PWMMusic.map

     文件      14285  2009-08-02 11:16  PWMMusic\bin\PWMMusic.plg

     文件        479  2009-08-02 10:53  PWMMusic\bin\PWMMusic.sct

     文件       1901  2009-08-02 11:16  PWMMusic\bin\PWMMusic.tra

     文件      31925  2009-08-02 11:00  PWMMusic\bin\STM32F10x.lst

     文件       4816  2009-08-02 11:00  PWMMusic\bin\STM32F10x.o

     文件      30017  2009-08-02 11:00  PWMMusic\bin\stm32f10x_flash.crf

     文件        341  2009-08-02 11:00  PWMMusic\bin\stm32f10x_flash.d

     文件      37860  2009-08-02 11:00  PWMMusic\bin\stm32f10x_flash.o

     文件      35060  2009-08-02 11:00  PWMMusic\bin\stm32f10x_gpio.crf

     文件        388  2009-08-02 11:00  PWMMusic\bin\stm32f10x_gpio.d

     文件      43284  2009-08-02 11:00  PWMMusic\bin\stm32f10x_gpio.o

     文件     127396  2009-08-02 11:00  PWMMusic\bin\stm32f10x_it.crf

     文件       1410  2009-08-02 11:00  PWMMusic\bin\stm32f10x_it.d

     文件     139996  2009-08-02 11:00  PWMMusic\bin\stm32f10x_it.o

............此处省略110个文件信息

评论

共有 条评论