[SOLVED] HiFi shield plus / Fluidsynth / Alsa / Distorted sound

Post Reply
HLB
Posts: 3
Joined: Thu Nov 14, 2019 6:55 am
languages_spoken: english/francais/deutsch
ODROIDs: C1+ and HiFi Shield plus
Has thanked: 0
Been thanked: 2 times
Contact:

[SOLVED] HiFi shield plus / Fluidsynth / Alsa / Distorted sound

Unread post by HLB » Thu Nov 14, 2019 7:25 am

Hi there!

I just start playing with a C1+ and a HiFi shield. The aim is to give a "voice" to a MIDI instrument.

I am using fluidsynth and Alsa to get data from a MIDI instrument (made out of an Arduino) and play notes out of a sf2 soundfont. Long story short, that actually runs on my desktop computer and I would like to embed that on the C1+/HiFi shield stack.

I successfully followed the HiFi shield tutorial from HK: https://wiki.odroid.com/accessory/sound/hifi_shield.

The device is detected :

Code: Select all

odroid@odroid:~$ lsusb 
Bus 001 Device 005: ID 2341:8037 Arduino SA 
Fluidsynth is configured as follow :

Code: Select all

odroid@odroid:~$ fluidsynth -C0 -R0 -r 44100 -v -d -a alsa -o audio.alsa.device=hw:1 -o synth.polyphony=64 -m alsa_seq /home/odroid/Documents/Bandoneon.sf2 
FluidSynth version 1.1.6
Copyright (C) 2000-2012 Peter Hanappe and others.
Distributed under the LGPL license.
SoundFont(R) is a registered trademark of E-mu Systems, Inc.

fluidsynth: warning: Failed to pin the sample data to RAM; swapping is possible.
fluidsynth: prog	0	0	0
fluidsynth: prog	1	0	0
fluidsynth: prog	2	0	0
fluidsynth: prog	3	0	0
fluidsynth: prog	4	0	0
fluidsynth: prog	5	0	0
fluidsynth: prog	6	0	0
fluidsynth: prog	7	0	0
fluidsynth: prog	8	0	0
fluidsynth: prog	9	128	0
fluidsynth: warning: No preset found on channel 9 [bank=128 prog=0]
fluidsynth: prog	10	0	0
fluidsynth: prog	11	0	0
fluidsynth: prog	12	0	0
fluidsynth: prog	13	0	0
fluidsynth: prog	14	0	0
fluidsynth: prog	15	0	0
Type 'help' for help topics.

event_pre_noteon 0 60 106
event_post_noteon 0 60 106
fluidsynth: noteon	0	60	106	00000	36.312	3.550	0.000	0
event_pre_noteoff 0 60 106
event_post_noteoff 0 60 106
fluidsynth: noteoff	0	60	0	00000	3.574	1
event_pre_noteon 0 60 106
event_post_noteon 0 60 106
fluidsynth: noteon	0	60	106	00001	39.626	3.876	0.000	0
event_pre_noteoff 0 60 106
^C
The link between fluidsynth and alsa input is done properly:

Code: Select all

odroid@odroid:~$ aconnect -io
client 0: 'System' [type=kernel]
    0 'Timer           '
    1 'Announce        '
client 24: 'Arduino Micro' [type=kernel]
    0 'Arduino Micro MIDI 1'
client 128: 'FLUID Synth (3113)' [type=user]
    0 'Synth input port (3113:0)'
odroid@odroid:~$ aconnect 24 128
And alsa is running (got nice sound on both ears, though alsamixer tell me that "this sound device (ODROID-DAC) does not have any controls"):

Code: Select all

odroid@odroid:~$ speaker-test -Dplughw:1 -c2 -f440 -twav

speaker-test 1.0.27.2

Playback device is plughw:1
Stream parameters are 48000Hz, S16_LE, 2 channels
WAV file(s)
Rate set to 48000Hz (requested 48000Hz)
Buffer size range from 32 to 16384
Period size range from 16 to 8192
Using max buffer size 16384
Periods = 4
was set period_size = 4096
was set buffer_size = 16384
 0 - Front Left
 1 - Front Right
Well, everything looks fine but the sound I get when playing the midi instrument is very distorted, noisy. Changing the rate did not improved anything. Weirdly enough, when switching to pulse audio ("fluidsynth -a pulseaudio...") gives expected sounds but with a 2~3 seconds latency.

Any clue about this?

Thanks!
HLB

User avatar
odroid
Site Admin
Posts: 32677
Joined: Fri Feb 22, 2013 11:14 pm
languages_spoken: English
ODROIDs: ODROID
Has thanked: 209 times
Been thanked: 364 times
Contact:

Re: HiFi shield plus / Fluidsynth / Alsa / Distorted sound

Unread post by odroid » Thu Nov 14, 2019 10:33 am

I have no idea what makes the problems. :(
I hope other (embedded) Linux sound system expert can help you.

HLB
Posts: 3
Joined: Thu Nov 14, 2019 6:55 am
languages_spoken: english/francais/deutsch
ODROIDs: C1+ and HiFi Shield plus
Has thanked: 0
Been thanked: 2 times
Contact:

Re: HiFi shield plus / Fluidsynth / Alsa / Distorted sound

Unread post by HLB » Fri Nov 15, 2019 5:44 am

Hi!

Thank you for this fair (and fast!) answer.

I actually gave a try with timidity, another MIDI/Alsa synthesizer:

Code: Select all

odroid@odroid:~$ timidity -iA -B2,8 -Os -EFreverb=0
Requested buffer size 2048, fragment size 1024
ALSA pcm 'default' set buffer size 2048, period size 680 bytes
TiMidity starting in ALSA server mode
Opening sequencer port: 129:0 129:1 129:2 129:3
Which gave audible sounds but a 1-2 seconds latency. Still it shows that it can run fine with Alsa. I am probably not that far from getting it right. I will ask directly the dev-list of fluidsynth.

HLB

HLB
Posts: 3
Joined: Thu Nov 14, 2019 6:55 am
languages_spoken: english/francais/deutsch
ODROIDs: C1+ and HiFi Shield plus
Has thanked: 0
Been thanked: 2 times
Contact:

Re: HiFi shield plus / Fluidsynth / Alsa / Distorted sound

Unread post by HLB » Fri Nov 22, 2019 6:26 am

Hi there!

With the help of the dev-list of fluidsynth, this issue is solved!

The size of the buffer was actually too small. By default it is 64 and a minimum of 256 is required here. So the parameter can be updated so with:

Code: Select all

-o audio.periods=2 -o audio.period-size=1024
I also got some extra optimization that worth testing:
  • -C0 and -R0 will switch chorus and reverb effects off
  • -o audio.alsa.device=hw:1,0 if you want to specify the audio output
  • -o synth.cpu-cores will set the number of threads, for multiple core cpu, can be useful with high level of polyphony.
  • avoid using -v (verbose) and -d (dump output on the shell)
Finally here is what I use for a two keyboard plug on fluidsynth:

Code: Select all

fluidsynth -C0 -R0 -r 48000 -o audio.periods=2 -o audio.period-size=1024 -a alsa -o audio.alsa.device=hw:1,0 -m alsa_seq --midi-channel 2 /home/odroid/Documents/bandoneon_v2.sf2 /home/odroid/Documents/bandoneon_v2.sf2
aconnect 24:0 128:0;
aconnect 28:0 128:0;
I finally configure Qsynth that way and add a script in the LXSession configuration/Autostart...

HLB
These users thanked the author HLB for the post (total 2):
rooted (Fri Nov 22, 2019 8:13 am) • odroid (Fri Nov 22, 2019 9:27 am)

User avatar
rooted
Posts: 6878
Joined: Fri Dec 19, 2014 9:12 am
languages_spoken: english
Location: Gulf of Mexico, US
Has thanked: 267 times
Been thanked: 58 times
Contact:

Re: HiFi shield plus / Fluidsynth / Alsa / Distorted sound

Unread post by rooted » Fri Nov 22, 2019 8:13 am

Thanks for posting the resolution and hints.

Post Reply

Return to “I2S Devices (HiFi Shield DAC and Stereo Boom Bonnet Kit)”

Who is online

Users browsing this forum: No registered users and 1 guest