-
Notifications
You must be signed in to change notification settings - Fork 111
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Audio analysis: mediorum changes #8536
Merged
michellebrier
merged 15 commits into
main
from
mbrier/proto-1827/mediorum-audio-analysis
May 30, 2024
Merged
Changes from all commits
Commits
Show all changes
15 commits
Select commit
Hold shift + click to select a range
06e4016
add audio analysis. todo infra, think more about findMissedJobs, and …
michellebrier 664b575
add script + remaining go code + retry endpoint
michellebrier 3d06301
add python as mediorum dep
michellebrier 4a53696
clean up
michellebrier 2d9ad66
clean up some more
michellebrier cf6dc4a
working locally
michellebrier 94f397c
use essentia docker images. unable to test bc post to docker containe…
michellebrier b73ab81
use libKeyFinder and aubio
michellebrier f7774cc
uncomment
michellebrier 8c15480
dockerfile dev
michellebrier 3cf6a07
PR comments
michellebrier 8ca4412
fix analysis for mp3
michellebrier cd44d2a
read audio in chunks in keyfinder.cpp
michellebrier 35ea40e
add timeout log
michellebrier 35fea74
persist bpm if succeeds even if key fails. clean up. use audio analyz…
michellebrier File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
// keyfinder.cpp | ||
#include <iostream> | ||
#include <vector> | ||
#include <keyfinder/keyfinder.h> | ||
#include <sndfile.h> | ||
|
||
// Convert KeyFinder key_t to string | ||
std::string keyToString(KeyFinder::key_t key) { | ||
switch (key) { | ||
case KeyFinder::A_MAJOR: return "A major"; | ||
case KeyFinder::A_MINOR: return "A minor"; | ||
case KeyFinder::B_FLAT_MAJOR: return "B flat major"; | ||
case KeyFinder::B_FLAT_MINOR: return "B flat minor"; | ||
case KeyFinder::B_MAJOR: return "B major"; | ||
case KeyFinder::B_MINOR: return "B minor"; | ||
case KeyFinder::C_MAJOR: return "C major"; | ||
case KeyFinder::C_MINOR: return "C minor"; | ||
case KeyFinder::D_FLAT_MAJOR: return "D flat major"; | ||
case KeyFinder::D_FLAT_MINOR: return "D flat minor"; | ||
case KeyFinder::D_MAJOR: return "D major"; | ||
case KeyFinder::D_MINOR: return "D minor"; | ||
case KeyFinder::E_FLAT_MAJOR: return "E flat major"; | ||
case KeyFinder::E_FLAT_MINOR: return "E flat minor"; | ||
case KeyFinder::E_MAJOR: return "E major"; | ||
case KeyFinder::E_MINOR: return "E minor"; | ||
case KeyFinder::F_MAJOR: return "F major"; | ||
case KeyFinder::F_MINOR: return "F minor"; | ||
case KeyFinder::G_FLAT_MAJOR: return "G flat major"; | ||
case KeyFinder::G_FLAT_MINOR: return "G flat minor"; | ||
case KeyFinder::G_MAJOR: return "G major"; | ||
case KeyFinder::G_MINOR: return "G minor"; | ||
case KeyFinder::A_FLAT_MAJOR: return "A flat major"; | ||
case KeyFinder::A_FLAT_MINOR: return "A flat minor"; | ||
case KeyFinder::SILENCE: return "Silence"; | ||
default: return "Unknown"; | ||
} | ||
} | ||
|
||
int main(int argc, char* argv[]) { | ||
if (argc != 2) { | ||
std::cerr << "Usage: " << argv[0] << " <audio file path>" << std::endl; | ||
return 1; | ||
} | ||
|
||
const char* filePath = argv[1]; | ||
|
||
// Open the audio file | ||
SF_INFO sfinfo; | ||
SNDFILE* sndfile = sf_open(filePath, SFM_READ, &sfinfo); | ||
if (!sndfile) { | ||
std::cerr << "Error opening audio file: " << sf_strerror(sndfile) << std::endl; | ||
return 1; | ||
} | ||
|
||
static KeyFinder::KeyFinder keyFinder; | ||
|
||
// Build an empty audio object | ||
KeyFinder::AudioData audioDataStruct; | ||
audioDataStruct.setFrameRate(sfinfo.samplerate); | ||
audioDataStruct.setChannels(sfinfo.channels); | ||
|
||
const size_t CHUNK_SIZE = 4096; | ||
std::vector<float> buffer(CHUNK_SIZE * sfinfo.channels); | ||
size_t totalSamples = 0; | ||
|
||
// Read and process the file in chunks | ||
while (sf_count_t framesRead = sf_readf_float(sndfile, buffer.data(), CHUNK_SIZE)) { | ||
totalSamples += framesRead * sfinfo.channels; | ||
audioDataStruct.addToSampleCount(framesRead * sfinfo.channels); | ||
for (size_t i = 0; i < framesRead * sfinfo.channels; ++i) { | ||
audioDataStruct.setSample(totalSamples - framesRead * sfinfo.channels + i, buffer[i]); | ||
} | ||
} | ||
|
||
sf_close(sndfile); | ||
|
||
KeyFinder::key_t key = keyFinder.keyOfAudio(audioDataStruct); | ||
std::string keyString = keyToString(key); | ||
std::cout << keyString << std::endl; | ||
return 0; | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
cool to see basically all the same deps as https://github.com/swesterfeld/audiowmark which @stereosteve and I have been messing with