alsa-devel.alsa-project.org archive mirror
 help / color / mirror / Atom feed
From: Amanda Ava Koci Pereira <arsoftware10@gmail.com>
To: alsa-devel@alsa-project.org
Subject: How to downmix 5.1 and 7.1 channels to 2 channels
Date: Mon, 19 Oct 2020 23:32:12 -0300	[thread overview]
Message-ID: <CALAz8EWAKP-LaeDyQZW0BauwYBthSbgJgxRT8hypuXEWEOfPhA@mail.gmail.com> (raw)

Hi guys...

We need some clues about to downmix 5.1 and 7.1 channels to 2 channels

for the moment we are using the following code ->

It works but fails miserably if all channels have data at same time


#define AR_K_P_ATTENUATION_LEVEL 1.0

int p = 0;
int i;
int save_channel_0_k_p;
int save_channel_1_k_p;
double save_channel_0_data_double_k_p;
double save_channel_1_data_double_k_p;
double sample_double_temp_k_p;
int number_of_samples_k_p = decoded_frame->nb_samples;
int ricardo_deslocador__ = 0;
frame_processed_k_p = 1;

int outputBufferLen = number_of_samples_k_p * 2 * 2;
*size_out=outputBufferLen;
short *outputBuffer = (int16_t *)buf;
int16_t * ar_buffer_ = (int16_t *) decoded_frame->data[0];

for(i=0; i < number_of_samples_k_p; i++)
{
//channel 0
int16_t sample_k_p = ar_buffer_[ricardo_deslocador__++];

save_channel_0_k_p = p;

save_channel_0_data_double_k_p = (double) sample_k_p;

p++;

///////////////////////////////////////////////
//channel 1
sample_k_p = ar_buffer_[ricardo_deslocador__++];

save_channel_1_k_p = p;//so usa no final...

save_channel_1_data_double_k_p = (double) sample_k_p;

p++;

////////////////////////////////////////////////
//center
sample_k_p = ar_buffer_[ricardo_deslocador__++];

sample_double_temp_k_p = (double) sample_k_p;

sample_double_temp_k_p *= AR_K_P_ATTENUATION_LEVEL;

save_channel_0_data_double_k_p += sample_double_temp_k_p;

if(32767.0 < save_channel_0_data_double_k_p)
{
save_channel_0_data_double_k_p = 32767.0;
}

if(-32768.0 > save_channel_0_data_double_k_p)
{
save_channel_0_data_double_k_p = -32768.0;
}

sample_double_temp_k_p = (double) sample_k_p;

sample_double_temp_k_p *= AR_K_P_ATTENUATION_LEVEL;

save_channel_1_data_double_k_p += sample_double_temp_k_p;

if(32767.0 < save_channel_1_data_double_k_p)
{
save_channel_1_data_double_k_p = 32767.0;
}

if(-32768.0 > save_channel_1_data_double_k_p)
{
save_channel_1_data_double_k_p = -32768.0;
}

//////////////////////////////////////////////////////
///////subwoffer
sample_k_p = ar_buffer_[ricardo_deslocador__++];

sample_double_temp_k_p = (double) sample_k_p;

sample_double_temp_k_p *= AR_K_P_ATTENUATION_LEVEL;

save_channel_0_data_double_k_p += sample_double_temp_k_p;

if(32767.0 < save_channel_0_data_double_k_p)
{
save_channel_0_data_double_k_p = 32767.0;
}

if(-32768.0 > save_channel_0_data_double_k_p)
{
save_channel_0_data_double_k_p = -32768.0;
}

sample_double_temp_k_p = (double) sample_k_p;

sample_double_temp_k_p *= AR_K_P_ATTENUATION_LEVEL;

save_channel_1_data_double_k_p += sample_double_temp_k_p;

if(32767.0 < save_channel_1_data_double_k_p)
{
save_channel_1_data_double_k_p = 32767.0;
}

if(-32768.0 > save_channel_1_data_double_k_p)
{
save_channel_1_data_double_k_p = -32768.0;
}
////////////////////////////////////////////////////
/////surround left 4
sample_k_p = ar_buffer_[ricardo_deslocador__++];

sample_double_temp_k_p = (double) sample_k_p;

sample_double_temp_k_p *= AR_K_P_ATTENUATION_LEVEL;

save_channel_0_data_double_k_p += sample_double_temp_k_p;

if(32767.0 < save_channel_0_data_double_k_p)
{
save_channel_0_data_double_k_p = 32767.0;
}

if(-32768.0 > save_channel_0_data_double_k_p)
{
save_channel_0_data_double_k_p = -32768.0;
}
///////////////////////////////////////////////
//////////surround right 5
sample_k_p = ar_buffer_[ricardo_deslocador__++];

sample_double_temp_k_p = (double) sample_k_p;

sample_double_temp_k_p *= AR_K_P_ATTENUATION_LEVEL;

save_channel_1_data_double_k_p += sample_double_temp_k_p;

if(32767.0 < save_channel_1_data_double_k_p)
{
save_channel_1_data_double_k_p = 32767.0;
}

if(-32768.0 > save_channel_1_data_double_k_p)
{
save_channel_1_data_double_k_p = -32768.0;
}
/////////////////////////////////////////////
//finalizing

outputBuffer[save_channel_0_k_p] = (signed short)
save_channel_0_data_double_k_p;
outputBuffer[save_channel_1_k_p] = (signed short)
save_channel_1_data_double_k_p;
}

/*

if possible point us to the files in ALSA that make the downmix and it will
be enough

Thanks a lot

*/

Ricardo

             reply	other threads:[~2020-10-21 13:42 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-10-20  2:32 Amanda Ava Koci Pereira [this message]
2020-10-21 13:57 ` How to downmix 5.1 and 7.1 channels to 2 channels Ricard Wanderlof
2020-10-22  9:11   ` Amanda Ava Koci Pereira

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=CALAz8EWAKP-LaeDyQZW0BauwYBthSbgJgxRT8hypuXEWEOfPhA@mail.gmail.com \
    --to=arsoftware10@gmail.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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).