Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependents: WavePlayer_MODDMA wave_player_DMA_mbed
Revision 1:11a670498598, committed 2016-03-16
- Comitter:
- ebradley6
- Date:
- Wed Mar 16 19:58:55 2016 +0000
- Parent:
- 0:286582877314
- Commit message:
- Updated comments.
Changed in this revision
| wave_player.cpp | Show annotated file Show diff for this revision Revisions of this file |
--- a/wave_player.cpp Wed Mar 16 03:28:44 2016 +0000
+++ b/wave_player.cpp Wed Mar 16 19:58:55 2016 +0000
@@ -108,6 +108,8 @@
fseek(wavefile,chunk_size-sizeof(wav_format),SEEK_CUR);
break;
case 0x61746164:
+ // Data chunk which contains the audio samples to send to the DAC
+
// allocate a buffer big enough to hold a slice
slice_buf=(char *)malloc(wav_format.block_align);
if (!slice_buf) {
@@ -157,6 +159,7 @@
->attach_err ( this,&wave_player::ERR1_callback )
; // config end
+ // Set the DAC to the audio sample rate
LPC_DAC->DACCNTVAL = dac_cntval;
// Begin (enable DMA and counter). Note, don't enable
@@ -176,6 +179,7 @@
// while 16 and 32 bit wave files use signed data
//
+ // Fill buffer 0 first
buf0_flag=1;
// Separate slices into sections of BUF_SIZE samples
@@ -192,6 +196,7 @@
DAC_buf1[k]=0;
}
else{
+ // Read audio samples from sd card
fread(slice_buf,wav_format.block_align,1,wavefile);
if (feof(wavefile)) {
printf("Oops -- not enough slices in the wave file\n");
@@ -299,12 +304,13 @@
}
}
-// Configuration callback on TC
+// Configuration callback on TC; runs when the DMA has finished transferring buffer 0 to the DAC
void wave_player::TC0_callback(void) {
// Get configuration pointer.
MODDMA_Config *config = dma.getConfig();
+ // Only run once
dma.haltAndWaitChannelComplete( (MODDMA::CHANNELS)config->channelNum());
// Finish the DMA cycle by shutting down the channel.
@@ -322,12 +328,13 @@
error("Oh no! My Mbed EXPLODED! :( Only kidding, go find the problem");
}
-// Configuration callback on TC
+// Configuration callback on TC; runs when the DMA has finished transferring buffer 1 to the DAC
void wave_player::TC1_callback(void) {
// Get configuration pointer.
MODDMA_Config *config = dma.getConfig();
+ // Only run once
dma.haltAndWaitChannelComplete( (MODDMA::CHANNELS)config->channelNum());
// Finish the DMA cycle by shutting down the channel.