Results 1 to 3 of 3
  1. #1
    cielle is offline Member
    Join Date
    Dec 2010
    Posts
    8
    Rep Power
    0

    Default Display sound data value from ByteArrayOutputStream

    hi People,

    Can advise what is the function that i can use to retrieve or display the data that i stored in ByteArrayoutputStream buffer?

    So far i can only store the data in... but how can i retrieve and display them on output panel?

    Many Thanks

  2. #2
    lovelesh is offline Senior Member
    Join Date
    Nov 2010
    Location
    Delhi
    Posts
    135
    Blog Entries
    1
    Rep Power
    0

    Post

    Code below might be of any help to you:

    Java Code:
    import java.io.ByteArrayOutputStream;
    import java.io.FileOutputStream;
    import java.io.IOException;
    import java.io.OutputStream;
    
    public class DateDifference
    {
    	public static void main(String[] args) throws IOException {
    		ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
    		String s = "Put this string in ByteArrayOutputStream";
    		byte buf[] = s.getBytes();
    		// write the bytes in ByteArrayOutputStream 
    		byteArrayOutputStream.write(buf);
    		
    		// Call for printing contents
    		printStreamContents(byteArrayOutputStream);
    		
    		// write the contents to file
    		writeToFile(byteArrayOutputStream);
    	}
    	
    	private static void printStreamContents(ByteArrayOutputStream baos){
    		
    		// printing the contents
    		System.out.println("ByteArrayOutputStream contents: " + baos.toString());
    	}
    	
    	private static void writeToFile(ByteArrayOutputStream baos) throws IOException{
    		
    		OutputStream outputStream = new FileOutputStream("example.txt");
    		baos.writeTo(outputStream);
    		outputStream.close();
    		
    	}
    }

  3. #3
    cielle is offline Member
    Join Date
    Dec 2010
    Posts
    8
    Rep Power
    0

    Default

    Thank you for your reply. I have tried with .toString method. But stilll ... Can advise on below?

    Below is my scenario:
    I wish to display the sound data value (numeric) at the output panel while i am capturing sound from my microphone.
    The program is included with the playback features which is not included in this topic.

    For this purpose, i have a temporary buffer to store the captured sound data temporary from audio dataline.

    Java Code:
    class CaptureThread extends Thread{
    byte tempBuffer[] = new byte[10000];
    
    public void run(){
    byteArrayOutputStream = new ByteArrayOutputStream();
    
    //Read data from the internal buffer of the data line.
    int cnt = targetDataLine.read(tempBuffer, 0, tempBuffer.length);
    
    if(cnt > 0){
    //Save data in output stream object.
    byteArrayOutputStream.write(tempBuffer, 0, cnt);
    System.out.println(byteArrayOutputStream.toString());
    }//end if
    
    byteArrayOutputStream.close();
    }
    The result that i got is a bunch of unknown character displayed on the output panel. I have gon through the method description for byteArrayOutputStream.toString(). ByteArrayOutputStream (Java 2 Platform SE v1.4.2)
    Suppose it shows the content of buffer.

    The purpose i wish to display the content because i wish to find out the way to retrieve the sound data for Fast Fourier transform.

    Like MATLAB, the sampled sound data (x) can be display with such function
    [x,fs,nb]=wavread("My_love.wav");

    Hereby wish to have your advise how can i get do the same thing of displaying the sound data value with Java.

    Please advise. Many thanks on correcting my mistake.

Similar Threads

  1. how to display the retriewing data in gridview
    By mahesh_mscit in forum AWT / Swing
    Replies: 0
    Last Post: 08-01-2009, 06:02 PM
  2. how to display data from oracle database?
    By deru4jesus in forum JavaServer Faces (JSF)
    Replies: 0
    Last Post: 04-16-2009, 09:46 AM
  3. ByteArrayInputStream and ByteArrayOutputStream
    By new_2_java in forum New To Java
    Replies: 6
    Last Post: 07-31-2008, 11:02 PM
  4. Best GUI Element to Display Mass Data
    By hannehomuth in forum Advanced Java
    Replies: 3
    Last Post: 07-30-2008, 12:18 AM
  5. how to display data in Jtree
    By paty in forum New To Java
    Replies: 1
    Last Post: 07-24-2007, 01:28 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •