- Timestamp:
- Nov 2, 2011 7:50:44 AM (13 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
pjproject/branches/1.x/pjmedia/src/pjmedia-codec/g7221.c
r3553 r3880 749 749 { 750 750 codec_private_t *codec_data = (codec_private_t*) codec->codec_data; 751 const Word16 *pcm_input; 752 Word16 mlt_coefs[MAX_SAMPLES_PER_FRAME]; 753 Word16 mag_shift; 751 unsigned nsamples, processed; 754 752 755 753 /* Check frame in & out size */ 756 PJ_ASSERT_RETURN((pj_uint16_t)input->size == 757 (codec_data->samples_per_frame<<1), 758 PJMEDIA_CODEC_EPCMTOOSHORT); 759 PJ_ASSERT_RETURN(output_buf_len >= codec_data->frame_size, 754 nsamples = input->size >> 1; 755 PJ_ASSERT_RETURN(nsamples % codec_data->samples_per_frame == 0, 756 PJMEDIA_CODEC_EPCMFRMINLEN); 757 PJ_ASSERT_RETURN(output_buf_len >= codec_data->frame_size * nsamples / 758 codec_data->samples_per_frame, 760 759 PJMEDIA_CODEC_EFRMTOOSHORT); 761 760 … … 789 788 } 790 789 791 /* Encoder adjust the input signal level */ 792 if (codec_data->pcm_shift) { 793 unsigned i; 794 pcm_input = (const Word16*)input->buf; 795 for (i=0; i<codec_data->samples_per_frame; ++i) { 796 codec_data->enc_frame[i] = 797 (pj_int16_t)(pcm_input[i] >> codec_data->pcm_shift); 790 processed = 0; 791 output->size = 0; 792 while (processed < nsamples) { 793 Word16 mlt_coefs[MAX_SAMPLES_PER_FRAME]; 794 Word16 mag_shift; 795 const Word16 *pcm_input; 796 pj_int8_t *out_bits; 797 798 pcm_input = (const Word16*)input->buf + processed; 799 out_bits = (pj_int8_t*)output->buf + output->size; 800 801 /* Encoder adjust the input signal level */ 802 if (codec_data->pcm_shift) { 803 unsigned i; 804 for (i=0; i<codec_data->samples_per_frame; ++i) { 805 codec_data->enc_frame[i] = 806 (Word16)(pcm_input[i] >> codec_data->pcm_shift); 807 } 808 pcm_input = codec_data->enc_frame; 798 809 } 799 pcm_input = codec_data->enc_frame; 800 } else { 801 pcm_input = (const Word16*)input->buf;802 } 803 804 /* Convert input samples to rmlt coefs */ 805 mag_shift = samples_to_rmlt_coefs(pcm_input, 806 codec_data->enc_old_frame,807 mlt_coefs,808 codec_data->samples_per_frame);809 810 /* Encode the mlt coefs. Note that encoder output stream is 16 bit array,811 * so we need to take care about endianness. 812 */ 813 encoder(codec_data->frame_size_bits, 814 codec_data->number_of_regions, 815 mlt_coefs,816 mag_shift,817 output->buf);818 819 /* Encoder output are in native host byte order, while ITU says 820 * it must be in network byte order (MSB first). 821 */ 822 swap_bytes((pj_uint16_t*)output->buf, codec_data->frame_size/2);810 811 /* Convert input samples to rmlt coefs */ 812 mag_shift = samples_to_rmlt_coefs(pcm_input, 813 codec_data->enc_old_frame, 814 mlt_coefs, 815 codec_data->samples_per_frame); 816 817 /* Encode the mlt coefs. Note that encoder output stream is 818 * 16 bit array, so we need to take care about endianness. 819 */ 820 encoder(codec_data->frame_size_bits, 821 codec_data->number_of_regions, 822 mlt_coefs, 823 mag_shift, 824 (Word16*)out_bits); 825 826 /* Encoder output are in native host byte order, while ITU says 827 * it must be in network byte order (MSB first). 828 */ 829 swap_bytes((pj_uint16_t*)out_bits, codec_data->frame_size/2); 830 831 processed += codec_data->samples_per_frame; 832 output->size += codec_data->frame_size; 833 } 823 834 824 835 output->type = PJMEDIA_FRAME_TYPE_AUDIO; 825 output->size = codec_data->frame_size;826 836 output->timestamp = input->timestamp; 827 837
Note: See TracChangeset
for help on using the changeset viewer.