Finished adding all data from directory, updated readme
This commit is contained in:
@@ -1,7 +1,7 @@
|
|||||||
# Purpose
|
# Purpose
|
||||||
Run knn on audio data which has been converted to images to find similar audio clips
|
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"`
|
`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
|
## stb_image.h
|
||||||
@@ -11,6 +11,6 @@ Used for gathering the image data
|
|||||||
`clang src/main.c -Iexternal -O2 -o soundknn.exe`
|
`clang src/main.c -Iexternal -O2 -o soundknn.exe`
|
||||||
|
|
||||||
### Todo
|
### Todo
|
||||||
- Load all images from directory
|
- [x] Load all images from directory
|
||||||
- Do knn algorithm
|
- [ ] Do knn algorithm
|
||||||
- Use opencl to accelerate algorithm execution
|
- [ ] Use opencl to accelerate algorithm execution
|
||||||
44
src/main.c
44
src/main.c
@@ -19,45 +19,31 @@ int main(){
|
|||||||
int x,y;
|
int x,y;
|
||||||
struct AudioData audioData[2000];
|
struct AudioData audioData[2000];
|
||||||
|
|
||||||
|
// Getting first file out of the loop
|
||||||
myHandle=FindFirstFileA(directory,&FindFileData);
|
myHandle=FindFirstFileA(directory,&FindFileData);
|
||||||
printf("%s\n",FindFileData.cFileName);
|
printf("%s\n",FindFileData.cFileName);
|
||||||
int counter=0;
|
char path[MAX_PATH];
|
||||||
while(FindNextFileA(myHandle,&FindFileData)){
|
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);
|
printf("%s\n",FindFileData.cFileName);
|
||||||
char path[MAX_PATH];
|
|
||||||
snprintf(path, MAX_PATH, "esc-50-audio/img/%s", 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].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);
|
audioData[counter].fileName = _strdup(path);
|
||||||
counter++;
|
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++){
|
// Freeing the memory
|
||||||
if(audioData[0].data[i]!=0){
|
for(int i=0;i<counter;i++){
|
||||||
printf("img1 info: %u",audioData[0].data[i]);
|
stbi_image_free(audioData[i].data);
|
||||||
printf(" name %s",audioData[0].fileName);
|
free(audioData[i].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");
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user