Skip to content

Added VU meter level read function #184

Description

@Frank-Bemelman

Hi Cellie,

Still having fun with my never ending project.

Noticed that some stations do connect, but sometimes apperently 'off line' as they just stream the sound of silence...
So I considered skipping those, and pick the next station in my list. Could do that after perhaps 5 seconds of continious silence.

For that I need the level of the actual sound being played. So I made this new member:

uint8_t ESP32_VS1053_Stream::getVuMeter()
{ // read  VU-meter registers
  // turn on Vu meter if need be

  if(!_http && !_playingFile)return 0;

  uint16_t regvalue = _vs1053->readRegister(SCI_STATUS); 
  if((regvalue & 0x0200)==0) _vs1053->writeRegister(SCI_STATUS, (regvalue | 0x200)); 
    
  uint16_t vu_values = _vs1053->readRegister(SCI_AICTRL3); 
  uint8_t left_channel = highByte(vu_values);
  uint8_t right_channel = lowByte(vu_values);

  return max(left_channel, right_channel);
}

And in ESP32_VS1053_Stream.h:

uint8_t getVuMeter();
...
const uint8_t SCI_AICTRL3 = 0x0F;
const uint8_t SCI_STATUS = 0x01;

So now I can check the real audio level, with stream.getVuMeter(). When nothing plays, return values are 0, when streaming music the average is 70-90. Pauses between tracks, maybe as low as 6.

A while back I added _vs1053->switchToMp3Mode(); in various spots, as I thought that was good for... yes for what, Since that also removes the loaded patches, I had no Vu meter functionality. So I had removed all those calls, and today it doesn't seem to cause new undesireable behviour, so it was probably a silly move of me to put those in, in the first place. Oh well ;-)

Cheers,
Frank

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions