Hi again

Here is a very interesting conversation I have just had with fritsch on kodi-dev:

Will keep you posted...
Oliver

<lich000king> Hi all
<lich000king> I try again with my question from a few days ago. Here is the 'default' output of aplay -l and aplay -L respectively:
<lich000king> https://pastebin.com/auz08kXj
<lich000king> The hifiberry shows up in kodi's audio devices and works flawlessly.
<lich000king> Now, if I build kodi with snd_aloop turned on in the linux kernel, it looks as follows:
<lich000king> https://pastebin.com/mCeHDyah
<lich000king> However, now I don't see the hifiberry anymore in kodi gui
<lich000king> Now it looks like this:
<lich000king> 1 PI: HDMI
<lich000king> 2 PI: Analogue
<lich000king> 3 PI: HDMI and Analogue
<lich000king> 4 ALSA: Loopback (@CARD=Loopback,DEV=0), LoopbackPCM
<lich000king> 5 ALSA: Loopback (surround21:CARD=Loopback,DEV=0), Loopback PCM
<lich000king> So the Hifiberry is gone, and not all aloop devices show up.
<lich000king> Furthermore the ones I can select don't work properly. I.e. sound is played through the hifiberry DAC+ instead of the loopback device.
<lich000king> The loopback device is working correctly outside of kodi.
<TeamKodi> [fritsch] We don't support loopback devices
<lich000king> So it appears something is going wrong with the population of the audio devices list within kodi as well as with the use of these devices when snd_aloop is turned on.
<TeamKodi> [fritsch] if you want to hack in support for it, check AESinkALSA.cpp
<TeamKodi> [fritsch] here we filter back and forth
<lich000king> Ah, it's as expected then.
<TeamKodi> [fritsch] depending on which distribution you run on your PI special patches might play a role
<TeamKodi> [fritsch] which we don't have control at all
<TeamKodi> [fritsch] so which distribution is it?
<lich000king> OpenADK
<TeamKodi> [fritsch] hehe, the biggest combination from "not supported"
<TeamKodi> [fritsch] hehe
<lich000king> Hm kodi is working rather well on it;-)
<TeamKodi> [fritsch] and which kodi version they build?
<TeamKodi> [fritsch] that's the interesting part.
<TeamKodi> [fritsch] btw. what happens if you do:
<TeamKodi> [fritsch] AE_SINK=ALSA kodi
<TeamKodi> [fritsch] and start kodi with that
<TeamKodi> [fritsch] which devices do you get now?
<TeamKodi> [fritsch] (if you use kodi from today, it's KODI_AE_SINK=ALSA)
<lich000king> 17.6
<TeamKodi> [fritsch] from our git?
<TeamKodi> [fritsch] or something patched around?
<lich000king> https://cgit.openadk.org/cgi/cgit/openadk.git/tree/package/kodi/Makefile
<lich000king> PKG_SITES:=  https://github.com/xbmc/xbmc/archive/
<TeamKodi> [fritsch] cool - vanilla
<TeamKodi> [fritsch] AE_SINK=ALSA kodi
<TeamKodi> [fritsch] what happens now?
* z1haze has quit (Ping timeout: 255 seconds)
<lich000king> err, don't get it to start this way
<TeamKodi> [fritsch] how do you start it?
<TeamKodi> [fritsch] systemd? then export AE_SINK=ALSA
<TeamKodi> [fritsch] and then post kodi's log
<lich000king> I start it as follows:
<lich000king> $ /etc/init.d/kodi start
<lich000king> where
<lich000king> https://pastebin.com/NTY6Z9Gu
<TeamKodi> [fritsch] LD_PRELOAD < can your remove the LD_PRELOAD=?
<lich000king> sure, will try right ahead
<TeamKodi> [fritsch] but I think kodi won't work anymore for you
<TeamKodi> [fritsch] they use it to overrule certain calls
<TeamKodi> [fritsch] never the less in this line: LD_PRELOAD=whatever AE_SINK=ALSA /path/to/kodi
<lich000king> Yeah, that's what I have just tried
<lich000king> but it did not change the device list
<TeamKodi> [fritsch] please post the kodi.log
<TeamKodi> [fritsch] I want to see what it enumerates
<lich000king> https://pastebin.com/SjSKA3f1
<lich000king> This is now with AE_SINK but without LD_PRELOAD. Makes no difference for the list of devices
<TeamKodi> [fritsch] jep, it did not work#
<TeamKodi> [fritsch] need to check something
<TeamKodi> [fritsch] Start to debug in AESinkALSA.cpp EnumerateDevicesEx method
<TeamKodi> [fritsch] I did not find why it would skip everything after having 5 devices in sum
<lich000king> Hm, ok. Will take a look at this then.
<TeamKodi> [fritsch] I also cannot remember having coded in this limit :p
<lich000king> Haha
<TeamKodi> [fritsch] you could stop kodi from your initd script and start it like:
<TeamKodi> [fritsch] AE_SINK=ALSA /path/to/kodi
<TeamKodi> [fritsch] that way only ALSA sinks should be enumerated
<TeamKodi> [fritsch] curious if you get different ones
<TeamKodi> [fritsch] I am off for the day -> champions league :)
<TeamKodi> [fritsch] bye and good luck
<lich000king> Ok, have fun!
<lich000king> Thanks!



Am Sonntag, 11. März 2018, 19:01:11 MEZ hat Oliver Schib <lich000king@yahoo.de> Folgendes geschrieben:


Hi everyone

In the last few weeks I have tried getting brutefir to work with kodi in openadk. My goal is to get room correction with kodi on my pi2. :-)

While it is quite simple to use the brutefir convolution engine with mpd through jack, this does not work so easily in kodi, since kodi does not support jack. At least there is no official support as far as I'm aware.

Now one possibility would be to try and implement jack support in kodi which I think would be rather hard, or maybe see if someone else has done something that could be used.

However, there seems to be an easier way. For alsa there is a loopback driver called 'aloop' available in the linux kernel. Basically it simply adds a 'virtual loopback cable' device. This means the audio you play through this device will be available for capture in another device. You can find more on it here:
So the idea is straight-forward: Set up kodi to play through this loopback device instead of the speakers, use the other end as input for brutefir, filter the audio and have brutefir output to the speakers.

I tried it out, and I think I'm close to having it work. If you are interested, here is a proof of concept:
- build adk with e.g. convolution, kodi and ADK_LINUX_KERNEL_SND_ALOOP.
- start brutefir:
$ brutefir -nodefault config.conf
where config.conf is the attached brutefir cofig file.
- play an audio file:
$ audio.wav -Dhw:0
On my pi2 with a hifiberry DAC+ installed this will play the brutefir-filtered audio through the hifiberry. If you don't have one, you may need to modify the config file.

Now I don't quite have it working with kodi yet.
With SND_ALOOP enabled, kodi's audio settings show 5 devices:
1 PI: HDMI
2 PI: Analogue
3 PI: HDMI and Analogue
4 ALSA: Loopback (@CARD=Loopback,DEV=0), LoopbackPCM
5 ALSA: Loopback (surround21:CARD=Loopback,DEV=0), Loopback PCM

Note that the hifiberry (which works fine in kodi without aloop) is missing here. Why is that? Something seems not quite right.
Also, when I select number 4 from the above, audio will be played through the berry even when brutefir is not running. And it is playing at full volume, ignoring kodi's volume setting, which does not sound nice at all.
So something is clearly no ok yet.
I do not have an asound file at this point (I think none should be needed?)
Does anyone have an idea what I'm missing?

Thanks for any ideas
All the best
Oliver

P.S.
Here are some aplay/arecord outputs for reference:

$ aplay -l
**** List of PLAYBACK Hardware Devices ****
card 0: Loopback [Loopback], device 0: Loopback PCM [Loopback PCM]
  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: Loopback [Loopback], device 1: Loopback PCM [Loopback PCM]
  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 1: sndrpihifiberry [snd_rpi_hifiberry_dacplus], device 0: HiFiBerry DAC+ HiFi pcm512x-hifi-0 []
  Subdevices: 1/1
  Subdevice #0: subdevice #0

$ aplay -L                                            
null
    Discard all samples (playback) or generate zero samples (capture)
default:CARD=Loopback
    Loopback, Loopback PCM
    Default Audio Device
sysdefault:CARD=Loopback
    Loopback, Loopback PCM
    Default Audio Device
front:CARD=Loopback,DEV=0
    Loopback, Loopback PCM
    Front speakers
surround21:CARD=Loopback,DEV=0
    Loopback, Loopback PCM
    2.1 Surround output to Front and Subwoofer speakers
surround40:CARD=Loopback,DEV=0
    Loopback, Loopback PCM
    4.0 Surround output to Front and Rear speakers
surround41:CARD=Loopback,DEV=0
    Loopback, Loopback PCM
    4.1 Surround output to Front, Rear and Subwoofer speakers
surround50:CARD=Loopback,DEV=0
    Loopback, Loopback PCM
    5.0 Surround output to Front, Center and Rear speakers
surround51:CARD=Loopback,DEV=0
    Loopback, Loopback PCM
    5.1 Surround output to Front, Center, Rear and Subwoofer speakers
surround71:CARD=Loopback,DEV=0
    Loopback, Loopback PCM
    7.1 Surround output to Front, Center, Side, Rear and Woofer speakers
default:CARD=sndrpihifiberry
    snd_rpi_hifiberry_dacplus,
    Default Audio Device
sysdefault:CARD=sndrpihifiberry
    snd_rpi_hifiberry_dacplus,
    Default Audio Device

$ arecord -l
**** List of CAPTURE Hardware Devices ****
card 0: Loopback [Loopback], device 0: Loopback PCM [Loopback PCM]
  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: Loopback [Loopback], device 1: Loopback PCM [Loopback PCM]
  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

$ arecord -L                                          
null
    Discard all samples (playback) or generate zero samples (capture)
default:CARD=Loopback
    Loopback, Loopback PCM
    Default Audio Device
sysdefault:CARD=Loopback
    Loopback, Loopback PCM
    Default Audio Device
front:CARD=Loopback,DEV=0
    Loopback, Loopback PCM
    Front speakers
surround21:CARD=Loopback,DEV=0
    Loopback, Loopback PCM
    2.1 Surround output to Front and Subwoofer speakers
surround40:CARD=Loopback,DEV=0
    Loopback, Loopback PCM
    4.0 Surround output to Front and Rear speakers
surround41:CARD=Loopback,DEV=0
    Loopback, Loopback PCM
    4.1 Surround output to Front, Rear and Subwoofer speakers
surround50:CARD=Loopback,DEV=0
    Loopback, Loopback PCM
    5.0 Surround output to Front, Center and Rear speakers
surround51:CARD=Loopback,DEV=0
    Loopback, Loopback PCM
    5.1 Surround output to Front, Center, Rear and Subwoofer speakers
surround71:CARD=Loopback,DEV=0
    Loopback, Loopback PCM
    7.1 Surround output to Front, Center, Side, Rear and Woofer speakers