想做一个录音程序,那位大虾清楚WAV的文件格式,能详细一点吗?谢谢

解决方案 »

  1.   

    new wave types 
    --------------------------------------------------------------------------------the necessary type, structure and constant defintions are in mmreg.h.all newly defined wave types must contain both a fact chunk and an extended wave format description within the 'fmt' chunk. riff wave files of type wave_format_pcm need not have the extra chunk nor the extended wave format description.fact chunkthis chunk stores file dependent information about the contents of the wave file. it currently specifies the length of the file in samples.waveformatexthe extended wave format structure is used to defined all non-pcm format wave data, and is described as follows in the include file mmreg.h:/* general extended waveform format structure *//* use this for all non pcm formats *//* (information common to all formats) */typedef struct waveformat_extended_tag {word wformattag; /* format type */word nchannels; /* number of channels (i.e. mono, stereo...) */dword nsamplespersec; /* sample rate */dword navgbytespersec; /* for buffer estimation */word nblockalign; /* block size of data */word wbitspersample; /* number of bits per sample of mono data */word cbsize; /* the count in bytes of the extra size */} waveformatex;wformattag defines the type of wave file. 
    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 11025, 22050, or 44100. other sample rates are allowed, but not encouraged. this rate is also used by the sample size entry in the fact chunk to determine the length in time of the data. 
    navgbytespersec average data rate.
    playback software can estimate the buffer size using the <navgbytespersec> value. 
    nblockalign the block alignment (in bytes) of the data in <data-ck>.
    playback software needs to process a multiple of <nblockalign> bytes of data at a time, so that the value of <nblockalign> can be used for buffer alignment. 
    wbitspersample this is the number of bits per sample per channel data. each channel is assumed to have the same sample resolution. if this field is not needed, then it should be set to zero.img 
    cbsize the size in bytes of the extra information in the wave format header not including the size of the waveformatex structure.. as an example, in the ima adpcm format cbsize is calculated as sizeof(imaadpcmwaveformat) - sizeof(waveformatex) which yeilds two.  defined wformattagsexpr1 wave form registration no - hex expr2 
    #define wave_format_g723_adpcm 0x0014 /* antex electronics corporation */ 
    #define wave_format_antex_adpcme 0x0033 /* antex electronics corporation */ 
    #define wave_format_g721_adpcm 0x0040 /* antex electronics corporation */ 
    #define wave_format_aptx 0x0025 /* audio processing technology */ 
    #define wave_format_audiofile_af36 0x0024 /* audiofile, inc. */ 
    #define wave_format_audiofile_af10 0x0026 /* audiofile, inc. */ 
    #define wave_format_control_res_vqlpc 0x0034 /* control resources limited */ 
    #define wave_format_control_res_cr10 0x0037 /* control resources limited */ 
    #define wave_format_creative_adpcm 0x0200 /* creative labs, inc */ 
    #define wave_format_dolby_ac2 0x0030 /* dolby laboratories */ 
    #define wave_format_dspgroup_truespeech 0x0022 /* dsp group, inc */ 
    #define wave_format_digistd 0x0015 /* dsp solutions, inc. */ 
    #define wave_format_digifix 0x0016 /* dsp solutions, inc. */ 
    #define wave_format_digireal 0x0035 /* dsp solutions, inc. */ 
    #define wave_format_digiadpcm 0x0036 /* dsp solutions, inc. */ 
    #define wave_format_echosc1 0x0023 /* echo speech corporation */ 
    #define wave_format_fm_towns_snd 0x0300 /* fujitsu corp. */ 
    #define wave_format_ibm_cvsd 0x0005 /* ibm corporation */ 
    #define wave_format_oligsm 0x1000 /* ing c. olivetti & c., s.p.a. */ 
    #define wave_format_oliadpcm 0x1001 /* ing c. olivetti & c., s.p.a. */ 
    #define wave_format_olicelp 0x1002 /* ing c. olivetti & c., s.p.a. */ 
    #define wave_format_olisbc 0x1003 /* ing c. olivetti & c., s.p.a. */ 
    #define wave_format_oliopr 0x1004 /* ing c. olivetti & c., s.p.a. */ 
    #define wave_format_ima_adpcm (wave_form_dvi_adpcm) /* intel corporation */ 
    #define wave_format_dvi_adpcm 0x0011 /* intel corporation */ 
    #define wave_format_unknown 0x0000 /* microsoft corporation */ 
    #define wave_format_pcm 0x0001 /* microsoft corporation */ 
    #define wave_format_adpcm 0x0002 /* microsoft corporation */ 
    #define wave_format_alaw 0x0006 /* microsoft corporation */ 
    #define wave_format_mulaw 0x0007 /* microsoft corporation */ 
    #define wave_format_gsm610 0x0031 /* microsoft corporation */ 
    #define wave_format_mpeg 0x0050 /* microsoft corporation */ 
    #define wave_format_nms_vbxadpcm 0x0038 /* natural microsystems */ 
    #define wave_format_oki_adpcm 0x0010 /* oki */ 
    #define wave_format_sierra_adpcm 0x0013 /* sierra semiconductor corp */ 
    #define wave_format_sonarc 0x0021 /* speech compression */ 
    #define wave_format_mediaspace_adpcm 0x0012 /* videologic */ 
    #define wave_format_yamaha_adpcm 0x0020 /* yamaha corporation of america */ unknown wave typeadded: 05/01/92
    author: microsoftfact chunk
     
      

  2.   

    new wave types 
    --------------------------------------------------------------------------------the necessary type, structure and constant defintions are in mmreg.h.all newly defined wave types must contain both a fact chunk and an extended wave format description within the 'fmt' chunk. riff wave files of type wave_format_pcm need not have the extra chunk nor the extended wave format description.fact chunkthis chunk stores file dependent information about the contents of the wave file. it currently specifies the length of the file in samples.waveformatexthe extended wave format structure is used to defined all non-pcm format wave data, and is described as follows in the include file mmreg.h:/* general extended waveform format structure *//* use this for all non pcm formats *//* (information common to all formats) */typedef struct waveformat_extended_tag {word wformattag; /* format type */word nchannels; /* number of channels (i.e. mono, stereo...) */dword nsamplespersec; /* sample rate */dword navgbytespersec; /* for buffer estimation */word nblockalign; /* block size of data */word wbitspersample; /* number of bits per sample of mono data */word cbsize; /* the count in bytes of the extra size */} waveformatex;wformattag defines the type of wave file. 
    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 11025, 22050, or 44100. other sample rates are allowed, but not encouraged. this rate is also used by the sample size entry in the fact chunk to determine the length in time of the data. 
    navgbytespersec average data rate.
    playback software can estimate the buffer size using the <navgbytespersec> value. 
    nblockalign the block alignment (in bytes) of the data in <data-ck>.
    playback software needs to process a multiple of <nblockalign> bytes of data at a time, so that the value of <nblockalign> can be used for buffer alignment. 
    wbitspersample this is the number of bits per sample per channel data. each channel is assumed to have the same sample resolution. if this field is not needed, then it should be set to zero.img 
    cbsize the size in bytes of the extra information in the wave format header not including the size of the waveformatex structure.. as an example, in the ima adpcm format cbsize is calculated as sizeof(imaadpcmwaveformat) - sizeof(waveformatex) which yeilds two.  defined wformattagsexpr1 wave form registration no - hex expr2 
    #define wave_format_g723_adpcm 0x0014 /* antex electronics corporation */ 
    #define wave_format_antex_adpcme 0x0033 /* antex electronics corporation */ 
    #define wave_format_g721_adpcm 0x0040 /* antex electronics corporation */ 
    #define wave_format_aptx 0x0025 /* audio processing technology */ 
    #define wave_format_audiofile_af36 0x0024 /* audiofile, inc. */ 
    #define wave_format_audiofile_af10 0x0026 /* audiofile, inc. */ 
    #define wave_format_control_res_vqlpc 0x0034 /* control resources limited */ 
    #define wave_format_control_res_cr10 0x0037 /* control resources limited */ 
    #define wave_format_creative_adpcm 0x0200 /* creative labs, inc */ 
    #define wave_format_dolby_ac2 0x0030 /* dolby laboratories */ 
    #define wave_format_dspgroup_truespeech 0x0022 /* dsp group, inc */ 
    #define wave_format_digistd 0x0015 /* dsp solutions, inc. */ 
    #define wave_format_digifix 0x0016 /* dsp solutions, inc. */ 
    #define wave_format_digireal 0x0035 /* dsp solutions, inc. */ 
    #define wave_format_digiadpcm 0x0036 /* dsp solutions, inc. */ 
    #define wave_format_echosc1 0x0023 /* echo speech corporation */ 
    #define wave_format_fm_towns_snd 0x0300 /* fujitsu corp. */ 
    #define wave_format_ibm_cvsd 0x0005 /* ibm corporation */ 
    #define wave_format_oligsm 0x1000 /* ing c. olivetti & c., s.p.a. */ 
    #define wave_format_oliadpcm 0x1001 /* ing c. olivetti & c., s.p.a. */ 
    #define wave_format_olicelp 0x1002 /* ing c. olivetti & c., s.p.a. */ 
    #define wave_format_olisbc 0x1003 /* ing c. olivetti & c., s.p.a. */ 
    #define wave_format_oliopr 0x1004 /* ing c. olivetti & c., s.p.a. */ 
    #define wave_format_ima_adpcm (wave_form_dvi_adpcm) /* intel corporation */ 
    #define wave_format_dvi_adpcm 0x0011 /* intel corporation */ 
    #define wave_format_unknown 0x0000 /* microsoft corporation */ 
    #define wave_format_pcm 0x0001 /* microsoft corporation */ 
    #define wave_format_adpcm 0x0002 /* microsoft corporation */ 
    #define wave_format_alaw 0x0006 /* microsoft corporation */ 
    #define wave_format_mulaw 0x0007 /* microsoft corporation */ 
    #define wave_format_gsm610 0x0031 /* microsoft corporation */ 
    #define wave_format_mpeg 0x0050 /* microsoft corporation */ 
    #define wave_format_nms_vbxadpcm 0x0038 /* natural microsystems */ 
    #define wave_format_oki_adpcm 0x0010 /* oki */ 
    #define wave_format_sierra_adpcm 0x0013 /* sierra semiconductor corp */ 
    #define wave_format_sonarc 0x0021 /* speech compression */ 
    #define wave_format_mediaspace_adpcm 0x0012 /* videologic */ 
    #define wave_format_yamaha_adpcm 0x0020 /* yamaha corporation of america */ unknown wave typeadded: 05/01/92
    author: microsoftfact chunk
     
      

  3.   

    new wave types 
    --------------------------------------------------------------------------------the necessary type, structure and constant defintions are in mmreg.h.all newly defined wave types must contain both a fact chunk and an extended wave format description within the 'fmt' chunk. riff wave files of type wave_format_pcm need not have the extra chunk nor the extended wave format description.fact chunkthis chunk stores file dependent information about the contents of the wave file. it currently specifies the length of the file in samples.waveformatexthe extended wave format structure is used to defined all non-pcm format wave data, and is described as follows in the include file mmreg.h:/* general extended waveform format structure *//* use this for all non pcm formats *//* (information common to all formats) */typedef struct waveformat_extended_tag {word wformattag; /* format type */word nchannels; /* number of channels (i.e. mono, stereo...) */dword nsamplespersec; /* sample rate */dword navgbytespersec; /* for buffer estimation */word nblockalign; /* block size of data */word wbitspersample; /* number of bits per sample of mono data */word cbsize; /* the count in bytes of the extra size */} waveformatex;wformattag defines the type of wave file. 
    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 11025, 22050, or 44100. other sample rates are allowed, but not encouraged. this rate is also used by the sample size entry in the fact chunk to determine the length in time of the data. 
    navgbytespersec average data rate.
    playback software can estimate the buffer size using the <navgbytespersec> value. 
    nblockalign the block alignment (in bytes) of the data in <data-ck>.
    playback software needs to process a multiple of <nblockalign> bytes of data at a time, so that the value of <nblockalign> can be used for buffer alignment. 
    wbitspersample this is the number of bits per sample per channel data. each channel is assumed to have the same sample resolution. if this field is not needed, then it should be set to zero.img 
    cbsize the size in bytes of the extra information in the wave format header not including the size of the waveformatex structure.. as an example, in the ima adpcm format cbsize is calculated as sizeof(imaadpcmwaveformat) - sizeof(waveformatex) which yeilds two.  defined wformattagsexpr1 wave form registration no - hex expr2 
    #define wave_format_g723_adpcm 0x0014 /* antex electronics corporation */ 
    #define wave_format_antex_adpcme 0x0033 /* antex electronics corporation */ 
    #define wave_format_g721_adpcm 0x0040 /* antex electronics corporation */ 
    #define wave_format_aptx 0x0025 /* audio processing technology */ 
    #define wave_format_audiofile_af36 0x0024 /* audiofile, inc. */ 
    #define wave_format_audiofile_af10 0x0026 /* audiofile, inc. */ 
    #define wave_format_control_res_vqlpc 0x0034 /* control resources limited */ 
    #define wave_format_control_res_cr10 0x0037 /* control resources limited */ 
    #define wave_format_creative_adpcm 0x0200 /* creative labs, inc */ 
    #define wave_format_dolby_ac2 0x0030 /* dolby laboratories */ 
    #define wave_format_dspgroup_truespeech 0x0022 /* dsp group, inc */ 
    #define wave_format_digistd 0x0015 /* dsp solutions, inc. */ 
    #define wave_format_digifix 0x0016 /* dsp solutions, inc. */ 
    #define wave_format_digireal 0x0035 /* dsp solutions, inc. */ 
    #define wave_format_digiadpcm 0x0036 /* dsp solutions, inc. */ 
    #define wave_format_echosc1 0x0023 /* echo speech corporation */ 
    #define wave_format_fm_towns_snd 0x0300 /* fujitsu corp. */ 
    #define wave_format_ibm_cvsd 0x0005 /* ibm corporation */ 
    #define wave_format_oligsm 0x1000 /* ing c. olivetti & c., s.p.a. */ 
    #define wave_format_oliadpcm 0x1001 /* ing c. olivetti & c., s.p.a. */ 
    #define wave_format_olicelp 0x1002 /* ing c. olivetti & c., s.p.a. */ 
    #define wave_format_olisbc 0x1003 /* ing c. olivetti & c., s.p.a. */ 
    #define wave_format_oliopr 0x1004 /* ing c. olivetti & c., s.p.a. */ 
    #define wave_format_ima_adpcm (wave_form_dvi_adpcm) /* intel corporation */ 
    #define wave_format_dvi_adpcm 0x0011 /* intel corporation */ 
    #define wave_format_unknown 0x0000 /* microsoft corporation */ 
    #define wave_format_pcm 0x0001 /* microsoft corporation */ 
    #define wave_format_adpcm 0x0002 /* microsoft corporation */ 
    #define wave_format_alaw 0x0006 /* microsoft corporation */ 
    #define wave_format_mulaw 0x0007 /* microsoft corporation */ 
    #define wave_format_gsm610 0x0031 /* microsoft corporation */ 
    #define wave_format_mpeg 0x0050 /* microsoft corporation */ 
    #define wave_format_nms_vbxadpcm 0x0038 /* natural microsystems */ 
    #define wave_format_oki_adpcm 0x0010 /* oki */ 
    #define wave_format_sierra_adpcm 0x0013 /* sierra semiconductor corp */ 
    #define wave_format_sonarc 0x0021 /* speech compression */ 
    #define wave_format_mediaspace_adpcm 0x0012 /* videologic */ 
    #define wave_format_yamaha_adpcm 0x0020 /* yamaha corporation of america */ unknown wave typeadded: 05/01/92
    author: microsoftfact chunk
     
      

  4.   

    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 headerchanged as of september 5, 1993: this wave format will not be defined. for development purposes, do not use 0x0000. instead, use 0xffff until an id has been obtained. # define wave_format_unknown (0x0000)wformattag this must be set to wave_format_unknown. 
    nchannels number of channels in the wave.(1 for mono) 
    nsamplespersec frequency the of the sample rate of wave file.  
    navgbytespersec average data rate.
    playback software can estimate the buffer size using the <navgbytespersec> value. 
    nblockalign block alignment of the data.
    playback software needs to process a multiple of <nblockalign> bytes of data at a time, so that the value of <nblockalign> 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. microsoft adpcmadded 05/01/92
    author: microsoftfact chunkthis 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_adpcm (0x0002)typedef struct adpcmcoef_tag {int icoef1;int icoef2;} adpcmcoefset; typedef struct adpcmwaveformat_tag {waveformatex wfxx;word wsamplesperblock;word wnumcoef;adpcmcoefset acoeff[wnumcoef];} adpcmwaveformat;wformattag this must be set to wave_format_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 11025, 22050, or 44100. other sample rates are allowed, but not encouraged. 
    navgbytespersec average data rate. ((nsamplespersec / nsamplesperblock) * nblockalign).
    playback software can estimate the buffer size using the value. 
    nblockalign the block alignment (in bytes) of the data in . 
      nsamplespersec x channels  nblockalign 
      8k 256 
      11k 256 
      22k 512 
      44k 1024 
      playback software needs to process a multiple of <nblockalign> bytes of data at a time, so that the value of <nblockalign> can be used for buffer alignment. 
    wbitspersample this is the number of bits per sample of adpcm. currently only 4 bits per sample is defined. other values are reserved. 
    cbsize the size in bytes of the extended information after the waveformatex structure.
    for the standard wave_format_adpcm using the standard seven coefficient pairs, this is 32. if extra coefficients are added, then this value will increase. 
    nsamplesperblock count of number of samples per block. 
    (((nblockalign - (7 * nchannels)) * 8) / (wbitspersample * nchannels)) + 2. 
    nnumcoef count of the number of coefficient sets defined in acoef. 
    acoeff  these are the coefficients used by the wave to play. they may be interpreted as fixed point 8.8 signed values. currently there are 7 preset coefficient sets. they must appear in the following order. 
      coef set coef1 coef2 
      0 256 0 
      1 512 -256 
      2 0 0 
      3 192 64 
      4 240 0 
      5 460 -208 
      6 392 -232 
      note that if even only 1 coefficient set was used to encode the file then all coefficient sets are still included. more coefficients may be added by the encoding software, but the first 7 must always be the same. note: 8.8 signed values can be divided by 256 to obtain the integer portion of the value.blockthe block has three parts, the header, data, and padding. the three together are <nblockalign> bytes.typedef struct adpcmblockheader_tag {byte bpredictor[nchannels];int idelta[nchannels];int isamp1[nchannels];int isamp2[nchannels];} adpcmblockheader;field description 
    bpredictor index into the acoef array to define the predictor used to encode this block. 
    idelta initial delta value to use. 
    isamp1 the second sample value of the block. when decoding this will be used as the previous sample to start decoding with. 
    isamp2 the first sample value of the block. when decoding this will be used as the previous' previous sample to start decoding with. datathe data is a bit string parsed in groups of (wbitspersample * nchannels). for the case of mono voice adpcm (wbitspersample = 4, nchannels = 1) we have:... ...where has or <(sample 2n + 2) (sample 2n + 3)>= ((4 bit error delta for sample (2 * n) + 2) << 4) | (4 bit error delta for sample (2 * n) + 3) for the case of stereo voice adpcm (wbitspersample = 4, nchannels = 2) we have:... ...where has or<(left channel of sample n + 2) (right channel of sample n + 2)>= ((4 bit error delta for left channel of sample n + 2) << 4) | (4 bit error delta for right channel of sample n + 2) paddingbit padding is used to round off the block to an exact byte length.the size of the padding (in bits):((nblockalign - (7 * nchannels)) * 8) - (((nsamplesperblock - 2) * nchannels) * wbitspersample)the padding does not store any data and should be made zero.
      

  5.   

    adpcm algorithmeach channel of the adpcm file can be encoded/decoded independently. however this should not destroy phase and amplitude information since each channel will track the original. since the channels are encoded/decoded independently, this document is written as if only one channel is being decoded. since the channels are interleaved, multiple channels may be encoded/decoded in parallel using independent local storage and temporaries.note that the process for encoding/decoding one block is independent from the process for the next block. therefore the process is described for one block only, and may be repeated for other blocks. while some optimizations may relate the process for one block to another, in theory they are still independent.note that in the description below the number designation appended to isamp (i.e. isamp1 and isamp2) refers to the placement of the sample in relation to the current one being decoded. thus when you are decoding sample n, isamp1 would be sample n - 1 and isamp2 would be sample n - 2. coef1 is the coefficient for isamp1 and coef2 is the coefficient for isamp2. this numbering is identical to that used in the block and format descriptions above.a sample application will be provided to convert a riff waveform file to and from adpcm and pcm formats.decodingfirst the predictor coefficients are determined by using the bpredictor field of block header. this value is an index into the acoef array in the file header. bpredictor = getbytethe initial idelta is also taken from the block header. idelta = getwordthen the first two samples are taken from block header. (they are stored as 16 bit pcm data as isamp1 and isamp2. isamp2 is the first sample of the block, isamp1 is the second sample.) isamp1= getintisamp2 = getintafter taking this initial data from the block header, the process of decoding the rest of the block may begin. it can be done in the following manner:while there are more samples in the block to decode:predict the next sample from the previous two samples. lpredsamp = ((isamp1 * icoef1) + (isamp2 *icoef2)) / fixed_point_coef_baseget the 4 bit signed error delta.(ierrordelta = getnibble)add the 'error in prediction' to the predicted next sample and prevent over/underflow errors.(lnewsamp = lpredsample + (idelta * ierrordelta)if lnewsample too large, make it the maximum allowable size.if lnewsample too small, make it the minimum allowable size.output the new sample.output( lnewsamp )adjust the quantization step size used to calculate the 'error in prediction'.idelta = idelta * adaptiontable[ ierrordelta] / fixed_point_adaption_baseif idelta too small, make it the minimum allowable size.update the record of previous samples.isamp2 = isamp1;isamp1 = lnewsample.encodingfor each block, the encoding process can be done through the following steps. (for each channel)determine the predictor to use for the block.determine the initial idelta for the block.write out the block header.encode and write out the data.the predictor to use for each block can be determined in many ways. 1. a static predictor for all files. 2. the block can be encoded with each possible predictor. then the predictor that gave the least error can be chosen. the least error can be determined from:1. sum of squares of differences. (from compressed/decompressed to original data)2. the least average absolute difference.3. the least average idelta3. the predictor that has the smallest initial idelta can be chosen. (this is an approximation of method 2.3)4. statistics from either the previous or current block. (e.g. a linear combination of the first 5 samples of a block that corresponds to the average predicted error.) the starting idelta for each block can also be determined in a couple of ways. 
      

  6.   

    1. one way is to always start off with the same initial idelta. 2. another way is to use the idelta from the end of the previous block. (note that for the first block an initial value must then be chosen.)3. the initial idelta may also be determined from the first few samples of the block. (idelta generally fluctuates around the value that makes the absolute value of the encoded output about half maximum absolute value of the encoded output. (for 4 bit error deltas the maximum absolute value is 8. this means the initial idelta should be set so that the first output is around 4.)4. finally the initial idelta for this block may be determined from the last few samples of the last block. (note that for the first block an initial value must then be chosen.)note that different choices for predictor and initial idelta will result in different audio quality.once the predictor and starting quantization values are chosen, the block header may be written out.first the choice of predictor is written out. (for each channel.)then the initial idelta (quantization scale) is written out. (for each channel.)then the 16 bit pcm value of the second sample is written out. (isamp1) (for each channel.)finally the 16 bit pcm value of the first sample is written out. (isamp2) (for each channel.)then the rest of the block may be encoded. (note that the first encoded value will be for the 3rd sample in the block since the first two are contained in the header.)while there are more samples in the block to decode:predict the next sample from the previous two samples. lpredsamp = ((isamp1 * icoef1) + (isamp2 *icoef2)) / fixed_point_coef_basethe 4 bit signed error delta is produced and overflow/underflow is prevented..ierrordelta = (sample(n) - lpredsamp) / ideltaif ierrordelta is too large, make it the maximum allowable size.if ierrordelta is too small, make it the minimum allowable size.then the nibble ierrordelta is written out.putnibble( ierrordelta )add the 'error in prediction' to the predicted next sample and prevent over/underflow errors.(lnewsamp = lpredsample + (idelta * ierrordelta)if lnewsample too large, make it the maximum allowable size.if lnewsample too small, make it the minimum allowable size.adjust the quantization step size used to calculate the 'error in prediction'.idelta = idelta * adaptiontable[ ierrordelta] / fixed_point_adaption_baseif idelta too small, make it the minimum allowable size.update the record of previous samples.isamp2 = isamp1;isamp1 = lnewsample.sample c codesample c code is contained in the file msadpcm.c, which is available with this document in electronic form and separately. see the overview section for how to obtain this sample code.cvsd wave typeadded 07/21/92
    author: dsp solutions, formerly digispeechfact chunkthis 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_ibm_cvsd (0x0005)wformattag this must be set to wave_format_ibm_cvsd 
    nchannels number of channels in the wave, 1 for mono, 2 for stereo... 
    nsamplespersec frequency the source was sampled at. see chart below. 
    navgbytespersec average data rate. see chart below. (one of 1800, 2400, 3000, 3600, 4200, or 4800)
    playback software can estimate the buffer size using the value. 
    nblockalign set to 2048 to provide efficient caching of file from cd-rom.
    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. this is always 1 for cvsd. 
    cbsize the size in bytes of the rest of the wave format header. this is zero for cvsd. the digispeech cvsd compression format is compatible with the ibm ps/2 speech adapter, which uses a motorola mc3418 for cvsd modulation. the motorola chip uses only one algorithm which can work at variable sampling clock rates. the cvsd algorithm compresses each input audio sample to 1 bit. an acceptable quality of sound is achieved using high sampling rates. the digispeech ds201 adapter supports six cvsd sampling frequencies, which are being used by most software using the ibm ps/2 speech adapter:sample rate bytes/second 
    14,400hz 1800 bytes 
    19,200hz 2400 bytes 
    24,000hz 3000 bytes 
    28,800hz 3600 bytes 
    33,600hz 4200 bytes 
    38,400hz 4800 bytes the cvsd format is a compression scheme which has been used by ibm and is supported by the ibm ps/2 speech adapter card. digispeech also has a card that uses this compression scheme. it is not digispeech's policy to disclose any of these algorithms to any third party vendor.ccitt standard companded wave types