bmc0 / dsp

An audio processing program with an interactive mode.
ISC License
219 stars 31 forks source link

Working with MPD #35

Closed arjunmenon closed 6 years ago

arjunmenon commented 6 years ago

Hey I have MPD installed in Rpi via upmpdcli. ALSA is default.

DSP is not running with MPD

There are no changes to the config, everything is default. The Pi itself has the audio routed to the default jack.

pi@raspberrypi:~ $ aplay -l
**** List of PLAYBACK Hardware Devices ****
card 0: ALSA [bcm2835 ALSA], device 0: bcm2835 ALSA [bcm2835 ALSA]
  Subdevices: 8/8
  Subdevice #0: subdevice #0
  Subdevice #1: subdevice #1
  Subdevice #2: subdevice #2
  Subdevice #3: subdevice #3
  Subdevice #4: subdevice #4
  Subdevice #5: subdevice #5
  Subdevice #6: subdevice #6
  Subdevice #7: subdevice #7
card 0: ALSA [bcm2835 ALSA], device 1: bcm2835 ALSA [bcm2835 IEC958/HDMI]
  Subdevices: 1/1
  Subdevice #0: subdevice #0

pi@raspberrypi:~ $ cat /proc/asound/cards
 0 [ALSA           ]: bcm2835 - bcm2835 ALSA
                      bcm2835 ALSA

This is the output for the configure file for dsp _(by default, why does it say disabled ladspa_host.o )_

pi@raspberrypi:~/dsp $ ./configure --disable-ffmpeg
enabled dsp
[dsp] enabled gpl code (reverb.o g2reverb.o)
[dsp] disabled ladspa_host.o
[dsp] enabled sndfile.o (sndfile)
[dsp] disabled ffmpeg.o (libavcodec libavformat libavutil)
[dsp] enabled resample.o fir.o (fftw3)
[dsp] enabled zita_convolver.o
[dsp] enabled alsa.o (alsa)
[dsp] enabled ao.o (ao)
[dsp] enabled mp3.o (mad)
[dsp] disabled pulse.o (libpulse-simple)
enabled ladspa_dsp
[ladspa_dsp] enabled gpl code (reverb.o g2reverb.o)
[ladspa_dsp] disabled ladspa_host.o
[ladspa_dsp] enabled fir.o (fftw3)
[ladspa_dsp] enabled zita_convolver.o
[ladspa_dsp] enabled sndfile.o (sndfile)

I searched for LADSPA with ASLA for Pi I followed this - https://www.raspberrypi.org/forums/viewtopic.php?t=46997 But with no luck. In the end of the post it says to comment two lines in /usr/share/alsa/alsa.conf if Pulse and Alsa are installed both, I tried it anyway,

Before commenting I got error with aplay

pi@raspberrypi:~ $ aplay music_test/test_track.mp3 
Playing raw data 'music_test/test_track.mp3' : Unsigned 8 bit, Rate 8000 Hz, Mono
ladspa_dsp: g2reverb: error: number of input channels must be 2
ladspa_dsp: error: failed to initialize effect: g2reverb
ALSA lib pcm_ladspa.c:643:(snd_pcm_ladspa_allocate_instances) Unable to create instance of LADSPA plugin 'ladspa_dsp'
aplay: set_params:1297: Unable to install hw params:
ACCESS:  RW_INTERLEAVED
FORMAT:  U8
SUBFORMAT:  STD
SAMPLE_BITS: 8
FRAME_BITS: 8
CHANNELS: 1
RATE: 8000
PERIOD_TIME: 125000
PERIOD_SIZE: 1000
PERIOD_BYTES: 1000
PERIODS: 4
BUFFER_TIME: 500000
BUFFER_SIZE: 4000
BUFFER_BYTES: 4000
TICK_TIME: 0

After commenting, I just heard noise. No errors. Just noise.

In $HOME/.config/ladspa_dsp/config

# effects_chain=gain -3.0 lowshelf 90 0.9s +3.0
effects_chain=gain 2.0 g2reverb -w 200 15 0.1 0.9 -10 -10 -10

Now this effect_chain worked perfectly while testing through the CLI

pi@raspberrypi:~ $ dsp music_test/test_track.mp3 gain 2.0 g2reverb -w 200 15 0.1 0.9 -10 -10 -10
dsp: output: default; type=alsa enc=s16 precision=16 channels=2 fs=44100 frames=12489984 [00:04:43.22]
dsp: info: running interactively; type 'h' for help
dsp: input: music_test/test_track.mp3; type=mp3 enc=mad_f precision=24 channels=2 fs=44100 frames=12489984 [00:04:43.22]
>  21.6%  00:01:01.31  -00:03:41.91  peak:1.89dBFS  clip:456  
dsp: info: signal 2: terminating...
dsp: warning: clipped 508 samples (1.89dBFS peak)
  1. What is goiong wrong?
  2. How can I play the tracks using UPNP/MPD to utilize the dsp effects?

Running on RPI 3 jessie version 8 kernel 4.9.35-v7+


EDIT - I also tried this effects chain in the config effects_chain=gain -30.0 lowshelf 90 0.9s +3.0

It still didnt work. The dsp device is loaded though

pi@raspberrypi:~ $ aplay -L
null
    Discard all samples (playback) or generate zero samples (capture)
dsp
default
sysdefault:CARD=ALSA
    bcm2835 ALSA, bcm2835 ALSA
    Default Audio Device
dmix:CARD=ALSA,DEV=0
    bcm2835 ALSA, bcm2835 ALSA
    Direct sample mixing device
dmix:CARD=ALSA,DEV=1
    bcm2835 ALSA, bcm2835 IEC958/HDMI
    Direct sample mixing device
dsnoop:CARD=ALSA,DEV=0
    bcm2835 ALSA, bcm2835 ALSA
    Direct sample snooping device
dsnoop:CARD=ALSA,DEV=1
    bcm2835 ALSA, bcm2835 IEC958/HDMI
    Direct sample snooping device
hw:CARD=ALSA,DEV=0
    bcm2835 ALSA, bcm2835 ALSA
    Direct hardware device without any conversions
hw:CARD=ALSA,DEV=1
    bcm2835 ALSA, bcm2835 IEC958/HDMI
    Direct hardware device without any conversions
plughw:CARD=ALSA,DEV=0
    bcm2835 ALSA, bcm2835 ALSA
    Hardware device with all software conversions
plughw:CARD=ALSA,DEV=1
    bcm2835 ALSA, bcm2835 IEC958/HDMI
    Hardware device with all software conversions

And doing mpg321 -a dsp music_test/test_track.mp3 plays the file with extremely low volume.

But the problem still remains, MPD output is ignoring the alsa config and playing unfiltered through the default audio jack.

bmc0 commented 6 years ago

Could you post your .asoundrc? What user is MPD running as? If MPD isn't running as pi, it won't find your .asoundrc.

aplay music_test/test_track.mp3

aplay can't decode MP3s, so it just plays them as raw data.

effects_chain=gain 2.0 g2reverb -w 200 15 0.1 0.9 -10 -10 -10

g2reverb requires a stereo input, so you have to set input_channels=2 and output_channels=2 in the ladspa_dsp config. You should also modify your .asoundrc. See the README for more info.

why does it say disabled ladspa_host.o

The ladspa_host effect requires libltdl. If you don't plan on loading LADSPA effects with dsp or ladspa_dsp, you don't need to worry about this.

arjunmenon commented 6 years ago

Hey Thanks for pointing out the channels for g2reverb.

I got it working now by removing the user specific configs for DSP and ALSA. I set them both to global defaults.

/etc/asound.conf

pcm.dsp {
        type plug
        slave {
                format FLOAT
                rate unchanged
                channels unchanged
                pcm {
                        type ladspa
                        path "/usr/lib/ladspa"
                        playback_plugins [{
                                label "ladspa_dsp"
                        }]
                        slave.pcm {
                                type plug
                                slave {
                                        pcm "hw:0,0"
                                        rate unchanged
                                        channels unchanged
                                }
                        }
                }
        }
}

pcm.!default {
        type copy
        slave.pcm "dsp"
}

I had to also remove any sound card settings in the MPD config as well. This was crashing the aplay with seg fault.

It works nice now, thanks!


The ladspa_host effect requires libltdl. If you don't plan on loading LADSPA effects with dsp or ladspa_dsp, you don't need to worry about this.

This was not the case when I had installed the module a while back. Is this a recent change?

In an earlier post you had suggested to use a LADSPA plugin for range compression, (though I am interested in room correction). I would like to try VLevel. This installs the plugin as a shared object file in /usr/local/lib/ladspa/vlevel-ladspa.so

I would have to simply link it like this? effects_chain=gain -3.0 ladspa_host /usr/local/lib/ladspa/vlevel-ladspa.so VLevel --length 88200 --max-multiplier 15

_I also like to know about zitaconvolver effects, but I will open a new thread, since this is not related to it.

bmc0 commented 6 years ago

Is this a recent change?

Not really. I added the ladspa_host effect in September of last year. It has always required libltdl.

I would have to simply link it like this?

Not quite. You can use the analyseplugin program to find the plugin labels and control ports. Looking at the code, I can see that the plugin provides two effects: vlevel_mono and vlevel_stereo. You probably want to use vlevel_stereo so you don't get a weird panning effect if the two channels have unequal volumes. The controls are given as numeric values in the order they appear, so you would load the effect like this:

ladspa_host /usr/local/lib/ladspa/vlevel-ladspa.so vlevel_stereo <Look-ahead (seconds)> <Strength> <Use Maximum Multiplier> <Maximum Multiplier> <Undo>

For the parameters you gave in your example, you'd invoke it like this:

ladspa_host /usr/local/lib/ladspa/vlevel-ladspa.so vlevel_stereo 2 0.8 - 15 -

- selects the default value. You can verify the values by running dsp or ladspa_dsp in verbose mode. Be sure to set the number of channels properly.

bmc0 commented 6 years ago

By the way, I just pushed a commit to add /usr/local/lib/ladspa to the default search path in the ladspa_host effect, so you don't have to give the full path anymore:

ladspa_host vlevel-ladspa vlevel_stereo 2 0.8 - 15 -
arjunmenon commented 6 years ago

Nice, ;)