CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 6 of 6
  1. #1
    Join Date
    Dec 2006
    Posts
    14

    Question How to append 2 wav file

    Hi All,

    I'm creating a midlet using j2me. I need to combine 2 wave file and save the newly created sound file on the phone. How do I go about combining (append, one after the other) 2 existing sound file?


    Any suggestions?

    Thanks
    Last edited by bubblestar; December 18th, 2006 at 10:53 AM.

  2. #2
    Join Date
    Dec 2006
    Posts
    14

    Question Re: How to append 2 wav file

    So, is there any1 who can help?

    Or maybe can teach me how do i do editing on the wav file itself?

  3. #3
    Join Date
    Mar 2000
    Location
    Vancouver, BC, Canada
    Posts
    278

    Re: How to append 2 wav file

    I've never tried that sort of thing, but have you tried messing around with simply reading the first file in as an array of bytes, writing it to a new file, then reading the 2nd file in as an array of bytes and appending it to the new file?
    David Meikle
    Quantum Unit Solutions, LLC
    www.quantumunit.com

  4. #4
    Join Date
    Dec 2001
    Location
    Greece, Athens
    Posts
    1,015

    Re: How to append 2 wav file

    Quote Originally Posted by dmeikle
    I've never tried that sort of thing, but have you tried messing around with simply reading the first file in as an array of bytes, writing it to a new file, then reading the 2nd file in as an array of bytes and appending it to the new file?
    That won't work, since the header information is not updated. Generally, I suppose you will have to take a look at the wav header format (try a search, there are plenty tutorials on the net). To append 2 wav files you shoud:
    1) Read the headers of the two wav files.
    2) Read the audio data (that is actually an array of short int, or int, depending on the sample resolution), for both files.
    3) IF the two signals have different sampling frequencies, then you will probably have to resample one of the two signals (in order to have 2 signals with the same sampling freq.).
    4) Create a new wav file (binary):
    4a) Firstly, write in that file a wav header which is the SAME as one of the two initial files EXEPT THAT you must have changed the chunkSize and Subchunk2Size, depending on the NEW data length (which is the sum of the lengths of the 2 signals). Also be sure that the sampling frequency field is the right one.
    4b) After the wav header is written, then simply write in that file the audio data (stored in int arrays) of the 2 signals.



    PS: The header fields (e.g. chunkSize) and generally the wav header is discribed in several tutorials and sites (here is an example).
    Theodore
    Personal Web Page (some audio segmentation tools): www.di.uoa.gr/~tyiannak

  5. #5
    Join Date
    Dec 2006
    Posts
    14

    Re: How to append 2 wav file

    Quote Originally Posted by yiannakop
    That won't work, since the header information is not updated. Generally, I suppose you will have to take a look at the wav header format (try a search, there are plenty tutorials on the net). To append 2 wav files you shoud:
    1) Read the headers of the two wav files.
    2) Read the audio data (that is actually an array of short int, or int, depending on the sample resolution), for both files.
    3) IF the two signals have different sampling frequencies, then you will probably have to resample one of the two signals (in order to have 2 signals with the same sampling freq.).
    4) Create a new wav file (binary):
    4a) Firstly, write in that file a wav header which is the SAME as one of the two initial files EXEPT THAT you must have changed the chunkSize and Subchunk2Size, depending on the NEW data length (which is the sum of the lengths of the 2 signals). Also be sure that the sampling frequency field is the right one.
    4b) After the wav header is written, then simply write in that file the audio data (stored in int arrays) of the 2 signals.



    PS: The header fields (e.g. chunkSize) and generally the wav header is discribed in several tutorials and sites (here is an example).

    hey thanks..
    but how to i start reading the content of the wav file using j2me? any codes to guide me along?

  6. #6
    Join Date
    Dec 2001
    Location
    Greece, Athens
    Posts
    1,015

    Re: How to append 2 wav file

    Quote Originally Posted by bubblestar
    hey thanks..
    but how to i start reading the content of the wav file using j2me? any codes to guide me along?
    Hi again. Sorry, I didn't notice you needed J2me functionality. Wel, I am not familiar with j2me, but there is an Api for using media resources, called Mobile Media API (link here).
    Theodore
    Personal Web Page (some audio segmentation tools): www.di.uoa.gr/~tyiannak

Posting Permissions

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





Click Here to Expand Forum to Full Width

Featured