Sound by algorithm

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
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
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
In the above t is not a byte, it's the time since start, measured in units of 8 thousandths of a second.
> 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/c++draft/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
It appears to be a Javascript program though.
Yes, but I am working on a C++ 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 ++
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).
Yes. In a baroque tuning standard. 😏
Ah, 415 Hz is quite the difference indeed.
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
Topic archived. No new replies allowed.