antiprism / mpd_oled

MPD, Volumio, RuneAudio and Moode OLED status and spectrum display for Raspberry Pi (and similar)
Other
168 stars 45 forks source link

New feature implemented: disable equaliser when paused #49

Closed supercrab closed 3 years ago

supercrab commented 3 years ago

Hi Adrian,

I've implemented a new feature whereby you can disable the equaliser when the player is paused with the -e parameter This is useful if you're using the mic input as the audio source of the equaliser with -c alsa,hw:5,0 When the player is paused, CAVA takes the noise from the input and slowly normalises the data so that it fits the entire graph, even though there is nothing playing. I simply clear the array that holds the spectrum data when the player is paused.

Main.cpp attached:

main.cpp.txt

antiprism commented 3 years ago

Hi Mase

Thanks for the changes. I don't think it needs an option, the spectrum display could just be disabled when the player isn't playing. Could you check the following code works for you

int num_bars_read = 0;
    if(select(FD_SETSIZE, &set, NULL, NULL, &timeout) > 0)
      num_bars_read = fread(&disp_info.spect.heights[0], sizeof(unsigned char),
          disp_info.spect.heights.size(), fifo_file);

    if(num_bars_read == 0 || disp_info.status.get_state() != MPD_STATE_PLAY) {
      std::fill(disp_info.spect.heights.begin(), disp_info.spect.heights.end(),
          0);
      usleep(0.1 * 1000000);  // 0.1 sec delay, don't idle too fast if no need
    }

Could you also test the following code please. It is to stop the spectrum lagging behing the audio, and also that the spectrum is sometimes "shift-rotated" so the bass bars are in the middle of the spectrum. It should also help clear the microphone data when you start playing audio, if that is an issue.

    int num_bars_read = 0;
    if(select(FD_SETSIZE, &set, NULL, NULL, &timeout) > 0) {
      do {
        num_bars_read = fread(&disp_info.spect.heights[0], sizeof(unsigned char),
          disp_info.spect.heights.size(), fifo_file);

        FD_ZERO(&set);
        FD_SET(fifo_fd, &set);
        timeout.tv_sec = 0;
        timeout.tv_usec = 0;
      } while (select(FD_SETSIZE, &set, NULL, NULL, &timeout) > 0);
    }

    if(num_bars_read == 0 || disp_info.status.get_state() != MPD_STATE_PLAY) {
      std::fill(disp_info.spect.heights.begin(), disp_info.spect.heights.end(),
          0);
      usleep(0.1 * 1000000);  // 0.1 sec delay, don't idle too fast if no need
    }

Adrian.

supercrab commented 3 years ago

Yes, you're right - having a parameter for it seems silly now. It definitely makes more sense to just disable the equaliser when the music is not playing.

Just tested and it all works fine :)

Mase

antiprism commented 3 years ago

Great. I'll add that in!

Adrian.