c# - What is actually contained in data chunk in wav file? -


for example take case of stereo channel wav file sample rate 44100 , bit depth of 16 bits.

exactly how 16 bits divided up?


the audio clip using, first 4 bytes had data first audio channel next 4 bits - have no idea is( when replaced 0 , there no effect on final audio file).


the next 4 bytes had data second audio channel next 4 bits - have no idea is( when replaced 0 , there no effect on final audio file).

so figure out 4 bits are.

wav format audio file starts 44 byte header followed payload uncompressed raw pcm audio data ... in payload area walk across pcm data each sample (point on audio curve) contain data channels ... header tell number of channels ... stereo using bit depth of 16 see 2 bytes (16 bits == bit depth) given channel followed 2 bytes of next channel etc...

for given channel given set of bytes (2 bytes in case) appear in 2 possible layouts determined choice of endianness ... 1st byte followed 2nd byte ... ordering of endianness important here ... header tells endianness using ... typically wav format little endian

each channel generate own audio curve

in code convert pcm data usable audio curve data point must combine bytes of given sample given channel single value ... typically integer , not floating point again header defines ... if integer signed or unsigned ... little endian means read file first (left most) byte become least significant byte followed each subsequent byte becomes next significant byte

in pseudo code :

int mydatapoint  // allocate integer audio curve data point 

step 0

mydatapoint = most-significant-byte 

stop here bit depth of 8

... if have bit depth greater 8 bits left shift make room following byte if

step 1

mydatapoint = mydatapoint << 8 // shove data left 8 bits                                // jacks value                                // , leaves empty right 8 bits 

step 2

// following operation bit wise or operation mydatapoint = mydatapoint  or next-most-significant-byte 

now repeat doing steps 1 & 2 each subsequent next byte of pcm data in order significant least significant (for little endian) ... essential bit depth beyond 16 24 bit audio or 32 bit need combine 3 or 4 bytes of pcm data single integer output audio curve data point

why doing bit shifting nonsense

the level of audio fidelity when converting analog digital driven how accurately recording audio curve ... analog audio continuous curve become digital must sampled discrete points along curve ... 2 factors determine fidelity when sampling analog curve create digital representation ... left right distance along analog audio curve determined sample rate , , down distance along audio curve determined bit depth ... higher sample rate gives more samples per second , greater bit depth gives more vertical points approximate instantaneous height of analog audio curve

bit depth  8 == 2^8  ==   256 distinct vertical values record curve height bit depth 16 == 2^16 == 65536 distinct vertical values record curve height 

so more accurately record digital height of our analog audio curve want become granular possible ... resultant audio curve smooth possible , not jagged happen if allocated 2 bits give 2^2 4 distinct values ... try connect dots when audio curve has 4 vertical values choose on plot ... bit shifting building single integer value many bytes of data ... numbers greater 256 cannot fit 1 byte , must spread across multiple bytes of pcm data

http://www-mmsp.ece.mcgill.ca/documents/audioformats/wave/wave.html


Comments

Popular posts from this blog

commonjs - How to write a typescript definition file for a node module that exports a function? -

openid - Okta: Failed to get authorization code through API call -

ios - Change Storyboard View using Seague -