Changeset 4001 for pjproject/trunk/pjmedia/src/pjmedia-codec/g7221.c
- Timestamp:
- Mar 30, 2012 7:53:36 AM (12 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
pjproject/trunk/pjmedia/src/pjmedia-codec/g7221.c
r3911 r4001 760 760 { 761 761 codec_private_t *codec_data = (codec_private_t*) codec->codec_data; 762 const Word16 *pcm_input; 763 Word16 mlt_coefs[MAX_SAMPLES_PER_FRAME]; 764 Word16 mag_shift; 762 unsigned nsamples, processed; 765 763 766 764 /* Check frame in & out size */ 767 PJ_ASSERT_RETURN((pj_uint16_t)input->size == 768 (codec_data->samples_per_frame<<1), 769 PJMEDIA_CODEC_EPCMTOOSHORT); 770 PJ_ASSERT_RETURN(output_buf_len >= codec_data->frame_size, 765 nsamples = input->size >> 1; 766 PJ_ASSERT_RETURN(nsamples % codec_data->samples_per_frame == 0, 767 PJMEDIA_CODEC_EPCMFRMINLEN); 768 PJ_ASSERT_RETURN(output_buf_len >= codec_data->frame_size * nsamples / 769 codec_data->samples_per_frame, 771 770 PJMEDIA_CODEC_EFRMTOOSHORT); 772 771 … … 800 799 } 801 800 802 /* Encoder adjust the input signal level */ 803 if (codec_data->pcm_shift) { 804 unsigned i; 805 pcm_input = (const Word16*)input->buf; 806 for (i=0; i<codec_data->samples_per_frame; ++i) { 807 codec_data->enc_frame[i] = 808 (pj_int16_t)(pcm_input[i] >> codec_data->pcm_shift); 801 processed = 0; 802 output->size = 0; 803 while (processed < nsamples) { 804 Word16 mlt_coefs[MAX_SAMPLES_PER_FRAME]; 805 Word16 mag_shift; 806 const Word16 *pcm_input; 807 pj_int8_t *out_bits; 808 809 pcm_input = (const Word16*)input->buf + processed; 810 out_bits = (pj_int8_t*)output->buf + output->size; 811 812 /* Encoder adjust the input signal level */ 813 if (codec_data->pcm_shift) { 814 unsigned i; 815 for (i=0; i<codec_data->samples_per_frame; ++i) { 816 codec_data->enc_frame[i] = 817 (Word16)(pcm_input[i] >> codec_data->pcm_shift); 818 } 819 pcm_input = codec_data->enc_frame; 809 820 } 810 pcm_input = codec_data->enc_frame; 811 } else { 812 pcm_input = (const Word16*)input->buf;813 } 814 815 /* Convert input samples to rmlt coefs */ 816 mag_shift = samples_to_rmlt_coefs(pcm_input, 817 codec_data->enc_old_frame,818 mlt_coefs,819 codec_data->samples_per_frame);820 821 /* Encode the mlt coefs. Note that encoder output stream is 16 bit array,822 * so we need to take care about endianness. 823 */ 824 encoder(codec_data->frame_size_bits, 825 codec_data->number_of_regions, 826 mlt_coefs,827 mag_shift,828 output->buf);829 830 /* Encoder output are in native host byte order, while ITU says 831 * it must be in network byte order (MSB first). 832 */ 833 swap_bytes((pj_uint16_t*)output->buf, codec_data->frame_size/2);821 822 /* Convert input samples to rmlt coefs */ 823 mag_shift = samples_to_rmlt_coefs(pcm_input, 824 codec_data->enc_old_frame, 825 mlt_coefs, 826 codec_data->samples_per_frame); 827 828 /* Encode the mlt coefs. Note that encoder output stream is 829 * 16 bit array, so we need to take care about endianness. 830 */ 831 encoder(codec_data->frame_size_bits, 832 codec_data->number_of_regions, 833 mlt_coefs, 834 mag_shift, 835 (Word16*)out_bits); 836 837 /* Encoder output are in native host byte order, while ITU says 838 * it must be in network byte order (MSB first). 839 */ 840 swap_bytes((pj_uint16_t*)out_bits, codec_data->frame_size/2); 841 842 processed += codec_data->samples_per_frame; 843 output->size += codec_data->frame_size; 844 } 834 845 835 846 output->type = PJMEDIA_FRAME_TYPE_AUDIO; 836 output->size = codec_data->frame_size;837 847 output->timestamp = input->timestamp; 838 848
Note: See TracChangeset
for help on using the changeset viewer.