Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Audio programming and how to invert a sound wave?

Tags:

java

audio

I'm trying to invert a sound wave (phase shift 180 degrees), but I'm not exactly sure how I would go about doing this. Can any audio programmers point me in the right direction?

like image 295
Steve Avatar asked Mar 06 '11 14:03

Steve


1 Answers

Inverting a sound wave should be generally easy if you have access to the byte array that makes up the sound. You simply need to take the negative of each value in the stream.

Audio streams come in many different flavors so it's impossible to be specific. However, if it was a 16bit PCM stream, which is full of 2-byte values, you'd loop over the data and for each two bytes in the stream: cast it to a short, take the negative of it, and put it back into the byte stream.

like image 186
Wes Hardaker Avatar answered Sep 28 '22 06:09

Wes Hardaker