t_g726_audio_encoder::t_g726_audio_encoder(uint16 payload_id, uint16 ptime, t_bit_rate bit_rate, t_user *user_config) : t_audio_encoder(payload_id, ptime, user_config) { _bit_rate = bit_rate; switch (bit_rate) { case BIT_RATE_16: _codec = CODEC_G726_16; break; case BIT_RATE_24: _codec = CODEC_G726_24; break; case BIT_RATE_32: _codec = CODEC_G726_32; break; case BIT_RATE_40: _codec = CODEC_G726_40; break; default: assert(false); } if (ptime == 0) _ptime = PTIME_G726; _max_payload_size = audio_sample_rate(_codec)/1000 * _ptime; _packing = user_config->get_g726_packing(); g72x_init_state(&_state); }
wxSoundStreamG72X::wxSoundStreamG72X(wxSoundStream& sndio) : wxSoundStreamCodec(sndio) { // PCM converter m_router = new wxSoundRouterStream(sndio); m_state = new g72state; g72x_init_state(m_state); }
int DecodeVoicePCM(int codec, void* pBufIn, int nLenIn, void* pBufOut, int nLenOut) { struct g72x_state state; int dec_bits; XBUFFER xbin; XBUFFER xbout; unsigned int nSavePackData = 0; int nSavePackBit = 0; unsigned char nUnpackEncData; switch (codec) { case G723_24 : dec_bits = 3; break; case G721_32 : dec_bits = 4; break; case G723_40 : dec_bits = 5; break; default : return 0; } g72x_init_state(&state); SetXBuffer(xbin , (unsigned char*) pBufIn , nLenIn , nLenIn, 0); SetXBuffer(xbout, (unsigned char*) pBufOut, nLenOut, 0 , 0); while (UnpackInput(nSavePackData, nSavePackBit, xbin, nUnpackEncData, dec_bits) >= 0) { int nUnpackSourceData; switch (codec) { case G723_24 : nUnpackSourceData = g723_24_decoder(nUnpackEncData, AUDIO_ENCODING_LINEAR, &state); break; case G721_32 : nUnpackSourceData = g721_decoder (nUnpackEncData, AUDIO_ENCODING_LINEAR, &state); break; case G723_40 : nUnpackSourceData = g723_40_decoder(nUnpackEncData, AUDIO_ENCODING_LINEAR, &state); break; } AddXBufferShort(xbout, nUnpackSourceData); } return xbout.nLen; }
LPITCB FAR PASCAL G23A05toIni (LPITCB lpITC, LPITCI lpIni) { lmemset (lpITC, 0, sizeof (*lpITC)); g72x_init_state (&lpITC->gbG2X); return (lpITC); /* Return Init/Term/Cont block */ }
VGMSTREAM * init_vgmstream_rsf(STREAMFILE *streamFile) { VGMSTREAM * vgmstream = NULL; char filename[260]; size_t file_size; /* check extension, case insensitive */ /* this is all we have to go on, rsf is completely headerless */ streamFile->get_name(streamFile,filename,sizeof(filename)); if (strcasecmp("rsf",filename_extension(filename))) goto fail; file_size = get_streamfile_size(streamFile); { /* extra check: G.721 has no zero nibbles, so we look at * the first few bytes*/ int8_t test_byte; off_t i; /* 0x20 is arbitrary, all files are much larger */ for (i=0;i<0x20;i++) { test_byte = read_8bit(i,streamFile); if (!(test_byte&0xf) || !(test_byte&0xf0)) goto fail; } /* and also check start of second channel */ for (i=(file_size+1)/2;i<(file_size+1)/2+0x20;i++) { test_byte = read_8bit(i,streamFile); if (!(test_byte&0xf) || !(test_byte&0xf0)) goto fail; } } /* build the VGMSTREAM */ vgmstream = allocate_vgmstream(2,0); if (!vgmstream) goto fail; /* fill in the vital statistics */ vgmstream->num_samples = file_size; vgmstream->sample_rate = 32000; vgmstream->coding_type = coding_G721; vgmstream->layout_type = layout_none; vgmstream->meta_type = meta_RSF; /* open the file for reading by each channel */ { int i; for (i=0;i<2;i++) { vgmstream->ch[i].streamfile = streamFile->open(streamFile,filename,STREAMFILE_DEFAULT_BUFFER_SIZE); if (!vgmstream->ch[i].streamfile) goto fail; vgmstream->ch[i].channel_start_offset= vgmstream->ch[i].offset= (file_size+1)/2*i; g72x_init_state(&(vgmstream->ch[i].g72x_state)); } } return vgmstream; /* clean up anything we may have opened */ fail: if (vgmstream) close_vgmstream(vgmstream); return NULL; }