Hi,
I thought it was great to write a program, which can edit audio-files (wav,mp3,...).
For example load two files, connect them and save as one or load a 1min file and cut out 20seconds and save.
But I searched the onlinehelp and the forum and have still no idea how to realize that. I have not found functions to edit or save audio-files, and I also do not know, how they are made (to cut them in memory per hand).
Could someone post an example or explain how to do it?
Thanks
Is it possible to edit audio-files?
-
- User
- Posts: 35
- Joined: Sat Aug 16, 2003 4:52 pm
- Location: Germany
Is it possible to edit audio-files?
I become better!!! 

Ok
Ok. Forget MP3 for now, start with .wav because the .wav are probably the simplest of the common formats for storing audio because its just raw data.
The WAV file itself consists of: The RIFF chunk which identifies the file as a WAV file, The FORMAT chunk which identifies parameters such as sample rate and the DATA chunk which contains the actual data.
Now you need to use the Openfile command to open the .wav file, and the ReadByte command to read in the different bytes. You probably will also want to use the FileSeek(NewPosition) to go to a position in the file. You probably will also want to use the WriteByte command to write a byte back out to the new merged .wav file.
The WAV file itself consists of: The RIFF chunk which identifies the file as a WAV file, The FORMAT chunk which identifies parameters such as sample rate and the DATA chunk which contains the actual data.
Code: Select all
RIFF Chunk (12 bytes in length total)
Byte Number
0 - 3
"RIFF" (ASCII Characters)
4 - 7
Total Length Of Package To Follow (this is what you will modify to be the size of the combined .wav)
8 - 11
"WAVE" (ASCII Characters)
FORMAT Chunk (24 bytes in length total)
Byte Number
0 - 3
"fmt_" (ASCII Characters)
4 - 7
Length Of FORMAT Chunk (Binary, always 0x10)
8 - 9
Always 0x01
10 - 11
Channel Numbers (Always 0x01=Mono, 0x02=Stereo)
12 - 15
Sample Rate (Binary, in Hz)
16 - 19
Bytes Per Second
20 - 21
Bytes Per Sample: 1=8 bit Mono, 2=8 bit Stereo or 16 bit Mono, 4=16 bit Stereo
22 - 23
Bits Per Sample
DATA
Byte Number
0 - 3
"data" (ASCII Characters)
4 - 7
Length Of Data To Follow
8 - end
-
- User
- Posts: 35
- Joined: Sat Aug 16, 2003 4:52 pm
- Location: Germany
I´m still not sure what to do now...
I think I have to read all bytes in i.e. an array, manipulate what I want and write again that array in a file.
I tried this and had the following problems:
1.
I tried to manipulate the sample rate (bytes 24,25,26,27), but when I wanted to play the wav, the mediaplayer wrote "unknown error".
Could you place an example?
2.
I think I have to read all bytes in i.e. an array, manipulate what I want and write again that array in a file.
I tried this and had the following problems:
1.
I tried to manipulate the sample rate (bytes 24,25,26,27), but when I wanted to play the wav, the mediaplayer wrote "unknown error".
Could you place an example?
2.
I do not know how to edit the bytes 8-end of the DATA chunk. What exactly does a byte change? Do I simply have to delete 10 bytes to make the wav some time shorter or is it more difficult?DATA
Byte Number
0 - 3
"data" (ASCII Characters)
4 - 7
Length Of Data To Follow
8 - end
I become better!!! 

Hmmm...
@Mega,
Okay, forget .wav for now. We have to keep backing up until we find a foundation you can build on. I don't have the time to write the code for you, but I can help you help yourself.
Do this, using the file commands, create a .txt file of 256 bytes and fill it with numbers. Now pull out the different bytes of the file, getting the exact number in that exact position. For example, pull out the 120 byte in the file, add 10 to it, and then write this to a third .txt file.
This will make sure that you understand how to read and write bytes from a file at any given position in that file, and then to alter them and write them back.
Once you have the file mechanics down of read byte and write byte so that you know you are writing the correct bytes out, then play with a .wav file. Go to a search engine and type in .wav format. There are thousands of helpful web sites that talk all about the .wav file format and which bytes to manipulate to do certain things.
Okay, forget .wav for now. We have to keep backing up until we find a foundation you can build on. I don't have the time to write the code for you, but I can help you help yourself.
Do this, using the file commands, create a .txt file of 256 bytes and fill it with numbers. Now pull out the different bytes of the file, getting the exact number in that exact position. For example, pull out the 120 byte in the file, add 10 to it, and then write this to a third .txt file.
This will make sure that you understand how to read and write bytes from a file at any given position in that file, and then to alter them and write them back.
Once you have the file mechanics down of read byte and write byte so that you know you are writing the correct bytes out, then play with a .wav file. Go to a search engine and type in .wav format. There are thousands of helpful web sites that talk all about the .wav file format and which bytes to manipulate to do certain things.
-
- User
- Posts: 35
- Joined: Sat Aug 16, 2003 4:52 pm
- Location: Germany