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:
https://alsa.opensrc.org/Jack_and_Loopback_device_as_Alsa-to-Jack_bridge
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