Libraryless. Click here for Pure Java version (6761L/39K).
// Just a spike (first try). Should use binary search / Newton's method! sclass AudioFrequencyDetectorSpike1 { AudioRecognizer recognizer; int vibrations = 24; // how many periods to look at double centerFreq = 440, step = 1; int freqs = 25; // how many frequencies to look at IF1<Double> f = freq2 -> abs(recognizer.complexSumOfVibrations_raw(recognizer.mainSample, 0, 0, freq2, vibrations))/32768; // returns most likely frequency double get() { new Best<Double> bestFreq; for (int iF : countIterator(-freqs/2, freqs/2)) { double freq2 = centerFreq+step*iF; double value = f.get(freq2); //print(freq2 + ": " + value); bestFreq.put(freq2, value); } ret bestFreq!; } static Scorer scoreMe(int n default 2000) { new Scorer scorer; repeat n { double freq = random(430, 450); AudioRecognizer recognizer = new(0.2, new SineSoundSource(freq), 1); new AudioFrequencyDetectorSpike1 detector; detector.recognizer = recognizer; double detected = detector!; print("Frequency detected: " + detected + ", was: " + freq); scorer.add(distanceToProbability(detected, freq)); } ret scorer; } }
download show line numbers debug dex old transpilations
Travelled to 4 computer(s): bhatertpkbcr, mowyntqkapby, mqqgnosmbjvj, pyentgdyhuwx
No comments. add comment
Snippet ID: | #1032428 |
Snippet name: | AudioFrequencyDetectorSpike1 |
Eternal ID of this version: | #1032428/5 |
Text MD5: | 6ca5da5d2883a744c427cd2b64b85adc |
Transpilation MD5: | 9374a95a29066169e3382369a2daa8b1 |
Author: | stefan |
Category: | javax / audio recognition |
Type: | JavaX fragment (include) |
Public (visible to everyone): | Yes |
Archived (hidden from active list): | No |
Created/modified: | 2021-09-03 07:22:19 |
Source code size: | 1247 bytes / 38 lines |
Pitched / IR pitched: | No / No |
Views / Downloads: | 205 / 333 |
Version history: | 4 change(s) |
Referenced in: | [show references] |