Discuss Scratch

daffy1234
Scratcher
100+ posts

More powerful microphone blocks

We have the option to listen to microphone volume, but that's it. I want the ability to get the amplitude of a particular frequency going into the microphone. This would open up many new project ideas.

Here's how the blocks would work.

// Outputs between 0 and 1 depending how loud the note A is being played into the microphone.
(amplitude of frequency [440] hz :: sensing)

// Outputs a number between 20 and 20000, in hz, depending on the loudest frequency.
(loudest frequency :: sensing)

This could be useful for projects like guitar tuners, SSTV decoders, dialup modems (!!), games where you control your character by singing (!!!!), and all sorts of things. Here's an example of a simple program that tells you what note it's hearing. This could be useful for tuning a guitar. It works by taking the loudest frequency and using some math to figure out how many notes away from A it is. You could use this and a table of notes to pin down whether it's hearing F#, G, B, or whatever note. You could, but it was getting a bit big for a forum post.

when green flag clicked
set [multiplier v] to ([10 ^ v] of (([log v] of [2]) / [12])) // Every note is 12th root of 2 (~1.059) times higher than the last.
... // After a 12 note scale, the frequency doubles.
... // just trust me on this ;)
forever
set [freq v] to (loudest frequency :: sensing)
set [note v] to ((freq) / (440)) // 440hz = note A, which is how most music is tuned
set [note v] to (round (([log v] of (note)) / ([log v] of (multiplier)))) // log(note) / log(multiplier) will be the number of notes...
... // ...above/below our note is from A.
change [note v] by [69] // This makes our note variable be the same note as used by the sound blocks.
say (note)
end

That's a guitar tuner in 8 lines of code!! Extremely powerful!

Another simple(r) project you can make with this is a script to listen for when you push the number 4 on a phone keypad. The tones used in the keypad beeps are very very specific, and that's so the computer on the other end knows which button you push. You can detect this yourself. For example, the button 4 uses frequencies 1209hz and 770hz combined together to make its unique beep sound. Here's a simple way to test for it.

when green flag clicked
forever
if <<(amplitude of frequency [1209] hz :: sensing) > [0.5]> and <(amplitude of frequency [770] hz :: sensing) > [0.5]>> then
say [I hear a 4!!]
else
say [I don't hear a 4]
end
end

I can imagine a couple issues with this that the scratch team (or other scratchers!) might bring up. First of all, is this safe for privacy? It's possible to use this to record someone's voice and upload it to a cloud variable. One very simple solution is to just not allow cloud variables when powerful microphone blocks are in use. I think that's a fair compromise. Otherwise, you could have a warning on the front like you do with the username block. “Note: this project is capable of recording your voice. Do you accept this?” for example.

Another issue is how difficult this would be to add to scratch, and having done research into fourier analysis and the discrete fourier transform, I can tell you it's actually quite straightforward! The thing you want to look for is called an FFT, or Fast Fourier Transform. If any scratch team member needs help with the research or implementation, I'd be happy to help wherever possible. I have quite a lot of experience in programming (outside of scratch), so I figure I could help out. I'd love to see this added to scratch.

Thanks for reading and let me know what you think!

Last edited by daffy1234 (Sept. 10, 2017 04:32:57)

Charles12310
Scratcher
1000+ posts

More powerful microphone blocks

daffy1234 wrote:

We have the option to listen to microphone volume, but that's it. I want the ability to get the amplitude of a particular frequency going into the microphone. This would open up many new project ideas.

Here's how the blocks would work.

// Outputs between 0 and 1 depending how loud the note A is being played into the microphone.
(amplitude of frequency [440] hz :: sensing)

// Outputs a number between 20 and 20000, in hz, depending on the loudest frequency.
(loudest frequency :: sensing)

This could be useful for projects like guitar tuners, SSTV decoders, dialup modems (!!), games where you control your character by singing (!!!!), and all sorts of things. Here's an example of a simple program that tells you what note it's hearing. This could be useful for tuning a guitar. It works by taking the loudest frequency and using some math to figure out how many notes away from A it is. You could use this and a table of notes to pin down whether it's hearing F#, G, B, or whatever note. You could, but it was getting a bit big for a forum post.

when green flag clicked
set [multiplier v] to ([10 ^ v] of (([log v] of [2]) / [12])) // Every note is 12th root of 2 (~1.059) times higher than the last.
... // After a 12 note scale, the frequency doubles.
... // just trust me on this ;)
forever
set [freq v] to (loudest frequency :: sensing)
set [note v] to ((freq) / (440)) // 440hz = note A, which is how most music is tuned
set [note v] to (round (([log v] of (note)) / ([log v] of (multiplier)))) // log(note) / log(multiplier) will be the number of notes...
... // ...above/below our note is from A.
change [note v] by [69] // This makes our note variable be the same note as used by the sound blocks.
say (note)
end

That's a guitar tuner in 8 lines of code!! Extremely powerful!

Another simple(r) project you can make with this is a script to listen for when you push the number 4 on a phone keypad. The tones used in the keypad beeps are very very specific, and that's so the computer on the other end knows which button you push. You can detect this yourself. For example, the button 4 uses frequencies 1209hz and 770hz combined together to make its unique beep sound. Here's a simple way to test for it.

when green flag clicked
forever
if <<(amplitude of frequency [1209] hz :: sensing) > [0.5]> and <(amplitude of frequency [770] hz :: sensing) > [0.5]>> then
say [I hear a 4!!]
else
say [I don't hear a 4]
end
end

I can imagine a couple issues with this that the scratch team (or other scratchers!) might bring up. First of all, is this safe for privacy? It's possible to use this to record someone's voice and upload it to a cloud variable. One very simple solution is to just not allow cloud variables when powerful microphone blocks are in use. I think that's a fair compromise. Otherwise, you could have a warning on the front like you do with the username block. “Note: this project is capable of recording your voice. Do you accept this?” for example.

Another issue is how difficult this would be to add to scratch, and having done research into fourier analysis and the discrete fourier transform, I can tell you it's actually quite straightforward! The thing you want to look for is called an FFT, or Fast Fourier Transform. If any scratch team member needs help with the research or implementation, I'd be happy to help wherever possible. I have quite a lot of experience in programming (outside of scratch), so I figure I could help out. I'd love to see this added to scratch.

Thanks for reading and let me know what you think!
Support for your reasons on why you are suggesting this.


Click This Link For Some Secrets About Me!
A few internet communication companies want to corrupt the internet by getting rid of net neutrality. Stop Them!
daffy1234
Scratcher
100+ posts

More powerful microphone blocks

Charles12310 wrote:

Support for your reasons on why you are suggesting this.

Thanks! Do you have any suggestions to make it better?
cul8er
Scratcher
500+ posts

More powerful microphone blocks

I was initially sceptical, but you've got me convinced!

I reckon just not permitting cloud variables in projects with the blocks is the best solution. In the editor, you could have the block go grey if you had a cloud variable in the project, and vice versa. Grey reporters would return a ( ).

Also, if you hovered or clicked on the grey blocks, it could display a label saying "Frequency blocks are not permitted to be used in conjunction with cloud variables. Learn more…", and it would direct you to a wiki article on frequency blocks (or cloud data?).

Last edited by cul8er (Sept. 10, 2017 10:40:55)


Gone.
Charles12310
Scratcher
1000+ posts

More powerful microphone blocks

daffy1234 wrote:

Charles12310 wrote:

Support for your reasons on why you are suggesting this.

Thanks! Do you have any suggestions to make it better?
I can't think so. Though your suggestion is useful, I actually don't know how to improve this more because I'm not an expert at microphones.


Click This Link For Some Secrets About Me!
A few internet communication companies want to corrupt the internet by getting rid of net neutrality. Stop Them!
_nix
Scratcher
1000+ posts

More powerful microphone blocks

Did you think of using this for making a music visualizer?

══ trans autistic lesbian enbydoggirl // harbinger of the waking world, just like you // 16, she/they
sparrows one word to the paragraph // go forth: change the world

daffy1234
Scratcher
100+ posts

More powerful microphone blocks

_nix wrote:

Did you think of using this for making a music visualizer?
I didn't, but that's exactly why I think it should be added! There's so many creative people on this site and I'm sure there's hundreds of ways this could be used that I haven't thought of yet.
Hypnotron
Scratcher
100+ posts

More powerful microphone blocks

If it's possible, then I would definitely support!
daffy1234
Scratcher
100+ posts

More powerful microphone blocks

Hypnotron wrote:

If it's possible, then I would definitely support!

I just found some FFT code online that uses the MIT license. So it's very possible!
daffy1234
Scratcher
100+ posts

More powerful microphone blocks

Bump
ericr
Scratch Team
24 posts

More powerful microphone blocks

This is a fun idea! I've played around with using javascript to analyze sound and detect pitch from the microphone. One way to experiment with this would be to make a ScratchX extension (see http://scratchx.org/). The ToneJS library would come in handy.

I like the idea of blocks that analyze the sound, and think they could be fun to play with- I love the examples mentioned above (like voice controlled games, music analyzers, etc.). One design challenge is that most people are not familiar with how frequencies work, so it could be confusing. I might want to make a menu that let you pick one of, say, a dozen frequency ranges to report the loudness of (this would be useful for making music visualizers). I would also want to have a block that reports the analyzed pitch of the sound (a bit like the “guitar tuner” example, above). It's challenging to get pitch detection to work reliably- I've played with autocorrelation-based methods in javascript and they can work pretty well for monophonic sounds at least. Could be cool!

braxbroscratcher
Scratcher
1000+ posts

More powerful microphone blocks

Actually, what's funny is that even if you took the frequencies of speech and stored them numerically, unless you were simultaneously detecting every frequency, all you'd ever get is garbled mess, so you don't even need the anti-cloud prevention.


My signature is kumquat proof.
But not tangerine pro-
nomnomnomnomnom










Current Project:
n/a
Quotes: “In our last hour, we burn the most brightly, trying to deny that we are burning out.” -Me
“Well, no. 1024 Killerbytes make a Murderbyte.” -MegaByteCorporations
“I hate out of context quotes.” -Me
“I hate it when Cubeupload breaks.” -Also me
SC-1
Scratcher
4 posts

More powerful microphone blocks

Actually I want to make morse decoder. So this thing might be a cool thing! If this thing can be possible, I'll support you!
TrueMoseCoder
Scratcher
7 posts

More powerful microphone blocks

This would be great for a singing game!
Wyan100
Scratcher
100+ posts

More powerful microphone blocks


cul8er wrote:

I was initially sceptical, but you've got me convinced!

I reckon just not permitting cloud variables in projects with the blocks is the best solution. In the editor, you could have the block go grey if you had a cloud variable in the project, and vice versa. Grey reporters would return a ( ).

Also, if you hovered or clicked on the grey blocks, it could display a label saying "Frequency blocks are not permitted to be used in conjunction with cloud variables. Learn more…", and it would direct you to a wiki article on frequency blocks (or cloud data?).

Wouldn't it just be easier for the frequency measure to just measure frequency in numbers instead of actually recording the noise…?

Edit: Based off what people are saying they make it sound like that these numbers can be computed into noise, but my small brain doesn't see that as mathematically possible.

Last edited by Wyan100 (April 8, 2020 00:21:20)


“But don't quote me on it!” - Wyan100, 2020
1132262
Scratcher
1000+ posts

More powerful microphone blocks

Wyan100 wrote:

cul8er wrote:

I was initially sceptical, but you've got me convinced!

I reckon just not permitting cloud variables in projects with the blocks is the best solution. In the editor, you could have the block go grey if you had a cloud variable in the project, and vice versa. Grey reporters would return a ( ).

Also, if you hovered or clicked on the grey blocks, it could display a label saying "Frequency blocks are not permitted to be used in conjunction with cloud variables. Learn more…", and it would direct you to a wiki article on frequency blocks (or cloud data?).

Wouldn't it just be easier for the frequency measure to just measure frequency in numbers instead of actually recording the noise…?

Edit: Based off what people are saying they make it sound like that these numbers can be computed into noise, but my small brain doesn't see that as mathematically possible.
Sound waves hit things. They make the things move a little bit, which makes noise. The “frequency” is how often they hit that thing. The faster they hit it, the higher pitched noise. Your computer can make sound waves with any frequency it wants. (Well, not really. It's more complicated than that. But pretty much any frequency that's useful.) The computer can be told “Play the frequency 440” and it will use it's speaker to hit things 440 times a second, making a nice “A” sound.




Powered by DjangoBB

Standard | Mobile