old demo that i want to try in mbed studio
Dependencies: mbed SDFileSystem_Copy_of_mbed_version I2S
Revision 0:e89d7a0bfa3b, committed 2019-02-16
- Comitter:
- roryhand
- Date:
- Sat Feb 16 17:19:43 2019 +0000
- Child:
- 1:aac37edee302
- Commit message:
- Doesn't work at present, however it does contain some rudimentary code for passing in the file names into a string array (too difficult compared to matlab)
Changed in this revision
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/I2S.lib Sat Feb 16 17:19:43 2019 +0000 @@ -0,0 +1,1 @@ +http://os.mbed.com/users/p07gbar/code/I2S/#9dd9537d8ab6
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/NotchingDemo.cpp Sat Feb 16 17:19:43 2019 +0000
@@ -0,0 +1,687 @@
+
+// 24/03/2018 update - I appear to be able to address the device and write something, as I am getting an ACK returned from the i2c write() function.
+//however if i use the write function with 4 arguments (as opposed to just 1 argument) then it doesnt work
+//only works with the 1 argument version!!!
+
+
+//THIS VERSION WORKED, CHANGED SOME THINGS, THEN CHANGED THEM BACK. NOW IT NO LONGER WORKS!!!!
+#include "mbed.h"
+#include "math.h"
+#include "I2S.h"
+#include "SDFileSystem.h"
+#include "wm8731_Config_setup.h"
+#include "WOLFSON_config_consts.h"
+#include <stdlib.h>
+#include <vector>
+#include <string>
+#define sample_freq 11025
+DigitalOut myled(LED1);
+DigitalOut led2(LED2);
+DigitalOut led3(LED3);
+DigitalIn NotchUp(p16);
+InterruptIn Horn(p16);
+Ticker sampletick;
+Ticker BellTick;
+Ticker EdTick;
+Ticker TickFadeOut;
+Timer t;
+Timer t2;
+
+Serial pc(USBTX, USBRX); // tx, rx //FOR DEBUGGING PROGRAM USING GNU SCREEN
+DigitalOut cs(p8);
+I2S i2s(I2S_TRANSMIT, p5, p6, p7);
+SDFileSystem sd(p11, p12, p13, p8, "sd"); // the new pinout that i am using
+
+
+/*struct A {
+ int data;
+ B b;
+};*/
+
+
+
+
+class classFade
+{
+ public:
+
+ float powerval;
+ float FadeIteration;
+ float DecayFactor;
+ float Denom;
+ float FadeCoeff;
+ float Natural_Exp;
+ int LengthSecs;
+ int Length;
+
+ //member Functions
+ float FadeOut(void)
+ {
+ powerval = -FadeIteration/Denom;
+ if (FadeIteration >=Length)
+ {
+ FadeCoeff = 0;
+
+ }
+ else
+ {
+ FadeCoeff = (Length - FadeIteration)/Length;
+ }
+ FadeIteration = FadeIteration + 1;
+ return FadeCoeff;
+
+ }
+ float FadeIn(void)
+ {
+ powerval = FadeIteration/Denom;
+ if (FadeIteration >=Length)
+ {
+ FadeCoeff = 1;
+
+ }
+ else
+ {
+ FadeCoeff = FadeIteration/Length;
+ }
+
+ FadeIteration = FadeIteration + 1;
+ return FadeCoeff;
+
+ }
+};
+
+classFade IdleFadeOut;
+classFade N2FadeIn;
+
+
+
+
+
+typedef struct uFMT_STRUCT{
+ short comp_code;
+ short num_channels;
+ unsigned sample_rate;
+ unsigned avg_Bps;
+ short block_align;
+ short sig_bps;
+} FMT_STRUCT;
+
+typedef struct uDATA_STRUCT {
+ unsigned subchunk2_ID;
+ unsigned subchunk2_size;
+ char * data_buf;
+}DATA_STRUCT;
+
+typedef struct uWAV_FILE_STRUCT{
+ FILE *WavFile;
+ int id_number;
+ char *slice_buf;
+ int num_slices;
+ FMT_STRUCT FileFormat;
+ DATA_STRUCT FileData;
+} WAV_FILE_STRUCT;
+
+/*typedef struct uWAV_FILE_STRUCT{
+ FILE* WavFile;
+
+
+}WAV_FILE_STRUCT;*/
+class classSoundFile
+{
+ WAV_FILE_STRUCT WavFile;
+ string filename[30];
+
+ WAV_FILE_STRUCT LoadFileStream()
+ {
+ //Declare RootFolder and the directory for the appropriate file.
+ //How we index into filename[] from the outside of this class is another
+ //issue...
+ string RootFolder = "/sd/mydir/SoundDecoder/";
+ string Directory = RootFolder + filename[0];
+ printf("%s\n\r",Directory);
+ const char* DirectoryChar = Directory.c_str();
+ WavFile.WavFile = fopen(DirectoryChar,"rb");
+ fseek(WavFile,20,SEEK_SET);
+ fread(&FileInfo.FileFormat,sizeof(FileInfo.FileFormat),1,wav_file);
+ printf("wav_format.sample_rate: %d\n\r",FileInfo.FileFormat.sample_rate);
+ fread(&FileInfo.FileData,sizeof(FileInfo.FileData),1,wav_file);
+ printf("wav_data.subchunk2_size: %d\n\r",FileInfo.FileData.subchunk2_size);
+ FileInfo.slice_buf = ( char *)malloc(FileInfo.FileFormat.block_align);
+ fread(FileInfo.slice_buf,FileInfo.FileFormat.block_align,1,wav_file); //This isnt actually required, its just a test
+ FileInfo.num_slices = FileInfo.FileData.subchunk2_size/FileInfo.FileFormat.block_align;
+ printf("Number of Slices: %d\n\r",FileInfo.num_slices);
+ return FileInfo;
+ }
+
+};
+
+
+int i = 0;
+int h = 0;
+short bufflen = 1;
+int buffer[1];
+int AudioFormat, NumChannels, SampleRate, BitsPerSample ;
+char *slice_buf;
+short *data_sptr;
+short *data_sptr_horn;
+short *data_sptr_IdleN2;
+short * data_sptr_bell;
+short * data_sptr_N2;
+short * data_sptr_Flange;
+unsigned char *data_bptr;
+int *data_wptr;
+unsigned channel;
+long slice, num_slices;
+int verbosity = 0;
+int verbosity2 = 0;
+int verbosity3 = 0;
+int verbosity4 = 0;
+int verbosity5 = 0;
+int interrupt_condition = 1;
+int sampling_freq = 11025;
+const int BufferLen = 2000;
+short Buffer1[BufferLen];
+short Buffer2[BufferLen];
+short place_hold1 = 0;
+short place_hold2 = 0;
+
+volatile int flag1 = 1;
+volatile int flag2 = 0;
+volatile int flag3 = 1;
+volatile int flag4 = 0;
+int FLAGBUFF1 = 0;
+int FLAGBUFF2 = 0;
+int BellFlag = 0;
+int BellFlag2 = 0;
+int FadeFlag = 0;
+int DualEngineFlag = 0;
+
+
+short value[1];
+FILE *HornWav;
+FILE *edsheeran_wav;
+FILE *Startup_wav;
+FILE *IdleN2Wav;
+FILE *N2Wav;
+FILE *BellWav;
+FILE *FlangeWav;
+//long long slice_value;
+int slice_value[1];
+
+
+WAV_FILE_STRUCT WavInfo_Horn;
+WAV_FILE_STRUCT WavInfo_IdleN2;
+WAV_FILE_STRUCT WavInfo_N2;
+WAV_FILE_STRUCT WavInfo_Bell;
+WAV_FILE_STRUCT WavInfo_Flange;
+Ticker flipper;
+char * slice_buf_bell;
+char * slice_buf_ed;
+char * slice_buf_startup;
+char * slice_buf_N2;
+//test
+//short *data_sptr_bell = 0;
+short *data_sptr_ed = 0;
+short *data_sptr_startup = 0;
+void flip() {
+ led2 = !led2;
+}
+
+
+void isr()
+{
+ if(flag1 == 0)
+ {
+ value[0] = Buffer1[place_hold1]>>4;
+ i2s.write(value,1);//Send next PWM value to amp
+ place_hold1 = place_hold1 + 1;
+ if( (place_hold1 >= BufferLen))
+ {
+ led2 = !led2;
+ place_hold1 = 0;
+ place_hold2 = 0;
+ flag1 = 1;
+ flag2 = 0;
+ }
+ }
+ else if(flag2 == 0)
+ {
+ value[0] = Buffer2[place_hold2]>>4;
+ i2s.write(value,1);//Send next PWM value to amp
+ place_hold2 = place_hold2 + 1;
+ if( (place_hold2 >= BufferLen) )
+ {
+ led2 = !led2;
+ place_hold1 = 0;
+ place_hold2 = 0;
+ flag1 = 0;
+ flag2 = 1;
+ FLAGBUFF2 = 0;
+ }
+ }
+}
+
+void horn_sound()
+{
+ BellFlag = 1;
+ fseek(HornWav,44,SEEK_SET);
+ fseek(BellWav,44,SEEK_SET);
+ fseek(FlangeWav,44,SEEK_SET);
+ fseek(N2Wav,44,SEEK_SET);
+}
+
+
+void N2SoundIsr()
+{
+ DualEngineFlag = 1;
+ fseek(N2Wav,44,SEEK_SET);
+ fseek(HornWav,44,SEEK_SET);
+ //TickFadeOut.detach(&N2SoundIsr);//,5.0);
+}
+
+
+void FadeOutIsr()
+{
+ FadeFlag = 1;
+ fseek(IdleN2Wav,44,SEEK_SET);
+ fseek(N2Wav,44,SEEK_SET);
+ fseek(HornWav,44,SEEK_SET);
+ fseek(FlangeWav,44,SEEK_SET);
+
+}
+
+
+/*void NotchUpIsr()
+{
+ if(1 <= Notch <= 8)
+ {
+ Notch = Notch + 1;
+ NotchDirection = 1;
+ }
+}
+
+void NotchDownIsr()
+{
+ if(1 <= Notch <= 8)
+ {
+ Notch = Notch - 1;
+ NotchDirection = 0;
+ }
+}*/
+
+
+
+
+//function prototypes
+WAV_FILE_STRUCT ReadFileInfo(WAV_FILE_STRUCT FileInfo, FILE * wav_file);
+classFade FadeDataInitialise(classFade FadeData);
+float FadeOut(void);
+void Play_WaveFile(FILE * my_wav, WAV_FILE_STRUCT FileInfo);
+void Play_WaveFileLoop(FILE * my_wav, WAV_FILE_STRUCT FileInfo);
+int main() {
+ //LocalFileSystem local("local");
+ NotchUp.mode(PullUp);
+
+
+ //classSoundFile Sounds[4];
+ /* for(int iii = 0; iii < 3; iii ++)
+ {
+ Sounds[iii].setX(iii);
+ }*/
+ WAV_FILE_STRUCT WavInfo_Startup;
+ WAV_FILE_STRUCT WavInfo_Idle;
+
+ pc.printf("Beginning of program\n");
+ FILE *StartupWav;
+ FILE *IdleWav;
+
+ char * RootFolder = "/sd/mydir/SoundDecoder/";]]
+ DIR *dir;
+ dirent *ent;
+ int iterator = 0;
+ string filename[10];
+ if ((dir = opendir ("/sd/mydir/SoundDecoder")) != NULL)
+ {
+
+ // print all the files and directories within directory
+ while ((ent = readdir (dir)) != NULL)
+ {
+ printf("%s\r\n",string(ent->d_name));
+ filename[iterator] = string(ent->d_name);
+
+ //printf("%s\r\n",filename[iterator]);
+ iterator = iterator + 1;
+ //printf("%s\r\n", ent->d_name);
+ //filenames.push_back(string(dirp->d_name));
+ }
+ closedir (dir);
+ }
+ for(iterator = 0;iterator < 10; iterator ++)
+ {
+ printf("All the Files: %s\r\n",filename[iterator]);
+ //printf("All the Files: %s\r\n",ent[iterator]);
+ }
+ //strcat(RootFolder,qdfilename[0]);
+ string folder = RootFolder + filename[9];
+ printf("%s\n\r",folder);
+
+
+ //printf("Files and Folders contained here: %d\n\r",readdir(dp));
+
+
+ //StartupWav = fopen("/sd/mydir/Startup.wav","rb");
+ const char* folder2 = folder.c_str();
+
+
+ classSoundFile Sounds[27];
+ for(iii = 0; iii < 26; iii++)
+ {
+ filename[iii];
+ Sounds[iii].LoadFileStream();
+ }
+
+
+ StartupWav = fopen(folder2,"rb");
+ //IdleWav = fopen("/sd/mydir/Idle_11k_quiet.wav","rb");
+ IdleWav = fopen("/sd/mydir/645Engine/N2_11k_minus10dB.wav","rb");
+ IdleN2Wav = fopen("/sd/mydir/645Engine/N2N3_11k_minus10dB.wav","rb");
+ HornWav = fopen("/sd/mydir/645Engine/K3H_1_A_short_quiet.wav","rb");
+ //HornWav = fopen("/sd/mydir/645Engine/N2_11k_minus10dB.wav","rb");
+ N2Wav = fopen("/sd/mydir/645Engine/N3_11k_minus11dB.wav","rb");
+ BellWav = fopen("/sd/mydir/645Engine/EMD_BRONZE_BELL_1_11k_minus10dB.wav","rb");
+ FlangeWav = fopen("/sd/mydir/645Engine/EX_FlangeJoint1_11k_minus12dB.wav","rb");
+
+
+ WavInfo_Startup = ReadFileInfo(WavInfo_Startup, StartupWav);
+ WavInfo_Idle = ReadFileInfo(WavInfo_Idle, IdleWav);
+ WavInfo_Horn = ReadFileInfo(WavInfo_Horn, HornWav);
+ WavInfo_IdleN2 = ReadFileInfo(WavInfo_IdleN2, IdleN2Wav);
+ WavInfo_N2 = ReadFileInfo(WavInfo_N2, N2Wav);
+ WavInfo_Bell = ReadFileInfo(WavInfo_Bell, BellWav);
+ WavInfo_Flange = ReadFileInfo(WavInfo_Flange, FlangeWav);
+ //Populate our class instances with some data (is there an implicit way to do this?)
+ N2FadeIn.LengthSecs = 4;
+ IdleFadeOut.LengthSecs = 2;
+ N2FadeIn = FadeDataInitialise(N2FadeIn);
+ IdleFadeOut = FadeDataInitialise(IdleFadeOut);
+
+
+ //Set up the wolfson Audio Codec board
+ wm8731_Config_setup();
+ //i2s audio data transfer code??
+ i2s.stereomono(I2S_STEREO);
+ i2s.masterslave(I2S_MASTER);
+ led3 = 1;
+ led2 = 1;
+ sampletick.attach(&isr,1.0/sampling_freq); //1/16000
+ //TickFadeOut.attach(&FadeOutIsr,10.0);
+ i2s.start();
+ Horn.rise(&FadeOutIsr);
+ slice = 0;
+ fseek(IdleN2Wav,44,SEEK_SET);
+ //Play_WaveFile(IdleN2Wav,WavInfo_IdleN2);
+ //Play_WaveFile(N2Wav,WavInfo_N2);
+ t.reset();
+ t.start();
+ N2FadeIn.FadeCoeff = N2FadeIn.FadeOut();
+ t.stop();
+ printf("Time to Calcualte Fade Coeff: %d\n\r",t.read_us());
+ t.reset();
+
+ fseek(IdleN2Wav,44,SEEK_SET);
+ t.start();
+ fread(WavInfo_IdleN2.slice_buf,WavInfo_IdleN2.FileFormat.block_align,1,IdleN2Wav);
+ data_sptr_IdleN2 = (short *)WavInfo_IdleN2.slice_buf;
+ t.stop();
+ printf("Time to Read in a slice: %dus\n\r",t.read_us());
+ t.reset();
+
+ printf("point to start sound: %d\n\r",((WavInfo_IdleN2.FileData.subchunk2_size) - N2FadeIn.Length));
+ printf("Size of Data: %d\n\r",WavInfo_IdleN2.FileData.subchunk2_size);
+
+ fseek(FlangeWav,44,SEEK_SET);
+ Play_WaveFile(StartupWav,WavInfo_Startup);
+ fseek(IdleN2Wav,44,SEEK_SET);//reset for use in the Loop code
+ slice = 0;
+ fseek(IdleWav,44,SEEK_SET);
+ Play_WaveFileLoop(IdleWav, WavInfo_Idle);
+ i2s.stop();
+
+}
+
+
+
+
+WAV_FILE_STRUCT ReadFileInfo(WAV_FILE_STRUCT FileInfo, FILE * wav_file)
+{
+ fseek(wav_file,20,SEEK_SET);
+ fread(&FileInfo.FileFormat,sizeof(FileInfo.FileFormat),1,wav_file);
+ printf("wav_format.sample_rate: %d\n\r",FileInfo.FileFormat.sample_rate);
+
+ fread(&FileInfo.FileData,sizeof(FileInfo.FileData),1,wav_file);
+ printf("wav_data.subchunk2_size: %d\n\r",FileInfo.FileData.subchunk2_size);
+ FileInfo.slice_buf = ( char *)malloc(FileInfo.FileFormat.block_align);
+ fread(FileInfo.slice_buf,FileInfo.FileFormat.block_align,1,wav_file); //This isnt actually required, its just a test
+ FileInfo.num_slices = FileInfo.FileData.subchunk2_size/FileInfo.FileFormat.block_align;
+ printf("Number of Slices: %d\n\r",FileInfo.num_slices);
+ return FileInfo;
+}
+classFade FadeDataInitialise(classFade FadeData)
+{
+ FadeData.DecayFactor = 1.3;
+ FadeData.FadeIteration = 1;
+ //FadeData.Denom = 11025*FadeData.DecayFactor;
+ FadeData.Denom = 11025*FadeData.DecayFactor;
+ FadeData.Natural_Exp = 2.7183;
+ FadeData.Length = 11025*FadeData.LengthSecs;
+ //FadeData.Natural_Exp = 2.7;
+ return FadeData;
+}
+
+//Playing Files Code
+/*float FadeIn(void)
+{
+ powervalFadeIn = FadeIterationIn/denom;
+ FadeCoeffFadeIn
+
+
+}*/
+/*float FadeOut(void)
+{
+ powerval = -FadeIteration/denom;
+ FadeCoeff = pow(natural_exp,powerval);
+ FadeIteration = FadeIteration + 1;
+ return FadeCoeff;
+
+}*/
+
+
+void Play_WaveFile(FILE * my_wav, WAV_FILE_STRUCT FileInfo)
+{
+ while(slice<FileInfo.num_slices)
+ {
+ fread(FileInfo.slice_buf,FileInfo.FileFormat.block_align,1,my_wav);
+ data_sptr=(short *)FileInfo.slice_buf; // 16 bit samples
+ for (channel=0;channel<FileInfo.FileFormat.num_channels;channel++)
+ {
+ if(flag1 == 1)
+ {
+ Buffer1[place_hold1] = data_sptr[channel];
+ place_hold1 = place_hold1 + 1;
+ if(place_hold1 >= BufferLen)
+ {
+ while(1)
+ {
+ if(flag1 == 0)
+ {
+
+ break;
+ }
+
+ }
+ }
+
+ }
+ else if(flag2 == 1)
+ {
+ Buffer2[place_hold2] = data_sptr[channel];
+ place_hold2 = place_hold2 + 1;
+ if(place_hold2 >= BufferLen)
+ {
+
+ while(1)
+ {
+ if(flag2 == 0)
+ {
+
+ break;
+ }
+ }
+ }
+ }
+
+ }
+ slice = slice + 1;
+ }
+}
+
+
+
+
+
+
+void Play_WaveFileLoop(FILE * my_wav, WAV_FILE_STRUCT FileInfo)//(classSoundFile Sounds)
+{
+ while(1)//might have to change this to a while(1) loop?
+ {
+ //New format!! This should be (roughly) the way that this is done, with the new structures and classes
+ ////fread(Sound[Notch].FileData.slice_buf,Sound[Notch].FileFormat.block_align,1,Sound[notch].WavFile);
+ //data_sptr=(short *)Sound[Notch].FileInfo.slice_buf;
+
+ if(BellFlag)
+ {
+ if(feof(BellWav))
+ {
+ if(feof(HornWav))
+ {
+
+ }
+ else
+ {
+ fseek(BellWav,44,SEEK_SET);
+ }
+ }
+ fread(WavInfo_Horn.slice_buf,WavInfo_Horn.FileFormat.block_align,1,HornWav);
+ fread(WavInfo_Bell.slice_buf,WavInfo_Bell.FileFormat.block_align,1,BellWav);
+ fread(WavInfo_Flange.slice_buf,WavInfo_Flange.FileFormat.block_align,1,FlangeWav);
+ fread(WavInfo_N2.slice_buf,WavInfo_N2.FileFormat.block_align,1,N2Wav);
+ }
+ if( slice == (FileInfo.num_slices-1) )
+ {
+ slice = 0;
+ fseek(my_wav,44,SEEK_SET);
+ }
+
+ fread(FileInfo.slice_buf,FileInfo.FileFormat.block_align,1,my_wav);
+ data_sptr=(short *)FileInfo.slice_buf; // 16 bit samples
+ if(DualEngineFlag)
+ {
+ fread(WavInfo_N2.slice_buf,WavInfo_N2.FileFormat.block_align,1,N2Wav);
+ data_sptr_N2 = (short *)WavInfo_N2.slice_buf;
+ *data_sptr = *data_sptr + *data_sptr_N2;
+ }
+
+
+ if(FadeFlag)
+ {
+ if(feof(N2Wav))
+ {
+ fseek(N2Wav,44,SEEK_SET);
+ }
+ IdleFadeOut.FadeCoeff = IdleFadeOut.FadeOut();
+ data_sptr_IdleN2 = (short *)WavInfo_IdleN2.slice_buf;
+ fread(WavInfo_IdleN2.slice_buf,WavInfo_IdleN2.FileFormat.block_align,1,IdleN2Wav);
+ if( ((WavInfo_IdleN2.FileData.subchunk2_size) - N2FadeIn.Length - 2*11025) <= (ftell(IdleN2Wav) + 44))
+ //if( (WavInfo_IdleN2.FileData.subchunk2_size)/8 <=ftell(IdleN2Wav) )
+ {
+
+ N2FadeIn.FadeCoeff = N2FadeIn.FadeIn();
+ fread(WavInfo_N2.slice_buf,WavInfo_N2.FileFormat.block_align,1,N2Wav);
+ data_sptr_N2 = (short *)WavInfo_N2.slice_buf;
+
+ if( (ftell(IdleN2Wav) + 44) >= WavInfo_IdleN2.FileData.subchunk2_size )
+ {
+ *data_sptr = *data_sptr_N2*N2FadeIn.FadeCoeff;
+ }
+ else
+ {
+ *data_sptr = *data_sptr*IdleFadeOut.FadeCoeff + *data_sptr_IdleN2 + *data_sptr_N2*N2FadeIn.FadeCoeff;// + *data_sptr_N2;
+ }
+
+ }
+ else
+ {
+ *data_sptr = *data_sptr*IdleFadeOut.FadeCoeff + *data_sptr_IdleN2;
+ }
+
+ }
+ if(BellFlag)
+ {
+ data_sptr_horn = (short *)WavInfo_Horn.slice_buf;
+ data_sptr_bell = (short *)WavInfo_Bell.slice_buf;
+ data_sptr_Flange = (short *)WavInfo_Flange.slice_buf;
+ data_sptr_N2 = (short *)WavInfo_N2.slice_buf;
+ *data_sptr = *data_sptr + *data_sptr_horn + *data_sptr_bell + *data_sptr_Flange + *data_sptr_N2;//use dereference operator
+ //*data_sptr = *data_sptr + *data_sptr_horn;
+ }
+ for (channel=0;channel<FileInfo.FileFormat.num_channels;channel++)
+ {
+ switch (FileInfo.FileFormat.sig_bps) {
+ case 16:
+ if(flag1 == 1)
+ {
+ Buffer1[place_hold1] = data_sptr[channel];
+ place_hold1 = place_hold1 + 1;
+ if(place_hold1 >= BufferLen)
+ {
+ while(1)
+ {
+ if(flag1 == 0)
+ {
+ break;
+ }//if(flag1 == 0)
+
+
+ }//while(1)
+ }//if(place_hold1 > = BufferLen)
+
+ }
+ else if(flag2 == 1)
+ {
+ Buffer2[place_hold2] = data_sptr[channel];
+ place_hold2 = place_hold2 + 1;
+ if(place_hold2 >= BufferLen)
+ {
+ while(1)
+ {
+
+ if(flag2 == 0)
+ {
+ break;
+ }
+ }
+ }
+
+ }
+ }
+ }
+ slice = slice + 1;
+ }
+}
+
+
+
+
+
+
+
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/SDFileSystem.lib Sat Feb 16 17:19:43 2019 +0000 @@ -0,0 +1,1 @@ +https://os.mbed.com/users/roryhand/code/SDFileSystem_Copy_of_mbed_version/#7ba9d50020de
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/WOLFSON_config_consts.h Sat Feb 16 17:19:43 2019 +0000 @@ -0,0 +1,49 @@ +#ifndef WOLFSON_config_consts +#define WOLFSON_config_consts +// WM8731 Drivers - from MIKROE LIBSTOCK: https://libstock.mikroe.com/projects/view/304/wm8731-example +/************************************************************************************************** +* WM8731 sound chip register addresses +**************************************************************************************************/ +const int WM8731_ADDRESS = 0x34; // WM8731 chip address on I2C bus +/************************************************************************************************** +* WM8731 sound chip register addresses +**************************************************************************************************/ +const int WM8731_REG_LLINE_IN = 0x00; // Left Channel Line Input Volume Control +const int WM8731_REG_RLINE_IN = 0x01; // Right Channel Line Input Volume Control +const int WM8731_REG_LHPHONE_OUT = 0x02; // Left Channel Headphone Output Volume Control +const int WM8731_REG_RHPHONE_OUT = 0x03; // Right Channel Headphone Output Volume Control +const int WM8731_REG_ANALOG_PATH = 0x04; // Analog Audio Path Control +const int WM8731_REG_DIGITAL_PATH = 0x05; // Digital Audio Path Control +const int WM8731_REG_PDOWN_CTRL = 0x06; // Power Down Control Register +const int WM8731_REG_DIGITAL_IF = 0x07; // Digital Audio Interface Format +const int WM8731_REG_SAMPLING_CTRL = 0x08; // Sampling Control Register +const int WM8731_REG_ACTIVE_CTRL = 0x09; // Active Control +const int WM8731_REG_RESET = 0x0F; // Reset register + +/************************************************************************************************** +* WM8731 sound chip constants (for default set up) +**************************************************************************************************/ +const int _WM8731_LEFT_LINEIN = 0X0180; // MIC SETTINGS: ENABLE MUTE, ENABLE SIMULTANEOUS LOAD TO LEFT AND RIGHT CHANNELS +const int _WM8731_RIGHT_LINEIN = 0X0180; // MIC SETTINGS: ENABLE MUTE, ENABLE SIMULTANEOUS LOAD TO LEFT AND RIGHT CHANNELS +const int _WM8731_LEFT_HP = 0X00F9; // HEADPHONE SETTINGS : 0DB +const int _WM8731_RIGHT_HP = 0X00F9; // HEADPHONE SETTINGS : 0DB +//const int _WM8731_LEFT_HP = 0X00E1; // HEADPHONE SETTINGS : -6?DB +//const int _WM8731_RIGHT_HP = 0X00E1; // HEADPHONE SETTINGS : -6?DB +const int _WM8731_ANALOGAUDIO = 0XD0; // DAC SELECT +const int _WM8731_DIGITALAUDIO = 0X00; //11011 +const int _WM8731_POWER = 0X00; // DISABLE POWER DOWN +const int _WM8731_DAIF = 0X02; // ENABLE SLAVE MODE, 16BIT DATA AND I2S DATA +//const int _WM8731_SAMPLING = 0x00; // 48000HZ,12.288MHz oscillator. +//const int _WM8731_SAMPLING = 0X2E; // 8000HZ,12.288MHz oscillator. +//const int _WM8731_SAMPLING = 0X0C; +//const int _WM8731_SAMPLING = 0X18; // 8000HZ,12.288MHz oscillator. +const int _WM8731_SAMPLING = 0x18; //32000HZ, 12.288MHz oscillator +const int _WM8731_ACTIVATE = 0X01; // MODULE IS ON +const int _WM8731_DEACTIVATE = 0X00; // MODULE IS OFF +const int _WM8731_RESET = 0X00; // RESET VALUE + +//do I need to delete these highlighted ones? (ie unused ones?) I think maybe theyre duplicates +/**************************************************************************************************/ + + +#endif \ No newline at end of file
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/mbed.bld Sat Feb 16 17:19:43 2019 +0000 @@ -0,0 +1,1 @@ +https://os.mbed.com/users/mbed_official/code/mbed/builds/a7c7b631e539 \ No newline at end of file
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/wm8731_Config_setup.cpp Sat Feb 16 17:19:43 2019 +0000
@@ -0,0 +1,144 @@
+#include "WOLFSON_config_consts.h"
+#include "mbed.h"
+I2C i2c(p9, p10);
+
+void wm8731_Config_setup(void)
+{
+ i2c.frequency(100000);
+ int addr = WM8731_REG_RESET;
+ int cmd = _WM8731_RESET;
+ addr = addr << 1;
+ addr = addr|((cmd >> 8 ))& 0x01;//mess around with order of operations
+ cmd = cmd&0xFF;
+ i2c.start();
+ i2c.write( WM8731_ADDRESS );
+ i2c.write( addr );
+ i2c.write( cmd );
+ i2c.stop();
+
+ addr = WM8731_REG_LLINE_IN;
+ cmd = _WM8731_LEFT_LINEIN;
+ addr = addr << 1;
+ addr = addr|((cmd >> 8 )) & 0x01;
+ cmd = cmd&0xFF;
+ i2c.start();
+ i2c.write( WM8731_ADDRESS );//take Fergus' suggestion and declare these to known values EARLIER in program
+ i2c.write( addr );
+ i2c.write( cmd );
+ i2c.stop();
+
+
+ addr = WM8731_REG_RLINE_IN;
+ cmd = _WM8731_RIGHT_LINEIN;
+ addr = addr << 1;
+ addr = addr|((cmd >> 8 )) & 0x01;
+ cmd = cmd&0xFF;
+ i2c.start();
+ i2c.write( WM8731_ADDRESS );//take Fergus' suggestion and declare these to known values EARLIER in program
+ i2c.write( addr );
+ i2c.write( cmd );
+ i2c.stop();
+
+
+ //4
+ addr = WM8731_REG_LHPHONE_OUT;
+ cmd = _WM8731_LEFT_HP;
+ addr = addr << 1;
+ addr = addr|((cmd >> 8 )) & 0x01;
+ cmd = cmd&0xFF;
+ i2c.start();
+ i2c.write( WM8731_ADDRESS );
+ i2c.write( addr );//WM8731_REG_LHPHONE_OUT, _WM8731_LEFT_HP
+ i2c.write(cmd);
+ i2c.stop();
+
+ //5
+ addr = WM8731_REG_RHPHONE_OUT;
+ cmd = _WM8731_RIGHT_HP;
+ addr = addr << 1;
+ addr = addr|((cmd >> 8 )) & 0x01;
+ cmd = cmd&0xFF;
+ i2c.start();
+ i2c.write( WM8731_ADDRESS );//WM8731_REG_RHPHONE_OUT, _WM8731_RIGHT_HP
+ i2c.write( addr );
+ i2c.write( cmd );
+ i2c.stop();
+
+
+ //6
+ addr = WM8731_REG_ANALOG_PATH;
+ cmd = _WM8731_ANALOGAUDIO;
+ addr = addr << 1;
+ addr = addr|((cmd >> 8 )) & 0x01;
+ cmd = cmd&0xFF;
+ i2c.start();
+ i2c.write( WM8731_ADDRESS );//WM8731_REG_ANALOG_PATH, _WM8731_ANALOGAUDIO
+ i2c.write( addr );
+ i2c.write( cmd );
+ i2c.stop();
+
+ //7
+ addr = WM8731_REG_DIGITAL_PATH;
+ cmd = _WM8731_DIGITALAUDIO;
+ addr = addr << 1;
+ addr = addr|((cmd >> 8 )) & 0x01;
+ cmd = cmd&0xFF;
+ i2c.start();
+ i2c.write( WM8731_ADDRESS );//WM8731_REG_DIGITAL_PATH, _WM8731_DIGITALAUDIO
+ i2c.write( addr );
+ i2c.write( cmd );
+ i2c.stop();
+
+ //8
+ addr = WM8731_REG_PDOWN_CTRL;
+ cmd = _WM8731_POWER;
+ addr = addr << 1;
+ addr = addr|((cmd >> 8 )) & 0x01;
+ cmd = cmd&0xFF;
+ i2c.start();
+ i2c.write( WM8731_ADDRESS );//WM8731_REG_PDOWN_CTRL, _WM8731_POWER)
+ i2c.write( addr );
+ i2c.write( cmd );
+ i2c.stop();
+
+
+ //9
+ addr = WM8731_REG_DIGITAL_IF;
+ cmd = _WM8731_DAIF;
+ addr = addr << 1;
+ addr = addr|((cmd >> 8 )) & 0x01;
+ cmd = cmd&0xFF;
+ i2c.start();
+ i2c.write( WM8731_ADDRESS );
+ i2c.write( addr );//WM8731_REG_DIGITAL_IF, _WM8731_DAIF
+ i2c.write( cmd );
+ i2c.stop();
+
+
+ //10
+ addr = WM8731_REG_SAMPLING_CTRL;
+ cmd = _WM8731_SAMPLING;
+ addr = addr << 1;
+ addr = addr|((cmd >> 8 )) & 0x01;
+ cmd = cmd&0xFF;
+ i2c.start();
+ i2c.write( WM8731_ADDRESS );//WM8731_REG_SAMPLING_CTRL, _WM8731_SAMPLING
+ i2c.write( addr );
+ i2c.write( cmd );
+ i2c.stop();
+
+
+
+
+ //11
+ addr = WM8731_REG_ACTIVE_CTRL;
+ cmd = _WM8731_ACTIVATE;
+ addr = addr << 1;
+ addr = addr|((cmd >> 8 )) & 0x01;
+ cmd = cmd&0xFF;
+ i2c.start();
+ i2c.write( WM8731_ADDRESS );//WM8731_REG_SAMPLING_CTRL, _WM8731_SAMPLING
+ i2c.write( addr );
+ i2c.write( cmd );//there is also a deactive version!!
+ i2c.stop();
+}
\ No newline at end of file
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/wm8731_Config_setup.h Sat Feb 16 17:19:43 2019 +0000 @@ -0,0 +1,17 @@ +// This is start of the header guard. ADD_H can be any unique name. By convention, we use the name of the header file. +/*#ifndef ADD_H +#define ADD_H + +// This is the content of the .h file, which is where the declarations go +void wm8731_Config(void) // function prototype for wm8731_Config.h -- don't forget the semicolon! + +// This is the end of the header guard +#endif*/ + + +#ifndef WM8731_CONFIG_SETUP +#define WM8731_CONFIG_SETUP + +void wm8731_Config_setup(void); // function prototype for wm8731_Config.h -- don't forget the semicolon! + +#endif \ No newline at end of file