Exemple #1
0
static switch_status_t switch_amrwb_destroy(switch_codec_t *codec)
{
#ifndef AMRWB_PASSTHROUGH
	struct amrwb_context *context = codec->private_info;

	if (context->encoder_state) {
		E_IF_exit(context->encoder_state);
	}
	if (context->decoder_state) {
		D_IF_exit(context->decoder_state);
	}
	codec->private_info = NULL;
#endif
	return SWITCH_STATUS_SUCCESS;
}
Exemple #2
0
static void decode_destructor(void *arg)
{
	struct audec_state *st = arg;

	switch (st->ac->srate) {

#ifdef AMR_NB
	case 8000:
		Decoder_Interface_exit(st->dec);
		break;
#endif

#ifdef AMR_WB
	case 16000:
		D_IF_exit(st->dec);
		break;
#endif
	}
}
Exemple #3
0
/*
 * Close codec.
 */
static pj_status_t amr_codec_close( pjmedia_codec *codec )
{
    struct amr_data *amr_data;

    PJ_ASSERT_RETURN(codec, PJ_EINVAL);

    amr_data = (struct amr_data*) codec->codec_data;
    PJ_ASSERT_RETURN(amr_data != NULL, PJ_EINVALIDOP);

    if (amr_data->encoder) {
        if (amr_data->enc_setting.amr_nb) {
#ifdef USE_AMRNB
            Encoder_Interface_exit(amr_data->encoder);
#endif
        } else {
#ifdef USE_AMRWB
            E_IF_exit(amr_data->encoder);
#endif
        }
        amr_data->encoder = NULL;
    }

    if (amr_data->decoder) {
        if (amr_data->dec_setting.amr_nb) {
#ifdef USE_AMRNB
            Decoder_Interface_exit(amr_data->decoder);
#endif
        } else {
#ifdef USE_AMRWB
            D_IF_exit(amr_data->decoder);
#endif
        }
        amr_data->decoder = NULL;
    }
    
    TRACE_((THIS_FILE, "AMR codec closed"));
    return PJ_SUCCESS;
}
Exemple #4
0
static int UpdateInput(amrwb* p)
{
	if (p->Decoder)
	{
		D_IF_exit(p->Decoder);
		p->Decoder = NULL;
	}
	BufferClear(&p->Buffer);

	if (p->Codec.In.Format.Type == PACKET_AUDIO)
	{
	    p->Decoder = D_IF_init();
		if (!p->Decoder)
			return ERR_OUT_OF_MEMORY;

		p->Codec.In.Format.Format.Audio.SampleRate = 16000;
		p->Codec.In.Format.Format.Audio.Channels = 1;

		PacketFormatPCM(&p->Codec.Out.Format,&p->Codec.In.Format,16);
	}

	return ERR_NONE;
}
Exemple #5
0
int main(int argc, char *argv[])
{
    FILE *f_serial;                        /* File of serial bits for transmission  */
    FILE *f_synth;                         /* File of speech data                   */

    Word16 synth[L_FRAME16k];              /* Buffer for speech @ 16kHz             */
    UWord8 serial[NB_SERIAL_MAX];
    Word16 mode;
    Word32 frame;

#ifndef IF2
	char magic[16];
#endif
    void *st;

    fprintf(stderr, "\n");
	   fprintf(stderr, "===================================================================\n");
	   fprintf(stderr, " 3GPP AMR-WB Floating-point Speech Decoder, v7.0.0, Mar 20, 2007\n");
	   fprintf(stderr, "===================================================================\n");
   fprintf(stderr, "\n");

    /*
     * Read passed arguments and open in/out files
     */
    if (argc != 3)
    {
        fprintf(stderr, "Usage : decoder  bitstream_file  synth_file\n");
        fprintf(stderr, "\n");
        fprintf(stderr, "Format for bitstream_file:\n");
#ifdef IF2
		fprintf(stderr, "  Described in TS26.201.\n");
#else
		fprintf(stderr, "  Described in RFC 3267 (Sections 5.1 and 5.3).\n");
#endif
        fprintf(stderr, "\n");
        fprintf(stderr, "Format for synth_file:\n");
        fprintf(stderr, "  Synthesis is written to a binary file of 16 bits data.\n");
        fprintf(stderr, "\n");
        exit(0);
    }

    /* Open file for synthesis and packed serial stream */
    if ((f_serial = fopen(argv[1], "rb")) == NULL)
    {
        fprintf(stderr, "Input file '%s' does not exist !!\n", argv[1]);
        exit(0);
    }
    else
    {
        fprintf(stderr, "Input bitstream file:   %s\n", argv[1]);
    }

    if ((f_synth = fopen(argv[2], "wb")) == NULL)
    {
        fprintf(stderr, "Cannot open file '%s' !!\n", argv[2]);
        exit(0);
    }
    else
    {
        fprintf(stderr, "Synthesis speech file:   %s\n", argv[2]);
    }

    /*
     * Initialization of decoder
     */
    st = D_IF_init();

#ifndef IF2
   /* read magic number */
   fread(magic, sizeof(char), strlen(AMRWB_MAGIC_NUMBER), f_serial);

   /* verify magic number */
   if (strncmp(magic, AMRWB_MAGIC_NUMBER, strlen(AMRWB_MAGIC_NUMBER)))
   {
	   fprintf(stderr, "%s%s\n", "Invalid magic number: ", magic);
	   fclose(f_serial);
	   fclose(f_synth);
	   exit(0);
   }
#endif

    /*
     * Loop for each "L_FRAME" speech data
     */
    fprintf(stderr, "\n --- Running ---\n");

    frame = 0;
    while (fread(serial, sizeof (UWord8), 1, f_serial ) > 0)
    {
#ifdef IF2
       mode = (Word16)(serial[0] >> 4);
#else
	   mode = (Word16)((serial[0] >> 3) & 0x0F);
#endif
	   fread(&serial[1], sizeof (UWord8), block_size[mode] - 1, f_serial );

	   frame++;

	   fprintf(stderr, " Decoding frame: %ld\r", frame);

	   D_IF_decode( st, serial, synth, _good_frame);

	   fwrite(synth, sizeof(Word16), L_FRAME16k, f_synth);
	   fflush(f_synth);
    }

    D_IF_exit(st);

    fclose(f_serial);
    fclose(f_synth);

    return 0;
}
Exemple #6
0
int main(int argc, char *argv[])
{
    FILE *f_serial;                        /* File of serial bits for transmission  */
    FILE *f_synth;                         /* File of speech data                   */

    Word16 synth[L_FRAME16k];              /* Buffer for speech @ 16kHz             */
    UWord8 serial[NB_SERIAL_MAX];
    Word16 mode;
    Word32 frame;

    void *st;

    fprintf(stderr, "\n");
	   fprintf(stderr, "===================================================================\n");
	   fprintf(stderr, " 3GPP AMR-WB Floating-point Speech Decoder, v5.0.0, Mar 05, 2002\n");
	   fprintf(stderr, "===================================================================\n");
   fprintf(stderr, "\n");

    /*
     * Read passed arguments and open in/out files
     */
    if (argc != 3)
    {
        fprintf(stderr, "Usage : decoder  bitstream_file  synth_file\n");
        fprintf(stderr, "\n");
        fprintf(stderr, "Format for bitstream_file:\n");
        fprintf(stderr, "  Described in TS26.201.\n");
        fprintf(stderr, "\n");
        fprintf(stderr, "Format for synth_file:\n");
        fprintf(stderr, "  Synthesis is written to a binary file of 16 bits data.\n");
        fprintf(stderr, "\n");
        exit(0);
    }

    /* Open file for synthesis and packed serial stream */
    if ((f_serial = fopen(argv[1], "rb")) == NULL)
    {
        fprintf(stderr, "Input file '%s' does not exist !!\n", argv[1]);
        exit(0);
    }
    else
    {
        fprintf(stderr, "Input bitstream file:   %s\n", argv[1]);
    }

    if ((f_synth = fopen(argv[2], "wb")) == NULL)
    {
        fprintf(stderr, "Cannot open file '%s' !!\n", argv[2]);
        exit(0);
    }
    else
    {
        fprintf(stderr, "Synthesis speech file:   %s\n", argv[2]);
    }

    /*
     * Initialization of decoder
     */
    st = D_IF_init();

    /*
     * Loop for each "L_FRAME" speech data
     */
    fprintf(stderr, "\n --- Running ---\n");

    frame = 0;
    while (fread(serial, sizeof (UWord8), 1, f_serial ) > 0)
    {
       mode = (Word16)(serial[0] >> 4);
       fread(&serial[1], sizeof (UWord8), block_size[mode] - 1, f_serial );

       frame++;

       fprintf(stderr, " Decoding frame: %ld\r", frame);

       D_IF_decode( st, serial, synth, _good_frame);

       fwrite(synth, sizeof(Word16), L_FRAME16k, f_synth);
       fflush(f_synth);
    }

    D_IF_exit(st);

    fclose(f_serial);
    fclose(f_synth);

    return 0;
}