Results 1 to 18 of 18
  1. #1
    prof.deedee is offline Member
    Join Date
    Oct 2009
    Posts
    36
    Rep Power
    0

    Default HEEEEElp or I will die

    Hi

    please help me or I going to kill myself or my supervisor will kill me:eek::eek:

    the story is:
    I need to read sound file change the data slightly then save this new data either in the same sound file or in other one...


    please help me

    what I did is:
    I read the file and made changes in the data but I am stuck in save these changes:confused::confused::confused:


    Java Code:
    int totalFramesRead = 0;
            File fileIn = new File("/Applications/tada22.wav");
    // somePathName is a pre-existing string whose value was
    // based on a user selection.
            try {
                AudioInputStream audioInputStream =
                        AudioSystem.getAudioInputStream(fileIn);
    
                 AudioFileFormat audioFileFormat =
                        AudioSystem.getAudioFileFormat(fileIn);
    
                int bytesPerFrame =
                        audioInputStream.getFormat().getFrameSize();
    
                // Set an arbitrary buffer size of 1024 frames.
                int numBytes = 1024 * bytesPerFrame;
                byte[] audioBytes = new byte[numBytes];
    
                try {
                    int numBytesRead = 0;
                    int numFramesRead = 0;
                    int count=0;
                    // Try to read numBytes bytes from the file.
                    while ((numBytesRead =
                            audioInputStream.read(audioBytes)) != -1) {
    
                        
    
                        // Calculate the number of frames actually read.
                        numFramesRead = numBytesRead / bytesPerFrame;
                        totalFramesRead += numFramesRead;
                        // Here, do something useful with the audio data that's
                        // now in the audioBytes array...
                       
                        [COLOR="Red"]for(int x=1;x<numBytes;x+=2)
                        {
                            
                            
                            String audio=Byte.toString(audioBytes[x]);
                            int m=Integer.parseInt(audio);
                            String audio2=Integer.toBinaryString(m);
    
    
                            if (audio2.charAt(0) == '0') {
                            String change="0111111111111111";
                            
                            int q = 0;
                            int r = 0;
                            
                                for (int o = change.length(); o >= 1; o--) {
                                    System.out.println("\nq=" + q+"r= "+r);
                                    q += (Integer.parseInt(change.substring(o - 1, o))) * Math.pow(2, r++);
                                }
    
    
                                audioBytes[x]=(byte)q;
    
                            }
    
                        }
    
                    }[/COLOR]
    
                        
                   
                } catch (Exception ex) {
                    // Handle the error...
                    System.out.println("inner try");
                }
            } catch (Exception e) {
                // Handle the error...
                System.out.println("outer try");
            }

    This code I found it in sun webpage ... it store part of the data from the sound file in byte[] audioBytes and then read another part...etc

    The read area is the changes to bytes that I did is to make the positive bytes=-1

  2. #2
    Norm's Avatar
    Norm is online now Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,307
    Rep Power
    25

    Default

    Why are you using a String when dealing with bytes?
    Why not keep all the data processing using bytes?

  3. #3
    prof.deedee is offline Member
    Join Date
    Oct 2009
    Posts
    36
    Rep Power
    0

    Default

    This is not my question :(

    my problem is how to save the byte[] audioBytes after made changes into file
    then read another part of data in audioBytes made changes then save it in that file and so on until finishing the whole data in the original file

    pleassssssssssssssssse help

    ok I will start crying

  4. #4
    PhHein's Avatar
    PhHein is offline Senior Member
    Join Date
    Apr 2009
    Location
    Germany
    Posts
    1,430
    Rep Power
    7

    Default

    Quote Originally Posted by prof.deedee View Post
    This is not my question :(
    But it's a suggestion from Norm.

    Quote Originally Posted by prof.deedee View Post

    ok I will start crying
    If it helps :rolleyes:
    Math problems? Call 1-800-[(10x)(13i)^2]-[sin(xy)/2.362x]
    The Ubiquitous Newbie Tips

  5. #5
    prof.deedee is offline Member
    Join Date
    Oct 2009
    Posts
    36
    Rep Power
    0

    Default

    but to answer your question:

    I need to change a single bit in that byte
    for example :
    if byte b=2
    this mean in 8 bit it =00000010

    what I need is to change the last bit to 1
    then b=00000011=3

    that why..............please if you have better idea help me:)

  6. #6
    j2me64's Avatar
    j2me64 is offline Senior Member
    Join Date
    Sep 2009
    Location
    Zurich, Switzerland
    Posts
    962
    Rep Power
    5

    Default

    Quote Originally Posted by prof.deedee View Post
    what I need is to change the last bit to 1
    then b=00000011=3

    use the boolean logical OR: a | b will chage the last bit to 1 if b = 1

  7. #7
    JosAH's Avatar
    JosAH is online now Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,432
    Blog Entries
    7
    Rep Power
    20

    Default

    Quote Originally Posted by prof.deedee View Post
    I need to change a single bit in that byte
    Replicating Norm's question: what is that String doing there if you want to fiddle with bits in a byte?

    kind regards,

    Jos

  8. #8
    Norm's Avatar
    Norm is online now Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,307
    Rep Power
    25

    Default

    the whole data in the original file
    Its better NOT to write over the original file. Especially when testing.
    Write to a new file, then rename after the files are closed.
    At some point you could delete the original file and only have the the new file that was renamed.

  9. #9
    prof.deedee is offline Member
    Join Date
    Oct 2009
    Posts
    36
    Rep Power
    0

    Default

    Thank you so much for your replays .... all of you

    but Norm, could you please slowly explain what you say and in code please:)

  10. #10
    prof.deedee is offline Member
    Join Date
    Oct 2009
    Posts
    36
    Rep Power
    0

    Default

    Thank you so much for your replays .... all of you

    but Norm, could you please slowly explain what you say and in code please:)

  11. #11
    Norm's Avatar
    Norm is online now Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,307
    Rep Power
    25

    Default

    To "edit" a file, open the input file and and an output file with a temp name.
    Copy the good data to the output file, change data as needed and write to the output file.
    Continue until all of the file has been read and copied to the new file.
    Close both files.
    Rename the input file to a unique name to save it. Rename the output file to the original file name.

  12. #12
    PhHein's Avatar
    PhHein is offline Senior Member
    Join Date
    Apr 2009
    Location
    Germany
    Posts
    1,430
    Rep Power
    7

    Default

    But, but that wasn't code ;)
    Math problems? Call 1-800-[(10x)(13i)^2]-[sin(xy)/2.362x]
    The Ubiquitous Newbie Tips

  13. #13
    JosAH's Avatar
    JosAH is online now Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,432
    Blog Entries
    7
    Rep Power
    20

    Default

    Quote Originally Posted by PhHein View Post
    But, but that wasn't code ;)
    True but the OP isn't dead yet; I haven't seen any smelly rotting carcass, falling apart because of the feasting maggots ...

    kindest regards,

    Jos

  14. #14
    prof.deedee is offline Member
    Join Date
    Oct 2009
    Posts
    36
    Rep Power
    0

    Default

    guys please my problem is:


    i've got a small app which processes audio data

    i'm reading the audio data from a WAV in small chunks of about 8000 bytes, using a loop with the audioInputStream.read() method to read each chunk of data into a byte array. the app then processes the data in the byte array, then repeats the loop for each consecutive chunk of data.

    i need to save the data to a new WAV file. ideally i'd like to stream the data out in a similar way as it's streaming in, so at the end of each iteration i can write the modified byte array out to the new file, and discard the data. i cannot seem to find ANY way of doing this at all.

    really what i need is a version of the AudioInputStream class that allows me to write to it rather than read from it (AudioOutputStream anyone?). then i could use this to write a new WAV file chunk by chunk as i need to.

    I have tried to save first chunk of byte[] that I have read in the first iteration in:
    ByteArrayInputStream tt=new ByteArrayInputStream(byte[] audioBytes);

    and then save this ByteArrayInputStream in audioInputStream to write it in the file
    audioInputStream=AudioSystem.getAudioInputStream(t t);

    but in this way I will only write the first bytes from the first iteration only since that I don't know how to read another chuck of data and concatenating it to the previous one and then when I finish write all of then to a file


    please help me it is urgent

  15. #15
    masijade is offline Senior Member
    Join Date
    Jun 2008
    Posts
    2,571
    Rep Power
    9

    Default Not!

    Quote Originally Posted by prof.deedee View Post
    HEEEEElp or I will die
    It's been nice knowing you.

  16. #16
    prof.deedee is offline Member
    Join Date
    Oct 2009
    Posts
    36
    Rep Power
    0

    Default

    so where is the help??

  17. #17
    PhHein's Avatar
    PhHein is offline Senior Member
    Join Date
    Apr 2009
    Location
    Germany
    Posts
    1,430
    Rep Power
    7

    Default

    In your textbook.
    Math problems? Call 1-800-[(10x)(13i)^2]-[sin(xy)/2.362x]
    The Ubiquitous Newbie Tips

  18. #18
    Norm's Avatar
    Norm is online now Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,307
    Rep Power
    25

    Default

    How about using classes that have pairs of input and output classes?

    How are you currently writing the bytes to a file?

Posting Permissions

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