TarsosDSP icon indicating copy to clipboard operation
TarsosDSP copied to clipboard

Pitch Shifting a Audio File on Android without extra dependencies e.g. ffmpeg

Open Agubuzoboy opened this issue 8 years ago • 3 comments

Hi First I would like to thank you for the amazing library, it is really powerful and full with features. However, I have been faced with a problem. I have been trying to Pitch Shift an already existing audio file on Android, but I have had no luck. What I have right now only produces static noise. I don't want to use the AudioDispatcherFactory.fromPipe() Method because it requires a ffmpeg, which not all Android machines have. Thank you for your time.

    `public class MainActivity extends AppCompatActivity {
      String _FileName;
       AudioDispatcher ad;
          PitchShifter ps;

      @Override
    protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

     _FileName = Environment.getExternalStorageDirectory().getAbsolutePath();
    _FileName += "/File/sound.3gp";
     }

     public  void OnButtonClick(View v){
      try{
      FileInputStream fs = new FileInputStream(_FileName);
       UniversalAudioInputStream Uas = new UniversalAudioInputStream(fs,new               TarsosDSPAudioFormat(22050,16,1,true,true));
       ad = new  AudioDispatcher(Uas,1024,512);
    Toast.makeText(MainActivity.this,"ad made u did somthing     right",Toast.LENGTH_SHORT).show();}
    catch (Exception e){

      Toast.makeText(MainActivity.this,"keep trying man",Toast.LENGTH_SHORT).show();

}

   //try{
       int minBuffSize= AudioTrack.getMinBufferSize(22050, AudioFormat.CHANNEL_OUT_MONO,    AudioFormat.ENCODING_PCM_16BIT);
   // ad.addAudioProcessor(new PitchShifter(ad,2,22050,1024,1024-256));

      ad.addAudioProcessor(new AndroidAudioPlayer(new   TarsosDSPAudioFormat(22050,16,1,true,true),minBuffSize, AudioManager.STREAM_MUSIC));
         new Thread(ad,"ad").start();
        Toast.makeText(MainActivity.this,"prossesor added",Toast.LENGTH_SHORT).show();
        new CountDownTimer(5000,1000) {
            @Override
            public void onTick(long millisUntilFinished) {

            }

            @Override
            public void onFinish() {
               ad.stop();
                Toast.makeText(MainActivity.this,"stoped",Toast.LENGTH_SHORT).show();
            }
        }.start(); 
    }}`

Agubuzoboy avatar Feb 21 '16 15:02 Agubuzoboy

Hi,

You can decode your audio (3gp) file to mono wav and read it directly without the need for ffmpeg.

The advantage of ffmpeg is that it can handle any audio encoding. The main disadvantage is that it is difficult to setup.

Good luck with your project!

JorenSix avatar Mar 31 '16 12:03 JorenSix

Hi! I have a mono wav. But I'm not sure about read it directly without the need for ffmpeg. Do I need to rebuild library with disabled convertion to mono?

ejiektpobehuk avatar Jun 04 '16 07:06 ejiektpobehuk

Hello, I have the mono wav file but it wouldn't read directly saying I need ffmpeg. @JorenSix What should I do in that case? I am using the AudioDispatcherFactory.fromPipe() method.

ranatrk avatar May 19 '17 08:05 ranatrk