📄 adpcm_算法.txt
字号:
diff = diff + ( steptab[ index ] >> 3 )
check the sign bit:
if ( sampx code & 8 )
diff = -diff
sampx = sampx-1 + diff
check for overflow and underflow errors:
if sampx too large, make it the maximum allowable size (32767)
if sampx too small, make it the minimum allowable size (-32768)
output the new sample, sampx
adjust the step table index:
index = index + indextab[ sampx code ]
check for step table index overflow and underflow:
if index too large, make it the maximum allowable size (88)
if index too small, make it the minimum allowable size (0)
save the previous sample value:
sampx-1 = sampx
this section describes the algorithm used for decoding the 3 bit dvi adpcm. this procedure must be followed for each block for each channel.
get the first sample, samp0, from the block header
set the initial step table index, index, from the block header
output the first sample, samp0
set the previous sample value:
sampx-1 = samp0
while there are still samples to decode
get the next sample code, sampx code
calculate the new sample:
calculate the difference:
diff = 0
if ( sampx code & 2 )
diff = diff + steptab[ index ]
if ( sampx code & 1 )
diff = diff + ( steptab[ index ] >> 1 )
diff = diff + ( steptab[ index ] >> 2 )
check the sign bit:
if ( sampx code & 4 )
diff = -diff
sampx = sampx-1 + diff
check for overflow and underflow errors:
if sampx too large, make it the maximum allowable size (32767)
if sampx too small, make it the minimum allowable size (-32768)
output the new sample, sampx
adjust the step table index:
index = index + indextab[ sampx code ]
check for step table index overflow and underflow:
if index too large, make it the maximum allowable size (88)
if index too small, make it the minimum allowable size (0)
save the previous sample value:
sampx-1 = sampx
encoding
this section describes the algorithm used for encoding the 4 bit dvi adpcm. this procedure must be followed for each block for each channel.
for the first block only, clear the initial step table index:
index = 0
get the first sample, samp0
create the block header:
write the first sample, samp0, to the header
write the initial step table index, index, to the header
set the previously predicted sample value:
predsamp = samp0
while there are still samples to encode, and we're not at the end of the block
get the next sample to encode, sampx
calculate the new sample code:
diff = sampx - predsamp
set the sign bit:
if ( diff <0 )
sampx code = 8
diff = -diff
else
sampx code = 0
set the rest of the code:
if ( diff >= steptab[ index ] )
sampx code = sampx code | 4
diff = diff - steptab[ index ]
if ( diff >= ( steptab[ index ] >> 1 )
sampx code = sampx code | 2
diff = diff - ( steptab[ index ] >> 1 )
if ( diff >= ( steptab[ index ] >> 2 )
sampx code = sampx code | 1
save the sample code, sampx code in the block
predict the current sample based on the sample code:
calculate the difference:
diff = 0
if ( sampx code & 4 )
diff = diff + steptab[ index ]
if ( sampx code & 2 )
diff = diff + ( steptab[ index ] >> 1 )
if ( sampx code & 1 )
diff = diff + ( steptab[ index ] >> 2 )
diff = diff + ( steptab[ index ] >> 3 )
check the sign bit:
if ( sampx code & 8 )
diff = -diff
sampx = sampx-1 + diff
check for overflow and underflow errors:
if predsamp too large, make it the maximum allowable size (32767)
if predsamp too small, make it the minimum allowable size (-32768)
adjust the step table index:
index = index + indextab[ sampx code ]
check for step table index overflow and underflow:
if index too large, make it the maximum allowable size (88)
if index too small, make it the minimum allowable size (0)
this section describes the algorithm used for encoding the 3 bit dvi adpcm. this procedure must be followed for each block for each channel.
for the first block only, clear the initial step table index:
index = 0
get the first sample, samp0
create the block header:
write the first sample, samp0, to the header
write the initial step table index, index, to the header
set the previously predicted sample value:
predsamp = samp0
while there are still samples to encode, and we're not at the end of the block
get the next sample to encode, sampx
calculate the new sample code:
diff = sampx - predsamp
set the sign bit:
if ( diff <0 )
sampx code = 4
diff = -diff
else
sampx code = 0
set the rest of the code:
if ( diff >= steptab[ index ] )
sampx code = sampx code | 2
diff = diff - steptab[ index ]
if ( diff >= ( steptab[ index ] >> 1 )
sampx code = sampx code | 1
save the sample code, sampx code in the block
predict the current sample based on the sample code:
calculate the difference:
diff = 0
if ( sampx code & 2 )
diff = diff + steptab[ index ]
if ( sampx code & 1 )
diff = diff + ( steptab[ index ] >> 1 )
diff = diff + ( steptab[ index ] >> 2 )
check the sign bit:
if ( sampx code & 4 )
diff = -diff
sampx = sampx-1 + diff
check for overflow and underflow errors:
if predsamp too large, make it the maximum allowable size (32767)
if predsamp too small, make it the minimum allowable size (-32768)
adjust the step table index:
index = index + indextab[ sampx code ]
check for step table index overflow and underflow:
if index too large, make it the maximum allowable size (88)
if index too small, make it the minimum allowable size (0)
dsp solutions formerly digispeech wave types
added: 05/22/92
author: digispeech
fact chunk
this chunk is required for all wave formats other than wave_format_pcm. it stores file dependent information about the contents of the wave data. it currently specifies the time length of the data in samples.
wave format header
# define wave_format_digistd (0x0015)
# define wave_format_digifix (0x0016)
wformattag this must be set to either wave_format_digistd or wave_format_digifix.
nchannels number of channels in the wave. (1 for mono)
nsamplespersec frequency the sample rate of the wave file. (8000). this value is also used by the fact chunk to determine the length in time units of the date.
navgbytespersec average data rate. (1100 for digistd or 1625 for digifix)
playback software can estimate the buffer size using the value.
nblockalign block alignment of 2 for digistd and 26 for digifix.
playback software needs to process a multiple of bytes of data at a time, so that the value of can be used for buffer alignment.
wbitspersample this is the number of bits per sample of data.
cbsize the size in bytes of the extra information in the extended wave 'fmt' header. this should be zero.
the definition of the data contained in the digistd and digifix formats are considered proprietary information of digispeech. they can be contacted at:
dsp solutions, inc.
2464 embarcadero way
palo alto, ca 94303
the digistd is a format used in a compression technique developed by digispeech, inc. digistd format provides good speech quality with average rate of about 1100 bytes/second. the blocks (or buffers) in this format cannot be cyclically repeated.
the digifix is a format used in a compression technique developed by digispeech, inc. digifix format provides good speech quality (similar to digistd) with average rate of exactly 1625 bytes/second. this format uses blocks of 26 bytes long.
yamaha adpcm
added 09/25/92
author: yamaha
fact chunk
this chunk is required for all wave formats other than wave_format_pcm. it stores file dependent information about the contents of the wave data. it currently specifies the time length of the data in samples.
wave format header
# define wave_format_yamaha_adpcm (0x0020)
wformattag this must be set to wave_format_yamaha_adpcm.
nchannels number of channels in the wave, 1 for mono, 2 for stereo.
nsamplespersec frequency of the sample rate of the wave file. this should be 5125, 7350, 9600, 11025, 22050, or 44100 hz. other sample rates are not allowed.
navgbytespersec average data rate..
playback software can estimate the buffer size using the value.
nblockalign this is dependent upon the number of bits per sample.
wbitspersample nblockalign
4 1
4 1
wbitspersample this is the number of bits per sample of yadpcm. currently only 4 bits per sample is defined. other values are reserved.
cbsize the size in bytes of the extra information in the extended wave 'fmt' header. this should be zero.
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -