From cf0f1146bfa90d416336b638d2464359b8cece84 Mon Sep 17 00:00:00 2001 From: Taylor Oxelgren Date: Thu, 5 Feb 2026 14:07:56 -0600 Subject: [PATCH] Finished adding all data from directory, updated readme --- README.md | 8 ++++---- src/main.c | 44 +++++++++++++++----------------------------- 2 files changed, 19 insertions(+), 33 deletions(-) diff --git a/README.md b/README.md index add9a04..1f0c9ed 100644 --- a/README.md +++ b/README.md @@ -1,7 +1,7 @@ # Purpose Run knn on audio data which has been converted to images to find similar audio clips -## Ffmpeg preporcessing command +## Ffmpeg preporcessing command to create spectrogram image `for %f in (*.wav) do ffmpeg -y -i "%f" -ar 44100 -lavfi "showspectrumpic=s=256x256:scale=log:legend=0" "img\%~nf.png"` ## stb_image.h @@ -11,6 +11,6 @@ Used for gathering the image data `clang src/main.c -Iexternal -O2 -o soundknn.exe` ### Todo -- Load all images from directory -- Do knn algorithm -- Use opencl to accelerate algorithm execution \ No newline at end of file +- [x] Load all images from directory +- [ ] 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 f593741..59f2b5e 100644 --- a/src/main.c +++ b/src/main.c @@ -19,45 +19,31 @@ int main(){ int x,y; struct AudioData audioData[2000]; + // Getting first file out of the loop myHandle=FindFirstFileA(directory,&FindFileData); printf("%s\n",FindFileData.cFileName); - int counter=0; - while(FindNextFileA(myHandle,&FindFileData)){ + 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); + // _strdup allocates new memory and copies the string so the struct keeps its own + audioData[0].fileName = _strdup(path); + + int counter=1; + while(FindNextFileA(myHandle,&FindFileData)&& counter<2000){ printf("%s\n",FindFileData.cFileName); - char path[MAX_PATH]; snprintf(path, MAX_PATH, "esc-50-audio/img/%s", FindFileData.cFileName); audioData[counter].data = stbi_load(path, &x, &y, NULL, 1); - // _strdup allocates new memory and copies the string so the struct keeps its own - // persistent filename (path is a temporary buffer that would otherwise go out of scope) audioData[counter].fileName = _strdup(path); counter++; } + // Closing windows handler + FindClose(myHandle); - // Loads data into 1D array 256x256 so 2nd row starts at 256 - - if (!audioData[0].data) { - printf("Failed to load image: %s\n", stbi_failure_reason()); - return 1; - } - if (!audioData[1].data) { - printf("Failed to load image: %s\n", stbi_failure_reason()); - return 1; - } - for(int i=11766;i<12766;i++){ - if(audioData[0].data[i]!=0){ - printf("img1 info: %u",audioData[0].data[i]); - printf(" name %s",audioData[0].fileName); - printf("\n"); - } - } - - for(int i=11766;i<12766;i++){ - if(audioData[1].data[i]!=0){ - printf("img2 info: %u",audioData[1].data[i]); - printf(" name %s",audioData[1].fileName); - printf("\n"); - } + // Freeing the memory + for(int i=0;i