Skip to content
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

Frequency detect mode for input[1] #382

Merged
merged 13 commits into from
Apr 15, 2021
Merged

Frequency detect mode for input[1] #382

merged 13 commits into from
Apr 15, 2021

Conversation

trentgill
Copy link
Collaborator

@trentgill trentgill commented Apr 14, 2021

Closes #277

DO NOT MERGE

This PR adds a new input mode freq short for frequency tracker. It functions the same as stream & volume modes, but returns values representing the frequency of an attached oscillation.

The detection algorithm is just looking for zero-crossings, so it will only work with raw oscillator sounds (though perhaps could be fun to explore with complex waves for harmonic-locking effects).

Working accurately up to about 1500Hz in my testing, with increasing jitter above this point.

//

I did notice that all the values were off by about 2%. After some investigation, it's not caused by the detection algorithm -- i tested sending LFOs from ASL, and they were also this same 2% off. It seems that the dsp block itself is running slow. I haven't investigated whether this is caused by variation between devices (it could be as I don't think our crystal is very accurate in an absolute sense - there is no dedicated audio crystal), or if the PLL that controls the audio-loop is incorrectly configured. Perhaps worth some investigation, but it shouldn't hold up this PR.

The good news is the frequency offset scales exponentially. To correct for it, one simply multiplies by 0.98 or so in frequency land. If converting to hertz, it just becomes an addition.

//

Before merging, i want to add a hztovolts function based on the same absolute freq range as just-friends / w/syn etc.
The reason i'm waiting is it can leverage the new justvolts function. Should just be:

function hztovolts(hz, ref)
  ref = ref or 261.63 -- optional. defaults to middle C
  return justvolts(hz/ref)
end

This is especially handy if you want to track a frequency input and control a module over ii, or even to take an input frequency and send it to an output as a voltage (so it can be doubled by another oscillator). This would be especially interesting if the output had a .scale applied, and in volts space, adding an offset becomes a direct transposition.

//

Together with the new calibration engine & public libs, we should make a norns-enabled script for volt-per-octave calibration of other modules.

Copy link
Member

@tehn tehn left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

looks great. impressed at the deep implementation, and seeing MIDI code made me smile

@trentgill trentgill merged commit f5649a0 into THREE Apr 15, 2021
trentgill added a commit that referenced this pull request Jun 30, 2021
* can now update output[n].scale(_) with .scale = {note list}, so it can be dynamically set like a regular table (#373)

* fix bug where aliasing an ii address before use could stack overflow (#374)

* querying output voltage now returns the shaped & scaled voltage (real voltage at jack)

* add just intonation helpers: justvolts(), just12()
* support input scales: input[n].mode( 'scale', {...}, 'ji')
* support output scales: output[n].scale({...}, 'ji')

* Python based bootloader support and dfureset (#377)
* `make pydfu` to use python3 dfu bootloader
* `make dfureset` jumps to bootloader from make
* `make zip` now builds dfu file as well as binary
* add instructions for using pydfu instead of dfu-util

* Frequency detect mode for input[1] (#382)
* `input[1].mode('freq', interval)` reports frequency of a signal connected to input 1 (no support for input 2)
* `hztovolts(hz, <ref>)` helper fn converts an input hz equivalent voltage (uses default reference to match Just-Friends & W/Syn)

* print an error to usb host if event queue overflows (#391)

* clock.lua module added (#393)

* New calibrate.lua & underlying engine (#397)
Breaking:
* `cal` lua module refactored with new API
* calibration no longer auto-runs if no vals saved (ie new factory modules)
* `util/recalibrate.lua` demonstrates usage, and can be used for factory calibration (or at home)

* double userscript storage size to 16kB (#396)

* add jacktest.lua

* strip debug info from crow lua libs for dramatic ram reduction (#395)

* Sequins.lua library (#387)
* add sequins library

* ASL2 (#399) ASL2 library. Runtime operates in C for greatly optimized performance & sample accuracy

* introduce Caw_printf

* Public.lua library for sharing parameters (#394)
* after calling init() crow sends '^^ready()'
* add 'public.view' for enabling live monitoring of in & out voltages

* Oscillate asllib fn (#407)
* add 'oscillate' asllib fn

* add note about not using `note` in asllib. kept only to avoid the breaking change

* add quote library & remove quotes global (#412)

* support ii getters from teletype (#403)

Co-authored-by: brian crabtree <tehn@monome.org>
@trentgill trentgill deleted the frequency_detect branch July 3, 2021 17:13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants