Finished adding all data from directory, updated readme
This commit is contained in:
@@ -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
|
||||
- [x] Load all images from directory
|
||||
- [ ] Do knn algorithm
|
||||
- [ ] Use opencl to accelerate algorithm execution
|
||||
44
src/main.c
44
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)){
|
||||
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);
|
||||
audioData[0].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[0].fileName = _strdup(path);
|
||||
|
||||
int counter=1;
|
||||
while(FindNextFileA(myHandle,&FindFileData)&& counter<2000){
|
||||
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);
|
||||
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<counter;i++){
|
||||
stbi_image_free(audioData[i].data);
|
||||
free(audioData[i].fileName);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
Reference in New Issue
Block a user