I am relatively new to programming and have been carefully studying the documentation regarding Java audio. My end goal is to create an audio analysis app however I am having issues regarding dealing with the incoming datastream.
I have requested a targetdataline with a specified format (For now assume I am dealing with just two channels, each with different content). What I need to do is split this stream into multiple circular buffers (one for each channel) that I can then process individually.
try { line = (TargetDataLine) AudioSystem.getLine(info); line.open(format); ByteArrayOutputStream out = new ByteArrayOutputStream(); int numBytesRead; byte[] data = new byte[line.getBufferSize() / 5]; line.start(); int size = 0; while (size< 1000) { size++; numBytesRead = line.read(data, 0, data.length); out.write(data, 0, numBytesRead); } out.writeTo(outputStream); System.out.println(out.size()); } catch (LineUnavailableException ex) { }finally{ outputStream.close(); }
This is my current code for getting the targetdataline into a buffer but this does not deal with splitting the channels. I have spent ages on google and cannot find a method for splitting the stream every two bytes. If anyone can even point me towards some reading material on this it would be much appreciated, or suggest a way to go about this.
Also, regarding this, is it more efficient to split the stream into multiple buffers (I could do each channel on a separate thread), or to write the entire stream to a buffer and then split the buffer content into separate channel data. (My head is telling me this is not efficient and I would need a bigger buffer size on one thread for this.
Thanks for your help. This is my first post so I hope I have done it right.