[应用方案] NUC505播放SD卡内的MP3文件

[复制链接]
 楼主| springvirus 发表于 2018-5-14 09:41 | 显示全部楼层 |阅读模式
本帖最后由 springvirus 于 2018-5-14 09:44 编辑

周末试了下NUC505的播放功能,直接用例程I2S_MP3PLAYER_SD播放,只是修改下MP3文件路径和名字

接上耳机,效果不错,可惜没法调音量,计划用TDA2822弄个小功放,再玩玩


dongnanxibei 发表于 2018-5-14 22:52 | 显示全部楼层
用的什么解码啊。
 楼主| springvirus 发表于 2018-5-15 08:11 | 显示全部楼层
本帖最后由 springvirus 于 2018-5-15 08:16 编辑

libmad + 内部的音频CODEC
yiyigirl2014 发表于 2018-5-15 11:11 | 显示全部楼层
牛叉,貌似我有这个开发板,回去我找找
小灵通2018 发表于 2018-5-15 19:11 | 显示全部楼层
官方提供了这个播放MP3的例子吗
 楼主| springvirus 发表于 2018-5-16 08:23 | 显示全部楼层
小灵通2018 发表于 2018-5-15 19:11
官方提供了这个播放MP3的例子吗

是的,BSP包里有
玛尼玛尼哄 发表于 2018-5-16 11:12 | 显示全部楼层
  1. /**************************************************************************//**
  2. * [url=home.php?mod=space&uid=288409]@file[/url]     main.c
  3. * [url=home.php?mod=space&uid=895143]@version[/url]  V2.1
  4. * $Revision: 8 $
  5. * $Date: 16/01/09 3:40p $
  6. * [url=home.php?mod=space&uid=247401]@brief[/url]    A MP3 file player demo using internal audio codec used to playback MP3 file stored in SD card.
  7. *
  8. * @note
  9. * Copyright (C) 2016 Nuvoton Technology Corp. All rights reserved.
  10. *
  11. ******************************************************************************/
  12. #include <stdio.h>
  13. #include <string.h>
  14. #include "NUC505Series.h"
  15. #include "config.h"
  16. #include "diskio.h"
  17. #include "ff.h"

  18. uint32_t volatile u32BuffPos = 0;

  19. FATFS FatFs[_VOLUMES];               /* File system object for logical drive */

  20. #ifdef __ICCARM__
  21. #pragma data_alignment=32
  22. BYTE Buff[16] ;                   /* Working buffer */
  23. #endif

  24. #ifdef __ARMCC_VERSION
  25. __align(32) BYTE Buff[16] ;       /* Working buffer */
  26. #endif

  27. /*---------------------------------------------------------*/
  28. /* User Provided RTC Function for FatFs module             */
  29. /*---------------------------------------------------------*/
  30. /* This is a real time clock service to be called from     */
  31. /* FatFs module. Any valid time must be returned even if   */
  32. /* the system does not support an RTC.                     */
  33. /* This function is not required in read-only cfg.         */

  34. unsigned long get_fattime (void)
  35. {
  36.     unsigned long tmr;

  37.     tmr=0x00000;

  38.     return tmr;
  39. }

  40. //---------------------------------------------------------
  41. //--- Initial SD0 multi-function GPIO pin
  42. //
  43. // NUC505 support 3 groups of GPIO pins and SD sockets for same one SD port.
  44. // Please select ONLY ONE configuration from them.
  45. // 1. SD-A socket on daughter board + default SD0_Init(). (Default)
  46. // 2. SD-B socket on main board + short JP3 and JP4
  47. //    + define compile flag "SDH_GPIO_GB" in SD0_Init().
  48. //    (Note: this configuration conflict with UART1)
  49. // 3. SD-C socket on main board + short JP3 and JP2
  50. //    + define compile flag "SDH_GPIO_GA" in SD0_Init()
  51. //    (Note: this configuration conflict with UART0)
  52. //---------------------------------------------------------
  53. void SD0_Init(void)
  54. {
  55. #ifdef SDH_GPIO_GA
  56.     // The group A are GPA10~11, GPA13~15, GPB0~1
  57.     // Conflict with UART0
  58.     // printf("SD_Open(): Configure GPIO group A as SDH pins.\n");
  59.     SYS->GPA_MFPH &= (~0x77707700);
  60.     SYS->GPA_MFPH |=   0x44404400;
  61.     SYS->GPA_MFPH &= (~0x00000077);
  62.     SYS->GPB_MFPL |=   0x00000044;

  63. #elif defined SDH_GPIO_GB
  64.     // The group B are GPB2~3, GPB5~9
  65.     // Conflict with UART1
  66.     // printf("SD_Open(): Configure GPIO group B as SDH pins.\n");
  67.     SYS->GPB_MFPL &= (~0x77707700);
  68.     SYS->GPB_MFPL |=   0x44404400;
  69.     SYS->GPB_MFPH &= (~0x00000077);
  70.     SYS->GPB_MFPH |=   0x00000044;

  71. #elif defined SDH_GPIO_G_48PIN
  72.     // The group 48PIN are GPB0~3, GPB5~7 for NUC505 48PIN chip
  73.     // Conflict with both UART0 and UART1
  74.     // printf("SD_Open(): Configure special GPIO as SDH pins for 48 pins NUC505 chip.\n");
  75.     SYS->GPB_MFPL &= (~0x77707777);
  76.     SYS->GPB_MFPL |=   0x44404444;

  77. #else   // default for defined SDH_GPIO_GC
  78.     // The group C are GPC0~2, GPC4~7
  79.     // printf("SD_Open(): Configure GPIO group C as SDH pins.\n");
  80.     SYS->GPC_MFPL &= (~0x77770777);
  81.     SYS->GPC_MFPL |=   0x11110111;
  82. #endif
  83. }

  84. void SYS_Init(void)
  85. {

  86. /*---------------------------------------------------------------------------------------------------------*/
  87. /* Init System Clock                                                                                       */
  88. /*---------------------------------------------------------------------------------------------------------*/
  89.     /* Unlock protected registers */
  90.     //SYS_UnlockReg();
  91.      
  92.     /* Enable  XTAL */
  93. //    CLK->PWRCTL |= CLK_PWRCTL_HXTEN_Msk;

  94.         CLK_SetCoreClock(100000000);
  95.    
  96.                 /* PCLK divider */
  97.                 CLK_SetModuleClock(PCLK_MODULE, NULL, 1);
  98.                
  99.     /* Lock protected registers */
  100.     //SYS_LockReg();

  101.                 //--- Initial SD0 multi-function pin
  102.     SD0_Init();
  103. }

  104. void UART0_Init(void)
  105. {
  106.                 /* Enable UART0 Module clock */
  107.     CLK_EnableModuleClock(UART0_MODULE);
  108.                 /* UART0 module clock from EXT */
  109.                 CLK_SetModuleClock(UART0_MODULE, CLK_UART0_SRC_EXT, 0);
  110.     /* Reset IP */
  111.     SYS_ResetModule(UART0_RST);   
  112.     /* Configure UART0 and set UART0 Baud-rate */
  113.                 UART_Open(UART0, 115200);
  114.                 /*---------------------------------------------------------------------------------------------------------*/
  115.     /* Init I/O Multi-function                                                                                 */
  116.     /*---------------------------------------------------------------------------------------------------------*/
  117.     /* Configure multi-function pins for UART0 RXD and TXD */
  118.                 SYS->GPB_MFPL  = (SYS->GPB_MFPL & (~SYS_GPB_MFPL_PB0MFP_Msk) ) | SYS_GPB_MFPL_PB0MFP_UART0_TXD;       
  119.                 SYS->GPB_MFPL  = (SYS->GPB_MFPL & (~SYS_GPB_MFPL_PB1MFP_Msk) ) | SYS_GPB_MFPL_PB1MFP_UART0_RXD;       
  120.        
  121. }

  122. void I2S_Init(void)
  123. {
  124.                 /* Enable I2S Module clock */
  125.     CLK_EnableModuleClock(I2S_MODULE);
  126.                 /* I2S module clock from APLL */
  127.         //FIXME APLL CLOCK
  128.                 // ideal clock is 49.152MHz, real clock is 49152031Hz
  129. //        CLK_SET_APLL(CLK_APLL_49152031);        // APLL is 49152031Hz for 48000Hz
  130.         CLK_SET_APLL(CLK_APLL_45158425);        // APLL is 45158425Hz for 44100Hz
  131.         CLK_SetModuleClock(I2S_MODULE, CLK_I2S_SRC_APLL, 0);        // 0 means (APLL/1)
  132.     /* Reset IP */
  133.     SYS_ResetModule(I2S_RST);   
  134.     /*---------------------------------------------------------------------------------------------------------*/
  135.     /* Init I/O Multi-function                                                                                 */
  136.     /*---------------------------------------------------------------------------------------------------------*/
  137.     /* Configure multi-function pins for I2S */
  138.                 // GPC[8]  = MCLK
  139.                 // GPC[9]  = DIN
  140.                 // GPC[10] = DOUT
  141.                 // GPC[11] = LRCLK
  142.                 // GPC[12] = BCLK
  143.                 SYS->GPC_MFPH  = (SYS->GPC_MFPH & (~SYS_GPC_MFPH_PC8MFP_Msk) ) | SYS_GPC_MFPH_PC8MFP_I2S_MCLK;       
  144.                 SYS->GPC_MFPH  = (SYS->GPC_MFPH & (~SYS_GPC_MFPH_PC9MFP_Msk) ) | SYS_GPC_MFPH_PC9MFP_I2S_DIN;       
  145.                 SYS->GPC_MFPH  = (SYS->GPC_MFPH & (~SYS_GPC_MFPH_PC10MFP_Msk) ) | SYS_GPC_MFPH_PC10MFP_I2S_DOUT;       
  146.                 SYS->GPC_MFPH  = (SYS->GPC_MFPH & (~SYS_GPC_MFPH_PC11MFP_Msk) ) | SYS_GPC_MFPH_PC11MFP_I2S_LRCLK;       
  147.                 SYS->GPC_MFPH  = (SYS->GPC_MFPH & (~SYS_GPC_MFPH_PC12MFP_Msk) ) | SYS_GPC_MFPH_PC12MFP_I2S_BCLK;       
  148.        
  149. }

  150. /*---------------------------------------------------------------------------------------------------------*/
  151. /*  Main Function                                                                                          */
  152. /*---------------------------------------------------------------------------------------------------------*/
  153. int32_t main (void)
  154. {
  155.     /* Init System, IP clock and multi-function I/O */
  156.     SYS_Init();

  157.     /* Init UART0 to 115200-8n1 for print message */
  158.     UART0_Init();

  159.     printf("+------------------------------------------------------------------------+\n");
  160.     printf("|                   MP3 Player Sample with Internal CODEC                |\n");
  161.     printf("+------------------------------------------------------------------------+\n");
  162.     printf(" Please put MP3 files on SD card \n");

  163.     printf("rc=%d\n", (WORD)disk_initialize(0));
  164.     disk_read(0, Buff, 2, 1);
  165.     //f_mount(0, &FatFs[0]);  // for FATFS v0.09
  166.                 // Register work area to the default drive
  167.     f_mount(&FatFs[0], "", 0);  // for FATFS v0.11

  168.         /* Init I2S, IP clock and multi-function I/O */
  169.         I2S_Init();

  170.     MP3Player();

  171.     while(1);
  172. }

  173. /*** (C) COPYRIGHT 2015 Nuvoton Technology Corp. ***/
玛尼玛尼哄 发表于 2018-5-16 11:12 | 显示全部楼层
太感谢了,终于知道哪个单片机可以播放MP3了。买个去。
 楼主| springvirus 发表于 2018-5-16 17:24 | 显示全部楼层

就是这个
只能说,新唐非常的给力!!
您需要登录后才可以回帖 登录 | 注册

本版积分规则

127

主题

4596

帖子

14

粉丝
快速回复 在线客服 返回列表 返回顶部