00001
00002
00003
00004
00005
00006
00007
00008
00009 #include <qapplication.h>
00010
00011 #include <stdio.h>
00012 #include <string.h>
00013 #include <errno.h>
00014 #include <iostream>
00015
00016 #ifndef WIN32
00017 #include <unistd.h>
00018 #include <fcntl.h>
00019 #include <sys/ioctl.h>
00020
00021 #include <mythtv/mythcontext.h>
00022 #include "config.h"
00023 #endif
00024
00025 #include "g711.h"
00026 #ifdef VA_G729
00027 #include "g729/va_g729a.h"
00028 #endif
00029
00030 #define PCM2G711U(p) (ulaw_comp_table[((p)/4)&0x3FFF])
00031 #define G711U2PCM(g) (ulaw_exp_table[g])
00032 #define PCM2G711A(p) (alaw_comp_table[((p)/4)&0x3FFF])
00033 #define G711A2PCM(g) (alaw_exp_table[g])
00034
00035
00036
00037 int g711ulaw::Encode(short *In, unsigned char *Out, int Samples, short &maxPower, int gain)
00038 {
00039 (void)gain;
00040 int Count = Samples;
00041 while (Count-- > 0)
00042 {
00043 maxPower = QMAX(maxPower, *In);
00044 *Out++ = PCM2G711U(*In++);
00045 }
00046 return Samples;
00047 }
00048
00049 int g711ulaw::Decode(unsigned char *In, short *Out, int Len, short &maxPower)
00050 {
00051 int Count = Len;
00052 while (Count-- > 0)
00053 {
00054 *Out = G711U2PCM(*In++);
00055 maxPower = QMAX(maxPower, *Out);
00056 *Out++;
00057 }
00058 return (Len*sizeof(short));
00059 }
00060
00061 int g711ulaw::Silence(uchar *out, int ms)
00062 {
00063 int len = ms * PCM_SAMPLES_PER_MS;
00064 memset(out, PCM2G711U(0), len);
00065 return len;
00066 }
00067
00068 int g711alaw::Encode(short *In, unsigned char *Out, int Samples, short &maxPower, int gain)
00069 {
00070 (void)gain;
00071 int Count = Samples;
00072 while (Count-- > 0)
00073 {
00074 maxPower = QMAX(maxPower, *In);
00075 *Out++ = PCM2G711A(*In++);
00076 }
00077 return Samples;
00078 }
00079
00080 int g711alaw::Decode(unsigned char *In, short *Out, int Len, short &maxPower)
00081 {
00082 int Count = Len;
00083 while (Count-- > 0)
00084 {
00085 *Out = G711A2PCM(*In++);
00086 maxPower = QMAX(maxPower, *Out);
00087 Out++;
00088 }
00089 return (Len*sizeof(short));
00090 }
00091
00092 int g711alaw::Silence(uchar *out, int ms)
00093 {
00094 int len = ms * PCM_SAMPLES_PER_MS;
00095 memset(out, PCM2G711A(0), len);
00096 return len;
00097 }
00098
00099 #ifdef VA_G729
00100
00101 g729::g729() :codec()
00102 {
00103 va_g729a_init_decoder();
00104 va_g729a_init_encoder();
00105 }
00106
00107 int g729::Encode(short *In, unsigned char *Out, int Samples, short &maxPower, int gain)
00108 {
00109 int Len = 0;
00110 while (Samples>0)
00111 {
00112 va_g729a_encoder(In, Out);
00113 In+=L_FRAME;
00114 Out+=L_FRAME_COMPRESSED;
00115 Len += L_FRAME_COMPRESSED;
00116 Samples -= L_FRAME;
00117 }
00118 return Len;
00119 }
00120
00121 int g729::Decode(unsigned char *In, short *Out, int Len, int &maxPower)
00122 {
00123 int bfi=0;
00124 int OutLen=0;
00125 while (Len>0)
00126 {
00127 va_g729a_decoder(In, Out, bfi);
00128 In+=L_FRAME_COMPRESSED;
00129 Out+=L_FRAME;
00130 Len -= L_FRAME_COMPRESSED;
00131 OutLen += L_FRAME;
00132 }
00133 return (OutLen);
00134 }
00135
00136 int g729::Silence(uchar *out, int ms)
00137 {
00138
00139 return 20;
00140 }
00141
00142 #endif