Forum: PC-Programmierung .wav dateien auslesen in c++


von Weixi (Gast)


Lesenswert?

Hallo liebe Programmierfreunde

Ich und mein Freund müssen für ein Projekt in der Schule
eine Wave Datei (.wav) auslesen und bearbeiten.

Jedoch haben wir bisher noch nichts mit diesem Thema zu tun gehabt.

Mene Frage:
Könnte hier jemand vll. einen Code zum einfachen aus- bzw. einlesen von 
.wav Dateien hereinstellen ?

Mfg Weixi

von Peter II (Gast)


Lesenswert?

einfach wie jede andere Datei auch öffnen.

von bubu (Gast)


Lesenswert?

Dafuer gibt es eine tolle Library: http://www.mega-nerd.com/libsndfile/

von Martin S. (sirnails)


Lesenswert?

Vergiss bei WAV nicht die PCM.

von lovos (Gast)


Lesenswert?

Man muss erst einen Header einlesen, wo die wichtigsten Parameter 
drinstehen.
Mehr-Byte größen sind im little endian Format gespeichert

1
0         4   ChunkID          Contains the letters "RIFF" in ASCII form
2
                               (0x52494646 big-endian form).
3
4         4   ChunkSize        36 + SubChunk2Size, or more precisely:
4
                               4 + (8 + SubChunk1Size) + (8 + SubChunk2Size)
5
                               This is the size of the rest of the chunk 
6
                               following this number.  This is the size of the 
7
                               entire file in bytes minus 8 bytes for the
8
                               two fields not included in this count:
9
                               ChunkID and ChunkSize.
10
8         4   Format           Contains the letters "WAVE"
11
                               (0x57415645 big-endian form).
12
13
The "WAVE" format consists of two subchunks: "fmt " and "data":
14
The "fmt " subchunk describes the sound data's format:
15
16
12        4   Subchunk1ID      Contains the letters "fmt "
17
                               (0x666d7420 big-endian form).
18
16        4   Subchunk1Size    16 for PCM.  This is the size of the
19
                               rest of the Subchunk which follows this number.
20
20        2   AudioFormat      PCM = 1 (i.e. Linear quantization)
21
                               Values other than 1 indicate some 
22
                               form of compression.
23
22        2   NumChannels      Mono = 1, Stereo = 2, etc.
24
24        4   SampleRate       8000, 44100, etc.
25
28        4   ByteRate         == SampleRate * NumChannels * BitsPerSample/8
26
32        2   BlockAlign       == NumChannels * BitsPerSample/8
27
                               The number of bytes for one sample including
28
                               all channels. I wonder what happens when
29
                               this number isn't an integer?
30
34        2   BitsPerSample    8 bits = 8, 16 bits = 16, etc.
31
          2   ExtraParamSize   if PCM, then doesn't exist
32
          X   ExtraParams      space for extra parameters
33
34
The "data" subchunk contains the size of the data and the actual sound:
35
36
36        4   Subchunk2ID      Contains the letters "data"
37
                               (0x64617461 big-endian form).
38
40        4   Subchunk2Size    == NumSamples * NumChannels * BitsPerSample/8
39
                               This is the number of bytes in the data.
40
                               You can also think of this as the size
41
                               of the read of the subchunk following this 
42
                               number.
43
44        *   Data             The actual sound data.
44
45
46
44   <block align>   der erste Abtastwert
47
  <block align>   der zweite Abtastwert

Bitte melde dich an um einen Beitrag zu schreiben. Anmeldung ist kostenlos und dauert nur eine Minute.
Bestehender Account
Schon ein Account bei Google/GoogleMail? Keine Anmeldung erforderlich!
Mit Google-Account einloggen
Noch kein Account? Hier anmelden.