All of lore.kernel.org
 help / color / mirror / Atom feed
From: Giuliano Zannetti - ART S.p.A. <giuliano.zannetti@artgroup-spa.com>
To: "alsa-devel@alsa-project.org" <alsa-devel@alsa-project.org>
Subject: dmix optimization
Date: Mon, 2 Aug 2021 09:25:38 +0000	[thread overview]
Message-ID: <DB9P192MB132193EF1C0E9DFA5161A298C5EF9@DB9P192MB1321.EURP192.PROD.OUTLOOK.COM> (raw)

Hi,

I'm trying to optimize the dmix because I'm working with a big number of channels (up to 16) and in this case the dmix has not a negligible impact on performance.

I'm working with ALSA 1.1.9. I gave my first look to the generic_mix_areas_16_native function (https://github.com/alsa-project/alsa-lib/blob/v1.1.9/src/pcm/pcm_dmix_generic.c#L130).

I would ask you if I can avoid to check, for each loop iteration, if the current dst sample is not 0.

    for (;;) {
        sample = *src;
        if (! *dst) {
            *sum = sample;
            *dst = *src;
        } else {
            sample += *sum;
            *sum = sample;
            if (sample > 0x7fff)
                sample = 0x7fff;
            else if (sample < -0x8000)
                sample = -0x8000;
            *dst = sample;
        }
        if (!--size)
            return;
        src = (signed short *) ((char *)src + src_step);
        dst = (signed short *) ((char *)dst + dst_step);
        sum = (signed int *)   ((char *)sum + sum_step);
    }

Could it be possible check for the first sample of the period only, as reported in the code below? My assumption is that if dst[0] is 0 also dst[1] ... dst[period-1] will be 0, and I don't need to check every time. This is already an optimization, but it could be also a starting point for other optimization based on my HW. But, first of all, I would ask to you if my assumption is right.

    if (! *dst) {
        for (;;) {
            sample = *src;
            *sum = sample;
            *dst = *src;

            if (!--size)
                return;

            src = (signed short *) ((char *)src + src_step);
            dst = (signed short *) ((char *)dst + dst_step);
            sum = (signed int *)   ((char *)sum + sum_step);
        }

    } else {
        for (;;) {
            sample = *src;
            sample += *sum;
            *sum = sample;

            if (sample > 0x7fff)
                sample = 0x7fff;
            else if (sample < -0x8000)
                sample = -0x8000;
            *dst = sample;

            if (!--size)
                return;

            src = (signed short *) ((char *)src + src_step);
            dst = (signed short *) ((char *)dst + dst_step);
            sum = (signed int *)   ((char *)sum + sum_step);
        }
    }

Thank you!

Best Regards,
Giuliano

             reply	other threads:[~2021-08-02  9:26 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-08-02  9:25 Giuliano Zannetti - ART S.p.A. [this message]
2021-08-02 16:27 ` dmix optimization Geraldo Nascimento
2021-08-03  7:26 ` I: " Giuliano Zannetti - ART S.p.A.
2021-08-03  7:34   ` Takashi Iwai

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=DB9P192MB132193EF1C0E9DFA5161A298C5EF9@DB9P192MB1321.EURP192.PROD.OUTLOOK.COM \
    --to=giuliano.zannetti@artgroup-spa.com \
    --cc=alsa-devel@alsa-project.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.