コード例 #1
0
ファイル: bv16.c プロジェクト: Accontech/mediastreamer2
	/***
	Encodes 8 kHz-sampled narrowband speech at a bit rate of or 16 kbit/s,
	uses 5 ms frames.
	The encoder receives 10 ms speech => 160 bytes.
	***/
static void enc_process (MSFilter *f){
	EncState *s=(EncState*)f->data;
	struct	BV16_Bit_Stream bs;
	short *buf= NULL;
	mblk_t *inputMessage = NULL, *outputMessage = NULL;
	int frame_per_packet=s->ptime/5;
	int in_rcvd_bytes = 0;

	in_rcvd_bytes = SIGNAL_FRAME_SIZE * frame_per_packet;
	buf=(short*)alloca(in_rcvd_bytes);
	memset((void*)buf,0, in_rcvd_bytes );

	while((inputMessage=ms_queue_get(f->inputs[0]))!=NULL){
		ms_bufferizer_put(s->bufferizer,inputMessage);

	}

	/* process ptimes ms of data : (ptime in ms)/1000->ptime is seconds * 8000(sample rate) * 2(byte per sample) */
	while(ms_bufferizer_get_avail(s->bufferizer)>= in_rcvd_bytes){
		int bufferIndex;
		outputMessage = allocb(BITSTREAM_FRAME_SIZE*frame_per_packet,0); /* output bitStream is 80 bits long * number of samples */
		/* process buffer in 5 ms frames but read everything first*/
		ms_bufferizer_read(s->bufferizer,(uint8_t*)buf,in_rcvd_bytes);
		for (bufferIndex=0; bufferIndex<frame_per_packet; bufferIndex++) {
			BV16_Encode(&bs, &s->state, (short*)&buf[bufferIndex*FRSZ]);
			BV16_BitPack( (UWord8*)outputMessage->b_wptr, &bs );
			outputMessage->b_wptr+=BITSTREAM_FRAME_SIZE;
		}
		mblk_set_timestamp_info(outputMessage,s->ts);
		ms_bufferizer_fill_current_metas(s->bufferizer, outputMessage);
		ms_queue_put(f->outputs[0],outputMessage);
		s->ts +=  FRSZ * frame_per_packet;
	}

}
コード例 #2
0
ファイル: bv16_jni.cpp プロジェクト: 371816210/mysipdroid
JNIEXPORT jint JNICALL Java_org_sipdroid_codecs_BV16_encode
    (JNIEnv *env, jobject obj, jshortArray lin, jint offset, jbyteArray encoded, jint size) {


	int i;
	unsigned int lin_pos = 0;

	if (!codec_open)
		return 0;
		
//    __android_log_print(ANDROID_LOG_DEBUG, LOG_TAG, 
//            "encoding frame size: %d\toffset: %d\n", size, offset); 		

	for (i = 0; i < size; i+=FRSZ) {
//		__android_log_print(ANDROID_LOG_DEBUG, LOG_TAG, 
//            "encoding frame size: %d\toffset: %d i: %d\n", size, offset, i); 		
	
		env->GetShortArrayRegion(lin, offset + i,frsz, enc_buffer);
		BV16_Encode((struct BV16_Bit_Stream*) enc_bs,(struct BV16_Encoder_State*) enc_state, enc_buffer);
		BV16_BitPack( (UWord8 *) enc_output_buffer, (struct BV16_Bit_Stream*) enc_bs );
		env->SetByteArrayRegion(encoded, RTP_HDR_SIZE+ lin_pos, BITSTREAM_SIZE, enc_output_buffer);
		lin_pos += BITSTREAM_SIZE;
	}
//	__android_log_print(ANDROID_LOG_DEBUG, LOG_TAG, 
//        "encoding **END** frame size: %d\toffset: %d i: %d lin_pos: %d\n", size, offset, i, lin_pos); 	
    return (jint)lin_pos;
}
コード例 #3
0
ファイル: bv.c プロジェクト: smking1122/heqinphone
int   main(int argc, char **argv)
{
   FILE     *fi, *fo, *fbdi=NULL;
   int      enc=1;
   int      nread, i;
   short    x[FRSZ];
   struct	BV16_Bit_Stream bs;
   struct   BV16_Encoder_State cs;
   struct	BV16_Decoder_State ds;
   
#if !G192BITSTREAM
   UWord8 PackedStream[10];
#endif
   
   int next_bad_frame=-1;
   
   fprintf(stderr,"/***************************************************************************/\n");
   fprintf(stderr,"/* BroadVoice(R)16, Copyright (c) 2000-12, Broadcom Corporation.           */\n");
   fprintf(stderr,"/* All Rights Reserved.                                                    */\n");
   fprintf(stderr,"/*                                                                         */\n");
   fprintf(stderr,"/* This software is provided under the GNU Lesser General Public License,  */\n");
   fprintf(stderr,"/* version 2.1, as published by the Free Software Foundation (\"LGPL\").     */\n");
   fprintf(stderr,"/* This program is distributed in the hope that it will be useful, but     */\n");
   fprintf(stderr,"/* WITHOUT ANY SUPPORT OR WARRANTY; without even the implied warranty of   */\n");
   fprintf(stderr,"/* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the LGPL for   */\n");
   fprintf(stderr,"/* more details.  A copy of the LGPL is available at                       */\n");
   fprintf(stderr,"/* http://www.broadcom.com/licenses/LGPLv2.1.php,                          */\n");
   fprintf(stderr,"/* or by writing to the Free Software Foundation, Inc.,                    */\n");
   fprintf(stderr,"/* 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.               */\n");
   fprintf(stderr,"/***************************************************************************/\n");

   if ((argc!=4)&&(argc!=5)) usage(argv[0]);
   if (!strcmp(argv[1],"enc")) enc=1;
   else if (!strcmp(argv[1],"dec")) enc=0;
   else usage(argv[0]);
   
   if (!(fi=fopen(argv[2],"rb"))) 
   {
      fprintf(stderr,"error: can't read %s\n", argv[2]);
      exit(2);
   }
   if (!(fo=fopen(argv[3],"wb"))) 
   {
      fprintf(stderr,"error: can't write to %s\n", argv[3]);
      exit(3);
   }
   if (argc==5)
   {
      if (!(fbdi=fopen(argv[4],"rb"))) 
      {
         fprintf(stderr,"error: can't read %s\n", argv[4]);
         exit(3);
      }
   }
   
   if (!strcmp(argv[1],"enc")) 
   {
      Reset_BV16_Encoder(&cs);
   } 
   else 
   {
      Reset_BV16_Decoder(&ds);
   }
   
   if (enc){
#if G192BITSTREAM
      fprintf(stderr," BroadVoice16 Floating-Point Encoder V1.2 with ITU-T G.192\n");
#else
      fprintf(stderr," BroadVoice16 Floating-Point Encoder V1.2 with packed bit-stream\n");
#endif
      fprintf(stderr," Input speech file     : %s\n",argv[2]);
      fprintf(stderr," Output bit-stream file: %s\n",argv[3]);
   }
   else{
#if G192BITSTREAM
      fprintf(stderr," BroadVoice16 Floating-Point Decoder V1.2 with ITU-T G.192\n");
#else
      fprintf(stderr," BroadVoice16 Floating-Point Decoder V1.2 with packed bit-stream\n");
#endif
      fprintf(stderr," Input bit-stream file : %s\n",argv[2]);
      fprintf(stderr," Output speech file    : %s\n",argv[3]);
   }
   
   /* START THE MAIN FRAME LOOP */
   frame=0; 
   /* read for the 1st bad frame */
   if (fbdi!=NULL)
      fscanf(fbdi,"%d", &next_bad_frame);
   
   while (1) 
   {
      
      /* FRAME COUNTER */
      frame++;
      
      /* READ IN ONE SPEECH FRAME */
      if (enc==1) 
      {
         nread=fread(x, sizeof(short), FRSZ, fi);
         if (nread<=0) goto End;
         for (i=nread;i<FRSZ;i++) x[i] = 0; 
      } 
      else 
      {
#if G192BITSTREAM
         nread = bv16_fread_g192bitstrm(&bs, fi);
#else
         nread = fread( PackedStream, sizeof(UWord8), 10, fi);
         BV16_BitUnPack ( PackedStream, &bs ); 
#endif
         if (nread<=0) goto End;
         if (frame==next_bad_frame) 
         {
            fscanf(fbdi,"%d", &next_bad_frame);
            bfi = 1;
         }
      }
      
      /* G.BRCM CODING */
      
      if (enc==1) 
      {
         BV16_Encode(&bs, &cs, x);
#if G192BITSTREAM
         bv16_fwrite_g192bitstrm(&bs,fo);
#else
         BV16_BitPack( PackedStream, &bs );
         fwrite(PackedStream, sizeof(UWord8), 10, fo);         
#endif
      } 
      else 
      {
         if (!bfi) 
            BV16_Decode(&bs, &ds, x);   
         else 
         {
            BV16_PLC(&ds,x); 
         }
         
         fwrite(x, sizeof(short), FRSZ, fo);
      }
      
      if (((frame/100)*100)==frame) fprintf(stderr, "\r %d %d-sample frames processed.", frame, FRSZ);
      bfi = 0;
   } /* END OF FRAME LOOP */
   
End: ;
     
     frame--;
     fprintf(stderr, "\r %d 40-sample frames processed.\n", frame);
     
     fclose(fi);
     fclose(fo);
     
     if (fbdi!=NULL)
        fclose(fbdi);

     fprintf(stderr, "\n\n");
     
     return 0;
}