schreibfaul1 / ESP32-audioI2S

Play mp3 files from SD via I2S
GNU General Public License v3.0
1.09k stars 284 forks source link

Get Data for a Spectrum Analyzer #381

Closed ProfZiebart closed 6 months ago

ProfZiebart commented 2 years ago

Hi, first of all thank you for your excellent Work.

I built a Webradio based on your Library with the Arduino IDE and an ESP32. Now I thought about adding a (1 band) spectrometer.

in the blotfi / ESP32-Radio-with-Spectrum-analyzer they added a spectrum analyzer to the Display.

This is done by a routine displaying the bars ( I think about some LEDs, frankly) and a snippet getting the maximum volume directly from the Codec:

void VS1053::getBands()
{
    write_register(SCI_WRAMADDR, BASE+2);
    bands = read_register(SCI_WRAM);
    write_register(SCI_WRAMADDR, BASE+4);
    for (uint8_t i = 0; i < 14; i++) {
        uint8_t val = read_register(SCI_WRAM);
        /* current value in bits 5..0, normally 0..31
        peak value in bits 11..6, normally 0..31 */
        uint8_t cur1 = val & 31;
        uint8_t cur = (cur1*curvol)/30; // big bars
        if ( cur < 0 ) cur = 0;
        else if ( cur > (Spectrum_hy-4) ) cur = Spectrum_hy-4;
        spectrum[i][0] = cur;
    }
}

I assume you wrote your own MP3 Codec, therefore I have no entry point where to get my beloved information about the current playing maximum Volume. Could you give me a hint where to look or how to realize this?

podaen commented 1 year ago

The easiest way to do it with an analog signal. don't look for the output, because that is digital. All incoming data is also digital, so you need an ADC. In most cases the data will be sterio, so you need to collect one byte and skip the next one... and so on. That's what you want to do.

ProfZiebart commented 1 year ago

This is trivial and no answer to my problem. I look for a digital solution like blotfi already HAS. Measuring analog signals costs energy I don't want to spend.

podaen commented 1 year ago

That's how I allready did. But feel free to make your own code!

ProfZiebart commented 1 year ago

Yeah, I want to but I need an entry point in the current MP3 Codec. Then I will. I can't find the peak value yet.

podaen commented 1 year ago

Can you from a compressed format?? You probably want PCM.

ProfZiebart commented 1 year ago

blotfi did, so I do think you can. Otherwise I would say you're right but somehow they managed it.

podaen commented 1 year ago

What can?

schreibfaul1 commented 1 year ago

Well, there are two ways to decouple the I2S signal, as a block void audio_process_extern(int16_t* buff, uint16_t len, bool *continueI2S)or individual samples audio_process_i2s(uint32_t* sample, bool *continueI2S) The ESPUino project https://github.com/biologist79/ESPuino uses this to transmit to a BT speaker. A Fast Fourier Transform should be possible with some skill.

podaen commented 1 year ago

And I have a third way. 😀

schreibfaul1 commented 1 year ago

Do you use the analog signal after the DAC for this?

podaen commented 1 year ago

No looked in to the code and found an other way. It reminds me that I have build after the dac a long time a go. I almost forgot... and that's the best way to do it, because more sources can be added and it will improve the audio by take all those algorithms out of the player.

stale[bot] commented 1 year ago

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

ProfZiebart commented 1 year ago

@podaen How did you do it?

podaen commented 1 year ago

Do you use the analog signal after the DAC for this?

Not after the DAC, but there are so many ways. After the decoder (I think i did it, long time ago) by split the signal. but you could if you know V0. I made a special cable for it. You only need the positive site to make a spectrum analyzer. Everything below relative 0, you leave out.

github-actions[bot] commented 7 months ago

This issue is stale because it has been open for 30 days with no activity.

github-actions[bot] commented 6 months ago

This issue was closed because it has been inactive for 14 days since being marked as stale.