[opus] Empty buffer on encoder write byte
Jesse Armand
armand.jesse at gmail.com
Mon May 27 04:04:37 PDT 2013
I realized that I haven't allocated the payload output buffer. A stupid
mistake.
However, I found out that the decoded audio data received from the network
are not producing any sound.
I'm using 8000 and 16000 as a sampling rate, and they don't produce any
sound.
If I receive an uncompressed PCM data at the length of 1024 / 2048 bytes,
it's all working fine, and it could be played. The decoded output from opus
format however is only 320 bytes.
On Mon, May 27, 2013 at 2:38 PM, Jesse Armand <armand.jesse at gmail.com>wrote:
> Hi,
>
> I've been trying to encode a live audio input from the microphone on iOS
> device using opus.
>
> Uncompressed audio recording works fine with
> http://theamazingaudioengine.com/
>
> Then, when I tried to do encoding, I'm stuck at figuring out why the
> buffer is empty:
>
> static int ec_write_byte(ec_enc *_this,unsigned _value){
> if(_this->offs+_this->end_offs>=_this->storage)return -1;
> _this->buf[_this->offs++]=(unsigned char)_value;
> return 0;
> }
>
> _this->buf is pointing to 1 byte unsigned char, which is basically has no
> data in it, and it throws a bad access exception, at this function.
>
> I set the max data bytes for output payload to 2048, application mode as
> VoIP, and complexity to 5.
>
> The following is a snippet in ObjC where I did the encoding:
>
> self.inputReceiver = [AEBlockAudioReceiver
> audioReceiverWithBlock:^(void *source, const AudioTimeStamp *time, UInt32
> frames, AudioBufferList *bufferList) {
>
> UInt32 numberOfBuffers = bufferList->mNumberBuffers;
>
> for (int bufferIndex = 0; bufferIndex < numberOfBuffers ;
> ++bufferIndex) {
> AudioBuffer audioBuffer = bufferList->mBuffers[bufferIndex];
>
> int frameSize = (samplingRate/1000) * sampleDuration; //
> sampling rate is 8000, sample duration is 20ms
> size_t count = frameSize*channels / sizeof(opus_int16);
> __block opus_int16 *pcmInput = calloc(count,
> sizeof(opus_int16));
> memcpy(pcmInput, audioBuffer.mData, count *
> sizeof(opus_int16));
>
> [_encoder encodeWithPCMInput:pcmInput frameSize:frameSize
> outputBlock:^(unsigned char *payloadOutput, opus_int32 payloadLength) {
> // Send the audio data through UDP socket.
>
> NSData *audioData = [NSData dataWithBytes:payloadOutput
> length:payloadLength];
> [_socket sendData:audioData toHost:RTC_SERVER_HOST
> port:RTC_MEDIA_SERVER_PORT withTimeout:PACKET_TIMEOUT tag:AUDIO_DATA_TAG];
>
> free(pcmInput);
> pcmInput = NULL;
> }];
> }
> }];
>
>
> The following is the backtrace:
>
> * thread #6: tid = 0x231f, 0x00180506
> RTCClient`ec_enc_carry_out(_this=0x04232238, _c=61) + 42 at entenc.c:62,
> stop reason = EXC_BAD_ACCESS (code=1, address=0x1)
>
> frame #0: 0x00180506 RTCClient`ec_enc_carry_out(_this=0x04232238,
> _c=61) + 42 at entenc.c:62
>
> frame #1: 0x0018070a RTCClient`ec_enc_icdf [inlined]
> ec_enc_normalize(_this=0x04232238) + 24 at entenc.c:104
>
> frame #2: 0x001806f2 RTCClient`ec_enc_icdf(_this=0x04232238) + 62 at
> entenc.c:172
>
> frame #3: 0x001880c0 RTCClient`silk_encode_indices(psEncC=0x0422c1c0,
> psRangeEnc=0x04232238) + 232 at encode_indices.c:85
>
> frame #4: 0x00192fee RTCClient`silk_encode_frame_FLP(psEnc=0x04239bb4,
> pnBytesOut=0x000027d8, psRangeEnc=0x04232238, condCoding=69435308) + 1886
> at encode_frame_FLP.c:196
>
> frame #5: 0x00187de8 RTCClient`silk_Encode(encState=0x001f000b,
> encControl=0xffd2ffe2, samplesIn=0xffc4ffce, nSamplesIn=-5570589) + 2792 at
> enc_API.c:466
>
> frame #6: 0x0019a1ce RTCClient`opus_encode_float(st=0x04234000,
> pcm=0x3b6c0000, frame_size=985923584, data=0x04232018) + 3922 at
> opus_encoder.c:973
>
> frame #7: 0x0019abd2 RTCClient`opus_encode() + 74 at
> opus_encoder.c:1306
>
> frame #8: 0x000e63be RTCClient`-[JAOpusEncoder
> encodeWithPCMInput:frameSize:outputBlock:](self=0x1fd2ffa0,
> _cmd=0x0019d131, pcmInput=0x21024870, frameSize=160,
> outputBlock=0x04232898) + 386 at JAOpusEncoder.m:98
>
>
> JAOpusEncoder is an ObjC class that encodes the PCM input using opus
> library.
>
> Any ideas on what I'm doing wrong?
>
> Thanks.
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.xiph.org/pipermail/opus/attachments/20130527/19ae3bb2/attachment.htm
More information about the opus
mailing list