Advertisement
Guest User

Untitled

a guest
Aug 30th, 2015
604
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.60 KB | None | 0 0
  1. void TIM7_IRQHandler()
  2. {
  3. // Clear the interrupt flag
  4. TIM7->SR &= ~(TIM_SR_UIF);
  5. // Get the new sample
  6.  
  7. memcpy(&left, &sd_data_buffer[index % sizeof(sd_data_buffer)], sizeof(uint16_t));
  8. memcpy(&right, &sd_data_buffer[(index % sizeof(sd_data_buffer)) + 2], sizeof(uint16_t));
  9.  
  10. left += 32768;
  11. right += 32768;
  12. // Scale the sample values
  13. diff = left - 32768;
  14. diff = diff *0.25;
  15. left = 32768+diff;
  16. diff = right - 32768;
  17. diff = diff *0.25;
  18. right = 32768+diff;
  19.  
  20.  
  21. samples = ((uint32_t)(left)<<16) + (uint32_t)right;
  22.  
  23. DAC_Put_Data_Dual_12bit_L(samples);
  24.  
  25. index += 4;
  26. // If next sample will wrap the sample array then change the buffer with samples
  27. if(index % sizeof(sd_data_buffer) == 0)
  28. {
  29. static buffer_index = 0;
  30. if(buffer_index % 2 == 0)
  31. {
  32. data_ptr = sd_data_buffer;
  33. empty_data_buf_ptr = sd_data_buffer_additional;
  34. }
  35. else
  36. {
  37. data_ptr = sd_data_buffer_additional;
  38. empty_data_buf_ptr = sd_data_buffer;
  39. }
  40. index = 0;
  41. if(wav_eof)
  42. {
  43. // Stop the DAC triggering timer
  44. TIM_Stop(TIM7);
  45. // Close the file
  46. ret_val = f_close(&sd_current_file);
  47. // Clear the flags
  48. wav_file_playing = false;
  49. wav_file_chosen = false;
  50. // Clear the green led
  51. GPIOD->ODR &= ~GPIO_ODR_ODR_12;
  52. // Set the next state
  53. state = STATE_EXECUTE_USER_REQUESTS;
  54. // clear the sample index
  55. buffer_index = 0;
  56. }
  57. else
  58. {
  59. // Change the state of device
  60. state = STATE_READ_SAMPLES;
  61. }
  62. // Increment the buffer index which indicates which sample array is currently used and which is to be filled with samples
  63. buffer_index++;
  64. }
  65. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement