Advertisement
Guest User

Untitled

a guest
Jan 23rd, 2018
94
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 7.11 KB | None | 0 0
  1. /**
  2. ******************************************************************************
  3. * @file main.cpp
  4. * @author Davide Aliprandi, STMicroelectronics
  5. * @version V1.0.0
  6. * @date March 25th, 2016
  7. * @brief mbed test application for the STMicroelectronics X-NUCLEO-CCA01M1
  8. * Sound Terminal Expansion Board.
  9. ******************************************************************************
  10. * @attention
  11. *
  12. * <h2><center>&copy; COPYRIGHT(c) 2016 STMicroelectronics</center></h2>
  13. *
  14. * Redistribution and use in source and binary forms, with or without modification,
  15. * are permitted provided that the following conditions are met:
  16. * 1. Redistributions of source code must retain the above copyright notice,
  17. * this list of conditions and the following disclaimer.
  18. * 2. Redistributions in binary form must reproduce the above copyright notice,
  19. * this list of conditions and the following disclaimer in the documentation
  20. * and/or other materials provided with the distribution.
  21. * 3. Neither the name of STMicroelectronics nor the names of its contributors
  22. * may be used to endorse or promote products derived from this software
  23. * without specific prior written permission.
  24. *
  25. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
  26. * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  27. * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  28. * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
  29. * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
  30. * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
  31. * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
  32. * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
  33. * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  34. * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  35. *
  36. ******************************************************************************
  37. */
  38.  
  39.  
  40. /* Includes ------------------------------------------------------------------*/
  41.  
  42. /* mbed specific header files. */
  43. #include "mbed.h"
  44. #include "rtos.h"
  45. #include "USBHostMSD.h"
  46.  
  47. #if DEVICE_I2S
  48.  
  49. /* Helper header files. */
  50. #include "DevI2C.h"
  51.  
  52. /* Component specific header files. */
  53. #include "STA350BW.h"
  54.  
  55. /* My song header file. */
  56. #include "my_song.h"
  57.  
  58.  
  59. /* Definitions ---------------------------------------------------------------*/
  60.  
  61. /* Events. */
  62. #define PLAY_STOP_EVENT (0x1)
  63.  
  64. /* Variables -----------------------------------------------------------------*/
  65. Serial pc(USBTX,USBRX);
  66. #define buffer_size 32767
  67. int16_t valori1[buffer_size]= {0}; //2 perchè ci sono due canali
  68. //int16_t valori2[2*buffer_size]= {0};
  69. DigitalOut myledMIO(LED1);
  70. //int16_t valori[buffer_size]={0};
  71. int c=0;
  72. int b=0;
  73. bool fine1=false;
  74. bool fine2=false;
  75. /* Initialization parameters. */
  76. STA350BW_init_t init = {
  77. 32000, /* Default Sampling Frequency [Hz]. */
  78. 100 /* Default Volume. */
  79. };
  80.  
  81. /* Sound Terminal Component. */
  82. STA350BW *sound_terminal;
  83.  
  84. /* Thread to manage I2S peripherals. */
  85. static rtos::Thread i2s_bh_daemon;
  86.  
  87. /* Threads. */
  88. Thread *play_stop_thread;
  89.  
  90. /* User button handling. */
  91. InterruptIn event(USER_BUTTON);
  92.  
  93.  
  94. /* Functions -----------------------------------------------------------------*/
  95.  
  96. /**
  97. * @brief User button handler function.
  98. * @param None.
  99. * @retval None.
  100. */
  101. void pressed(void)
  102. {
  103. /* Signal to play/stop handler thread. */
  104. play_stop_thread->signal_set(PLAY_STOP_EVENT);
  105. }
  106.  
  107. /**
  108. * @brief Play/stop handler function.
  109. * @param None.
  110. * @retval None.
  111. */
  112. /*void play_stop_handler(void)
  113. {
  114. while (true)
  115. {
  116. static bool stop = true;
  117.  
  118. // Waiting for play/stop events.
  119. play_stop_thread->signal_wait(PLAY_STOP_EVENT);
  120.  
  121. if (stop)
  122. sound_terminal->stop();
  123. else
  124. sound_terminal->play((int16_t *) valori, (uint16_t) sizeof(valori), true);
  125. printf("--> %s\r\n", stop ? "Stop." : "Playing...");
  126.  
  127. stop = !stop;
  128. }
  129. }*/
  130.  
  131.  
  132.  
  133. /**
  134. * @brief Entry point function of mbedOS.
  135. * @param None
  136. * @retval None
  137. */
  138. int main(void)
  139. {
  140. USBHostMSD msd("usb");
  141. /*----- Initialization. -----*/
  142. printf("TP1\r\n");
  143. if (!msd.connect()) {
  144. error("USB Flash drive not found.\n");
  145. }
  146. printf("TP2\r\n");
  147.  
  148. /*----- Initialization. -----*/
  149.  
  150. /* Initializing I2C bus. */
  151. DevI2C *dev_i2c = new DevI2C(PB_9, PB_8);
  152.  
  153. /* Initializing Sound Terminal Component. */
  154. #ifndef USE_I2S2
  155. sound_terminal = new STA350BW(PA_10, STA350BW_ADDRESS_1, *dev_i2c, PB_15, PB_13, PB_12, NC, PC_6);
  156. #else
  157. sound_terminal = new STA350BW(PA_10, STA350BW_ADDRESS_2, *dev_i2c, PC_12, PC_10, PA_4, NC, PC_7);
  158. #endif
  159. if (sound_terminal->init(&init) != COMPONENT_OK) {
  160. error("Initialization of the Sound Terminal Expansion Board failed.\r\n");
  161. exit(EXIT_FAILURE);
  162. }
  163.  
  164. /* Starting a thread to manage I2S peripherals. */
  165. Callback<void()> i2s_bh_task(&I2S::i2s_bh_queue, &events::EventQueue::dispatch_forever);
  166. i2s_bh_daemon.start(i2s_bh_task);
  167.  
  168. /* Scheduling the play/stop function. */
  169. // play_stop_thread = new Thread();
  170. // osStatus status = play_stop_thread->start(play_stop_handler);
  171. //if (status != osOK)
  172. // printf("Could not start the play/stop handler thread.\r\n");
  173. //event.fall(&pressed);
  174.  
  175. /* Setting Sound Terminal Component's parameters. */
  176. sound_terminal->set_frequency(44100);
  177. sound_terminal->set_volume(STA350BW_CHANNEL_MASTER, 100);
  178.  
  179. /* Printing to the console. */
  180. printf("Sound Terminal Application Example\r\n\n");
  181.  
  182. FILE *fp = fopen("/usb/coez.wav", "r");
  183.  
  184. while(c!=EOF)
  185. {
  186. c=(c+2);
  187. //b=(b+4);
  188.  
  189.  
  190. // pc.printf("Val=%i\n\r",fp);
  191.  
  192.  
  193. for(int k=0; k<c; k++) {
  194. for(int i=0; i<(buffer_size); i++)
  195. {
  196. valori1[i+1]=valori1[i];
  197. fread(&valori1[i],2,1,fp);
  198.  
  199. }
  200. //printf("v1%d\r\n",valori1);
  201.  
  202. }
  203.  
  204. /* fine1=true;
  205. printf("b%d\r\n",b);
  206. for (int x=0; x<b; x++) {
  207. for(int f=0; f<buffer_size; f++)
  208. {
  209. fread(&valori2[2*f],2,1,fp);
  210. valori2[2*f+1]=valori2[2*f];
  211. }
  212. printf("v2%d\r\n",valori2);
  213. }
  214. fine2=true;*/
  215.  
  216.  
  217.  
  218. /*----- Playing. -----*/
  219.  
  220. /* Printing to the console. */
  221. // printf("--> Playing...\r\n");
  222.  
  223.  
  224. // if(fine1==true) {
  225. sound_terminal->play((int16_t *) valori1, (uint16_t) sizeof(valori1), true);
  226. //wait(0.2);
  227. //fine1=false;
  228. //}
  229. /*if(fine2==true) {
  230. sound_terminal->play((int16_t *) valori2, (uint16_t) sizeof(valori2), true);
  231. fine2=false;
  232. }*/
  233. }
  234. fclose(fp);
  235. }
  236. #else // DEVICE_I2S
  237.  
  238. int main(void)
  239. {
  240. printf("The target does not support I2S API.\r\n");
  241. }
  242.  
  243. #endif // DEVICE_I2S
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement