.from: https://github.com/leroilion/mbed/blob/master/PlayMusic/Examples/PlayMusic/main.cpp
#include "mbed.h"#include "SDFileSystem.h"
SDFileSystem sd(11, 12, 13, 14, "sd");AnalogOut aout(18);
int main() { int ch; //first read byte int ch2; //second read byte int dat; //combined 16 bit word for DtoA
FILE *fp = fopen("/sd/QI2.wav", "r"); //open File to read if(fp == NULL) {error("Could not open file for write\n");}
while(!feof(fp)) { //Play the music until End Of File dat = 0; ch = fgetc(fp); //get first byte ch2 =fgetc(fp); //get second byte ch = ch << 8; //shift bits 8 places to left dat = ch2 | ch; //combine bits to single 16 bit int aout.write_u16((unsigned short)(dat)); //DtoA conversion wait_us(88); //set for 11k sample rate }
fclose(fp); //close the file
}
No comments:
Post a Comment