Recent

Author Topic: programmatically invert sound output polarity on raspberry?  (Read 1502 times)

Ramses

  • New Member
  • *
  • Posts: 41
programmatically invert sound output polarity on raspberry?
« on: January 31, 2021, 04:58:30 am »
Is there an easy way to programaticaly invert the sound output polarity on a raspberry board?

I mean programmatically changing the positive to negative, and negative to positive few minutes. then programmatically turn it back to normal..

Thanks!

Fred vS

  • Hero Member
  • *****
  • Posts: 3168
    • StrumPract is the musicians best friend
Re: programmatically invert sound output polarity on raspberry?
« Reply #1 on: February 02, 2021, 03:05:32 pm »
The easier way is to multiply each sample by -1.

If your samples are stored into a array, just do:

Code: Pascal  [Select][+][-]
  1. for x:=0 to length(datasamples)-1 do
  2. datasamples[x] := datasamples[x] * -1;
I use Lazarus 2.2.0 32/64 and FPC 3.2.2 32/64 on Debian 11 64 bit, Windows 10, Windows 7 32/64, Windows XP 32,  FreeBSD 64.
Widgetset: fpGUI, MSEgui, Win32, GTK2, Qt.

https://github.com/fredvs
https://gitlab.com/fredvs
https://codeberg.org/fredvs

Ramses

  • New Member
  • *
  • Posts: 41
Re: programmatically invert sound output polarity on raspberry?
« Reply #2 on: February 02, 2021, 03:28:19 pm »
Thanks for your reply!

But for now, i dont play the sound from my application, (I have not specify it in my first post: my mistake)

So let say that another external application is playing something on the speaker, and i want to programmatically invert sound output polarity on raspberry pi 3 board, is there an easy way to do this?

(Actually the way i found to invert my polarity is to use a relay and turn the relay on to invert the polarity, this work great, but i wanna know if i can do it from my code to save space in my project box, and to use less hardware as possible...)

 

TinyPortal © 2005-2018