Skip to content

Another audio visualizer #617

Closed Answered by board707
Nitin-Arora82 asked this question in Q&A
Discussion options

You must be logged in to vote

Interestingly if I replace the following line:
barHeights[i/divisor] = log(fftValue + 1)/log(255) * 64;

with the following to simulate random values, the behavior is fluid:

barHeights[i/divisor] = random(1, 64);

If this is not a typo, it means that esp32 evaluates the first expression too long.
Let's try to simplify it and convert it to integer mathematics:

// calculate the log2 of fftValue + 1
uint16_t x = fftValue + 1; 
uint8_t r =0;  // r will be log base 2 of (x)

while ( x >>= 1)  {
 r++;
}
barHeights[i/divisor] = r/8 * 64;

Replies: 2 comments 1 reply

Comment options

You must be logged in to vote
1 reply
@Nitin-Arora82
Comment options

Answer selected by Nitin-Arora82
Comment options

You must be logged in to vote
0 replies
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants