heikomat / linux

Linux kernel source tree
Other
43 stars 8 forks source link

Really bad sound output #5

Open asdplayer opened 5 years ago

asdplayer commented 5 years ago

I compiled and installed succesfully your kernel, but I got problems at runtime. I used localmodconfig, and everything else is working. I also followed the instructions given in this repository. I attached a dmesg and my kernel config that I used (I've renamed it to .txt just to upload it). cx2072x_dmesg_while_using.log cx2072x_kernel_config_4.19.4.txt

I tried to reproduce audio, but there are some problems. Everything was also checked against a working USB soundcard, the Behringer UMC404HD, to rule out the most obvious issues in user software.

=== Play mp3/m4a/ogg/wav using Audacious player, to ALSA: plays at 2x speed (and 2x pitch), with some noise, like gross aliasing. The card is reported twice (this is normal I think), as: -> sysdefault:CARD=chtcx2072x -> usbstream:CARD=chtcx2072x selecting the latter results in an error: "ALSA error: snd_pcm_open failed: Invalid argument." Why does it say "usbstream" anyway? The same is reported by aplay -L (list pcm outputs)

=== Play using Audacity editor, to ALSA: plays at normal speed and pitch. (There is consistent lagging of the UI when changing play/capture settings from the toolbars, while the soundcard is disabled and reinitialized many (~10) times, but this is fault of Audacity).

=== Play mp3/m4a/ogg/wav/video using Parole video player, which uses gstreamer, which uses PulseAudio: There is major distortion, but playback speed is OK. See below for an hypothesis.

=== Play mp3/m4a/ogg/wav/video using VLC player, to ALSA: Audio is played at 2x speed and 2x pitch, but is sinchronized to real time. So, some length of audio is played, then there is a void, then it restarts... At random intervals, maybe 3 gaps a second. The play time is therefore not shortened. Using Pulseaudio backend instead of direct ALSA, VLC yelds the same exact result obtained from Parole.

=== Play test signals with kokkinizita's jaaa, through JACK, 1024 sample buffer: I played various test signals. Playing a 200 Hz sine:

=== Playing various sounds through JACK, with synths and audio players: Every application that outputs over around -45 dB of digital signal results is harsh distorsion out of the soundcard. Some applications kind of work, they reproduce audio at 2x speed and 2x pitch, and output gets distorted over about -45 dB; they are: jaaa, synth_v1, audacious (which also has a JACK backend), yoshimi. Some applications don't work, and sometimes wreck the JACK instance so that the JACK server is running, but no sound can be reproduced anymore by any application: mixxx, fluidsynth. Bristol crashes 3 seconds after started, but that is kind of expected, as the code is old and unstable. VLC (which has a JACK backend, too) sounds as before, pitch and speed are 2x, except that now intervals with and without sounds are equally spaced and have the same duration, like 50%/50%.

JACK is configured for "playback only", because I could not start it in "duplex" mode (so I only have output, and not input + output). If I try to start JACK in duplex mode, it says something unhelpful like "overall operation failed", and in the dmesg log appear hundreds of these lines: [ 177.914611] intel_sst_acpi 808622A8:00: sst: Busy wait failed, cant send this msg This is a good topic for another report maybe.

EDIT: My computer is the Asus E200H, the soundcard is the CX20723. And some typo fixes. And another thing: If you see the need, in a week's time I can attach an oscilloscope to the headphone output to diagnose further; by now I don't have time. Let me know!

heikomat commented 5 years ago

Oh damn, you've gone way more in-depth than i ever have, nice work! I'd be very interested in at least reproducing your findings, but i have only ever worked with debian-based distributions. Getting this to work on arch-based distributions would be really nice though.

this guy seems to have been successfull at using this kernel, but he probably used kernel version 4.17, and some things have changed since then.

I see your kernel-version is 4.19.4. The newset version i merged is 4.19. Did you apply the fixes of my cx2072x branch yourself?

Could you write up something like a reproduction manual? This way i might see if something is odd or missing, and could try it myself.

asdplayer commented 5 years ago

I'm writing the complete process of compilation I followed. Basically I edit Arch linux build scripts (PKGBUILD files), either the ones used to compile official packages or user-provided ones in the AUR. I made patches from your branch of the kernel. I don't have enough free space on my E200 to pull two source trees at the same time, so, instead of using diff and learning git, I copied and pasted from the Files changed tab of this page in your repository into patches I modified by hand. They output some warning messages when applied, but otherwise work (How unexpected!). I checked each file by hand afterwards. By the way I also wonder why is there a difference in a seemingly unrelated file: drivers/pwm/pwm-lpss.c. Having both the modified tree AND the patches, I tried various kernels, and I obtained the same results on all of them.

All these kernels used make localmodconfig, then I configured them further with make menuconfig to enable native compiler optimization and enable the two options for the cx2072x. And to check every thing I know. The realtime kernels also had many security features disabled, including memory layout randomization and even features I don't entirely understand. Instead, while configuring the kernel from the official Arch repo, I left everything as default (other than enabling cx2072x and compile optimization for the Atom architecture), so almost all sensible security features are compiled in. Before the week ends I'll have more storage space, so I'll try to compile another kernel, based only on this repository, and see if it works. I also tried to read the sources of the cx2072x driver, but I don't understand many things and I don't have proper documentation of the codec. For example it would be good to be able to use the inbuilt equalizer, or the 192 kHz sample rate, but I'm not ready to code yet. Thank you for the time you spend on this, I'll post the complete compilation steps soon.

heikomat commented 5 years ago

The specific (seemingly unrelated) function you mentioned was not orignally added by me. When i started this patched kernel, i based it on Fixes from tiwai. he had 3 different branches that fixed different things reagarding cherrytrail.

The specific commit including the reasoning for adding the function was this one

I'll later check if it is really no longer needed, and if so, remove it

7twin commented 5 years ago

@heikomat @asdplayer Just saw this - never got a notification for it. I did indeed not have it on 4.19 yet, as on my 4.19 setup I didn't yet have need for sound.

4.20 is supposed to come soon too, so I would be definitely interested in how to get it to work with either 4.19.12 or 4.20.

Thanks for doing all this work for getting sound working!

heikomat commented 5 years ago

@7twin nice to see you here :) I'll merge 4.20 tomorrow (in about 10-12 hours from now) and make the regular debian/ubuntu build

heikomat commented 5 years ago

As promised, 4.20 is merged and the installer-script updated

7twin commented 5 years ago

Thanks, well done! will try to test it asap!

7twin commented 5 years ago

@heikomat can confirm it working, thanks! the only thing I faced was having to rename: /net/netfilter/xt_rateest.ko to /net/netfilter/xt_RATEEST.ko else during make modules_install it would complain about not being able to stat that file.

I did get two warnings after the successful install about xt_rateest_put together with another one possibly not existing, but haven't seen anything break (yet), so not sure if that is anything to be worried about and possibly just the regular warning output.

heikomat commented 5 years ago

@7twin what are the steps you took to build the kernel? Maybe we can dockerize the process and add a download for arch in future versions

7twin commented 5 years ago

@heikomat good that you mentioned that, reminded me that I anyway wanted to write down the process of getting it to work on arch for a long time, but kept forgetting it, here it is: https://github.com/7twin/arch_sound_e200ha

I am terrible at docker though, so can't help much there, hopefully somebody can pick up those instructions and create a working docker image.

heikomat commented 5 years ago

Thanks for that! I do a lot with docker, so i'll give it a try

heikomat commented 5 years ago

ok, i tried a few things, and building the kernel in a docker container is most likely not a problem. What is a problem though, is that i'd like to make it build pacman-installable linux-header and linux-image files. I found some tutorials on how to make them, but they require configuration files (like a PKGBUILD file) to work, which i don't have.

It is probably very possible to write these package-config-files and then use them to create these installable kernel packages, but as i'm not yet that familiar with arch and pacman, creating these would certainly take me hours or even a day or two, because i'd need to read and learn a lot, which i (at this moment) don't want to invest, as i have other things to do.

Titotix commented 5 years ago

@asdplayer I had same troubles you described but only for encoded sounds files (so wav for sounds and mov for video were working fine). I did steps described by 7twin, it works for me, you should give it a try ;)

asdplayer commented 5 years ago

@Titotix Thank you, I definitely have to try the new version. Unluckily my internet connection is down because some moron stepped on optical fiber left on the floor under a manhole cover (and obviously made a mess, the fiber is broken somewhere inside the pipe to my house probably because it was pulled too strong). I had some kind of disconnected holiday, remembering the lost beauty of ADSL. In two days I'll be back at University, if I have time left I'll give this a try. It's unbelievable how short vacations become when in fact you have to work...

asdplayer commented 5 years ago

Good evening, I tried the new kernel. Basically I have the same myriad of problems I had with the previous version. Here is the PKGBUILD file I used to build the kernel: https://pastebin.com/eCdLU2Zr To use it (on Arch), download all the files from this page containing files regarding the official kernel package of Arch (by hand, or using ABS (type asp export linux)); then use this PKGBUILD instead of the original one (or edit by yourself). Here is the .config I used. Copy it in the PKGBUILD directory with the other files, overwrite the existing config file (without trailing dot). The issues I have are similar to those I had with the previous version. This time audio playback with Audacious player is much better: playback speed is right now, however the aliasing-like artifacts remain. They can be clearly heard on the end of a song, when it fades away but there is still some signal. Jack audio doesn't work well, apparently applications play at twice the speed, or break because they are aware of the real playback speed they should achieve. Playback happens only from the second (right) logical channel, to both headphone speakers; playing from the first (left) logical channel only results in a small distorted output (from both headphone speakers), like analog crosstalk. This was tested with Jack, if that matters. I'm not sure why, but the second time I plugged in the hedphones, playback happened through the speakers anyway. It may be due to the fact I touched settings in alsamixer which may be related to the speaker/headphone switching and I messed up something. I had no time to test further, I apologize for this. And I don't understand many things about programming, too. So feel free to ask for more testing, I'll get the notification email and answer ASAP.

heikomat commented 5 years ago

@asdplayer thanks for the info and config files. I'll give building the kernel packages using docker another try on the weekend, using these files.

If we have installable packages, we might reproduce your issues on other devices. we could also compare the config you used with the one used by @7twin

7twin commented 5 years ago

@heikomat absolutely, I'll be happy to upload my .config I sourced on my e200ha if needed

asdplayer commented 5 years ago

@heikomat Do you mean you want to try my compiled package? It doesn't seem too secure on your side, however if you want I can upload it on Drive or something.

heikomat commented 5 years ago

@asdplayer close. I meant that i'll try to build the package myself, using your config files

asdplayer commented 5 years ago

Ok that's nicer, I misunderstood your message. :-| Thank you for your effort by the way.

heikomat commented 5 years ago

@7twin @asdplayer Apparently someone already made an arch package for this kernel O.o https://aur.archlinux.org/packages/linux-cx2072x/

Can you guys check if this works for you? (i still haven't installed arch on my laptop ^^)

7twin commented 5 years ago

@heikomat impressive to see, but to be quite honest I am not sure how I would use that, also lines like that make it seem somewhat odd: https://aur.archlinux.org/cgit/aur.git/tree/PKGBUILD?h=linux-cx2072x#n146

heikomat commented 5 years ago

Sorry for the delayed progress on this, but this month is really packed for me. A lot of work, and a lot of studying. I'm still interested in debugging this, but I just don't known when I'll be able to do so.

7twin commented 5 years ago

@heikomat absolutely no issue, take your time, exams have much higher priority

asdplayer commented 5 years ago

No problem, I'm short of time too.