Skip to content

Swapped audio channels #214

@romekb

Description

@romekb

I found bug in Audio::Gain function causing audio channel swapping and wrong balance operation.
The correct function should look like this:

int32_t Audio::Gain(int16_t s[2]) {
   int32_t v[2];
   float step = (float)m_vol /254;
   uint8_t l = 0, r = 0;

   if(m_balance < 0){
       step = step * (float)(abs(m_balance) * 16);
       r = (uint8_t)(step);            // bugfix
   }
   if(m_balance > 0){
       step = step * m_balance * 16;
       l = (uint8_t)(step);            // bugfix
   }

   v[LEFTCHANNEL] = (s[LEFTCHANNEL]  * (m_vol - l)) >> 8;
   v[RIGHTCHANNEL]= (s[RIGHTCHANNEL] * (m_vol - r)) >> 8;

   return (v[RIGHTCHANNEL] << 16) | (v[LEFTCHANNEL] & 0xffff);   // bugfix
} 

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions