GithubHelp home page GithubHelp logo

pimoroni / pivumeter Goto Github PK

View Code? Open in Web Editor NEW
59.0 18.0 22.0 189 KB

ALSA plugin for displaying VU meters on various Raspberry Pi add-ons - derived from ameter

License: GNU General Public License v3.0

Makefile 0.08% M4 0.15% Shell 89.36% C 10.41%
vu-meter alsa-plugin alsa fftw

pivumeter's People

Contributors

ali1234 avatar gadgetoid avatar nicholas-gh avatar nicokaiser avatar roguem avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

pivumeter's Issues

Segmentation Fault in get_channel_level accessing data at channel buffer pointer - Raspbian Stretch

This issue seems either revealed by, or exacerbated by Raspbian Stretch and does not appear in Jessie either at all, or often enough to be reported widely.

VLC will play for 1-2 minutes before crashing with the below segfault, caused by Pi VU Meter.

Removing Pi VU Meter from the equation appears to fix the problem, although testing to confirm whether there is another issue is ongoing since VLC could be crashing and taking Pi VU Meter with it.

Relevant code:

pivumeter/src/pivumeter.c

Lines 96 to 135 in 8bddc3e

static int get_channel_level(int channel, snd_pcm_scope_ameter_t *level, snd_pcm_uframes_t offset, snd_pcm_uframes_t size1, snd_pcm_uframes_t size2,
int max_decay, int max_decay_temp){
int16_t *ptr;
int s, lev = 0;
snd_pcm_uframes_t n;
snd_pcm_scope_ameter_channel_t *l;
l = &level->channels[channel];
// Iterate through the channel buffer and find the highest level value
ptr = snd_pcm_scope_s16_get_channel_buffer(level->s16, channel) + offset;
for (n = size1; n > 0; n--) {
s = *ptr;
if (s < 0) s = -s;
if (s > lev) lev = s;
ptr++;
}
ptr = snd_pcm_scope_s16_get_channel_buffer(level->s16, channel);
for (n = size2; n > 0; n--) {
s = *ptr;
if (s < 0) s = -s;
if (s > lev) lev = s;
ptr++;
}
/* limit the decay */
if (lev < l->levelchan) {
/* make max_decay go lower with level */
max_decay_temp = max_decay / (32767 / (l->levelchan));
lev = l->levelchan - max_decay_temp;
max_decay_temp = max_decay;
}
l->levelchan = lev;
l->previous =lev;
return lev;
}

Thread 8 "vlc" received signal SIGSEGV, Segmentation fault.
[Switching to Thread 0xb363d380 (LWP 1202)]
get_channel_level (channel=channel@entry=0, offset=offset@entry=18816, size1=size1@entry=46720, size2=1063584424, size2@entry=3060062160, max_decay=max_decay@entry=3787718,
    max_decay_temp=<optimized out>, level=<optimized out>, level=<optimized out>) at src/pivumeter.c:116
116             s = *ptr;

I have a couple of working theories for this:

  • The meter is threaded, and is attempting to access a buffer that has been destroyed (ie: too slow!)
  • The buffer is being populated with less data than is computed- perhaps because it's VLC that's crashing

Buffer size computation:

    size = snd_pcm_meter_get_now(pcm) - level->old;
    if (size < 0){
        size += snd_pcm_meter_get_boundary(pcm);
    }

    offset = level->old % snd_pcm_meter_get_bufsize(pcm);
    cont = snd_pcm_meter_get_bufsize(pcm) - offset;
    size1 = size;
    if (size1 > cont){
        size1 = cont;
    }

    size2 = size - size1;

Relevant lines:

pivumeter/src/pivumeter.c

Lines 137 to 180 in 8bddc3e

static void level_update(snd_pcm_scope_t * scope)
{
snd_pcm_scope_ameter_t *level = snd_pcm_scope_get_callback_private(scope);
snd_pcm_t *pcm = level->pcm;
snd_pcm_sframes_t size;
snd_pcm_uframes_t size1, size2;
snd_pcm_uframes_t offset, cont;
unsigned int channels;
unsigned int ms;
int max_decay, max_decay_temp;
int meter_level_l = 0;
int meter_level_r = 0;
size = snd_pcm_meter_get_now(pcm) - level->old;
if (size < 0){
size += snd_pcm_meter_get_boundary(pcm);
}
offset = level->old % snd_pcm_meter_get_bufsize(pcm);
cont = snd_pcm_meter_get_bufsize(pcm) - offset;
size1 = size;
if (size1 > cont){
size1 = cont;
}
size2 = size - size1;
ms = size * 1000 / snd_pcm_meter_get_rate(pcm);
max_decay = 32768 * ms / level->decay_ms;
channels = snd_pcm_meter_get_channels(pcm);
if(channels > 2){channels = 2;}
meter_level_l = get_channel_level(0, level, offset, size1, size2, max_decay, max_decay_temp);
meter_level_r = meter_level_l;
if(channels > 1){
meter_level_r = get_channel_level(1, level, offset, size1, size2, max_decay, max_decay_temp);
}
output_device.update(meter_level_l, meter_level_r, level);
level->old = snd_pcm_meter_get_now(pcm);
}

How to use pivumeter alongside the python phatbeat library?

When I try to use the phatbeat python library by setting some pixels (as documented here http://docs.pimoroni.com/phatbeat/) while playing music with pivumeter installed on my phatbeat, I can only see some random pixels (even when I set only 1 pixel) briefly flashing.
I can send the exact same command several times and witness how different random pixels flash briefly.
Even when using the VLC project. The play / pause button has the clear function used (https://github.com/pimoroni/phat-beat/blob/master/projects/vlc-radio/phatbeatd/usr/bin/phatbeatd). When I play pause I can see how the vumeter disappear and also a random flash of some random colours appear, at pause, and play.

I have to stop the pulseaudio.service in order to shutdown pivumeter before I can use the phatbeat python library as expected.

I would really like to keep the vumeter going and also at the same time insert some other user interfaces through the use of the LEDs with the python library.
Is that possible?
Can I use pivumter only on 1 LED channel and free the other channel of the phatbeat to use with the python library?

Thanks!

Not working with Raspotify and blinkt

Following a brief discussion with sandy on discord...

Trying to get this to work with a blinkt playing music over spotify. Installed fine, but LEDs wont light up

running aplay -L gives:

null
    Discard all samples (playback) or generate zero samples (capture)
default
pivumeter
softvol_and_pivumeter
sysdefault:CARD=sndrpihifiberry
    snd_rpi_hifiberry_dac,
    Default Audio Device
dmix:CARD=sndrpihifiberry,DEV=0
    snd_rpi_hifiberry_dac,
    Direct sample mixing device
dsnoop:CARD=sndrpihifiberry,DEV=0
    snd_rpi_hifiberry_dac,
    Direct sample snooping device
hw:CARD=sndrpihifiberry,DEV=0
    snd_rpi_hifiberry_dac,
    Direct hardware device without any conversions
plughw:CARD=sndrpihifiberry,DEV=0
    snd_rpi_hifiberry_dac,
    Hardware device with all software conversions```

Use with volumio

Hey, I have the great volumio system running on my pi Zero. But I can't get the alsa settings to work right.

The sound plays but the LED are not showing any reaction.

The original asound.conf looks like this:

pcm.softvolume {                                                                         
    type             plug                                                                
    slave.pcm       "softvol"                                                            
}                                                                                        
                                                                                         
pcm.softvol {                                                                            
    type            softvol                                                              
    slave {                                                                              
        pcm         "plughw:1,0"                                                         
    }                                                                                    
    control {                                                                            
        name        "SoftMaster"                                                         
        card        1                                                                    
        device      0                                                                    
    }                                                                                    
max_dB 0.0                                                                               
min_dB -50.0                                                                             
resolution 100                                                                           
}                   

How can I change this to use the LED's?

Support for X ( please read if you want support for a new device )

C-specific modes for Pi VU Meter are considered EOL- there wont be any new device support built-in. However, the library is still transitioning to a socket based method of communication where a Python script will be responsible for displaying VU data on the output device.

Currently the following output devices have been requested. I'm keen to see Python implementations of these submitted to this repository once #15 is merged, but I wont necessarily have the time to do these myself.

  • #13 - Support for generic SN3218 (such as piglow)
  • #12 - support i2c lcd display (16x2 or parametric)
  • #11 - How about support for the Unicorn pHat?
  • #9 - (support for) DOT hat bargraph

For the time being, if you have a request please post it below. Thank you!

Won't work

Hey guys,
It might well be my own fault, but I can't get it to work with my pi3 and scrollphat. I installed according to instructions and copy/pasted your example asound.conf but edited to add scrollphat as output. Nothing happening when playing different audio. Do I need to do something else to the asound.conf? I have no soundcard attached. Cheers.

Locks up audio stream

I'm running the lastest Raspbian Jessie/PIXEL build with all updates on a Raspberry Pi 3 with a BLINKT! attached. I compiled pivumeter and ran setup.sh which seems to have installed properly. I'm running headless, so I've only tried pianobar and mpg123 so far. Both will occasionally light up one LED on the BLINKT!, however the audio stream freezes and I have to hard-kill the audio player apps. I've tried with HDMI attached and without, and with audio output manually set to HDMI and headphone port. In all cases, the results are the same.

Removing asound.conf allows audio to play just fine, however, the BLINKT! is obviously not doing anything at that point.

Welcome to pianobar (2014.06.08)! Press ? for a list of commands.
(i) Login... Ok.
(i) Get stations... Ok.
0) q 1200 Micrograms Radio
1) 80s Pop Radio
2) q Armin Van Buuren Radio
3) Binary Finary Radio
[ ... ]
[?] Select station: 2
|> Station "Armin Van Buuren Radio" (2034637540235068767)
(i) Receiving new playlist... Ok.
|> "Bright Morningstar" by "Tiesto" on "Elements Of Life"
ALSA lib pcm.c:2239:(snd_pcm_open_noupdate) Unknown PCM cards.pcm.front
Using device: blinkt
-08:19/08:19

And that's all I get. The timer doesn't move, and I get no audio.

pivumeter and dmixer do not work together

I am looking for a way to use pivumeter with a pHAT DAC. This works fine, however only with one single sound source.

Since the pHAT DAC (just like the HiFiBerry) does not have a hardware mixer, I need to use the ALSA ´dmix` plugin, which also works fine per se.

Now when I try to combine both, I struggle. Since I cannot set a non-hardware device as slave for dmix I need to route the output through pivumeter first and the to dmixer:

pcm.!default {
        type plug
        slave.pcm "softvol_and_pivumeter"
}

ctl.!default {
        type hw
        card 0
}

pcm.pivumeter {
        type meter
        #slave.pcm "hw:0,0"
        slave.pcm "dmixer"
        scopes.0 pivumeter
}

pcm.softvol_and_pivumeter {
        type softvol
        slave.pcm "pivumeter"
        control {
                name "PCM"
                card 0
        }
}

pcm_scope.pivumeter {
        type pivumeter
        decay_ms 500
        peak_ms 400
        brightness 128
        output_device phat-beat
}

pcm_scope_type.pivumeter {
        lib /usr/local/lib/libpivumeter.so
}

pcm.dsp0 pivumeter

pcm.dmixer {
        type dmix
        ipc_key 1024
        ipc_key_add_uid false
        ipc_perm 0666
        slave {
                pcm "hw:0,0"
                period_time 0
                period_size 1024
                buffer_size 8192
                #rate 44100
                #format S16_LE
        }
        bindings {
                0 0
                1 1
        }
}

But with this config, there is no pivumeter output. Do you have an idea on how to solve this?

Segmentation Fault in get_channel_level

Well, my problem looks identical to the issue in #16 but since I am already using the asound.conf file listed there (which removes dmix), I'm not sure how best to proceed.

I have a Pimoroni Pirate Radio, with Raspian Buster installed (Linux raspberrypi 5.10.63+ #1457). I'm running "pianobar" (version 2020.11.28) which lets me use it to stream Pandora radio. Pianobar segfaults after a couple of minutes. I got a core dump, and the backtrace looks identical to the one in issue #16:

(gdb) backtrace
#0  get_channel_level (channel=0, offset=<optimized out>, size1=53960, size2=1853429792,
    max_decay=3496476, max_decay_temp=<optimized out>, level=<optimized out>,
    level=<optimized out>) at src/pivumeter.c:116
#1  0xadd06494 in level_update (scope=<optimized out>) at src/pivumeter.c:171
#2  0xaf105efc in ?? () from /lib/arm-linux-gnueabihf/libasound.so.2

So I disabled pivumeter (just by renaming the asound.conf file, since I don't know the right way to disable it), and pianobar doesn't crash now. Any ideas on how to keep pivumeter from seg faulting?

pHat DAC option...

This is more of a request/inquiry, can this VU meter be used with the pHat DAC board?

That would make an awesome combo.

Support for generic SN3218 (such as piglow)

I plan to add support for both piglow (https://shop.pimoroni.com/products/piglow) and ws2812b based LED strips. For the piglow, I thought maybe almost nothing is needed, since the README.md (https://github.com/pimoroni/pivumeter/blob/8bddc3e94d996bf745d43a854793ca70b7bda12f/README.md#output_device) mentions:

default (18-segment VU driven by SN3218)

However, I don't find any such support (for example, https://github.com/pimoroni/pivumeter/blob/8bddc3e94d996bf745d43a854793ca70b7bda12f/src/pivumeter.c doesn't allow 'default' as a valid output device type, and grep for sn3218 finds nothing). I've looked through history to see if support was removed, but I don't find that happening.

Is the mention in the README.md a plan that didn't happen yet, or do I miss some option/flag?

Thank you!

wiringpi is deprecated and not in the bullseye repos

I used the airdac installer script from Pimoroni with a Pirate Radio kit and saw this during the installation:

wiringpi is required                                                                                                                                                                                                 
Installing wiringpi...                                                                                                                                                                                               
E: Unable to locate package wiringpi                                                                      
Apt failed to install wiringpi!                 
Falling back on pypi... 

And later during the configuration of pivumeter:

checking for wiringPiSetup in -lwiringPi... no
configure: error: You need libwiringPi installed

Installing Pi VU Meter...
make: *** No rule to make target 'install'.  Stop.

All done!

Seems like wiringPi needs to be replaced (or compiled separately).

pivumeter server - only 0 values?

I'm trying to do something with server from devel branch, but all I get are 0 values for right and left.

Enviroment: raspbian jessie on Pi Zero W (no DAC or sound card)

What have I done:
cloned devel branch, run 'setup.sh socket'

created sample file in pivumeter/python_server/library/ (also - I don't know how to install pivumeter module to use it 'normally')

#!/usr/bin/env python
import pivumeter
import signal

class OutputBlinkt(pivumeter.OutputDevice):
    def setup(self):
        print 'setup'

    def display_fft(self, bins):
        pass

    def display_vu(self, left, right):
        print left, right

    def cleanup(self):
        print 'cleanup'
        self.display_vu(0, 0)

pivumeter.run(OutputBlinkt)
signal.pause()

When I play something using shairport-sync or run speaker-test I get only 0 0 values in console

Question - what have I done wrong?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.