We are about to switch to a new forum software. Until then we have removed the registration on this forum.
I have two audio files..One contains some voice messages and other contains a continuous sound of 10khz..Spectrum is generated from two files and is plotted..I want to determine which spectrum is generated from which file upon a mouseclick event..Any help..TIA.. Below image representing spectrum from two files
Answers
If you plot both files, then you have access to the data for each source. When you have a mouseEvent, you compare the mouseX/mouseY points to your data points and you should determine which point is the closest to the mouse pointer. Then you need to figure out if that point belongs to the voice data set or from the second file.
Kf
Yes I have the data for each source..But how can I compare the data points and mouseX/mouseY...I mean where should I look into among the data.. @kfrajer
What structures are you using to store the data?
Second question: How do you map your data to your window dimensions?
Are you using translate/rotate?
I would use the dist() function: https://processing.org/reference/dist_.html and find the point with the shortest distance to the mouse pointer's coordinates.
Kf
This is the structure I followed for 1 file..If you could Kindly look into it..And suggest which way I should go with this..
One easy solution:
Checking a pixel in a PGraphics with spectrum1.get() based on mouseX, mouseY is a simple array lookup -- you can also do this spectrum1.pixels[] -- and you were already keeping the spectrum data in the array for drawing.
On the global scope:
Now replace line 66 with:
As you see, the dist operation here determines if your mouse pointer is close to the data. The value of distanceThreshold can be adjusted to be more accurate in selecting the spectrum (or differentiating multiple spectra) but in your case, it is inconvenient because your spectrum changes really fast, in you might not have enough time to detect when the mouse pointer is on top of the graph.
This code is valid if you don't use transformations. Notice you can adjust your offset and gain and the dist algorithm will still work. That is because and I am working using the data you are plotting and not on your raw data.
Since one can change the color from red to white, referring to selected or non-selected resp., then it is in this part of your code where you can inquire if the data came from your first or second file.
Kf