GsmCompress.cpp
上传用户:amei960
上传日期:2007-02-05
资源大小:143k
文件大小:1k
- #include "Stdafx.h"
- #include "GsmCompress.h"
- #pragma comment(lib,"gsm.lib")
- CGsmCompress::CGsmCompress()
- {
- m_hGsm = NULL;
- m_hGsm = gsm_create();
- }
- CGsmCompress::~CGsmCompress()
- {
- if( m_hGsm != NULL )
- {
- gsm_destroy( m_hGsm );
- m_hGsm = NULL;
- }
- }
- void CGsmCompress::SetOption(long,long*)
- {
- if( m_hGsm == NULL )
- return;
- // gsm_option(m_hGsm, long, long *));
- }
- BOOL CGsmCompress::Compress(char* src,int srclen,char* dst,int* dstlen)
- {
- if( m_hGsm == NULL )
- return FALSE;
- gsm_frame dst_gsm;
- int i , l = 0;
-
- for (i = 0 ; i < srclen; i += 160)
- {
- gsm_encode( m_hGsm , (short*)(src + i), dst_gsm);
- memcpy(dst + l, dst_gsm, sizeof(dst_gsm));
- l += sizeof(dst_gsm);
- }
- *dstlen = l;
- return TRUE;
- }
- BOOL CGsmCompress::UnCompress(char* src,int srclen,char* dst,int* dstlen)
- {
- if( m_hGsm == NULL )
- return FALSE;
- gsm_signal dst_gsm[160];
- int i , l = 0;
- for (i = 0; i < srclen; i += sizeof(gsm_frame) )
- {
- gsm_decode(m_hGsm , (gsm_byte*)src + i, dst_gsm);
- memcpy(dst + l, dst_gsm, sizeof(dst_gsm));
- l += 160;
- }
- *dstlen = l;
- return TRUE;
- }