Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #33085

Re: Numpy combine channels

Date 2012-11-10 08:05 -0500
From Dave Angel <d@davea.name>
Subject Re: Numpy combine channels
References <de5d9415-f3d8-47b9-bcc2-822dc57fd1d8@googlegroups.com> <mailman.465.1347307911.27098.python-list@python.org> <k7kl8b$5g0$1@panix5.panix.com>
Newsgroups comp.lang.python
Message-ID <mailman.3534.1352552737.27098.python-list@python.org> (permalink)

Show all headers | View raw


On 11/09/2012 11:30 PM, Aahz wrote:
> In article <mailman.465.1347307911.27098.python-list@python.org>,
> MRAB  <python-list@python.org> wrote:
>> <snip>
>>
>> But should they be added together to make mono?
>>
>> Suppose, for example, that both channels have a maximum value. Their
>> sum would be _twice_ the maximum.
>>
>> Therefore, I think that it should probably be the average.
>>
>>>>> (a[:, 0] + a[:, 1]) / 2
>> array([1, 1, 2])
> I'd actually think it should be the max.  Consider a stereo where one
> side is playing a booming bass while the other side is playing a rest
> note -- should the mono combination be half as loud as as the bass?

max would sound awful.

The right answer is to add them with weighting, then scale the whole
waveform according to a new calculation of clipping. Just like a mixer,
you have level controls on each input, then an overall gain.

So if the inputs were x and y, the output would be   gain *( x_scale * x
+ y_scale * y), but it'd normally be done in two passes, so as to
minimize the places that are clipped, while maximizing the average. 
it's also possible to have gain vary across the time axis, like an agc. 
But you wouldn't want that as a default, as it'd destroy the dynamics of
a musical piece.

One more consideration.  If these are unsigned values (eg. 0 to 255),
then you should adjust both signals by 128 before storing them as signed
values, do your arithmetic, and then adjust again by adding 128.  You
could do the algebraic equivalent, but the programming would be much
simpler on signed values.



-- 

DaveA

Back to comp.lang.python | Previous | NextPrevious in thread | Find similar | Unroll thread


Thread

Numpy combine channels Wanderer <wanderer@dialup4less.com> - 2012-09-10 12:39 -0700
  Re: Numpy combine channels Wanderer <wanderer@dialup4less.com> - 2012-09-10 12:56 -0700
  RE: Numpy combine channels Nick Cash <nick.cash@npcinternational.com> - 2012-09-10 19:50 +0000
  Re: Numpy combine channels MRAB <python@mrabarnett.plus.com> - 2012-09-10 21:11 +0100
    Re: Numpy combine channels Wanderer <wanderer@dialup4less.com> - 2012-09-10 13:14 -0700
      Re: Numpy combine channels Wanderer <wanderer@dialup4less.com> - 2012-09-10 13:15 -0700
      Re: Numpy combine channels Wanderer <wanderer@dialup4less.com> - 2012-09-10 13:15 -0700
    Re: Numpy combine channels Wanderer <wanderer@dialup4less.com> - 2012-09-10 13:14 -0700
    Re: Numpy combine channels aahz@pythoncraft.com (Aahz) - 2012-11-09 20:30 -0800
      Re: Numpy combine channels Dave Angel <d@davea.name> - 2012-11-10 08:05 -0500

csiph-web