Sonsivri
 
*
Welcome, Guest. Please login or register.
Did you miss your activation email?
November 01, 2024, 01:13:38 01:13


Login with username, password and session length


Pages: [1]
Print
Author Topic: Speech Compression & Decompression using ADPCM with AVR microcontroller  (Read 9325 times)
0 Members and 1 Guest are viewing this topic.
yasir9909
Active Member
***
Offline Offline

Posts: 153

Thank You
-Given: 7
-Receive: 107


« on: October 23, 2009, 08:25:19 20:25 »

I have implemented Adaptive Differential Pulse Code Modulation (ADPCM) based speech compression algorithm (with decompression implemented on PC side) on ATmega8535.I have got this project work published in an article in 'Electronics World Magazine' (http://www.electronicsworld.co.uk/).

I would like to share this implementation with this community.The scanned pages of my article published in 'Electronics World Magazine'  are :









I would elaborate the implementation details of this MCU application in my next posts.

regards
m.yasir


Posted on: October 23, 2009, 09:14:12 21:14 - Automerged

Note : The publisher of this magazine has committed a mistake in publishing this article,she has placed the diagram of Encoder in place of Decoder and has placed the diagram of Decoder in place of Encoder
« Last Edit: November 09, 2009, 07:18:01 19:18 by yasir9909 » Logged

regards
m.yasir
yasir9909
Active Member
***
Offline Offline

Posts: 153

Thank You
-Given: 7
-Receive: 107


« Reply #1 on: November 08, 2009, 04:44:40 16:44 »

Generic C code for ADPCM Speech Encoding Function:

ADPCMEncoder() FUNCTION

Code:
/* Table of index changes */
const int IndexTable[16] = {
0xff, 0xff, 0xff, 0xff, 2, 4, 6, 8,
0xff, 0xff, 0xff, 0xff, 2, 4, 6, 8
};
/* Quantizer step size lookup table */
const long StepSizeTable[89] = {
7, 8, 9, 10, 11, 12, 13, 14, 16, 17,
19, 21, 23, 25, 28, 31, 34, 37, 41, 45,
50, 55, 60, 66, 73, 80, 88, 97, 107, 118,
130, 143, 157, 173, 190, 209, 230, 253, 279, 307,
337, 371, 408, 449, 494, 544, 598, 658, 724, 796,
876, 963, 1060, 1166, 1282, 1411, 1552, 1707, 1878, 2066,
2272, 2499, 2749, 3024, 3327, 3660, 4026, 4428, 4871, 5358,
5894, 6484, 7132, 7845, 8630, 9493, 10442, 11487, 12635, 13899,
15289, 16818, 18500, 20350, 22385, 24623, 27086, 29794, 32767
};
signed long diff; /* Difference between sample and predicted sample */
long step; /* Quantizer step size */
signed long predsample; /* Output of ADPCM predictor */
signed long diffq; /* Dequantized predicted difference */
int index; /* Index into step size table */
/*****************************************************************************
* ADPCMEncoder - ADPCM encoder routine *
******************************************************************************
* Input Variables: *
* signed long sample - 16-bit signed speech sample *
* Return Variable: *
* char - 8-bit number containing the 4-bit ADPCM code *
*****************************************************************************/
char ADPCMEncoder( signed long sample )
{
int code; /* ADPCM output value */
int tempstep; /* Temporary step size */
/* Restore previous values of predicted sample and quantizer step
size index
*/
predsample = state.prevsample;
index = state.previndex;
step = StepSizeTable[index];
/* Compute the difference between the actual sample (sample) and the
the predicted sample (predsample)
*/
diff = sample - predsample;
if(diff >= 0)
code = 0;
else
{
code = 8;
diff = -diff;
}
/* Quantize the difference into the 4-bit ADPCM code using the
the quantizer step size
*/
tempstep = step;
if( diff >= tempstep )
{
code |= 4;
diff -= tempstep;
}
tempstep >>= 1;
if( diff >= tempstep )
{
code |= 2;
diff -= tempstep;
}
tempstep >>= 1;
if( diff >= tempstep )
code |= 1;
/* Inverse quantize the ADPCM code into a predicted difference
using the quantizer step size
*/
diffq = step >> 3;
if( code & 4 )
diffq += step;
if( code & 2 )
diffq += step >> 1;
if( code & 1 )
diffq += step >> 2;
/* Fixed predictor computes new predicted sample by adding the
old predicted sample to predicted difference
*/
if( code & 8 )
predsample -= diffq;
else
predsample += diffq;
/* Check for overflow of the new predicted sample
*/
if( predsample > 32767 )
predsample = 32767;
else if( predsample < -32768 )
predsample = -32768;
/* Find new quantizer stepsize index by adding the old index
to a table lookup using the ADPCM code
*/
index += IndexTable[code];
/* Check for overflow of the new quantizer step size index
*/
if( index < 0 )
index = 0;
if( index > 88 )
index = 88;
/* Save the predicted sample and quantizer step size index for
next iteration
*/
state.prevsample = predsample;
state.previndex = index;
/* Return the new ADPCM code */
return ( code & 0x0f );
}

//=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*==*=*=*=*=*=*=*=*=*=*=*=*=//

Generic C code for ADPCM Speech Decoding Function:

ADPCMDecoder() FUNCTION

Code:
/* Table of index changes */
const int IndexTable[16] = {
0xff, 0xff, 0xff, 0xff, 2, 4, 6, 8,
0xff, 0xff, 0xff, 0xff, 2, 4, 6, 8
};
/* Quantizer step size lookup table */
const long StepSizeTable[89] = {
7, 8, 9, 10, 11, 12, 13, 14, 16, 17,
19, 21, 23, 25, 28, 31, 34, 37, 41, 45,
50, 55, 60, 66, 73, 80, 88, 97, 107, 118,
130, 143, 157, 173, 190, 209, 230, 253, 279, 307,
337, 371, 408, 449, 494, 544, 598, 658, 724, 796,
876, 963, 1060, 1166, 1282, 1411, 1552, 1707, 1878, 2066,
2272, 2499, 2749, 3024, 3327, 3660, 4026, 4428, 4871, 5358,
5894, 6484, 7132, 7845, 8630, 9493, 10442, 11487, 12635, 13899,
15289, 16818, 18500, 20350, 22385, 24623, 27086, 29794, 32767
};
long step; /* Quantizer step size */
signed long predsample; /* Output of ADPCM predictor */
signed long diffq; /* Dequantized predicted difference */
int index; /* Index into step size table */
/*****************************************************************************
* ADPCMDecoder - ADPCM decoder routine *
******************************************************************************
* Input Variables: *
* char code - 8-bit number containing the 4-bit ADPCM code *
* Return Variable: *
* signed long - 16-bit signed speech sample *
*****************************************************************************/
signed long ADPCMDecoder(char code )
{
/* Restore previous values of predicted sample and quantizer step
size index
*/
predsample = state.prevsample;
index = state.previndex;
/* Find quantizer step size from lookup table using index
*/
step = StepSizeTable[index];
/* Inverse quantize the ADPCM code into a difference using the
quantizer step size
*/
diffq = step >> 3;
if( code & 4 )
diffq += step;
if( code & 2 )
diffq += step >> 1;
if( code & 1 )
diffq += step >> 2;
/* Add the difference to the predicted sample
*/
if( code & 8 )
predsample -= diffq;
else
predsample += diffq;
/* Check for overflow of the new predicted sample
*/
if( predsample > 32767 )
predsample = 32767;
else if( predsample < -32768 )
predsample = -32768;
/* Find new quantizer step size by adding the old index and a
table lookup using the ADPCM code
*/
index += IndexTable[code];
/* Check for overflow of the new quantizer step size index
*/
if( index < 0 )
index = 0;
if( index > 88 )
index = 88;
/* Save predicted sample and quantizer step size index for next
iteration
*/
state.prevsample = predsample;
state.previndex = index;
/* Return the new speech sample */
return( predsample );
}

[/code][/code]
« Last Edit: November 08, 2009, 05:50:56 17:50 by yasir9909 » Logged

regards
m.yasir
Pages: [1]
Print
Jump to:  


DISCLAIMER
WE DONT HOST ANY ILLEGAL FILES ON THE SERVER
USE CONTACT US TO REPORT ILLEGAL FILES
ADMINISTRATORS CANNOT BE HELD RESPONSIBLE FOR USERS POSTS AND LINKS

... Copyright © 2003-2999 Sonsivri.to ...
Powered by SMF 1.1.18 | SMF © 2006-2009, Simple Machines LLC | HarzeM Dilber MC