Esempio n. 1
0
/*====================================================================*/
int
Csrc::sr_convert_init ( int source, int channels, int bits,
                        int target, int target_channels,
                        int *encode_cutoff_freq )
{
    int min_samps, min_inbuf_bytes;
    int kfilter, byte_input;

    memset ( &src, 0, sizeof ( src ) ); // mod 12/15/98 for identical bitstreams
    // on second time around encodes

    if ( ( bits != 16 ) && ( bits != 8 ) )
        return 0;
    if ( channels < 1 )
        return 0;
    if ( channels > 2 )
        return 0;
    if ( source < 8000 )
        return 0;
    if ( source > 48000 )
        return 0;
    if ( target < 5000 )
        return 0;
    if ( target > 50400 )
        return 0;

    if ( target_channels < 1 )
        target_channels = 1;
    if ( target_channels > channels )
        target_channels = channels;

    kfilter = 0;
    if ( ( channels == 2 ) && ( target_channels == 2 ) )
        kfilter = 1;
    if ( ( channels == 2 ) && ( target_channels == 1 ) )
        kfilter = 2;

    byte_input = 0;
    if ( bits == 8 )
        byte_input = 1;

    min_samps = gen_src_filter ( source, target );      // return 0 if can't handle
    if ( min_samps <= 0 )
        return 0;

    min_inbuf_bytes = min_samps * channels * bits / 8;

    src_bytes_out = sizeof ( short ) * target_channels * 1152;

//src_filter = src_filter_table[byte_input][kfilter][src.ncase];
    src_filter = ( 3 * 5 ) * byte_input + 5 * kfilter + src.ncase;

/* return cutoff frequency for encoder */
    *encode_cutoff_freq = ( int ) ( 0.90f * HX_MIN ( target, source ) / 2 );

    return min_inbuf_bytes;
}
Esempio n. 2
0
void
CHXVector::SetSize(UINT32 ulNewSize)
{
    HX_ASSERT_VALID_PTR(this);

    if (ulNewSize == 0)
    {
        m_ulSize = 0;
        m_ulAlloc = 0;
        delete[] m_ppunkData;
        m_ppunkData = NULL;
    }
    else if (m_ppunkData == NULL)
    {
        m_ppunkData = new IUnknown*[ ulNewSize ];
        m_ulAlloc = ulNewSize;
        m_ulSize = ulNewSize;
    }
    else
    {
        if (ulNewSize > m_ulAlloc)
        {
            UINT32      ulGrow;
            UINT32      ulNewAlloc;
            IUnknown**  ppunkNewData;

            ulGrow = m_ulGrow;
            if (ulGrow == 0)
            {
                // Default is to grow by 1/8 with bounds of [4,1024]
                ulGrow = HX_MIN(1024, HX_MAX(4, m_ulSize/8));
            }
            ulNewAlloc = HX_MAX(ulNewSize, m_ulAlloc + ulGrow);
            HX_ASSERT(ulNewAlloc > m_ulAlloc); // Catch overflow

            ppunkNewData = new IUnknown*[ ulNewAlloc ];
            memcpy(ppunkNewData, m_ppunkData, m_ulSize * sizeof(IUnknown*));
            delete[] m_ppunkData;
            m_ppunkData = ppunkNewData;
            m_ulAlloc = ulNewAlloc;
        }

        m_ulSize = ulNewSize;
    }
}
Esempio n. 3
0
///////////////////////////////////
//
//  DoProcess
//
//  *** Called by Process and ProcessOutput ***
//
//  The DoProcess method processes the sound data.
//
//  Parameters
//
//      pbData
//          Pointer to the output buffer
//
//      pbInputData
//          Pointer to the input buffer
//
//      dwQuanta
//          Number of quanta to process
//
//  Return Value
//      S_OK Success
//
HRESULT CHXAudioDeviceHookBase::DoProcess(BYTE *pbData, const BYTE *pbInputData, DWORD dwQuanta)
{
    if( m_pHook )
    {
	DWORD dwInputBufSize = dwQuanta * WaveFormat()->nBlockAlign;
	IHXBuffer* pBuffer = NULL;
	if (HXR_OK == CreateAndSetBufferWithoutAllocCCF(pBuffer,
							(UCHAR*) pbInputData,
							dwInputBufSize,
							m_pContext))
	{
	    HXBOOL bChanged = FALSE;
	    if( SUCCEEDED( m_pHook->ProcessAudioDeviceHooks( pBuffer, bChanged )) && bChanged )
	    {
		memcpy( pbData, pBuffer->GetBuffer(), HX_MIN( dwInputBufSize, pBuffer->GetSize()) );
	    }

	    HX_RELEASE( pBuffer );
	}
    }

    return S_OK;
}
Esempio n. 4
0
void
CHXRingBuffer::SetSize(UINT32 ulNewSize)
{
    HX_ASSERT_VALID_PTR(this);

    if (ulNewSize == 0)
    {
        UINT32 i;
        for (i = 0; i < m_ulAlloc; i++)
        {
            if (m_ppunkData[i])
            {
                m_ppunkData[i]->Release();
            }
        }
        delete[] m_ppunkData;
        m_ppunkData = NULL;
        m_ulAlloc = 0;
        m_ulCount = 0;
        m_ulHead = 0;
        m_ulTail= 0;
    }
    else
    {
        if (ulNewSize > m_ulAlloc)
        {
            UINT32      ulGrow;
            UINT32      ulNewAlloc;
            IUnknown**  ppunkNewData;

            ulGrow = m_ulGrow;
            if (ulGrow == 0)
            {
                // Default is to grow by 1/4 with bounds of [8,1024]
                ulGrow = HX_MIN(1024, HX_MAX(8, ulNewSize/4));
            }
            ulNewAlloc = HX_MAX(ulNewSize, m_ulAlloc + ulGrow);
            HX_ASSERT(ulNewAlloc > m_ulAlloc); // Catch overflow

            ppunkNewData = new IUnknown*[ ulNewAlloc ];

            memset((void*)ppunkNewData, 0, sizeof(IUnknown*) * ulNewAlloc);

            UINT32      i;
            UINT32      j=0;
            if (m_ppunkData)
            {
                if (m_ppunkData[m_ulHead])
                {
                    for (i = m_ulHead; (i < m_ulAlloc); i++)
                    {
                        ppunkNewData[j++] = m_ppunkData[i];
                    }

                    if (m_ulHead >= m_ulTail)
                    {
                        for (i = 0; (i < m_ulTail); i++)
                        {
                            ppunkNewData[j++] = m_ppunkData[i];
                        }
                    }
                }

                delete[] m_ppunkData;
            }

            m_ppunkData = ppunkNewData;
            m_ulAlloc = ulNewAlloc;
            m_ulHead = 0;
            m_ulTail = j;
        }
    }
}