Ambiera Forum

Discussions, Help and Support.

Ambiera Forum > CopperCube > Programming and Scripting
CopperCube controller from audio pitch detection

hadoken
Registered User
Quote
2023-12-02 01:21:56

Hey friends,

I want to create an input controller for CopperCube from the pitch detection of a monophonic audio signal from the player's musical instrument.

I've already found a free tool from Chris Wilson at GitHub that does the detection part in Firefox pretty well with my cheap USB microphone, a small program that basically consists of just one index.html file as front-end plus a JavaScript file for the recognition algorithm part called "pitchdetect.js":

https://github.com/cwilso/pitchd...

The tool detects with low latency nearly real-time, it can simply run offline as a background process in a browser window, while CopperCube projects can run in the foreground at the same time.

To achieve my goal, I think it should be sufficient to make "pitchdetect.js" write the detected pitch to a text file in short intervals and let CopperCube take over from that point on.

But - getting a JavaScript file executed in the browser to save a local file is not an easy task due to the common sandbox security concept of modern browsers.

Theoretically, Node.js could provide its built-in so called fs module for file access handling with JavaScript but I could not get fs initialized successfully for "pitchdetect.js" so far which makes me wish I could save a text file in this case without fs somehow.

I have also already tested some code from stackoverflow.com and other web sources which did successfully write a text file but needed to prompt the user and ask for mouse click confirmation. (I would rather need auto file writing in the background without user interaction.)

So, maybe anyone could help me out here to close the data transfer gap for this project. I think we could create some awesome stuff from it. Many thanks in advance.

🔎︎



just_in_case
Moderator
Quote
2023-12-02 08:07:54

You can try using the download feature of the browser to save the text file in the computer without prompting or need for the user to perform a click event, but it might not allow you to specify the directory in which you want to save the text file and will prevent you from overwriting the existing file.

so yeah other way around is to save the file to the server itself with the help of server-side scripting like php, nodejs, etc.
You can then use the command ccbDoHttpRequest() to get the text content of the file.

some features might not work with the coppercube javascript environment otherwise you can directly translate the "pitchdetect.js" to copper cube javascript.

I am not sure why you are not able to use the Node.js to write the file.

Below is a sample nodejs project file that I created for you, that saves a random value to a textfile from the browser every 3 seconds.

It uses express package of nodeJS to work with the static HTML file, and we have to do some error checking with the response for the nodeJS otherwise the execution gets stopped after few seconds.

here is the link to the project file.
https://cdn.discordapp.com/attac...

you can check the index.html and app.js file. When you start the nodeJS server for the app and then upon running the index.html file.
It will create a recipe.txt file with random value every 3 seconds of interval.

Hope this helps.


hadoken
Guest
Quote
2023-12-02 10:18:43

Thank you very much @just_in_case. I'll see if I can get any further with it.


Create reply:


Posted by: (you are not logged in)


Enter the missing letter in: "Internationa?" (you are not logged in)


Text:

 

  

Possible Codes


Feature Code
Link [url] www.example.com [/url]
Bold [b]bold text[/b]
Image [img]http://www.example.com/image.jpg[/img]
Quote [quote]quoted text[/quote]
Code [code]source code[/code]

Emoticons


   






Copyright© Ambiera e.U. all rights reserved.
Privacy Policy | Terms and Conditions | Imprint | Contact