[speex-dev] Framesize for UWB vs. WB encoding

Robert M. robert.m at ib-caddy.si
Tue Jun 3 09:48:17 PDT 2003



Christian Buchner wrote:

>Hi there.
>
>I am having a little trouble understanding the frame sizes chosen
>by the codec.
>  
>
Christian, here is a code snippet from my ACM driver that will explain 
how to calculate bits per frame and block alignment. As you can see I 
don't use predefined tables for this. Maybe you can extract something 
useful for your project... If you need some assistence, please let me know.

<p>#define SPEEX10_STEREO_BITS 17

INT SpeexGetBitsPerEncodedFrame(PVOID pEncoder, SpeexMode* pMode)
{
    INT nBitsPerFrameNB;
    INT nBitsPerFrameWB;
    INT nBitsPerFrameUWB;
    SpeexMode* pModeNB;
    SpeexMode* pModeWB;
    SpeexMode* pModeUWB;
    EncState* pEncoderNB;
    SBEncState* pEncoderWB;
    SBEncState* pEncoderUWB;
   
    if (pMode->modeID == 0)
    {
        pModeNB = pMode;
        pEncoderNB = (EncState*)pEncoder;
    }
    else if (pMode->modeID == 1)
    {
        pEncoderWB = (SBEncState*)pEncoder;
        pModeWB = pMode;
        pEncoderNB = (EncState*)pEncoderWB->st_low;
        pModeNB = pEncoderNB->mode;
    }
    else if (pMode->modeID == 2)
    {
        pEncoderUWB = (SBEncState*)pEncoder;
        pModeUWB = pMode;
        pEncoderWB = (SBEncState*)pEncoderUWB->st_low;
        pModeWB = pEncoderWB->mode;
        pEncoderNB = (EncState*)pEncoderWB->st_low;
        pModeNB = pEncoderNB->mode;
    }

    if (speex_encoder_ctl(pEncoderNB, SPEEX_GET_MODE, &nBitsPerFrameNB) 
== -1)
        return -1;
    if (speex_mode_query(pModeNB, SPEEX_SUBMODE_BITS_PER_FRAME, 
&nBitsPerFrameNB) == -1)
        return -1;
    if (pMode->modeID == 0)
        return nBitsPerFrameNB;

    nBitsPerFrameWB = pEncoderWB->submodeID;
    if (speex_mode_query(pModeWB, SPEEX_SUBMODE_BITS_PER_FRAME, 
&nBitsPerFrameWB) == -1)
        return -1;
    if (pMode->modeID == 1)
        return (nBitsPerFrameNB + nBitsPerFrameWB);

    nBitsPerFrameUWB = pEncoderUWB->submodeID;
    if (speex_mode_query(pModeUWB, SPEEX_SUBMODE_BITS_PER_FRAME, 
&nBitsPerFrameUWB) == -1)
        return -1;
    return (nBitsPerFrameNB + nBitsPerFrameWB + nBitsPerFrameUWB);
}
/////////////////////////////////////////////////////////////////////////////
INT SpeexGetBlockAlignment(PVOID pEncoder, SpeexMode* pMode, UINT uChannels)
{
    UINT nBlockAlign;

    nBlockAlign = SpeexGetBitsPerEncodedFrame(pEncoder, pMode);
    if (nBlockAlign == -1)
        return nBlockAlign;

    if (uChannels == 2)
        nBlockAlign += SPEEX10_STEREO_BITS;
    else if (uChannels != 1)
        return -1;

    nBlockAlign = nBlockAlign >> 3;
    if (0 != (nBlockAlign % 8))
        nBlockAlign++;

    return nBlockAlign;
}

<p>>testenc_uwb.c from the speex-1.0 source distribution has a framesize
>of 640 hardcoded and makes use of this value exclusively.
>
>However, a mode query on the actual codec returns 320 as a framesize
>for this mode.
>
>   int tmp;
>   speex_mode_query(&speex_uwb_mode, SPEEX_MODE_FRAME_SIZE, &tmp);
>
>
>testenc_wb.c from the speex-1.0 source distribution has a framesize
>of 320 hardcoded and makes use of this value exclusively.
>
>However, a mode query on the actual codec returns 160 as a framesize
>for this mode.
>
>   int tmp;
>   speex_mode_query(&speex_wb_mode, SPEEX_MODE_FRAME_SIZE, &tmp);
>
>How can this discrepancy be explained?
>
>Could anyone shed some light here? ;) thanks.
>
>Christian
>
>--- >8 ----
>List archives:  http://www.xiph.org/archives/
>Ogg project homepage: http://www.xiph.org/ogg/
>To unsubscribe from this list, send a message to 'speex-dev-request at xiph.org'
>containing only the word 'unsubscribe' in the body.  No subject is needed.
>Unsubscribe messages sent to the list will be ignored/filtered.
>
>
>  
>


-- 
Best regards

Robert Milharcic

ib-CADdy d.o.o. / www.ib-caddy.si
e-mail: robert.milharcic at ib-caddy.si

<p><p><p><p>--- >8 ----
List archives:  http://www.xiph.org/archives/
Ogg project homepage: http://www.xiph.org/ogg/
To unsubscribe from this list, send a message to 'speex-dev-request at xiph.org'
containing only the word 'unsubscribe' in the body.  No subject is needed.
Unsubscribe messages sent to the list will be ignored/filtered.




More information about the Speex-dev mailing list