This software will read a .wav file from an SD card and display the header information contained within it. It is designed to work with the SD card on the mbed carrier which is part of the RS-EDP system.

Dependencies:   mbed SDFileSystem

Committer:
DavidGilesHitex
Date:
Fri Nov 19 09:54:23 2010 +0000
Revision:
0:35c1800c59e6

        

Who changed what in which revision?

UserRevisionLine numberNew contents of line
DavidGilesHitex 0:35c1800c59e6 1 /* SD-Card Utility Program for RS-EDP and RS-EDP mbed adapter module */
DavidGilesHitex 0:35c1800c59e6 2 /* ***************************************************************** */
DavidGilesHitex 0:35c1800c59e6 3
DavidGilesHitex 0:35c1800c59e6 4
DavidGilesHitex 0:35c1800c59e6 5
DavidGilesHitex 0:35c1800c59e6 6 #include "mbed.h"
DavidGilesHitex 0:35c1800c59e6 7
DavidGilesHitex 0:35c1800c59e6 8 #include "defines.h"
DavidGilesHitex 0:35c1800c59e6 9 #include "misra_types.h"
DavidGilesHitex 0:35c1800c59e6 10 #include "mbed_Port_Structure.h"
DavidGilesHitex 0:35c1800c59e6 11
DavidGilesHitex 0:35c1800c59e6 12 #include "SDFileSystem.h"
DavidGilesHitex 0:35c1800c59e6 13 #include "Wav_Support_File.h"
DavidGilesHitex 0:35c1800c59e6 14
DavidGilesHitex 0:35c1800c59e6 15
DavidGilesHitex 0:35c1800c59e6 16
DavidGilesHitex 0:35c1800c59e6 17
DavidGilesHitex 0:35c1800c59e6 18 /* Main Loop Here */
DavidGilesHitex 0:35c1800c59e6 19 int main(void)
DavidGilesHitex 0:35c1800c59e6 20 {
DavidGilesHitex 0:35c1800c59e6 21 FILE *wavfile;
DavidGilesHitex 0:35c1800c59e6 22 char file_name_with_root_and_path[30];
DavidGilesHitex 0:35c1800c59e6 23 char input_file_name[30];
DavidGilesHitex 0:35c1800c59e6 24 char *pointer1;
DavidGilesHitex 0:35c1800c59e6 25 char *pointer2;
DavidGilesHitex 0:35c1800c59e6 26 char n = 0;
DavidGilesHitex 0:35c1800c59e6 27 uint8_t wave_array[30];
DavidGilesHitex 0:35c1800c59e6 28
DavidGilesHitex 0:35c1800c59e6 29
DavidGilesHitex 0:35c1800c59e6 30
DavidGilesHitex 0:35c1800c59e6 31 for (n = 0; n < 30; n++) /* initialise arrays to zero */
DavidGilesHitex 0:35c1800c59e6 32 {
DavidGilesHitex 0:35c1800c59e6 33 file_name_with_root_and_path[n] = 0;
DavidGilesHitex 0:35c1800c59e6 34 input_file_name[n] = 0;
DavidGilesHitex 0:35c1800c59e6 35 }
DavidGilesHitex 0:35c1800c59e6 36
DavidGilesHitex 0:35c1800c59e6 37 setup_mbed_ports(); /* Setup the I/O Structure of the mbed module */
DavidGilesHitex 0:35c1800c59e6 38
DavidGilesHitex 0:35c1800c59e6 39 pc.printf("\n\n\n\n\n\n\n\rWelcome the the mbed SD-CARD Utility\n\r");
DavidGilesHitex 0:35c1800c59e6 40 pc.printf("Software Revision Number: %d\n\r\n", FIRMWARE_VERSION);
DavidGilesHitex 0:35c1800c59e6 41
DavidGilesHitex 0:35c1800c59e6 42 pc.printf("This application reads a .WAV file from the SC-CARD and\n\r");
DavidGilesHitex 0:35c1800c59e6 43 pc.printf("displays the header information contained within it\n\n\r");
DavidGilesHitex 0:35c1800c59e6 44
DavidGilesHitex 0:35c1800c59e6 45 User_Led1 = LED_OFF;
DavidGilesHitex 0:35c1800c59e6 46 User_Led2 = LED_OFF;
DavidGilesHitex 0:35c1800c59e6 47 User_Led3 = LED_OFF;
DavidGilesHitex 0:35c1800c59e6 48 User_Led4 = LED_OFF;
DavidGilesHitex 0:35c1800c59e6 49
DavidGilesHitex 0:35c1800c59e6 50 while(1)
DavidGilesHitex 0:35c1800c59e6 51 {
DavidGilesHitex 0:35c1800c59e6 52 pointer1 = file_name_with_root_and_path; /* set pointer1 to point at the complete name and path array */
DavidGilesHitex 0:35c1800c59e6 53 strcpy(pointer1, "/sd/"); /* Start to build the root, directory and file name of the file we want to examine */
DavidGilesHitex 0:35c1800c59e6 54
DavidGilesHitex 0:35c1800c59e6 55 pointer2 = input_file_name; /* set pointer2 to point at an empty string array to take the user input file name */
DavidGilesHitex 0:35c1800c59e6 56 pc.printf("Enter the file name you wish to check\n\r");
DavidGilesHitex 0:35c1800c59e6 57
DavidGilesHitex 0:35c1800c59e6 58 scanf("%s", pointer2); /* Get the file name into an array called 'input_file_name', pointed to by a pointer called pointer2 */
DavidGilesHitex 0:35c1800c59e6 59 strcat(pointer1, pointer2); /* Add on the entered file name to the root direcotry */
DavidGilesHitex 0:35c1800c59e6 60
DavidGilesHitex 0:35c1800c59e6 61 pc.printf("Opening the file: %s\n\r", file_name_with_root_and_path); /* Print the name including the root and path of the file */
DavidGilesHitex 0:35c1800c59e6 62 wavfile = fopen(file_name_with_root_and_path,"r"); /* Attempt to open the file for read only*/
DavidGilesHitex 0:35c1800c59e6 63
DavidGilesHitex 0:35c1800c59e6 64 if (wavfile == 0 )
DavidGilesHitex 0:35c1800c59e6 65 {
DavidGilesHitex 0:35c1800c59e6 66 /* Problems - can not open the file whos name we just inputed */
DavidGilesHitex 0:35c1800c59e6 67 pc.printf("Unable to open wav file '%s'\n\r", file_name_with_root_and_path);
DavidGilesHitex 0:35c1800c59e6 68 pc.printf("Please try again\n\r");
DavidGilesHitex 0:35c1800c59e6 69 }
DavidGilesHitex 0:35c1800c59e6 70 else{
DavidGilesHitex 0:35c1800c59e6 71 /* ok file is now open - lets print the header file */
DavidGilesHitex 0:35c1800c59e6 72 wave_file_check(wave_array, wavfile);
DavidGilesHitex 0:35c1800c59e6 73 }
DavidGilesHitex 0:35c1800c59e6 74
DavidGilesHitex 0:35c1800c59e6 75
DavidGilesHitex 0:35c1800c59e6 76 /* you can now access all of the .WAV header file information in a global structure called 'wave_file_info' */
DavidGilesHitex 0:35c1800c59e6 77 /* the structure provides you with all the necessary information to manage sample rates and timings etc */
DavidGilesHitex 0:35c1800c59e6 78 /* eg */
DavidGilesHitex 0:35c1800c59e6 79 /* sample_rate = wave_file_info.samples_per_second; */
DavidGilesHitex 0:35c1800c59e6 80 /* stereo_or_mono = wave_file_info.number_of_channels */
DavidGilesHitex 0:35c1800c59e6 81
DavidGilesHitex 0:35c1800c59e6 82 fclose(wavfile); /* Close the file */
DavidGilesHitex 0:35c1800c59e6 83 }
DavidGilesHitex 0:35c1800c59e6 84 }
DavidGilesHitex 0:35c1800c59e6 85