贝多芬的月光奏鸣曲第一乐章

 

 

贝多芬的月光奏鸣曲第一乐章--- 2012.03.11

 

闲话

 

.. 今天是女儿一周假期的第一天,可她这周却排得满满的

.. 送她到学校后回到家,家里空荡荡的,我锁上门提前上班了

摇了摇头,心想:

 

好笑,晚上就见上面了

 

.. 忽然脑海里浮现一幕,妈妈背依门框,与我们挥着手

 

可~ 她 一等 就要 等上 一年 !

 

 

120205b2_DSC_0136_NoFIVE

-- 12/03/2012 Writing
-- 05/02/2012 Photo

 

曲名:月光奏鸣曲 (Moonlight Sonata) --- 第一乐章 (First Movement)

原作者:Ludwig Van Beethoven (1770 - 1827) 路德维希.范.贝多芬

改编: Sharon Aaronson

: << Sharon Aaronson top 10 classical favorites >>

--- 10 of the world's Most Treasured Masterpieces Arranged for intermediate to Late Intermediate Pianists

录制日期:11/03/2012

 

--- 16/03/2012

转载于:https://www.cnblogs.com/orderedchaos/archive/2012/03/16/2399701.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
要编写一个驱动STM32喇叭播放贝多芬的命运交响曲的程序,需要用到STM32的音频输出模块和相应的音频文件解码库。以下是一个简单的程序框架: 1. 配置音频输出模块和时钟。 ``` #include "stm32f10x.h" #include "stm32f10x_conf.h" void RCC_Configuration(void) { /* Enable GPIOA and AFIO clocks */ RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA | RCC_APB2Periph_AFIO, ENABLE); /* Enable TIM6 and DAC clocks */ RCC_APB1PeriphClockCmd(RCC_APB1Periph_TIM6 | RCC_APB1Periph_DAC, ENABLE); } void GPIO_Configuration(void) { GPIO_InitTypeDef GPIO_InitStructure; /* Configure PA4 as DAC channel 1 output */ GPIO_InitStructure.GPIO_Pin = GPIO_Pin_4; GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AIN; GPIO_Init(GPIOA, &GPIO_InitStructure); } void TIM6_Configuration(void) { TIM_TimeBaseInitTypeDef TIM_TimeBaseStructure; /* Configure TIM6 to trigger DAC */ TIM_TimeBaseStructure.TIM_Prescaler = 0; TIM_TimeBaseStructure.TIM_Period = 1000; TIM_TimeBaseStructure.TIM_ClockDivision = 0; TIM_TimeBaseStructure.TIM_CounterMode = TIM_CounterMode_Up; TIM_TimeBaseInit(TIM6, &TIM_TimeBaseStructure); TIM_SelectOutputTrigger(TIM6, TIM_TRGOSource_Update); TIM_Cmd(TIM6, ENABLE); } void DAC_Configuration(void) { DAC_InitTypeDef DAC_InitStructure; /* Configure DAC */ DAC_InitStructure.DAC_Trigger = DAC_Trigger_T6_TRGO; DAC_InitStructure.DAC_WaveGeneration = DAC_WaveGeneration_None; DAC_InitStructure.DAC_LFSRUnmask_TriangleAmplitude = DAC_LFSRUnmask_Bit0; DAC_InitStructure.DAC_OutputBuffer = DAC_OutputBuffer_Enable; DAC_Init(DAC_Channel_1, &DAC_InitStructure); DAC_Cmd(DAC_Channel_1, ENABLE); } ``` 2. 配置音频文件解码库,读取音频文件。 ``` #include "stm32f10x.h" #include "stm32f10x_conf.h" #include "mp3dec.h" #define MP3_BUFFER_SIZE 1024 int main(void) { int16_t pcm_sample[MP3_BUFFER_SIZE / 2]; uint8_t mp3_buffer[MP3_BUFFER_SIZE]; HMP3Decoder mp3_decoder; uint32_t mp3_bytes_left; uint8_t* mp3_read_ptr; uint32_t mp3_error; /* Initialize decoder */ mp3_decoder = MP3InitDecoder(); /* Open audio file */ FILE* audio_file = fopen("beethoven.mp3", "rb"); if (audio_file == NULL) { /* Handle error */ } /* Read and decode audio data */ while (1) { /* Read MP3 data from file */ mp3_bytes_left = fread(mp3_buffer, 1, MP3_BUFFER_SIZE, audio_file); if (mp3_bytes_left == 0) { /* End of file reached */ break; } /* Decode MP3 data */ mp3_error = MP3Decode(mp3_decoder, &mp3_read_ptr, &mp3_bytes_left, pcm_sample, 0); if (mp3_error != ERR_MP3_NONE) { /* Handle error */ } /* Send PCM data to DAC */ for (int i = 0; i < MP3_BUFFER_SIZE / 2; i++) { DAC_SetChannel1Data(DAC_Align_12b_R, pcm_sample[i]); } } /* Close audio file */ fclose(audio_file); /* Deinitialize decoder */ MP3FreeDecoder(mp3_decoder); while (1) { /* Wait for interrupt */ } } ``` 3. 将PCM数据发送给音频输出模块的DAC,播放音乐。 ``` #include "stm32f10x.h" #include "stm32f10x_conf.h" int main(void) { int16_t pcm_sample[MP3_BUFFER_SIZE / 2]; uint8_t mp3_buffer[MP3_BUFFER_SIZE]; HMP3Decoder mp3_decoder; uint32_t mp3_bytes_left; uint8_t* mp3_read_ptr; uint32_t mp3_error; /* Initialize decoder */ mp3_decoder = MP3InitDecoder(); /* Open audio file */ FILE* audio_file = fopen("beethoven.mp3", "rb"); if (audio_file == NULL) { /* Handle error */ } /* Read and decode audio data */ while (1) { /* Read MP3 data from file */ mp3_bytes_left = fread(mp3_buffer, 1, MP3_BUFFER_SIZE, audio_file); if (mp3_bytes_left == 0) { /* End of file reached */ break; } /* Decode MP3 data */ mp3_error = MP3Decode(mp3_decoder, &mp3_read_ptr, &mp3_bytes_left, pcm_sample, 0); if (mp3_error != ERR_MP3_NONE) { /* Handle error */ } /* Send PCM data to DAC */ for (int i = 0; i < MP3_BUFFER_SIZE / 2; i++) { DAC_SetChannel1Data(DAC_Align_12b_R, pcm_sample[i]); } } /* Close audio file */ fclose(audio_file); /* Deinitialize decoder */ MP3FreeDecoder(mp3_decoder); while (1) { /* Wait for interrupt */ } } ``` 注意,以上是一个简单的程序框架,实际编写时需要根据具体的硬件和软件环境进行适当的修改和调试。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值