Add bytes

F

Fran Garcia

I´m trying to do a concatenator of wav files and I´ve the next
problem: The wav files have a header with 44 bytes and the bytes from
40 to 43 represents the length of the wav samples. Now, I want to add
this portion of header of two files but I don´t know how to do it. Can
anybody help me?

|0|1|2|........|40|41|42|43| --> wav file1
|0|1|2|........|40|41|42|43| --> wav file2
-------------------------------------------------------------------
|0|1|2|........|40|41|42|43| --> wav union

Thanks in advance

Fran García
 
S

Stefan Schulz

I´m trying to do a concatenator of wav files and I´ve the next
problem: The wav files have a header with 44 bytes and the bytes from
40 to 43 represents the length of the wav samples. Now, I want to add
this portion of header of two files but I don´t know how to do it. Can
anybody help me?

|0|1|2|........|40|41|42|43| --> wav file1
|0|1|2|........|40|41|42|43| --> wav file2

Get the represented number:
int l1 = x[40] << 24 | x[41] << 16 | x[42] << 8 | x[43]
int l2 = y[40] << 24 | y[41] << 16 | y[42] << 8 | y[43]

add them
int newl = l1 + l2

put it bytewise in your output header.
byte [] outbytes =
{ newl & 0xFF000000 >> 24, newl & 0xFF0000 >> 16, newl & 0xFF00 >> 8,
newl & 0xFF}
 
C

Chris Smith

Fran Garcia said:
I=3Fm trying to do a concatenator of wav files and I=3Fve the next
problem: The wav files have a header with 44 bytes and the bytes from
40 to 43 represents the length of the wav samples. Now, I want to add
this portion of header of two files but I don=3Ft know how to do it. Can
anybody help me?

Sure. Assuming both wav files use the same audio format (e.g., sampling
frequency and such), you would need to find the length of both streams,
add the given 32-bit values, write the new header, then write the audio
data sequentially. There isn't anything too difficult about this.

On the other hand, if the wav files are in different formats, then you
need to convert them, and that can be hard.

--
www.designacourse.com
The Easiest Way To Train Anyone... Anywhere.

Chris Smith - Lead Software Developer/Technical Trainer
MindIQ Corporation
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,774
Messages
2,569,599
Members
45,173
Latest member
GeraldReund
Top