by Rob Toulson and Tim Wilmshurst from textbook "Fast and Effective Embedded Systems Design: Applying the ARM mbed"

Dependencies:   mbed

Committer:
robt
Date:
Sun Jun 16 15:19:38 2013 +0000
Revision:
0:ca6a20d158df
by Rob Toulson and Tim Wilmshurst from textbook "Fast and Effective Embedded Systems Design: Applying the ARM mbed"

Who changed what in which revision?

UserRevisionLine numberNew contents of line
robt 0:ca6a20d158df 1 /* Program Example 11.4 Wave file header reader
robt 0:ca6a20d158df 2 */
robt 0:ca6a20d158df 3 #include "mbed.h"
robt 0:ca6a20d158df 4 #include "SDFileSystem.h"
robt 0:ca6a20d158df 5
robt 0:ca6a20d158df 6 SDFileSystem sd(p5, p6, p7, p8, "sd");
robt 0:ca6a20d158df 7 Serial pc(USBTX,USBRX); // set up terminal link
robt 0:ca6a20d158df 8 char c1, c2, c3, c4; // chars for reading data in
robt 0:ca6a20d158df 9 int AudioFormat, NumChannels, SampleRate, BitsPerSample ;
robt 0:ca6a20d158df 10
robt 0:ca6a20d158df 11 int main() {
robt 0:ca6a20d158df 12 pc.printf("\n\rWave file header reader\n\r");
robt 0:ca6a20d158df 13 FILE *fp = fopen("/sd/sinewave.wav", "rb");
robt 0:ca6a20d158df 14
robt 0:ca6a20d158df 15 fseek(fp, 20, SEEK_SET); // set pointer to byte 20
robt 0:ca6a20d158df 16
robt 0:ca6a20d158df 17 fread(&AudioFormat, 2, 1, fp); // check file is PCM
robt 0:ca6a20d158df 18 if (AudioFormat==0x01) {
robt 0:ca6a20d158df 19 pc.printf("Wav file is PCM data\n\r");
robt 0:ca6a20d158df 20 }
robt 0:ca6a20d158df 21 else {
robt 0:ca6a20d158df 22 pc.printf("Wav file is not PCM data\n\r");
robt 0:ca6a20d158df 23 }
robt 0:ca6a20d158df 24
robt 0:ca6a20d158df 25 fread(&NumChannels, 2, 1, fp); // find number of channels
robt 0:ca6a20d158df 26 pc.printf("Number of channels: %d\n\r",NumChannels);
robt 0:ca6a20d158df 27
robt 0:ca6a20d158df 28 fread(&SampleRate, 4, 1, fp); // find sample rate
robt 0:ca6a20d158df 29 pc.printf("Sample rate: %d\n\r",SampleRate);
robt 0:ca6a20d158df 30
robt 0:ca6a20d158df 31 fread(&BitsPerSample, 2, 1, fp); // find resolution
robt 0:ca6a20d158df 32 pc.printf("Bits per sample: %d\n\r",BitsPerSample);
robt 0:ca6a20d158df 33
robt 0:ca6a20d158df 34 fclose(fp);
robt 0:ca6a20d158df 35 }
robt 0:ca6a20d158df 36