Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- void TIM7_IRQHandler()
- {
- // Clear the interrupt flag
- TIM7->SR &= ~(TIM_SR_UIF);
- // Get the new sample
- memcpy(&left, &sd_data_buffer[index % sizeof(sd_data_buffer)], sizeof(uint16_t));
- memcpy(&right, &sd_data_buffer[(index % sizeof(sd_data_buffer)) + 2], sizeof(uint16_t));
- left += 32768;
- right += 32768;
- // Scale the sample values
- diff = left - 32768;
- diff = diff *0.25;
- left = 32768+diff;
- diff = right - 32768;
- diff = diff *0.25;
- right = 32768+diff;
- samples = ((uint32_t)(left)<<16) + (uint32_t)right;
- DAC_Put_Data_Dual_12bit_L(samples);
- index += 4;
- // If next sample will wrap the sample array then change the buffer with samples
- if(index % sizeof(sd_data_buffer) == 0)
- {
- static buffer_index = 0;
- if(buffer_index % 2 == 0)
- {
- data_ptr = sd_data_buffer;
- empty_data_buf_ptr = sd_data_buffer_additional;
- }
- else
- {
- data_ptr = sd_data_buffer_additional;
- empty_data_buf_ptr = sd_data_buffer;
- }
- index = 0;
- if(wav_eof)
- {
- // Stop the DAC triggering timer
- TIM_Stop(TIM7);
- // Close the file
- ret_val = f_close(&sd_current_file);
- // Clear the flags
- wav_file_playing = false;
- wav_file_chosen = false;
- // Clear the green led
- GPIOD->ODR &= ~GPIO_ODR_ODR_12;
- // Set the next state
- state = STATE_EXECUTE_USER_REQUESTS;
- // clear the sample index
- buffer_index = 0;
- }
- else
- {
- // Change the state of device
- state = STATE_READ_SAMPLES;
- }
- // Increment the buffer index which indicates which sample array is currently used and which is to be filled with samples
- buffer_index++;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement