[opus] Encoder off by one

Hermann Weber hermie.weber at gmx.de
Sun Oct 6 09:56:58 PDT 2013


Well, I used the 5760 version now. I am still confused about the 359, 
but it works.

But it did not result in the speed gain I was expecting, it is nearly 
the same as with a smaller frame size.

I am using

     m_enc = opus_encoder_create(48000, 1, 
OPUS_APPLICATION_RESTRICTED_LOWDELAY, &err);
     opus_encoder_ctl(m_enc, OPUS_SET_BITRATE(48000));
     opus_encoder_ctl(m_enc, OPUS_SET_VBR(0));

Jean Marc, could you please tell me what you would do if you were me to 
get a better decoder speed?
I can not reduce the quality of the encoding.

Thank you for any suggestions.

I am currently decoding frames one-by-one like this:

void COpusCodec::DecodeFile(std::string uPathInput,std::string uPathOutput)
{
     FILE *fin= fopen(uPathInput.c_str(), "rb");
     FILE *fout=fopen(uPathOutput.c_str(), "wb");

     if (!fin)
     {
         return;
     }
     if (!fout)
     {
         return;
     }

     int stop=0;
     int curr_read=0;

     int iTotalBytesRead=0;
     int iTotalBytes=0;

     while (!stop)
     {
         int iBytesRead=fread(m_EncodedBytes, 1, 
g_iByteSize1FrameEncoded, fin);
         iTotalBytesRead+=iBytesRead;
         if (iBytesRead<g_iByteSize1FrameEncoded)
         {
             //during runtime/when decoding audio we will not overread 
of course because we know where our audio data end, but for testing 
without knowing the length, this is fine here
             break;
         }
         int iSizeShortsDecoded = opus_decode(m_dec, 
m_EncodedBytes,(opus_int32) g_iByteSize1FrameEncoded, m_ShortDecoded,  
(960*6), 0);
         if (iSizeShortsDecoded>0)
         {
             if (fwrite(m_ShortDecoded, sizeof(short), 
iSizeShortsDecoded, fout) != (unsigned)(iSizeShortsDecoded))
             {
                 fprintf(stderr, "Error writing.\n");
             }
             else
             {
                 int iLen;
                 iLen=ftell(fout);
                 int iBla;
                 iBla=0;
             }
         }
         else
         {
             fprintf(stderr, "error decoding frame: %s\n",
                             opus_strerror(iSizeShortsDecoded));
         }
     }
}



Am 06.10.2013 17:55, schrieb Hermann Weber:
> If you encode with
>
>            int iByteSizeEncoded = opus_encode(m_enc, m_ShortsInput,
> (1920/sizeof(short)), m_EncodedBytes, (960*6));
>
> ... the byte size is 120.
>
> I thought that an odd value like 359 has to be a fault on my side.
>
> I thought it would be a multiple of something.
> So 359 is really correct???
>
> Thank you for clearing this up.
>
>
>
> Am 06.10.2013 16:50, schrieb Jean-Marc Valin:
>> Why should it return 360 in the first place???
>>
>> On 10/06/2013 06:33 AM, Hermann Weber wrote:
>>> Why does opus_encode return 359, and not 360, please?
>>>
>>> This is my code:
>>>
>>>            int iShortsRead = fread(m_RawBytes, sizeof(short),
>>> (5760/sizeof(short)), fin);
>>>            for(int i=0;i<iShortsRead;i++)
>>>            {
>>>                opus_int32 s;
>>>                s=m_RawBytes[2*i+1]<<8|m_RawBytes[2*i];
>>>                s=((s&0xFFFF)^0x8000)-0x8000;
>>>                m_ShortsInput[i]=s;
>>>            }
>>>            int iByteSizeEncoded = opus_encode(m_enc, m_ShortsInput,
>>> (5760/sizeof(short)), m_EncodedBytes, (960*6));
>>> _______________________________________________
>>> opus mailing list
>>> opus at xiph.org
>>> http://lists.xiph.org/mailman/listinfo/opus
>>>
> _______________________________________________
> opus mailing list
> opus at xiph.org
> http://lists.xiph.org/mailman/listinfo/opus
>



More information about the opus mailing list