Libraryless. Click here for Pure Java version (6761L/39K).
1 | // Just a spike (first try). Should use binary search / Newton's method! |
2 | sclass AudioFrequencyDetectorSpike1 { |
3 | AudioRecognizer recognizer; |
4 | |
5 | int vibrations = 24; // how many periods to look at |
6 | double centerFreq = 440, step = 1; |
7 | int freqs = 25; // how many frequencies to look at |
8 | |
9 | IF1<Double> f = freq2 -> abs(recognizer.complexSumOfVibrations_raw(recognizer.mainSample, 0, 0, freq2, vibrations))/32768; |
10 | |
11 | // returns most likely frequency |
12 | double get() { |
13 | new Best<Double> bestFreq; |
14 | for (int iF : countIterator(-freqs/2, freqs/2)) { |
15 | double freq2 = centerFreq+step*iF; |
16 | double value = f.get(freq2); |
17 | //print(freq2 + ": " + value); |
18 | bestFreq.put(freq2, value); |
19 | } |
20 | ret bestFreq!; |
21 | } |
22 | |
23 | static Scorer scoreMe(int n default 2000) { |
24 | new Scorer scorer; |
25 | repeat n { |
26 | double freq = random(430, 450); |
27 | AudioRecognizer recognizer = new(0.2, new SineSoundSource(freq), 1); |
28 | |
29 | new AudioFrequencyDetectorSpike1 detector; |
30 | detector.recognizer = recognizer; |
31 | |
32 | double detected = detector!; |
33 | print("Frequency detected: " + detected + ", was: " + freq); |
34 | scorer.add(distanceToProbability(detected, freq)); |
35 | } |
36 | ret scorer; |
37 | } |
38 | } |
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: | 206 / 335 |
Version history: | 4 change(s) |
Referenced in: | [show references] |