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: Capacitive_Touch_Sensor_MP3_Player
Fork of wave_player by
Revision 2:87acbc2d0023, committed 2016-11-21
- Comitter:
- maxmbrown
- Date:
- Mon Nov 21 21:13:54 2016 +0000
- Parent:
- 1:acc3e18e77ad
- Commit message:
- First Draft
Changed in this revision
| wave_player.cpp | Show annotated file Show diff for this revision Revisions of this file |
| wave_player.h | Show annotated file Show diff for this revision Revisions of this file |
--- a/wave_player.cpp Tue Jan 18 03:57:27 2011 +0000
+++ b/wave_player.cpp Mon Nov 21 21:13:54 2016 +0000
@@ -14,8 +14,7 @@
#include <mbed.h>
#include <stdio.h>
#include <wave_player.h>
-
-
+int g_volume = 0;
//-----------------------------------------------------------------------------
// constructor -- accepts an mbed pin to use for AnalogOut. Only p18 will work
wave_player::wave_player(AnalogOut *_dac)
@@ -44,7 +43,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, int *startStop, int *volume)
{
unsigned chunk_id,chunk_size,channel;
unsigned data,samp_int,i;
@@ -56,6 +55,7 @@
int *data_wptr;
FMT_STRUCT wav_format;
long slice,num_slices;
+
DAC_wptr=0;
DAC_rptr=0;
for (i=0;i<256;i+=2) {
@@ -134,6 +134,13 @@
printf("Oops -- not enough slices in the wave file\n");
exit(1);
}
+ //exit when user stops song
+ if (*startStop == 0){
+ break;
+ }
+ //pass volume to dac_out
+ g_volume = *volume;
+
data_sptr=(short *)slice_buf; // 16 bit samples
data_bptr=(unsigned char *)slice_buf; // 8 bit samples
data_wptr=(int *)slice_buf; // 32 bit samples
@@ -194,6 +201,7 @@
}
fread(&chunk_id,4,1,wavefile);
fread(&chunk_size,4,1,wavefile);
+
}
}
@@ -204,7 +212,8 @@
#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 - g_volume))>>4);
DAC_rptr=(DAC_rptr+1) & 0xff;
}
}
--- a/wave_player.h Tue Jan 18 03:57:27 2011 +0000 +++ b/wave_player.h Mon Nov 21 21:13:54 2016 +0000 @@ -43,7 +43,7 @@ * * @param wavefile A pointer to an opened wave file */ -void play(FILE *wavefile); +void play(FILE *wavefile, int *startStop, int *volume); /** Set the printf verbosity of the wave player. A nonzero verbosity level * will put wave_player in a mode where the complete contents of the wave @@ -57,6 +57,8 @@ * @param v the verbosity level */ void set_verbosity(int v); +int g_volume; +int startStop; private: void dac_out(void);
