democloid / picoTracker

BSD 3-Clause "New" or "Revised" License
187 stars 17 forks source link

Add a VU meter #182

Open maks opened 3 months ago

maks commented 3 months ago

This adds a VU meter for the the master output, displayed on the far right hand side of the Song, Chain, Phrase and Groove screens (currently no space on the Table screen).

PXL_20240407_080239839 MP_exported_967

Fixes: #42

maks commented 2 months ago

Now rebased onto v2.0 branch

democloid commented 2 months ago

@maks Few observations, let me know what you think:

  1. It seems like we are not sampling all channels, or at least it's not showing correctly. Tardline for example, 3rd line, VU meter seems to follow channel 2 but no (aparent) incidence on sound of channel 4
  2. Meter goes to red pretty often, but I'd expect the max to be coincident to clipping
  3. For chains that do not have any sound, the last output level that was displayed is used rather than 0 (this shows when playing a chain individually for example)
  4. When stopping, VU meter doesn't go to zero, it stays in the last displayed value
maks commented 2 months ago

@democloid hmm the code samples the master audio coming out of the audio driver, not individual channels, you can see the left channel code here. It does only take the peak value per sample period (size of the mixbuffer). I wonder if that could be causing the display to be a bit off? I did think about that perhaps I should be getting the RMS power value which is I think what real VU meters try to show but wasn't sure if that would be too heavy calculation doing it per sample?

With clipping, I didn't think following the existing clipping code:

if (v > f_32767) {
        v = f_32767;
        clipped_ = true;
      } 

but I guess I can change the colour to match that too, what do you think?

With chains, I'm not showing the chains audio, just the master audio out. All the screens only show master mix out at the moment, as there is no infrastructure to get the per channel audio levels at the moment exposed up to the UI layer, it can be done, it just needs to repeat what I did here for the master mix, but I think that should be a separate PR.

For stopping, yes good point! thats a bug because I must not be clearing the last value on stop event, will fix that.

democloid commented 2 months ago

Doing this on a per sample basis may not be the most accurate way of doing this. What is actually being displayed in that case? given that we update the screen at 50Hz and we have 44100Hz sound, what is actually being displayed? probably the last sample measured before rewriting the screen.

When I mention chains, I mean when you play on the chains screen. In that case, the chain audio IS the master audio. My point is that it doesn't seem like samples from other channels are being represented in the master VU meter. i.e if you check the VU meter for channel 4 you see it's oscillating around ~33% when playing that line I mentioned, but when playing all channels together, VU meter goes to zero often. It could be an artifiact of the sampling I mentioned before.