diff --git a/README.md b/README.md index 1f0c9ed..7577a2a 100644 --- a/README.md +++ b/README.md @@ -2,8 +2,14 @@ Run knn on audio data which has been converted to images to find similar audio clips ## Ffmpeg preporcessing command to create spectrogram image +Spectogramspectrogram + `for %f in (*.wav) do ffmpeg -y -i "%f" -ar 44100 -lavfi "showspectrumpic=s=256x256:scale=log:legend=0" "img\%~nf.png"` +With loudnorm to try to improve performance + +`for %f in (*.wav) do ffmpeg -y -i "%f" -ar 44100 -lavfi "loudnorm,showspectrumpic=s=256x256:scale=log:legend=0" "img\%~nf.png"` + ## stb_image.h Used for gathering the image data @@ -12,5 +18,5 @@ Used for gathering the image data ### Todo - [x] Load all images from directory -- [ ] Do knn algorithm +- [x] Do knn algorithm - [ ] Use opencl to accelerate algorithm execution \ No newline at end of file diff --git a/src/main.c b/src/main.c index 1ba2b35..0f110e0 100644 --- a/src/main.c +++ b/src/main.c @@ -1,14 +1,33 @@ #include +#include +#include #include #define STB_IMAGE_IMPLEMENTATION #include "stb_image.h" -struct AudioData{ +typedef struct AudioData{ unsigned char *data; char *fileName; -}; +}AudioData; + + +float EuclideanDistance(AudioData *im1,AudioData *im2){ + // Using hard coded x,y for now + int x,y; + x=256; + y=256; + float distance=0; + + for(int i=0;i<(x*y);i++){ + float d = (float)im1->data[i] - (float)im2->data[i]; + distance += d * d; + } + + + return sqrtf(distance); +} int main(){ @@ -21,7 +40,6 @@ int main(){ // Getting first file out of the loop myHandle=FindFirstFileA(directory,&FindFileData); - printf("%s\n",FindFileData.cFileName); char path[MAX_PATH]; snprintf(path, MAX_PATH, "esc-50-audio/img/%s", FindFileData.cFileName); audioData[0].data = stbi_load(path, &x, &y, NULL, 1); @@ -29,8 +47,9 @@ int main(){ audioData[0].fileName = _strdup(path); int counter=1; + // Gets all other files while(FindNextFileA(myHandle,&FindFileData)&& counter<2000){ - printf("%s\n",FindFileData.cFileName); + // printf("%s\n",FindFileData.cFileName); snprintf(path, MAX_PATH, "esc-50-audio/img/%s", FindFileData.cFileName); audioData[counter].data = stbi_load(path, &x, &y, NULL, 1); audioData[counter].fileName = _strdup(path); @@ -44,7 +63,29 @@ int main(){ distanceArrays[i]=calloc(2000,sizeof(float)); } + // Searches for index of specific image + char img[]="esc-50-audio/img/1-32318-A-0.png"; + int fileindex; + for(int i=0;i