Mahmoud Nagy
Mahmoud Nagy

Reputation: 31

Changing audio pitch using Java (Android)

I want to change the pitch of the sound without changing the speed of the audio, and then save it to a wav or mp3 file, the idea is to make some sound effects using java on android, I didn't find a clear way to do so, is there any tutorials to read?

Upvotes: 1

Views: 2382

Answers (2)

James Paul Millard
James Paul Millard

Reputation: 621

Below is a link to a simple and valuable tutorial function in C by Stephan M. Bernsee, called smbPitchShift.cpp, which can raise or lower the pitch of a musical signal.

I was also able to also use it to slow-down or speed-up music without changing its pitch. If you want to instead do a time-stretch without altering the original pitch, you may have to apply re-sampling.

Looks like Bernsee has created some changes to his code since the version linked at GitHub. His newer code is available for download from his website -- it may increase the range of shifting from his original specification. I tweaked his original code so that I could pitch shift up by 8x.

https://github.com/AndyA/BatPhone/blob/master/pitchshift.c

http://blogs.zynaptiq.com/bernsee/time-pitch-overview/

Upvotes: 2

siddhesh
siddhesh

Reputation: 563

After a bit of researching, I found that what you're trying to do is called "pitch shifting". It involves a lot of math and mucking about with sound packets apparently because changing the pitch of a sound, automatically changes it's playback speed. Getting it back to the speed you want while still keeping the audio at something considered "normal" is no walk in the park.

In any case, since Unity3D uses C#, you might (and I stress the word might) be able to use this open source library to get the sound effect you need. It's based on NAudio (also open source, and C#) so you should theoretically be able to use it, or parts of it in your project.

Upvotes: 0

Related Questions