Page 1 of 2

using openmha with HiFiBerry DAC+DSP card

Posted: Tue Sep 10, 2024 10:52 pm
by dpoznan
I have openmha installed on a raspi with audio card HiFiBerry DAC+DSP.

I am using Alsa and have ear pod connect to the audio card jacks, and apple airpods connected via bluetooth.

Running the aplay commands:
aplay -D hw:0,0 Front_Center_stereo.wav
produces output to the ear pods connect to jacks

aplay -D bluealsa:DEV=08:65:18:E8:C9:18,PROFILE=a2dp Front_Center_stereo.wav
produces audio output to the airpods


However I get error in openmha
mhalib = mhachain
srate = 24000
fragsize = 55
iolib = MHAIOalsa
io.in.device = null
io.out.device = "hw:0,0"
cmd=prepare

produces...
ALSA lib pcm.c:2666:(snd_pcm_open_noupdate) Unknown PCM "hw:0,0"
Error: (mha_parser) (mhafw_lib) IO error: (MHAIOalsa) Unable to open device ""hw:0,0"" for playback: No such file or directory


and
mhalib = mhachain
srate = 24000
fragsize = 55
iolib = MHAIOalsa
io.in.device = null
io.out.device = "bluealsa:DEV=08:65:18:E8:C9:18,PROFILE=a2dp"
cmd=prepare


produces...
ALSA lib pcm.c:2666:(snd_pcm_open_noupdate) Unknown PCM "bluealsa:DEV=08:65:18:E8:C9:18,PROFILE=a2dp"
Error: (mha_parser) (mhafw_lib) IO error: (MHAIOalsa) Unable to open device ""bluealsa:DEV=08:65:18:E8:C9:18,PROFILE=a2dp"" for playback: No such file or directory


I have set ~/.asoundrc to the following
pcm.!default {
type plug
slave.pcm {
type bluealsa
device "08:65:18:E8:C9:18"
profile "a2dp"
channels = 2
}
}

ctl.!default {
type bluealsa
}
pcm.airpods {
type plug
slave {
pcm {
type bluealsa
device "08:65:18:E8:C9:18"
profile "a2dp"
}
channels 2
}
}
pcm.bluetooth {
type bluealsa
device "08:65:18:E8:C9:18" # Replace this with your AirPods' MAC address
profile "a2dp"
}
ctl.bluetooth {
type bluealsa
}



How do I determine the proper io.out.device


Suggestions??????


Dan Poznanovic

Re: using openmha with HiFiBerry DAC+DSP card

Posted: Wed Sep 11, 2024 6:03 pm
by tobiasherzke
dpoznan wrote:
Tue Sep 10, 2024 10:52 pm
io.out.device = "hw:0,0"
I would remove the double quotes.

Re: using openmha with HiFiBerry DAC+DSP card

Posted: Wed Sep 11, 2024 6:27 pm
by dpoznan
I changed to to
mhalib = mhachain
srate = 24000
fragsize = 55
iolib = MHAIOalsa
io.in.device = null
io.out.device=hw:0,0
cmd=prepare

and get
(mha_parser) (mhafw_lib) IO error: (MHAIOalsa) Unable to set channel number for hw:0,0: Invalid argument
(while parsing "check_jacks.cfg" line 7)
(MHA:failure)

Re: using openmha with HiFiBerry DAC+DSP card

Posted: Wed Sep 11, 2024 6:31 pm
by dpoznan
Here is what alsa knows.....
pi@hearingpi4:~/DSPcode $ aplay -l
**** List of PLAYBACK Hardware Devices ****
card 0: sndrpihifiberry [snd_rpi_hifiberrydacplusdsp_sou], device 0: Hifiberry DAC+DSP SoundCard HiFi dacplusdsp-hifi-0 [Hifiberry DAC+DSP SoundCard HiFi dacplusdsp-hifi-0]
Subdevices: 1/1
Subdevice #0: subdevice #0
pi@hearingpi4:~/DSPcode $ aplay -L
null
Discard all samples (playback) or generate zero samples (capture)
lavrate
Rate Converter Plugin Using Libav/FFmpeg Library
samplerate
Rate Converter Plugin Using Samplerate Library
speexrate
Rate Converter Plugin Using Speex Resampler
bluealsa
Bluetooth Audio
jack
JACK Audio Connection Kit
oss
Open Sound System
pulse
PulseAudio Sound Server
speex
Plugin using Speex DSP (resample, agc, denoise, echo, dereverb)
upmix
Plugin for channel upmix (4,6,8)
vdownmix
Plugin for channel downmix (stereo) with a simple spacialization
default
Playback/recording through the PulseAudio sound server
airpods
bluetooth
hw:CARD=sndrpihifiberry,DEV=0
snd_rpi_hifiberrydacplusdsp_sou, Hifiberry DAC+DSP SoundCard HiFi dacplusdsp-hifi-0
Direct hardware device without any conversions
plughw:CARD=sndrpihifiberry,DEV=0
snd_rpi_hifiberrydacplusdsp_sou, Hifiberry DAC+DSP SoundCard HiFi dacplusdsp-hifi-0
Hardware device with all software conversions
sysdefault:CARD=sndrpihifiberry
snd_rpi_hifiberrydacplusdsp_sou, Hifiberry DAC+DSP SoundCard HiFi dacplusdsp-hifi-0
Default Audio Device
dmix:CARD=sndrpihifiberry,DEV=0
snd_rpi_hifiberrydacplusdsp_sou, Hifiberry DAC+DSP SoundCard HiFi dacplusdsp-hifi-0
Direct sample mixing device
usbstream:CARD=sndrpihifiberry
snd_rpi_hifiberrydacplusdsp_sou
USB Stream Output
pi@hearingpi4:~/DSPcode $


What is the proper device to use in io.out.device

Re: using openmha with HiFiBerry DAC+DSP card

Posted: Wed Sep 11, 2024 6:39 pm
by tobiasherzke
dpoznan wrote:
Wed Sep 11, 2024 6:27 pm
I changed to to
mhalib = mhachain
srate = 24000
fragsize = 55
iolib = MHAIOalsa
io.in.device = null
io.out.device=hw:0,0
cmd=prepare

and get
(mha_parser) (mhafw_lib) IO error: (MHAIOalsa) Unable to set channel number for hw:0,0: Invalid argument
(while parsing "check_jacks.cfg" line 7)
(MHA:failure)
Progress! Your device could be opened now! It just does not support being configured with one output channel. Try two. As your configuration does not change the number of channels inside MHA, set nchannels_in = 2.

Re: using openmha with HiFiBerry DAC+DSP card

Posted: Wed Sep 11, 2024 8:45 pm
by dpoznan
mhalib = mhachain
srate = 24000
fragsize = 55
iolib = MHAIOalsa
nchannels_in=2
io.in.device = null
io.out.device=hw:0,0
cmd=prepare

Produces...
mha [1] ?read:check_jacks.cfg
xcb_connection_has_error() returned true
(mha_parser) (mhafw_lib) IO error: (MHAIOalsa) Unable to link PCMs: Function not implemented
(while parsing "check_jacks.cfg" line 8)
(MHA:failure)

Re: using openmha with HiFiBerry DAC+DSP card

Posted: Wed Sep 11, 2024 9:40 pm
by tobiasherzke
Great, the device could be opened for output with two channels!

Now the alsa output device could not be linked to your alsa input device via snd_pcm_link.

Two options to solve this: Either use the same device for input as for output (if the driver for that device supports linking input and output), or tell MHAIOalsa to not attempt to link input and output with io.link=no (see section on MHAIOalsa in https://www.openmha.org/docs/openMHA_plugins.pdf)

Re: using openmha with HiFiBerry DAC+DSP card

Posted: Wed Sep 11, 2024 10:50 pm
by dpoznan
Adding the io.link=no allowed the cfg to prepare and start

However then I started to add the required cfg to be able to generate a sine audio.
mhalib = mhachain
srate = 24000
fragsize = 55
iolib = MHAIOalsa

nchannels_in=2
io.link=no
io.in.device = null
io.out.device = hw:0,0
io.priority = 90
mha.algos = [ transducers route:sort_output gain:mute_dummies ]

mha.transducers.plugin_name = mhachain
mha.transducers.calib_in.peaklevel=[110]
mha.transducers.calib_out.peaklevel=[110]

And I get
(mhafw_lib) IO error: (MHAIOalsa) Unable to set channel number for hw:0,0: Invalid argument
(MHA:failure)

If I leave out the peaklevels....I get
(transducers) The number of entries in the peaklevel vector must be either 2 (one per channel) or 1 (same peaklevel for all channels)

Progress....But.....

Re: using openmha with HiFiBerry DAC+DSP card

Posted: Wed Sep 11, 2024 11:27 pm
by dpoznan
Further progress...


mhalib = mhachain
srate = 24000
fragsize = 55
iolib = MHAIOalsa

nchannels_in=2
io.link=no
io.in.device = null
io.out.device = hw:0,0
io.priority = 90
mha.algos = [sine gain ]

#mha.transducers.plugin_name = mhachain
#mha.transducers.calib_in.peaklevel=[110]
#mha.transducers.calib_out.peaklevel=[110]
mha.gain.min=-120
mha.gain.max=120
mha.gain.gains=[-100 0]
mha.sine.channels=1
mha.sine.mode=replace
mha.sine.f=4000
mha.sine.lev=80
cmd=start

gets me audio in the left ear pod connected to the audio card jacks.


So I am able to use openmha to generate audio using alsa to connect to my audio card.

However I want to connect via bluetooth to my apple airpods. What device with that be???

Re: using openmha with HiFiBerry DAC+DSP card

Posted: Thu Sep 12, 2024 12:19 am
by dpoznan
SUCCESS!!!! Iused device bluealsa:DEV=08:65:18:E8:C9:18,PROFILE=a2dp and had to change fragsize to 2048
and I get audio out to the right airpod!!!

io.priority = 90mhalib = mhachain
srate = 24000
#fragsize = 55
io.priority = 90
fragsize = 2048
iolib = MHAIOalsa

nchannels_in=2
io.link=no
io.in.device = null
#io.out.device = hw:0,0
io.out.device = bluealsa:DEV=08:65:18:E8:C9:18,PROFILE=a2dp
io.priority = 90
mha.algos = [sine gain ]

#mha.transducers.plugin_name = mhachain
#mha.transducers.calib_in.peaklevel=[110]
#mha.transducers.calib_out.peaklevel=[110]
mha.gain.min=-120
mha.gain.max=120
mha.gain.gains=[-100 0]
mha.sine.channels=1
mha.sine.mode=replace
mha.sine.f=4000
mha.sine.lev=80

mha [2] cmd=start
[21234] D: ../../../src/asound/bluealsa-pcm.c:1632: Getting BlueALSA PCM: PLAYBACK 08:65:18:E8:C9:18 a2dp
[21234] D: ../../../src/asound/bluealsa-pcm.c:1387: /org/bluealsa/hci0/dev_08_65_18_E8_C9_18/a2dpsrc/sink: Setting constraints
[21234] D: ../../../src/asound/bluealsa-pcm.c:566: /org/bluealsa/hci0/dev_08_65_18_E8_C9_18/a2dpsrc/sink: Initializing HW
[21234] D: ../../../src/asound/bluealsa-pcm.c:648: /org/bluealsa/hci0/dev_08_65_18_E8_C9_18/a2dpsrc/sink: FIFO buffer size: 1024 frames
[21234] D: ../../../src/asound/bluealsa-pcm.c:653: /org/bluealsa/hci0/dev_08_65_18_E8_C9_18/a2dpsrc/sink: Selected HW buffer: 2 periods x 16384 bytes <= 32772 bytes
[21234] D: ../../../src/asound/bluealsa-pcm.c:684: /org/bluealsa/hci0/dev_08_65_18_E8_C9_18/a2dpsrc/sink: Initializing SW
[21234] D: ../../../src/asound/bluealsa-pcm.c:684: /org/bluealsa/hci0/dev_08_65_18_E8_C9_18/a2dpsrc/sink: Initializing SW
[21234] D: ../../../src/asound/bluealsa-pcm.c:684: /org/bluealsa/hci0/dev_08_65_18_E8_C9_18/a2dpsrc/sink: Initializing SW
[21234] D: ../../../src/asound/bluealsa-pcm.c:734: /org/bluealsa/hci0/dev_08_65_18_E8_C9_18/a2dpsrc/sink: Prepared
[21773] D: ../../../src/asound/bluealsa-pcm.c:428: /org/bluealsa/hci0/dev_08_65_18_E8_C9_18/a2dpsrc/sink: Stopping
(MHA:success)
[21773] D: mha [3] ../../../src/asound/bluealsa-pcm.c:734: /org/bluealsa/hci0/dev_08_65_18_E8_C9_18/a2dpsrc/sink: Prepared
[21773] D: ../../../src/asound/bluealsa-pcm.c:392: /org/bluealsa/hci0/dev_08_65_18_E8_C9_18/a2dpsrc/sink: Starting
[21774] D: ../../../src/asound/bluealsa-pcm.c:235: /org/bluealsa/hci0/dev_08_65_18_E8_C9_18/a2dpsrc/sink: Starting IO loop: 17
mha.sine.f=1000
(MHA:success)
mha [4]

I also changed the frequency dynamically to 1000

It works!!!

So now I just need to get my hearing aid logic added in. I suspect some issues when I put The transducers
plugin back in....