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.
Fork of wave_player by
Diff: wave_player.cpp
- Revision:
- 2:3af9b368c30c
- Parent:
- 0:62c18ade9a60
diff -r acc3e18e77ad -r 3af9b368c30c wave_player.cpp
--- a/wave_player.cpp Tue Jan 18 03:57:27 2011 +0000
+++ b/wave_player.cpp Wed Mar 26 18:18:53 2014 +0000
@@ -23,6 +23,7 @@
wave_DAC=_dac;
wave_DAC->write_u16(32768); //DAC is 0-3.3V, so idles at ~1.6V
verbosity=0;
+ volume=0;
}
//-----------------------------------------------------------------------------
@@ -37,6 +38,11 @@
verbosity=v;
}
+
+int * wave_player:: getVolume()
+{
+ return &volume;
+}
//-----------------------------------------------------------------------------
// player function. Takes a pointer to an opened wave file. The file needs
// to be stored in a filesystem with enough bandwidth to feed the wave data.
@@ -44,7 +50,7 @@
// SDcard filesystem can be hotrodded by increasing the SPI frequency it uses
// internally.
//-----------------------------------------------------------------------------
-void wave_player::play(FILE *wavefile)
+void wave_player::play(FILE *wavefile, bool *ptr)
{
unsigned chunk_id,chunk_size,channel;
unsigned data,samp_int,i;
@@ -129,6 +135,8 @@
// while 16 and 32 bit wave files use signed data
//
for (slice=0;slice<num_slices;slice+=1) {
+ if(*ptr==0)
+ break;
fread(slice_buf,wav_format.block_align,1,wavefile);
if (feof(wavefile)) {
printf("Oops -- not enough slices in the wave file\n");
@@ -204,7 +212,7 @@
#ifdef VERBOSE
printf("ISR rdptr %d got %u\n",DAC_rptr,DAC_fifo[DAC_rptr]);
#endif
- wave_DAC->write_u16(DAC_fifo[DAC_rptr]);
+ wave_DAC->write_u16(DAC_fifo[DAC_rptr]*(16-volume)>>4);
DAC_rptr=(DAC_rptr+1) & 0xff;
}
}
