Sound by algorithm

Sep 4, 2022 at 9:13pm
There is a way to generate sounds according to an algorithm. It's very weird, but interesting. At the link below you can take a look at the principle with a little example (beware! the sound is too loud). I have no clue what it means. Is there a way to know what this algo generates as chars?

https://greggman.com/downloads/examples/html5bytebeat/html5bytebeat.html

((t >> 10) & 42) * t
Sep 4, 2022 at 9:33pm
A sound is just a pressure wave (through the air). You create one by telling the speaker how to push (or pull) the air by energizing an electro magnet attached to the back of the speaker membrane.

This translates to an electrical signal. For the simplest (i.e. old PC speaker noise) that is just an on/off switch.

The frequency of the sound changes its pitch — the note you hear. For example, a wave that oscillates at roughly 440 hz — that is, 440 times on and off per second — is A4, the Stuttgart tuning note. https://en.wikipedia.org/wiki/A440_(pitch_standard)
It’s really closer to A-sharp, but meh, whatever, right?

That equation you see is an interval for time measured in seconds. You see that by playing with it in weird ways (using bit shifts and bit masks) you can get a weird little tune.
Last edited on Sep 4, 2022 at 9:34pm
Sep 7, 2022 at 12:52pm
Hello. I could not answer because of a bug on the forum, but thank you for your comment. Just another question. A bitwise left or right has a logical limit. I saw in the previous example >> 10, but after 8 I restart the loop no? Why they use a number which is more than the number of the bits?
Last edited on Sep 7, 2022 at 12:53pm
Sep 7, 2022 at 1:24pm
In the above t is not a byte, it's the time since start, measured in units of 8 thousandths of a second.
Sep 7, 2022 at 1:25pm
> A bitwise left or right has a logical limit.

The behavior is undefined if the right operand is negative, or greater than or equal to the width of the promoted left operand.
https://eel.is/Pythondraft/expr.shift#1



> Why they use a number which is more than the number of the bits?

The left operand is promoted.
https://en.cppreference.com/w/cpp/language/implicit_conversion#Integral_promotion
Last edited on Sep 7, 2022 at 1:25pm
Sep 7, 2022 at 1:46pm
It appears to be a Javascript program though.
Sep 7, 2022 at 2:41pm
Yes, but I am working on a Python class which does the work.
It works as expected (funny), but in order to develop some readable algorithm I have to understand all these operands. Thank you for your explanations ++
Sep 7, 2022 at 3:59pm
Duthomhas wrote:
It’s really closer to A-sharp, but meh, whatever, right?
What do you mean by this? 440 Hz is an A, exactly, because we say it's an A (depending on the tuning standard).
Sep 7, 2022 at 7:26pm
Yes. In a baroque tuning standard. 😏
Sep 7, 2022 at 8:32pm
Ah, 415 Hz is quite the difference indeed.
Sep 7, 2022 at 10:42pm
Sep 8, 2022 at 12:48pm
I didn't realize some orchestras tune their instruments to even higher than 440 Hz.
https://www.youtube.com/watch?v=UCAOkP2BatM
Last edited on Sep 8, 2022 at 1:44pm
Topic archived. No new replies allowed.