IMA/DVI ADPCM
[Advanced]


Detailed Description

All the IMA/DVI ADPCM functions implemented in the DSP advanced library.

Benchmark on the AT32UC targets



Functions

void dsp_adpcm_ima_decode (S16 *out, void *in, int size, S16 *step_index, S16 *predicted_value)
 IMA/DVI ADPCM decoder.
S16 dsp_adpcm_ima_decode_nibble (S8 nibble, S16 *step_index, S16 *predicted_value)
 IMA/DVI ADPCM sample decoder.
void dsp_adpcm_ima_encode (void *out, S16 *in, int size, S16 *step_index, S16 *predicted_value)
 IMA/DVI ADPCM encoder.
S8 dsp_adpcm_ima_encode_nibble (S16 nibble, S16 *step_index, S16 *predicted_value)
 IMA/DVI ADPCM sample encoder.


Function Documentation

void dsp_adpcm_ima_decode ( S16 *  out,
void *  in,
int  size,
S16 *  step_index,
S16 *  predicted_value 
)

IMA/DVI ADPCM decoder.

Parameters:
out A 16-bit data vector that will contain the decoded data.
in A 4-bit data vector that contains the IMA/DVI ADPCM encoded data to decode.
size The number of data to decode.
step_index A pointer on a 16 bits data which contain the current step index of the ADPCM algorithm.
predicted_value A pointer on a 16 bits data which contain the current predicted value of the ADPCM algorithm.

Definition at line 182 of file adpcm.c.

References ADPCM_IMA_DECODE_NIBBLE.

00183 {
00184   U8 *c_in = in;
00185   int i, nibble, step, diff;
00186   int int_predicted_value, int_step_index;
00187 
00188   // Cast the predicted value and the step index into 32-bit values
00189   int_predicted_value = *predicted_value;
00190   int_step_index = *step_index;
00191 
00192   // Main loop
00193   for(i=0; i<size; i+=2)
00194   {
00195     // Decode the low-nibble (4-bit) of the byte
00196     nibble = ((int) *c_in)&0xF;
00197     // Macro to decode a 4-bit sample with the IMA/DVI ADPCM algorithm 
00198     ADPCM_IMA_DECODE_NIBBLE(nibble, int_step_index, int_predicted_value);
00199     // Store the result
00200     out[i] = (S16) int_predicted_value;
00201 
00202     // Decode the high-nibble (4-bit) of the byte
00203     nibble = (((int) *c_in) >> 4)&0xF;
00204     // Macro to decode a 4-bit sample with the IMA/DVI ADPCM algorithm 
00205     ADPCM_IMA_DECODE_NIBBLE(nibble, int_step_index, int_predicted_value);
00206     // Store the result
00207     out[i + 1] = (S16) int_predicted_value;
00208 
00209     c_in++;
00210   }
00211 
00212   // Restore the predicted value and step index
00213   *predicted_value = int_predicted_value;
00214   *step_index = int_step_index;
00215 }

S16 dsp_adpcm_ima_decode_nibble ( S8  nibble,
S16 *  step_index,
S16 *  predicted_value 
)

IMA/DVI ADPCM sample decoder.

Parameters:
nibble The sample to decode. It must be a 4-bit data.
step_index A pointer on a 16 bits data which contain the previous step index of the ADPCM algorithm.
predicted_value A pointer on a 16 bits data which contain the previous predicted value of the ADPCM algorithm.
Returns:
A 16-bit data that corresponds to the sample decoded.

Definition at line 161 of file adpcm.c.

References ADPCM_IMA_DECODE_NIBBLE.

00162 {
00163   int diff, step;
00164   int int_predicted_value, int_step_index;
00165 
00166   // Cast the predicted value and the step index into 32-bit values
00167   int_predicted_value = (int) *predicted_value;
00168   int_step_index = (int) *step_index;
00169 
00170   // Macro to decode a 4-bit sample with the IMA/DVI ADPCM algorithm 
00171   ADPCM_IMA_DECODE_NIBBLE(((int) nibble), int_step_index, int_predicted_value);
00172 
00173   // Restore the predicted value and step index
00174   *predicted_value = (S16) int_predicted_value;
00175   *step_index = (S16) int_step_index;
00176 
00177   // Return the result stored in int_predicted_value
00178   return int_predicted_value;
00179 }

void dsp_adpcm_ima_encode ( void *  out,
S16 *  in,
int  size,
S16 *  step_index,
S16 *  predicted_value 
)

IMA/DVI ADPCM encoder.

Parameters:
out A 4-bit data vector that will contain the encoded data.
in A 16-bit data vector that contains the data to encode.
size The number of data to encode.
step_index A pointer on a 16 bits data which contain the current step index of the ADPCM algorithm.
predicted_value A pointer on a 16 bits data which contain the current predicted value of the ADPCM algorithm.
Note:
Can be performed "in-place".

Definition at line 239 of file adpcm.c.

References ADPCM_IMA_ENCODE_NIBBLE.

00240 {
00241   U8 *c_out = out;
00242   int i;
00243   int int_predicted_value, int_step_index;
00244   int nibble, diff, step, delta, sign, vpdiff;
00245 
00246   // Cast the predicted value and the step index into 32-bit values
00247   int_predicted_value = *predicted_value;
00248   int_step_index = *step_index;
00249 
00250   // Main loop
00251   for(i=0; i<size; i+=2)
00252   {
00253     // Get the first sample to encode
00254     nibble = in[i];
00255     // Macro to encode a sample with the IMA/DVI ADPCM algorithm 
00256     ADPCM_IMA_ENCODE_NIBBLE(delta, nibble, int_step_index, int_predicted_value);
00257     // Store the result in the low-nibble (4-bit) of the byte
00258     *c_out = delta;
00259 
00260     // Get the second sample to encode
00261     nibble = in[i + 1];
00262     // Macro to encode a sample with the IMA/DVI ADPCM algorithm 
00263     ADPCM_IMA_ENCODE_NIBBLE(delta, nibble, int_step_index, int_predicted_value);
00264     // Store the result in the high-nibble (4-bit) of the byte
00265     *c_out |= delta << 4;
00266 
00267     c_out++;
00268   }
00269 
00270   // Restore the predicted value and step index
00271   *predicted_value = int_predicted_value;
00272   *step_index = int_step_index;
00273 }

S8 dsp_adpcm_ima_encode_nibble ( S16  nibble,
S16 *  step_index,
S16 *  predicted_value 
)

IMA/DVI ADPCM sample encoder.

Parameters:
nibble The sample to encode.
step_index A pointer on a 16 bits data which contain the current step index of the ADPCM algorithm.
predicted_value A pointer on a 16 bits data which contain the current predicted value of the ADPCM algorithm.
Returns:
A 4-bit data that corresponds to the sample encoded.

Definition at line 218 of file adpcm.c.

References ADPCM_IMA_ENCODE_NIBBLE.

00219 {
00220   int int_predicted_value, int_step_index;
00221   int diff, step, delta, sign, vpdiff;
00222 
00223   // Cast the predicted value and the step index into 32-bit values
00224   int_predicted_value = (int) *predicted_value;
00225   int_step_index = (int) *step_index;
00226 
00227   // Macro to encode a sample with the IMA/DVI ADPCM algorithm 
00228   ADPCM_IMA_ENCODE_NIBBLE(delta, ((int) nibble), int_step_index, int_predicted_value);
00229 
00230   // Restore the predicted value and step index
00231   *predicted_value = (S16) int_predicted_value;
00232   *step_index = (S16) int_step_index;
00233 
00234   // Return the result stored in delta
00235   return (S8) delta;
00236 }


Generated on Fri Feb 19 02:23:23 2010 for AVR32 UC3 - EVK1104 DSPLib Demo Documentation by  doxygen 1.5.5