acidanthera / bugtracker

Acidanthera Bugtracker
385 stars 45 forks source link

alc282 with applealc had loud pops at start up and shutdown #1942

Closed loverto closed 2 years ago

loverto commented 2 years ago
  1. I have also had loud pops at start up and shutdown
  2. I have some linux references here。 Sound Card Database
  3. The following is the lilu and applealc log alclog.txt
loverto commented 2 years ago

The core step to fix this problem on Linux is to customize the sound card initialization and shutdown callback functions. Is there a place to do the same in applealc @vit9696

loverto commented 2 years ago

2A165EF9-FC19-49E8-B31E-1445932150A9 image image

loverto commented 2 years ago

I started using dump_coeff on my computer to dump the coeff on the mac, but it doesn't work? Help.

RtHDDump.txt dump_coef.txt

loverto commented 2 years ago

dump_coef.txt RtHDDump.txt

loverto commented 2 years ago

@narcyzzo

loverto commented 2 years ago

Failed to find ALCUserClientProvider services.

Core-i99 commented 2 years ago

Failed to find ALCUserClientProvider services.

Do you have alcverbs=1 bootarg?

mikebeaton commented 2 years ago

Instructions updated @ https://github.com/acidanthera/AppleALC/wiki/Dumping-processing-coefficients :

alc-verb (available in AppleALC releases) must be installed on your path, and must also be enabled in config.plist (either write a non-zero value to the alc-verb property in DeviceProperties for your card, or add alcverbs=1 to boot-args).

loverto commented 2 years ago

It has been turned on, and now coefs is the same, but there is still noise when sleeping and waking up, continue to check the Linux source code, sound/pci/hda/patch_realtek.c

loverto commented 2 years ago

Now it can be confirmed that this code is the same for linux and mac.

image

image

image

image

loverto commented 2 years ago

Fix the noise after suspend and resume on ALC282 codec When the power state of ALC283 codec goes to D3 or return back to D0, it gives a noise via headphone output. To follow the depop procedure, it will be better.


// init
static void alc282_init(struct hda_codec *codec)
{
    struct alc_spec *spec = codec->spec;

    hda_nid_t hp_pin = alc_get_hp_pin(spec);
    bool hp_pin_sense;
    int coef78;

    alc282_restore_default_value(codec);

    if (!hp_pin)
        return;
    // detect jack
    hp_pin_sense = snd_hda_jack_detect(codec, hp_pin);
    coef78 = alc_read_coef_idx(codec, 0x78);

    /* Index 0x78 Direct Drive HP AMP LPM Control 1  */
    /* Headphone capless set to high power mode */
    alc_write_coef_idx(codec, 0x78, 0x9004);

    if (hp_pin_sense)
        msleep(2);

    snd_hda_codec_write(codec, hp_pin, 0,
                AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE);

    if (hp_pin_sense)
        msleep(85);

    snd_hda_codec_write(codec, hp_pin, 0,
                AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT);

    if (hp_pin_sense)
        msleep(100);

    /* Headphone capless set to normal mode  */
    alc_write_coef_idx(codec, 0x78, coef78);
}
// 
static void alc282_shutup(struct hda_codec *codec)
{
    struct alc_spec *spec = codec->spec;
    hda_nid_t hp_pin = alc_get_hp_pin(spec);
    bool hp_pin_sense;
    int coef78;

    if (!hp_pin) {
        alc269_shutup(codec);
        return;
    }
        // 
    hp_pin_sense = snd_hda_jack_detect(codec, hp_pin);
    coef78 = alc_read_coef_idx(codec, 0x78);
    alc_write_coef_idx(codec, 0x78, 0x9004);

    if (hp_pin_sense)
        msleep(2);

    snd_hda_codec_write(codec, hp_pin, 0,
                AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE);

    if (hp_pin_sense)
        msleep(85);

    if (!spec->no_shutup_pins)
        snd_hda_codec_write(codec, hp_pin, 0,
                    AC_VERB_SET_PIN_WIDGET_CONTROL, 0x0);

    if (hp_pin_sense)
        msleep(100);

    alc_auto_setup_eapd(codec, false);
    alc_shutup_pins(codec);
    alc_write_coef_idx(codec, 0x78, coef78);
}

// Like this code how to fix it in applealc?

// detect jack
    hp_pin_sense = snd_hda_jack_detect(codec, hp_pin);
    coef78 = alc_read_coef_idx(codec, 0x78);

    /* Index 0x78 Direct Drive HP AMP LPM Control 1  */
    /* Headphone capless set to high power mode */
    alc_write_coef_idx(codec, 0x78, 0x9004);

    if (hp_pin_sense)
        msleep(2);

    snd_hda_codec_write(codec, hp_pin, 0,
                AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE);

    if (hp_pin_sense)
        msleep(85);

    snd_hda_codec_write(codec, hp_pin, 0,
                AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT);

    if (hp_pin_sense)
        msleep(100);

    /* Headphone capless set to normal mode  */
    alc_write_coef_idx(codec, 0x78, coef78);
loverto commented 2 years ago

@vit9696 @Core-i99 @mikebeaton

loverto commented 2 years ago

https://www.kernel.org/doc/html/latest/sound/hd-audio/realtek-pc-beep.html

mikebeaton commented 2 years ago

Thanks for the cc. It seems to me this is an issue specific to the startup of the given card and layout: with research, you should be able to add/alter the verbs sent to the card to avoid the pops. I believe you can just change the config for your specific card in AppleALC, and if you fix it, make a PR. It is not clear that any change to the main code of AppleALC is needed.

loverto commented 2 years ago

This is not a problem with a single sound card, but a series. On linux, there will be hooks for startup and shutdown to handle this. I looked at the source code of applealc, but I didn't find where it can be operated. Maybe I need an example, I Try to modify the source code of applealc this week.

loverto commented 2 years ago

I've tried putting the command directly into configdata, but that doesn't work

loverto commented 2 years ago

Maybe applealc also needs to open two hooks for initialization and shutdown

Core-i99 commented 2 years ago

This is not a problem with a single sound card, but a series. On linux, there will be hooks for startup and shutdown to handle this. I looked at the source code of applealc, but I didn't find where it can be operated. Maybe I need an example, I Try to modify the source code of applealc this week.

Applealc can send verbs on startup. But not on shutdown, alcplugfix swift can do that.

Applealc uses resources for this, no need for code changes.

liangyi9812 commented 1 year ago

I also have the same issue with my MSI B760M-P motherboard's ALC897. The most noticeable manifestation occurs at the beginning of boot at stage two, where the audio device emits 5~6 consecutive loud pop sounds. Is there a universal solution to this problem? Not long ago, my computer suddenly couldn't find the audio device, and after that restart, the motherboard became unresponsive and couldn't boot anymore. As a result, I had to send my motherboard for repairs. I'm not sure if it's related to this issue.@loverto