Analyzing audio files java -


i'm working on music visualizer in java i'm running conceptual issue i'm having trouble getting around. program reads audio, , i've figured out mathematical operations/drawing functions, issue figuring out how set methods such programs draws visuals while audio plays.

this snippet of code reading in audio (after line has been created, , audioinputsystem, saved ais, has been called on file getaudioinputstream):

byte[] data = new byte[ext_buff_size]; int bytesread =0; while(bytesread!= -1){    try{       bytesread = ais.read(data,0,data.length);    }catch(ioexception e){e.printstacktrace();}    if(bytesread>0){       int byteswritten = line.write(data,0,bytesread);    } } line.drain(); line.close(); 

i've tried putting calls other functions @ different places inside while or try no avail. hoping perhaps putting before line.write() work doesn't.

it seems solution call read , write functions on increments of file instead of whole thing, i'm afraid create discontinuities in playback. first time posting on here, after lot of lurking, detailed enough in explaining question. if not try 1 last time: how 1 organize program read audio file, bunch of arithmetic operations on file, while appears both happening simultaneously (or perhaps both happen simultaneously using thread scheduling or can't quite figure out)? in advance , help!

you should able process , play-back audio file in "chunks" of specific size same way audio drivers process audio streams. (128, 256, 512, etc. samples per chunk) more samples per chunk means more "visualization processing" time per chunk before audio player ready next chunk of audio samples. can experiment chunk sizes find balance between enough visualization processing time , glitch free playback.


Comments

Popular posts from this blog

ZeroMQ on Windows, with Qt Creator -

unity3d - Unity SceneManager.LoadScene quits application -

python - Error while using APScheduler: 'NoneType' object has no attribute 'now' -