java - Tarsos dsp Android AudioTrack plays static or too fast -


this problem has been frustrating me while. i'm trying use tarsos dsp perform basic signal processing on project i'm working on android. audio comes standard wav file 44.1k, 16bit stereo. when set , run tarsos audiodispatcher using audioprocessor uses android's audiotrack output sound static or audio plays way fast.

here code sets audio dispatcher

public void play(string source, double starttime, final double endtime){     inputstream wavstream;     try {         wavstream = new fileinputstream(source);         universalaudioinputstream audiostream = new universalaudioinputstream(wavstream, audioformat);          dispatcher = new audiodispatcher(audiostream, buffersize, overlap);         androidaudioplayer player = new androidaudioplayer(audioformat, buffersize);         dispatcher.addaudioprocessor(player);         dispatcher.skip(starttime);         new thread(new runnable() {             @override             public void run() {                 while (dispatcher.secondsprocessed() < endtime) {                     try {                         thread.sleep(10);                     } catch (interruptedexception e) {                         e.printstacktrace();                     }                 }                 dispatcher.stop();             }         }).start();         dispatcher.run();         try {             audiostream.close();         } catch (ioexception e) {             e.printstacktrace();         }     }catch (filenotfoundexception e){e.printstacktrace();} } 

one thing i've noted if let audiodispatcher run through entire wav file reports total number of seconds processed longer indicated in header of wav file makes methods set start , end times inaccurate still within bounds (usually). (why happen?)**

here code androidaudioplayer implements tarsos audioprocessor:

public class androidaudioplayer implements audioprocessor { private audiotrack audiotrack; androidaudioplayer(tarsosdspaudioformat audioformat, int buffersize){     audiotrack = new audiotrack(audiomanager.stream_music,             (int)audioformat.getsamplerate(),             audioformat.channel_out_stereo,             audioformat.encoding_pcm_16bit,             buffersize,             audiotrack.mode_stream); } @override public boolean process(audioevent audioevent){     short[] shorts = new short[audioevent.getbuffersize() / 2];     bytebuffer.wrap(audioevent.getbytebuffer()).order(byteorder.little_endian).asshortbuffer().get(shorts);     audiotrack.write(shorts, 0, shorts.length);     audiotrack.play();     return true; }  @override public void processingfinished(){} 

}

i have audio processor wrote uses audiodispatcher write clip wav file using javazoom produces static or incorrect audio. however, when write clip wav file using inputstream , javazoom works fine of time or produces static assuming because starttime , stoptime variables set incorrectly methods rely on tarsos. insight appreciated.

before methods above called, call method uses audiodispatcher on same wav file oscilloscope , complexonsetdetector audio processors generate waveform view , fill array timecodes onsets. audioformat variable created this: tarsosdspaudioformat audioformat = new tarsosdspaudioformat(samplerate, 16, 2, false, false);, sample rate read wav file , i've checked reads correctly. *the buffer size 1024 , overlap 512 , i've tried playing of these values.

i have changed buffer size 64kb , overlap 32kb. when audio plays, sounds correct, skipping little bit. however, still plays static , no matter length of wav file use, audiodispatcher reports 315 seconds long*.

**i have fixed problem. loading wav file being created javazoom mp3 converter continually overwriting file without deleting first. think tarsos using file length determine play length incorrect due overwriting out deletion. deleting file first solved problem.

i need figure out why audio skipping during playback , plays static , think i'm go.

use mono(1 channel) input. tarsosdsp audio processors not support stereo currently.


Comments

Popular posts from this blog

php - Submit Form Data without Reloading page -

linux - Rails running on virtual machine in Windows -

php - $params->set Array between square bracket -