plug-in/wav/wav.c

00001 /*
00002  * $Id: wav.c 711 2008-02-10 18:52:44Z sayer $
00003  *
00004  * Copyright (C) 2002-2003 Fhg Fokus
00005  *
00006  * This file is part of sems, a free SIP media server.
00007  *
00008  * sems is free software; you can redistribute it and/or modify
00009  * it under the terms of the GNU General Public License as published by
00010  * the Free Software Foundation; either version 2 of the License, or
00011  * (at your option) any later version
00012  *
00013  * For a license to use the ser software under conditions
00014  * other than those described here, or to purchase support for this
00015  * software, please contact iptel.org by e-mail at the following addresses:
00016  *    info@iptel.org
00017  *
00018  * sems is distributed in the hope that it will be useful,
00019  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00020  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00021  * GNU General Public License for more details.
00022  *
00023  * You should have received a copy of the GNU General Public License 
00024  * along with this program; if not, write to the Free Software 
00025  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00026  */
00027 
00028 #include "amci.h"
00029 #include "codecs.h"
00030 #include "g711.h"
00031 #include "wav_hdr.h"
00032 #include "../../log.h"
00033 
00074 #define WAV_PCM  1 
00075 
00076 #define WAV_ALAW 6 
00077 
00078 #define WAV_ULAW 7 
00079 
00080 static int ULaw_2_Pcm16( unsigned char* out_buf, unsigned char* in_buf, unsigned int size,
00081                          unsigned int channels, unsigned int rate, long h_codec );
00082 
00083 static int ALaw_2_Pcm16( unsigned char* out_buf, unsigned char* in_buf, unsigned int size,
00084                          unsigned int channels, unsigned int rate, long h_codec );
00085 
00086 static int Pcm16_2_ULaw( unsigned char* out_buf, unsigned char* in_buf, unsigned int size,
00087                          unsigned int channels, unsigned int rate, long h_codec );
00088 
00089 static int Pcm16_2_ALaw( unsigned char* out_buf, unsigned char* in_buf, unsigned int size,
00090                          unsigned int channels, unsigned int rate, long h_codec );
00091 
00092 static unsigned int g711_bytes2samples(long, unsigned int);
00093 static unsigned int g711_samples2bytes(long, unsigned int);
00094 
00095 BEGIN_EXPORTS( "wav" , AMCI_NO_MODULEINIT, AMCI_NO_MODULEDESTROY )
00096 
00097      BEGIN_CODECS
00098 CODEC( CODEC_ULAW, Pcm16_2_ULaw, ULaw_2_Pcm16, 
00099        AMCI_NO_CODEC_PLC, AMCI_NO_CODECCREATE, AMCI_NO_CODECDESTROY, 
00100        g711_bytes2samples, g711_samples2bytes )
00101      CODEC( CODEC_ALAW, Pcm16_2_ALaw, ALaw_2_Pcm16, 
00102             AMCI_NO_CODEC_PLC, AMCI_NO_CODECCREATE, AMCI_NO_CODECDESTROY, 
00103             g711_bytes2samples, g711_samples2bytes )
00104      END_CODECS
00105     
00106 BEGIN_PAYLOADS
00107 PAYLOAD( 0, "PCMU", 8000, 1, CODEC_ULAW, AMCI_PT_AUDIO_LINEAR )
00108      PAYLOAD( 8, "PCMA", 8000, 1, CODEC_ALAW, AMCI_PT_AUDIO_LINEAR )
00109      END_PAYLOADS
00110 
00111 BEGIN_FILE_FORMATS
00112 BEGIN_FILE_FORMAT( "Wav", "wav", "audio/x-wav", wav_open, wav_close, wav_mem_open, wav_mem_close)
00113      BEGIN_SUBTYPES
00114 SUBTYPE( WAV_PCM,  "Pcm16",  8000, 1, CODEC_PCM16 ) // we only support 8000/1 channel !
00115      SUBTYPE( WAV_ALAW, "A-Law",  8000, 1, CODEC_ALAW )
00116      SUBTYPE( WAV_ULAW, "Mu-Law", 8000, 1, CODEC_ULAW )
00117      END_SUBTYPES
00118 END_FILE_FORMAT
00119 END_FILE_FORMATS
00120 
00121 END_EXPORTS
00122 
00123 static unsigned int g711_bytes2samples(long h_codec, unsigned int num_bytes)
00124 {
00125   /* ALAW and ULAW formats has one sample per byte */
00126   return num_bytes;
00127 }
00128 
00129 static unsigned int g711_samples2bytes(long h_codec, unsigned int num_samples)
00130 {
00131   /* ALAW and ULAW formats has one sample per byte */
00132   return num_samples;
00133 }
00134 
00135 static int ULaw_2_Pcm16( unsigned char* out_buf, unsigned char* in_buf, unsigned int size,
00136                          unsigned int channels, unsigned int rate, long h_codec )
00137 {
00138   unsigned short* out_b = (unsigned short*)out_buf;
00139   unsigned char*  in_b  = in_buf;
00140   unsigned char*  end   = in_b + size;
00141 
00142   while(in_b != end){
00143     //  int i = st_ulaw2linear16(*(in_b++));
00144     //  *(out_b++) = i;
00145     *(out_b++) = st_ulaw2linear16(*(in_b++));
00146   }
00147   return size*2;
00148 }
00149 
00150 static int ALaw_2_Pcm16( unsigned char* out_buf, unsigned char* in_buf, unsigned int size,
00151                          unsigned int channels, unsigned int rate, long h_codec )
00152 {
00153   unsigned short* out_b = (unsigned short*)out_buf;
00154   unsigned char*  in_b  = in_buf;
00155   unsigned char*  end   = in_b + size;
00156 
00157   while(in_b != end){
00158     //  int i = st_alaw2linear16(*(in_b++));
00159     //  *(out_b++) = i;
00160     *(out_b++) = st_alaw2linear16(*(in_b++));
00161   }
00162   return size*2;
00163 }
00164 
00165 int Pcm16_2_ULaw( unsigned char* out_buf, unsigned char* in_buf, unsigned int size,
00166                   unsigned int channels, unsigned int rate, long h_codec )
00167 {
00168   unsigned char* out_b = out_buf;
00169   short* in_b          = (short*)(in_buf);
00170   short* end           = (short*)((unsigned char*)in_buf + size);
00171 
00172   while(in_b != end){
00173     short s = *(in_b++) >> 2;
00174     *(out_b++) = st_14linear2ulaw(s);
00175   }
00176   return size/2;
00177 }
00178 
00179 int Pcm16_2_ALaw( unsigned char* out_buf, unsigned char* in_buf, unsigned int size,
00180                   unsigned int channels, unsigned int rate, long h_codec )
00181 {
00182   unsigned char* out_b = out_buf;
00183   short* in_b          = (short*)(in_buf);
00184   short* end           = (short*)((unsigned char*)in_buf + size);
00185 
00186   while(in_b != end){
00187     short s = (*(in_b++)) >> 3;
00188     *(out_b++) = st_13linear2alaw(s);
00189   }
00190 
00191   return size/2;
00192 }
00193 
00194 

Generated on Fri May 16 12:02:05 2008 for SEMS by  doxygen 1.5.1
Home |  Recent changes |  Search |  Glossary |  Sitemap |  Login