* How to downmix 5.1 and 7.1 channels to 2 channels
@ 2020-10-20 2:32 Amanda Ava Koci Pereira
2020-10-21 13:57 ` Ricard Wanderlof
0 siblings, 1 reply; 3+ messages in thread
From: Amanda Ava Koci Pereira @ 2020-10-20 2:32 UTC (permalink / raw)
To: alsa-devel
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
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: How to downmix 5.1 and 7.1 channels to 2 channels
2020-10-20 2:32 How to downmix 5.1 and 7.1 channels to 2 channels Amanda Ava Koci Pereira
@ 2020-10-21 13:57 ` Ricard Wanderlof
2020-10-22 9:11 ` Amanda Ava Koci Pereira
0 siblings, 1 reply; 3+ messages in thread
From: Ricard Wanderlof @ 2020-10-21 13:57 UTC (permalink / raw)
To: Amanda Ava Koci Pereira; +Cc: alsa-devel
On Tue, 20 Oct 2020, Amanda Ava Koci Pereira wrote:
> 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
>
Is the problem that you get clipping if there is audio on more than one
input channel?
In general, if you sum a number (N)( of digital channels which have a
maximum amplitude of M, then the maximum amplitude of the sum will be N *
M. So in this case you need to reduce the output amplitude by 1/N if you
want to keep the maximum amplitude of the sum at M.
So in your case you need to set
> #define AR_K_P_ATTENUATION_LEVEL 1.0
according to the number of channels being downmixed per output channel.
/Ricard
--
Ricard Wolf Wanderlof ricardw(at)axis.com
Axis Communications AB, Lund, Sweden www.axis.com
Phone +46 46 272 2016 Fax +46 46 13 61 30
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: How to downmix 5.1 and 7.1 channels to 2 channels
2020-10-21 13:57 ` Ricard Wanderlof
@ 2020-10-22 9:11 ` Amanda Ava Koci Pereira
0 siblings, 0 replies; 3+ messages in thread
From: Amanda Ava Koci Pereira @ 2020-10-22 9:11 UTC (permalink / raw)
To: Ricard Wanderlof; +Cc: alsa-devel
Thanks for the tip!
Em qua., 21 de out. de 2020 às 10:57, Ricard Wanderlof <ricardw@axis.com>
escreveu:
>
> On Tue, 20 Oct 2020, Amanda Ava Koci Pereira wrote:
>
> > 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
> >
>
> Is the problem that you get clipping if there is audio on more than one
> input channel?
>
> In general, if you sum a number (N)( of digital channels which have a
> maximum amplitude of M, then the maximum amplitude of the sum will be N *
> M. So in this case you need to reduce the output amplitude by 1/N if you
> want to keep the maximum amplitude of the sum at M.
>
> So in your case you need to set
>
> > #define AR_K_P_ATTENUATION_LEVEL 1.0
>
> according to the number of channels being downmixed per output channel.
>
> /Ricard
> --
> Ricard Wolf Wanderlof ricardw(at)axis.com
> Axis Communications AB, Lund, Sweden www.axis.com
> Phone +46 46 272 2016 Fax +46 46 13 61 30
>
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2020-10-22 10:15 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-10-20 2:32 How to downmix 5.1 and 7.1 channels to 2 channels Amanda Ava Koci Pereira
2020-10-21 13:57 ` Ricard Wanderlof
2020-10-22 9:11 ` Amanda Ava Koci Pereira
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).