Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 2 of 2

Thread: Multichannel Audio Stream into separate channel Buffers

  1. #1
    Junior Member
    Join Date
    Dec 2017
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Post Multichannel Audio Stream into separate channel Buffers

    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.

  2. #2
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,139
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default Re: Multichannel Audio Stream into separate channel Buffers

    Just so everyone knows, also posted at: Multichannel Audio Into Buffer With Separate Arrays - Java | Dream.In.Code
    If you don't understand my answer, don't ignore it, ask a question.

Similar Threads

  1. Input stream buffers up to 4K before available to read
    By sasatap in forum File I/O & Other I/O Streams
    Replies: 6
    Last Post: June 18th, 2014, 11:33 AM
  2. Message Buffers and Data Structures in Java
    By bytownbrooks in forum Java Theory & Questions
    Replies: 1
    Last Post: January 23rd, 2014, 05:41 PM
  3. Threads, Audio Application, Audio loading twice error
    By dpjmie in forum What's Wrong With My Code?
    Replies: 2
    Last Post: April 19th, 2013, 01:18 PM
  4. Getting audio stream to play from jar file instead of system directory?
    By nivangerow in forum What's Wrong With My Code?
    Replies: 26
    Last Post: October 5th, 2011, 09:51 AM
  5. could not create audio stream from input stream
    By chronoz13 in forum What's Wrong With My Code?
    Replies: 11
    Last Post: June 2nd, 2011, 02:08 AM

Tags for this Thread