473,473 Members | 2,100 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Merging 2 binary data files together in C

3 New Member
Hi,
I want to be able to merge audio file A and audio file B into a new file C.
All of the files are binary, however I am stooped of how to do it. I'm not sure if different lengths of the audio files will affect the merging to create file C.
Could someone help me out?

*I had a look at the python thread on merging 2 binary files together, however I don't know how to implement it in C

Thank you.
Sep 18 '11 #1
5 4334
weaknessforcats
9,208 Recognized Expert Moderator Expert
There may be more to this than you think. Audio files have a precise format so your merged file C probably has to be created by processing file A and B rather than just appending them together.

You don't say what kind of audio files you have but I would research the file format before proceeding.
Sep 18 '11 #2
kmak
3 New Member
The audio files I have are WAV files.

typedef struct wav_s {
u32 chunk_ID; /* 'RIFF' - 0x52494646 */
u32 chunk_size; /* size of remainder of file, in bytes */
u32 format_ID; /* 'WAVE' - 0x57415645 */
u32 subchunk1_ID; /* 'fmt ' - 0x666d7420 */
u32 subchunk1_size; /* 16 (size in bytes of rest of this header) */
u16 audio_format; /* 1 (PCM) */
u16 num_channels; /* 2 (left and right stereo) */
u32 sample_rate; /* 48000 */
u32 byte_rate; /* sample rate * channels * bits per sample/8 */
u16 block_align; /* bytes for one sample (all channels) */
u16 bits_per_sample; /* 16 */
u32 subchunk2_ID; /* 'data' - 0x64617461 */
u32 subchunk2_size; /* size of sample data, in bytes */
} wav_t;

At the moment for my program, I can play a WAV file by storing the data into two ping-pong buffers which are then passed to an audio codec.

My aim is to mix two audio wav files (of the same format) together so that the mixed audio data can be passed to the codec to be played at the same time. I know that the raw audio data begins 44 bytes into the file.

Also, I am not sure if it is easier to create a sine function to create a beep (440hz -> 'A') and then mix it to the raw audio data (sampled at 48000hz). However, I don't know how to implement the values to be at 16bit.

Once again, any help on merging two wav files would be greatly appreciated.
Thank you
Sep 18 '11 #3
weaknessforcats
9,208 Recognized Expert Moderator Expert
Can you not play file A and file B concurrently on separate threads?
Sep 18 '11 #4
kmak
3 New Member
I can't play both files at the same time, as the data stored in the buffers are passed to the same codec driver one block at a time.0 If I try to run both separately, only one file is played then other the sequentially.

So my idea is that since both files are WAV files and that the raw audio data starts 44 bytes into each file, if the audio data can be somehow merged then the buffer should be able to play the contents of both. I am still stomped on how to do this unfortunately.
Sep 19 '11 #5
Banfa
9,065 Recognized Expert Moderator Expert
WAV file format is fairly well known and easily findable on the internet.

Concatinating 2 files that were already using the same sampling rate, etc should be a fairly easy task of just copying the samples on one file and then the samples of the other file and then writing the file header appropriately.

Merging 2 files may be a little more complex but again, assuming the data has the sample sampling rate, not an insurmountable problem. Something as simple as adding the samples together and then normalising them back to the original amplitude would probably work.
Sep 19 '11 #6

Sign in to post your reply or Sign up for a free account.

Similar topics

4
by: Simon | last post by:
Hi all, I have a process, where I take a dataset from an SQL call, and need to write an XML file from that dataset. The data set can contain 10's of tables, each with 100's of rows, and I have...
4
by: Dimitri Papoutsis | last post by:
Hi there, ... i want to read in a binary data file and to cast each pair of 2 bytes to a signed short value. i try to different ways, but none results in what i suppose it should result. ...
3
by: GMane Python | last post by:
Hello All. I have a program that downloads 'gigabytes' of Axis NetCam photos per day. Right now, I set up the process to put the images into a queue, and every 30 or so seconds, 'pop' them from...
15
by: Xarky | last post by:
Hi, Is it possible to make use of data files in C? If yes can someone tell how or suggest me a site from where I can learn them. Thanks in Advance for your patience.
4
by: Nikolay Petrov | last post by:
Any general ideas how to get binary data(files) from WebService to an ASP .NET app and then save it to client's machine? Thanks
3
by: David Warner | last post by:
Greetings! I am working on a C app that needs to read print files generated by lp that contain HP LaserJet PCL codes. If the PCL contains binary data to define a bit map to be printed on the...
0
by: Michael B. Trausch | last post by:
I am attempting to piece together a Python client for Fotobilder, the picture management server on Livejournal. The protocol calls for binary data to be transmitted, and I cannot seem to be able...
1
by: adamrace | last post by:
Hi, I've got two excel files, one has a list of products and their current prices and they all have a product ID, I have another file with a list of price's that need updating. I was wondering...
5
by: =?Utf-8?B?VHJhY2tz?= | last post by:
I include some sample binary data files (produced by my software) with my application installation for the user to do what they want with. I put the files in the Users Personal Data...
4
by: BerlinBrown | last post by:
Is it possible to just build the binary content of a zip file. I want to create the content in memory (e.g. return binary data) and then get those byte strings representing the zip file? Is that...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
0
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.