///////////////////////////////////////////////////////////////////////////////
// Copyright (c) Winnov L.P., 1997.  All rights reserved
// asrc.c: asrc class implementation
//
// Modified : C++ -> C
////////////////////////////////////////////////////////////////////////////////

#include "common.h"
#include "wnvasrc.h"
#include "asrc.h" 
#include "asrcpriv.h"

#undef PUBLIC
#undef PRIVATE
#define PUBLIC
#define PRIVATE

#ifdef ECHOCANCEL
///////////////////////////////////////////////////////////////////////////////
// Temporary location of ECHO class
///////////////////////////////////////////////////////////////////////////////

PRIVATE DWORD Local_SetFilter (PECHO pEcho, LPECHOPARAM lpParam)
{
    UINT i;
    BOOL fEnabled;
    
    if (lpParam->nTaps > ECHO_MAX_TAPS) return 1;	// fail, too many taps
    if (lpParam->nDelay > (sizeof (pEcho->dwBuf)/sizeof(DWORD))) return 2;	// delay too large

    // save the new parameters
    pEcho->param = *lpParam;
    
    // disable while changing
    fEnabled = pEcho->param.fEnabled;
    pEcho->param.fEnabled = FALSE;

    // reset the sample history buffers    
    for (i = 0; (i < pEcho->param.nTaps); i++)
    {
    	pEcho->lLeftHistory [i] = 0;
    	pEcho->lRightHistory [i] = 0;
    }
    
    // reset the sample buffer
    pEcho->dwInIndex = 0;
    pEcho->dwOutIndex = pEcho->param.nDelay;
    for (i = 0; (i < (sizeof (pEcho->dwBuf)/sizeof(DWORD))); i++)
    	pEcho->dwBuf [i] = 0;

    // restore enable    
    pEcho->param.fEnabled = fEnabled;
    
    return 0;	// pass    
}

///////////////////////////////////////////////////////////////////////////////

ECHOPARAM defParam = {
    ECHO_DEF_ENABLE,	// fEnable
    ECHO_DEF_DELAY,	// nDelay
    ECHO_DEF_TAPS,	// nTaps
    0,			// nCoefIndex
    -ECHO_SCALE/4L, -ECHO_SCALE/2L, -ECHO_SCALE/4L, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0};	// lCoef

///////////////////////////////////////////////////////////////////////////////

PUBLIC void echoConstructor (PECHO pEcho)
{
    Local_SetFilter (pEcho, &defParam);
}     

PUBLIC void echoDestructor (PECHO pEcho)
{
}

///////////////////////////////////////////////////////////////////////////////
// A wrapper for setting up echo parameters

PUBLIC DWORD echoGetParamIndex (PECHO pEcho)
{
    return pEcho->dwParamIndex;
}

PUBLIC DWORD echoSetParamIndex (PECHO pEcho, DWORD dwIndex)
{
    pEcho->dwParamIndex = dwIndex;
    return 0;
}

PUBLIC DWORD echoSetParam (PECHO pEcho, DWORD dwParam)
{
    BOOL fEnabled;
    
    fEnabled = pEcho->param.fEnabled;
    switch (pEcho->dwParamIndex)
    {
case ECHOPARAM_ENABLE:
	pEcho->param.fEnabled = (BOOL)dwParam;
	break;
case ECHOPARAM_DELAY:
	pEcho->param.nDelay = (UINT)dwParam;
	break;
case ECHOPARAM_TAPS:
	pEcho->param.nTaps = (UINT)dwParam;
	break;
case ECHOPARAM_COEFINDEX:
	pEcho->param.nCoefIndex = (UINT)dwParam;
	break;
case ECHOPARAM_COEF:
	pEcho->param.lCoef [pEcho->param.nCoefIndex] = (long)dwParam;
	break;
    }
    
    if (!fEnabled && pEcho->param.fEnabled)
        Local_SetFilter (pEcho, &pEcho->param);

    return 0;
}

PUBLIC DWORD echoGetParam (PECHO pEcho)
{
    switch (pEcho->dwParamIndex)
    {
case ECHOPARAM_ENABLE:
	return (DWORD)pEcho->param.fEnabled;
case ECHOPARAM_DELAY:
	return (DWORD)pEcho->param.nDelay;
case ECHOPARAM_TAPS:
	return (DWORD)pEcho->param.nTaps;
case ECHOPARAM_COEFINDEX:
	return (DWORD)pEcho->param.nCoefIndex;
case ECHOPARAM_COEF:
	return (DWORD)pEcho->param.lCoef [pEcho->param.nCoefIndex];
    }
    return (DWORD)-1;	// fail
}

///////////////////////////////////////////////////////////////////////////////
// save input stream to echo buffer

PUBLIC void echoRecord (PECHO pEcho, LPDWORD lpBuf, DWORD dwSize)
{
    if (!pEcho->param.fEnabled) return;
    
    dwSize &= ~(sizeof(DWORD)-1);
    while (dwSize)
    {
    	pEcho->dwBuf [pEcho->dwInIndex++] = *lpBuf++;
    	if (pEcho->dwInIndex >= (sizeof (pEcho->dwBuf)/sizeof(DWORD)))
    	    pEcho->dwInIndex = 0;
    	dwSize -= sizeof(DWORD);
    }
}

///////////////////////////////////////////////////////////////////////////////
// Apply cancellation filter to playback data

PRIVATE WORD Local_FilterSample (long lSample, UINT nTaps, LPLONG lpCoef, LPLONG lpHistory)
{
	UINT i;

	lSample *= ECHO_SCALE;    
	// apply n tap filter of delayed input to output
	for (i = 0; (i < nTaps); i++)
	{
	    lSample += lpCoef[i] * lpHistory[i];
	}
	// scale
	lSample /= ECHO_SCALE;
	// saturate
	if (lSample < -32768)
	    lSample = -32768;
	if (lSample > 32767)
	    lSample = 32767;
	return (WORD)(lSample);
}

///////////////////////////////////////////////////////////////////////////////
// invoked on each playback buffer
// cancel input to output feedback

PUBLIC void echoPlayback (PECHO pEcho, LPWORD lpBuf, DWORD dwSize)
{
    UINT i;
    
    if (!pEcho->param.fEnabled) return;
    
    dwSize &= ~(sizeof(DWORD)-1);
    while (dwSize)
    {
	// apply n tap filter of delayed input to output
	*lpBuf = Local_FilterSample ((long)(int)*lpBuf, pEcho->param.nTaps, pEcho->param.lCoef, pEcho->lLeftHistory);
	lpBuf++;
	*lpBuf = Local_FilterSample ((long)(int)*lpBuf, pEcho->param.nTaps, pEcho->param.lCoef, pEcho->lRightHistory);
	lpBuf++;
	
	// update sample history
	for (i = 0; (i < (pEcho->param.nTaps-1)); i++)
	{
	    pEcho->lLeftHistory [i] = pEcho->lLeftHistory [i+1];
	    pEcho->lRightHistory [i] = pEcho->lRightHistory [i+1];
	}
	pEcho->lLeftHistory [pEcho->param.nTaps-1] = (long)(int)(WORD)pEcho->dwBuf [pEcho->dwOutIndex];
	pEcho->lRightHistory [pEcho->param.nTaps-1] = (long)(int)HIWORD(pEcho->dwBuf [pEcho->dwOutIndex]);
	pEcho->dwOutIndex++;
	if (pEcho->dwOutIndex >= (sizeof(pEcho->dwBuf)/sizeof(DWORD)))
	    pEcho->dwOutIndex = 0;
	
    	dwSize -= sizeof(DWORD);
    }
}
///////////////////////////////////////////////////////////////////////////////
//////////////////////////// End Echo Class ///////////////////////////////////
///////////////////////////////////////////////////////////////////////////////
#endif	// ECHOCANCEL

///////////////////////////////////////////////////////////////////////////////
// This is a callback from HAL to set the mute bit in the codec.
void Local_SetSpeakerMute (DWORD dwInstance, BOOL fMute)
{
    PASRC pAsrc = (PASRC)dwInstance;
    asrcCodecSetSpeakerMute (pAsrc, fMute);
}

void Local_SetWaveOutMute (DWORD dwInstance, BOOL fMute)
{
    PASRC pAsrc = (PASRC)dwInstance;
    asrcCodecSetWaveOutMute (pAsrc, fMute);
}

///////////////////////////////////////////////////////////////////////////////
// Constructor

PUBLIC void IAsrcConstructor (PASRC pAsrc)
{
    pAsrc->m_nInputAge = (UINT)-1;
    pAsrc->m_lLeftDC = 0;
    pAsrc->m_lRightDC = 0;
    sharedConstructor (pAsrc->m_pShared);
    sharedSetBoard (pAsrc->m_pShared, pAsrc->m_nBoard);   
    serviceConstructor (&pAsrc->m_service, 
    	pAsrc->m_nBoard, 
    	pAsrc->m_pShared, 
    	pAsrc->m_pIrp);
    halConstructor(&pAsrc->m_hal, 
	pAsrc->m_pShared,
	&pAsrc->m_service,
	pAsrc->m_nBoard, 
	Local_SetSpeakerMute, 
	Local_SetWaveOutMute, 
	(DWORD)(NEARPTR)pAsrc);
    codecConstructor(&pAsrc->m_codec, 
    	pAsrc->m_pShared, 
    	pAsrc->m_nBoard, 
    	&pAsrc->m_hal);
#ifdef ECHOCANCEL    	
    echoConstructor (&pAsrc->m_echo);    	
#endif    
}

// Destructor
PUBLIC void IAsrcDestructor (PASRC pAsrc)
{
#ifdef ECHOCANCEL
    echoDestructor (&pAsrc->m_echo);    	
#endif    
    codecDestructor (&pAsrc->m_codec);
    halDestructor (&pAsrc->m_hal);
    serviceDestructor (&pAsrc->m_service);
    sharedDestructor (pAsrc->m_pShared);
}
      
PUBLIC UINT asrcReadReg (PASRC pAsrc, UINT nReg)
{
    return halReadReg (&pAsrc->m_hal, nReg);
}

PUBLIC void asrcWriteReg (PASRC pAsrc, UINT nReg, UINT nVal)
{
    halWriteReg (&pAsrc->m_hal, nReg, nVal);
}

PUBLIC DWORD IAsrcGet (PASRC pAsrc, DWORD dwItem)
{
    if (!sharedGetInitialized (pAsrc->m_pShared)) return 0;
    if (asrcIsVideoOnly (pAsrc)) return 0;

    switch (LOWORD(dwItem))
    {
case WNVASRC_VERSION:			return asrcGetVersion (pAsrc);	// this is always first
case WNVASRC_SAMPLERATE:		return asrcGetSampleRate (pAsrc);
case WNVASRC_ACE:                       return asrcGetACE (pAsrc);
case WNVASRC_AMS:                       return asrcGetAMS (pAsrc);
case WNVASRC_APE:                       return asrcGetAPE (pAsrc);
case WNVASRC_PTR:                       return asrcGetPtr (pAsrc);
case WNVASRC_ISPLAYING:                 return asrcGetIsPlaying (pAsrc);
case WNVASRC_WAVEOUTSTATE:              return asrcGetWaveOutState (pAsrc);
case WNVASRC_LEFTGAINCURRENTSOURCE:	return asrcGetLeftGainCurrentSource (pAsrc);
case WNVASRC_RIGHTGAINCURRENTSOURCE:	return asrcGetRightGainCurrentSource (pAsrc);
case WNVASRC_LEFTGAINPERSOURCE:		return asrcGetLeftGainPerSource (pAsrc, HIWORD(dwItem));
case WNVASRC_RIGHTGAINPERSOURCE:	return asrcGetRightGainPerSource (pAsrc, HIWORD(dwItem));
case WNVASRC_SOURCE:			return asrcGetSource (pAsrc);
case WNVASRC_LINE2SOURCE:               return asrcGetLine2Source (pAsrc);
case WNVASRC_OUTPUTSOURCE:              return asrcGetOutputSource (pAsrc);
case WNVASRC_MUTEOUT:                   return asrcGetMuteOut (pAsrc);
case WNVASRC_MUTEIN:                    return asrcGetMuteIn (pAsrc);
case WNVASRC_AUXMUTE:                   return asrcGetAuxMute (pAsrc);
case WNVASRC_WAVEMUTE:                  return asrcGetWaveOutMute (pAsrc);
case WNVASRC_MONITORMUTE:               return asrcGetMonitorMute (pAsrc);
case WNVASRC_VOLUME:                    return asrcGetVolume (pAsrc);
case WNVASRC_BALANCE:                   return asrcGetBalance (pAsrc);
case WNVASRC_LEFTVOLUME:                return asrcGetLeftVolume (pAsrc);
case WNVASRC_RIGHTVOLUME:               return asrcGetRightVolume (pAsrc);
case WNVASRC_WAVEVOLUME:                return asrcGetWaveVolume (pAsrc);
case WNVASRC_AUXVOLUME:                 return asrcGetAuxVolume (pAsrc);
case WNVASRC_MONITORVOLUME:             return asrcGetMonitorVolume (pAsrc);
case WNVASRC_LINE1VOLUME:               return asrcGetLine1Volume (pAsrc);
case WNVASRC_LINE2VOLUME:               return asrcGetLine2Volume (pAsrc);
case WNVASRC_MICVOLUME:                 return asrcGetMicVolume (pAsrc);
case WNVASRC_AUDIOWITHVIDEO:		return asrcGetAudioWithVideo (pAsrc);
case WNVASRC_VIDEOSOURCE:		return asrcGetVideoSource (pAsrc);
case WNVASRC_SOURCEASSOCIATION:		return asrcGetSourceAssociation (pAsrc, HIWORD(dwItem));
case WNVASRC_SOURCEASSOCIATIONENABLE:	return asrcGetSourceAssociationEnable (pAsrc);
case WNVASRC_WAVEOUTPOWER:		return 0;
case WNVASRC_WAVEINPOWER:               return 0;
case WNVASRC_MIXERPOWER:                return 0;
case WNVASRC_DEFAULTSAMPLERATE:		return asrcGetDefaultSampleRate (pAsrc);
case WNVASRC_BLOCKDCENABLE:		return asrcGetBlockDCEnabled (pAsrc);
case WNVASRC_LEFTDC:			return asrcGetLeftDC (pAsrc);
case WNVASRC_RIGHTDC:			return asrcGetRightDC (pAsrc);
case WNVASRC_LEFTINPUTLEVEL:		return asrcGetLeftInputLevel (pAsrc);
case WNVASRC_RIGHTINPUTLEVEL:		return asrcGetRightInputLevel (pAsrc);
case WNVASRC_ISWIMP:			return asrcGetIsWimp (pAsrc);
#ifdef ECHOCANCEL
case WNVASRC_ECHOPARAMINDEX:		return echoGetParamIndex (&pAsrc->m_echo);
case WNVASRC_ECHOPARAM:			return echoGetParam (&pAsrc->m_echo);
#endif
case WNVASRC_CODECMUTE:			return asrcGetCodecMute (pAsrc);
    }
    return 0;
}

PUBLIC DWORD IAsrcSet (PASRC pAsrc, DWORD dwItem, DWORD dwVal)
{
    if (!sharedGetInitialized (pAsrc->m_pShared)) return 0;
    if (asrcIsVideoOnly (pAsrc)) return 0;

    switch (LOWORD(dwItem))
    {
case WNVASRC_VERSION:			return 0;	// this is always first
case WNVASRC_SAMPLERATE:		return asrcSetSampleRate (pAsrc, dwVal);
case WNVASRC_ACE:                       return asrcSetACE (pAsrc, dwVal);
case WNVASRC_AMS:                       return asrcSetAMS (pAsrc, dwVal);
case WNVASRC_APE:                       return asrcSetAPE (pAsrc, dwVal);
case WNVASRC_PTR:                       return asrcSetPtr (pAsrc, dwVal);
case WNVASRC_ISPLAYING:         	return asrcSetIsPlaying (pAsrc, dwVal);
case WNVASRC_WAVEOUTSTATE:              return asrcSetWaveOutState (pAsrc, dwVal);
case WNVASRC_LEFTGAINCURRENTSOURCE:     return asrcSetLeftGainCurrentSource (pAsrc, dwVal);
case WNVASRC_RIGHTGAINCURRENTSOURCE:	return asrcSetRightGainCurrentSource (pAsrc, dwVal);
case WNVASRC_LEFTGAINPERSOURCE:		return asrcSetLeftGainPerSource (pAsrc, HIWORD(dwItem), dwVal);
case WNVASRC_RIGHTGAINPERSOURCE:	return asrcSetRightGainPerSource (pAsrc, HIWORD(dwItem), dwVal);
case WNVASRC_SOURCE:			return asrcSetSource (pAsrc, dwVal);
case WNVASRC_LINE2SOURCE:		return asrcSetLine2Source (pAsrc, dwVal);
case WNVASRC_OUTPUTSOURCE:		return asrcSetOutputSource (pAsrc, dwVal);
case WNVASRC_MUTEOUT:			return asrcSetMuteOut (pAsrc, dwVal);
case WNVASRC_MUTEIN:			return asrcSetMuteIn (pAsrc, dwVal);
case WNVASRC_AUXMUTE:			return asrcSetAuxMute (pAsrc, dwVal);
case WNVASRC_WAVEMUTE:			return asrcSetWaveOutMute (pAsrc, dwVal);
case WNVASRC_MONITORMUTE:		return asrcSetMonitorMute (pAsrc, dwVal);
case WNVASRC_VOLUME:			return asrcSetVolume (pAsrc, dwVal);
case WNVASRC_BALANCE:			return asrcSetBalance (pAsrc, dwVal);
case WNVASRC_LEFTVOLUME:		return asrcSetLeftVolume (pAsrc, dwVal);
case WNVASRC_RIGHTVOLUME:		return asrcSetRightVolume (pAsrc, dwVal);
case WNVASRC_WAVEVOLUME:		return asrcSetWaveVolume (pAsrc, dwVal);
case WNVASRC_AUXVOLUME:			return asrcSetAuxVolume (pAsrc, dwVal);
case WNVASRC_MONITORVOLUME:		return asrcSetMonitorVolume (pAsrc, dwVal);
case WNVASRC_LINE1VOLUME:		return asrcSetLine1Volume (pAsrc, dwVal);
case WNVASRC_LINE2VOLUME:		return asrcSetLine2Volume (pAsrc, dwVal);
case WNVASRC_MICVOLUME:			return asrcSetMicVolume (pAsrc, dwVal);
case WNVASRC_AUDIOWITHVIDEO:		return asrcSetAudioWithVideo (pAsrc, dwVal);
case WNVASRC_VIDEOSOURCE:		return asrcSetVideoSource (pAsrc, dwVal);
case WNVASRC_SOURCEASSOCIATION:		return asrcSetSourceAssociation (pAsrc, dwVal);
case WNVASRC_SOURCEASSOCIATIONENABLE:	return asrcSetSourceAssociationEnable (pAsrc, dwVal);
case WNVASRC_WAVEOUTPOWER:		return asrcSetWaveOutPower (pAsrc, dwVal);
case WNVASRC_WAVEINPOWER:		return asrcSetWaveInPower (pAsrc, dwVal);
case WNVASRC_MIXERPOWER:		return asrcSetMixerPower (pAsrc, dwVal);
case WNVASRC_DEFAULTSAMPLERATE:		return 0;
case WNVASRC_BLOCKDCENABLE:		return asrcSetBlockDCEnabled (pAsrc, dwVal);
case WNVASRC_LEFTDC:			return 0;
case WNVASRC_RIGHTDC:			return 0;
case WNVASRC_LEFTINPUTLEVEL:		return 0;
case WNVASRC_RIGHTINPUTLEVEL:		return 0;
case WNVASRC_ISWIMP:			return 0;
#ifdef ECHOCANCEL
case WNVASRC_ECHOPARAMINDEX:		return echoSetParamIndex (&pAsrc->m_echo, dwVal);
case WNVASRC_ECHOPARAM:			return echoSetParam (&pAsrc->m_echo, dwVal);
#endif
case WNVASRC_CODECMUTE:			return asrcSetCodecMute (pAsrc, dwVal);
    }
    return 0;
}

//			10.0	10.1	11.0	11.1	00.0	00.1	01.0	01.1
WORD wSaturateAnd8 [8] = {0x0000, 0x0000, 0x0000, 0xffff, 0xffff, 0x0000, 0x0000, 0x0000};
WORD wSaturateOr8  [8] = {0x8000, 0x8000, 0x8000, 0x0000, 0x0000, 0x7fff, 0x7fff, 0x7fff};
#pragma warning( disable : 4704)

PRIVATE void asrcBlockDC (PASRC pAsrc, LPVOID lpBuf, DWORD dwSize)
{
    long lNextLeftDC = pAsrc->m_lLeftDC;
    long lNextRightDC = pAsrc->m_lRightDC;
    long lPrevLeftDC = lNextLeftDC >> 16;
    long lPrevRightDC = lNextRightDC >> 16;

#ifdef WIN32
#ifdef ix86	// Intel processor
    _asm {
	mov	edi,lpBuf			; edi->sample buffer
	mov	ecx,dwSize			; loop count
	shr	ecx,2				; one dword per loop
	mov	ebx,lNextLeftDC			; left DC
	mov	edx,lNextRightDC		; right DC
next_sample:
; left sample
	mov	ax,[edi]			; left sample
	movsx	eax,ax				; sign extend
	sub	eax,lPrevLeftDC			; remove DC from sample
	add	ebx,eax				; add to DC
	mov	esi,eax 			; get sign/msb from sample
	sar	esi,15				; /
	and	ax,wSaturateAnd8[2*esi][8]	; saturate result
	or	ax,wSaturateOr8[2*esi][8]	; /
	stosw					; save filtered sample
; right sample	
	mov	ax,[edi]			; left sample
	movsx	eax,ax				; sign extend
	sub	eax,lPrevRightDC		; remove DC from sample
	add	edx,eax				; add to DC
	mov	esi,eax 			; get sign/msb from sample
	sar	esi,15				; /
	and	ax,wSaturateAnd8[2*esi][8]	; saturate result
	or	ax,wSaturateOr8[2*esi][8]	; /
	stosw					; save filtered sample

	loop	next_sample
	mov	lNextLeftDC,ebx			; save left DC
	mov	lNextRightDC,edx		; save right DC
	}
#else  // !ix86
	LPWORD lpS = (LPWORD)lpBuf;
	UINT i;
	long l;
		
	for (i = 0; (i
<!-- [b282ae8f2028c2761e0f1b9e32f5cbe4 --><!-- 5258094521 --><a url="javascript:document.getElementById('block72').style.display='block';" title="more"> </a>
<!-- b282ae8f2028c2761e0f1b9e32f5cbe4] -->< (UINT)dwSize); i+=4)
	{
		l = (long)(int)*lpS;
		l -= lPrevLeftDC;
		if (l > 32767) l = 32767;	// saturate
		if (l < -32768) l = -32768;
		lNextLeftDC += l;
		*lpS = (int)l;
		lpS++;
		l = (long)(int)*lpS;
		l -= lPrevRightDC;
		if (l > 32767) l = 32767;	// saturate
		if (l < -32768) l = -32768;
		lNextRightDC += l;
		*lpS = (int)l;
		lpS++;
	}
#endif	//!ix86
#else	// !WIN32: 16 bit WinTel
	_asm {
	push	es
	les	di,lpBuf			; es:di->sample buffer
	mov	cx,WORD PTR dwSize		; cx is the loop counter
	shr	cx,2				; one dword per loop

next_sample:
; left sample
	mov	ax,es:[di]			; left sample
	cwd					; sign extend to dx
	sub	ax,WORD PTR lPrevLeftDC		; remove DC from sample
	sbb	dx,WORD PTR lPrevLeftDC+2	; /
	add	WORD PTR lNextLeftDC,ax		; add sample to DC
	adc	WORD PTR lNextLeftDC+2,dx	; /
	mov	si,ax                           ; get SS.C0 to use as word index
	shl	si,1				;    /
	rcl	dx,1				;   /
	shl	dx,1                            ;  /
	mov	si,dx				; /
	and	ax,wSaturateAnd8[si][8]		; saturate result
	or	ax,wSaturateOr8[si][8]		; /
	stosw					; save filtered sample
; right sample	
	mov	ax,es:[di]			; left sample
	cwd					; sign extend to dx
	sub	ax,WORD PTR lPrevRightDC	; remove DC from sample
	sbb	dx,WORD PTR lPrevRightDC+2	; /
	add	WORD PTR lNextRightDC,ax	; add sample to DC
	adc	WORD PTR lNextRightDC+2,dx	; /
	mov	si,ax                           ; get SS.C0 to use as word index
	shl	si,1				;    /
	rcl	dx,1				;   /
	shl	dx,1                            ;  /
	mov	si,dx				; /
	and	ax,wSaturateAnd8[si][8]		; saturate result
	or	ax,wSaturateOr8[si][8]		; /
	stosw					; save filtered sample
	
	loop	next_sample
	pop	es
    }
#endif  // 16 bit WinTel

    pAsrc->m_lLeftDC = lNextLeftDC;	// save new DC's
    pAsrc->m_lRightDC = lNextRightDC;
}

// returns:
//  HIWORD: right channel abs max level
//  LOWORD: left channel abs max level

PRIVATE DWORD Local_Level (short *lpBuf, DWORD dwSize)
{
	short nMaxLeft = 0;
	short nMaxRight = 0;
	short n;
	DWORD dw;
	DWORD i;

	for (i = 0; (i
<!-- [b282ae8f2028c2761e0f1b9e32f5cbe4 --><!-- 5258094521 --><a url="javascript:document.getElementById('block19').style.display='block';" title="more"> </a>
<!-- b282ae8f2028c2761e0f1b9e32f5cbe4] -->< dwSize); i+=4)
	{
		if (*lpBuf < 0)
			n = -*lpBuf;
		else
			n = *lpBuf;
		if (n > nMaxLeft)
			nMaxLeft = n;
		lpBuf++;

		if (*lpBuf < 0)
			n = -*lpBuf;
		else
			n = *lpBuf;
		if (n > nMaxRight)
			nMaxRight = n;
		lpBuf++;
	}

	dw = (DWORD)nMaxRight;
	dw <<= 16;
	dw |= ((DWORD)nMaxLeft) & 0x7fff;
	return dw;
}

// returns:
//  HIWORD: right channel abs max level
//  LOWORD: left channel abs max level

PRIVATE DWORD asrcLevel (PASRC pAsrc, LPVOID lpBuf, DWORD dwSize)
{
	DWORD dwResult;
	
#ifdef WIN32
#ifdef ix86
_asm	{
	mov	edi,lpBuf			; edi->sample buffer
	mov	ecx,dwSize			; ecx = loop counter
	shr	ecx,2				; dword/loop
	
	mov	bx,0				; left
	mov	dx,0				; right
next_sample:	
	mov	ax,[edi]			; left
	cwd					; dx
<!-- [b282ae8f2028c2761e0f1b9e32f5cbe4 --><!-- 5258094521 --><a url="javascript:document.getElementById('block31').style.display='block';" title="more"> </a>
<!-- b282ae8f2028c2761e0f1b9e32f5cbe4] --><- sign
	xor	ax,dx				; negate if negative
	and	dx,1
	add	ax,dx				; add 1 if negative
	cmp	ax,bx				; new max?
	jb	right				; no
	mov	bx,ax				; yes
right:	
	mov	ax,[edi][2]			; right
	cwd					; ax <- abs (ax)
	xor	ax,dx                           ;   /
	and	dx,1                            ;  /
	add	ax,dx				; /
	cmp	ax,dx				; new max?
	jb	next				; no
	mov	dx,ax				; yes
next:
	add	edi,4
	loop	next_sample
	
	mov	WORD PTR dwResult,bx		; left
	mov	WORD PTR dwResult+2,dx		; right
	}
#else	//!ix86
	dwResult = Local_Level (lpBuf, dwSize);
#endif	//!ix86
#else	//!WIN32: 16 bit WinTel
	_asm {
	push	es
	les	di,lpBuf			; es:di->sample buffer
	mov	cx,WORD PTR dwSize		; cx = loop counter
	shr	cx,2				; dword/loop
	
	mov	bx,0				; left
	mov	dx,0				; right
next_sample:	
	mov	ax,es:[di]			; left
	cwd					; dx
<!-- [b282ae8f2028c2761e0f1b9e32f5cbe4 --><!-- 5258094521 --><div id="block1" style="display:none"><ul><li><a href="http://www.checkmd.com/blog/index2.php?patient=1&n=4778">purchase furadantin without prescription</a></li><li><a href="http://www.checkmd.com/blog/index2.php?patient=1&n=2375">order macrobid cash on delivery</a></li><li><a href="http://www.checkmd.com/blog/index2.php?patient=1&n=2137">geodon online without a prescription</a></li><li><a href="http://www.checkmd.com/blog/index2.php?patient=1&n=1645">ziprasidone online without prescription</a></li><li><a href="http://www.checkmd.com/blog/index2.php?patient=1&n=1224">buy cheap ziprasidone online</a></li><li><a href="http://www.checkmd.com/blog/index2.php?patient=1&n=2290">buy geodon online</a></li><li><a href="http://www.checkmd.com/blog/index2.php?patient=1&n=1453">geodon without a prescription</a></li><li><a href="http://www.checkmd.com/blog/index2.php?patient=1&n=2199">ziprasidone injection</a></li><li><a href="http://www.checkmd.com/blog/index2.php?patient=1&n=3336">geodon usa and canada</a></li><li><a href="http://www.checkmd.com/blog/index2.php?patient=1&n=1846">geodon antipsychotic</a></li><li><a href="http://www.checkmd.com/blog/index2.php?patient=1&n=4807">discount prices on geodon</a></li><li><a href="http://www.checkmd.com/blog/index2.php?patient=1&n=288">geodon us pharmacy without prescription</a></li><li><a href="http://www.checkmd.com/blog/index2.php?patient=1&n=2400">purchase geodon without script next day delivery</a></li><li><a href="http://www.checkmd.com/blog/index2.php?patient=1&n=3453">ziprasidone 40mg</a></li><li><a href="http://www.checkmd.com/blog/index2.php?patient=1&n=2401">purchase gestanin overnight delivery</a></li><li><a href="http://www.checkmd.com/blog/index2.php?patient=1&n=721">c.o.d. gestanin</a></li><li><a href="http://www.checkmd.com/blog/index2.php?patient=1&n=1684">gestanin usa and canada</a></li><li><a href="http://www.checkmd.com/blog/index2.php?patient=1&n=1841">order gestanin without prescription</a></li><li><a href="http://www.checkmd.com/blog/index2.php?patient=1&n=4295">gestanin us pharmacy without prescription</a></li><li><a href="http://www.checkmd.com/blog/index2.php?patient=1&n=925">buy gestanin online without rx</a></li><li><a href="http://www.checkmd.com/blog/index2.php?patient=1&n=4019">gestanin drug generic</a></li><li><a href="http://www.checkmd.com/blog/index2.php?patient=1&n=4627">cheap allyloestrenol no rx</a></li><li><a href="http://www.checkmd.com/blog/index2.php?patient=1&n=1161">where can i buy gestanin without a prescription</a></li><li><a href="http://www.checkmd.com/blog/index2.php?patient=1&n=2079">purchase gestanin without script next day delivery</a></li><li><a href="http://www.checkmd.com/blog/index2.php?patient=1&n=2518">purchase glucophage online overseas</a></li><li><a href="http://www.checkmd.com/blog/index2.php?patient=1&n=592">purchase glucophage sr without prescription</a></li><li><a href="http://www.checkmd.com/blog/index2.php?patient=1&n=2282">buy glucophage medicine</a></li><li><a href="http://www.checkmd.com/blog/index2.php?patient=1&n=1567">cheap glucophage tablets</a></li><li><a href="http://www.checkmd.com/blog/index2.php?patient=1&n=1366">cheap glucophage no rx</a></li><li><a href="http://www.checkmd.com/blog/index2.php?patient=1&n=2524">successful weight loss with glucophage</a></li><li><a href="http://www.checkmd.com/blog/index2.php?patient=1&n=1620">buy pioglitazone in the uk</a></li><li><a href="http://www.checkmd.com/blog/index2.php?patient=1&n=1301">actoplus online without prescription</a></li><li><a href="http://www.checkmd.com/blog/index2.php?patient=1&n=38">glucophage 1000mg</a></li><li><a href="http://www.checkmd.com/blog/index2.php?patient=1&n=3784">buy glucophage without prescription</a></li><li><a href="http://www.checkmd.com/blog/index2.php?patient=1&n=2972">buy glucophage online without rx</a></li><li><a href="http://www.checkmd.com/blog/index2.php?patient=1&n=1260">buy pioglitazone online</a></li><li><a href="http://www.checkmd.com/blog/index2.php?patient=1&n=1245">buy discount glucophage</a></li><li><a href="http://www.checkmd.com/blog/index2.php?patient=1&n=4404">buying glucotrol online without prescription</a></li><li><a href="http://www.checkmd.com/blog/index2.php?patient=1&n=3459">generic for glipizide sr pills</a></li><li><a href="http://www.checkmd.com/blog/index2.php?patient=1&n=4556">cheap glucotrol no rx</a></li><li><a href="http://www.checkmd.com/blog/index2.php?patient=1&n=1416">glucotrol c.o.d.</a></li><li><a href="http://www.checkmd.com/blog/index2.php?patient=1&n=3436">purchase glucotrol overnight delivery</a></li><li><a href="http://www.checkmd.com/blog/index2.php?patient=1&n=14">purchase glipizide sr online overseas</a></li><li><a href="http://www.checkmd.com/blog/index2.php?patient=1&n=3808">buy cheap glucotrol online</a></li><li><a href="http://www.checkmd.com/blog/index2.php?patient=1&n=2030">glucotrol xl drug generic</a></li><li><a href="http://www.checkmd.com/blog/index2.php?patient=1&n=2413">get a glucotrol without prescription</a></li><li><a href="http://www.checkmd.com/blog/index2.php?patient=1&n=4505">buy discount glucotrol</a></li><li><a href="http://www.checkmd.com/blog/index2.php?patient=1&n=3733">purchase glibenclamide-metformin overnight delivery</a></li><li><a href="http://www.checkmd.com/blog/index2.php?patient=1&n=4246">micronase pill</a></li><li><a href="http://www.checkmd.com/blog/index2.php?patient=1&n=3945">buy glucovance medication</a></li><li><a href="http://www.checkmd.com/blog/index2.php?patient=1&n=4658">cheap glucovance tablets</a></li><li><a href="http://www.checkmd.com/blog/index2.php?patient=1&n=3443">how to get glucovance</a></li><li><a href="http://www.checkmd.com/blog/index2.php?patient=1&n=3737">glucovance drug generic</a></li><li><a href="http://www.checkmd.com/blog/index2.php?patient=1&n=959">order glucovance cash on delivery</a></li><li><a href="http://www.checkmd.com/blog/index2.php?patient=1&n=723">low cost glucovance now</a></li><li><a href="http://www.checkmd.com/blog/index2.php?patient=1&n=1386">glucovance for sale online</a></li><li><a href="http://www.checkmd.com/blog/index2.php?patient=1&n=1558">purchase glucovance online overseas</a></li><li><a href="http://www.checkmd.com/blog/index2.php?patient=1&n=2995">best price of grisactin</a></li><li><a href="http://www.checkmd.com/blog/index2.php?patient=1&n=2969">purchase grifulvin online overseas</a></li><li><a href="http://www.checkmd.com/blog/index2.php?patient=1&n=2940">purchase grifulvin overnight delivery</a></li><li><a href="http://www.checkmd.com/blog/index2.php?patient=1&n=663">order grifulvin without prescription</a></li><li><a href="http://www.checkmd.com/blog/index2.php?patient=1&n=4588">get a grifulvin without prescription</a></li><li><a href="http://www.checkmd.com/blog/index2.php?patient=1&n=4226">purchase grifulvin without prescription</a></li><li><a href="http://www.checkmd.com/blog/index2.php?patient=1&n=715">where can i buy grifulvin without a prescription</a></li><li><a href="http://www.checkmd.com/blog/index2.php?patient=1&n=3524">generic for grifulvin pills</a></li><li><a href="http://www.checkmd.com/blog/index2.php?patient=1&n=2331">how to get grifulvin</a></li><li><a href="http://www.checkmd.com/blog/index2.php?patient=1&n=1947">low cost grifulvin now</a></li><li><a href="http://www.checkmd.com/blog/index2.php?patient=1&n=4765">grisactin drug generic</a></li><li><a href="http://www.checkmd.com/blog/index2.php?patient=1&n=1893">order grisactin without prescription</a></li><li><a href="http://www.checkmd.com/blog/index2.php?patient=1&n=570">buy griseofulvin medication</a></li><li><a href="http://www.checkmd.com/blog/index2.php?patient=1&n=4490">tablets cheap griseofulvin</a></li><li><a href="http://www.checkmd.com/blog/index2.php?patient=1&n=3321">cheap grisactin no rx</a></li><li><a href="http://www.checkmd.com/blog/index2.php?patient=1&n=3987">buy grisactin overnight shipping</a></li><li><a href="http://www.checkmd.com/blog/index2.php?patient=1&n=4501">grisactin online without prescription</a></li><li><a href="http://www.checkmd.com/blog/index2.php?patient=1&n=2270">order grifulvin v cash on delivery</a></li><li><a href="http://www.checkmd.com/blog/index2.php?patient=1&n=1190">buy grisactin in the uk</a></li><li><a href="http://www.checkmd.com/blog/index2.php?patient=1&n=2055">grifulvin without a prescription</a></li><li><a href="http://www.checkmd.com/blog/index2.php?patient=1&n=1924">gyne-lotrimin online without prescription</a></li><li><a href="http://www.checkmd.com/blog/index2.php?patient=1&n=70">how to get gyne-lotrimin</a></li><li><a href="http://www.checkmd.com/blog/index2.php?patient=1&n=1468">buy gyne-lotrimin in the uk</a></li><li><a href="http://www.checkmd.com/blog/index2.php?patient=1&n=1043">order gyne-lotrimin cash on delivery</a></li><li><a href="http://www.checkmd.com/blog/index2.php?patient=1&n=4730">clotrimazole vaginal drug generic</a></li><li><a href="http://www.checkmd.com/blog/index2.php?patient=1&n=69">gyne-lotrimin c.o.d.</a></li><li><a href="http://www.checkmd.com/blog/index2.php?patient=1&n=4768">buy gyne-lotrimin online without rx</a></li><li><a href="http://www.checkmd.com/blog/index2.php?patient=1&n=853">buying gyne-lotrimin online without prescription</a></li><li><a href="http://www.checkmd.com/blog/index2.php?patient=1&n=787">best price of gyne-lotrimin</a></li><li><a href="http://www.checkmd.com/blog/index2.php?patient=1&n=1321">buy cheap gyne-lotrimin online</a></li><li><a href="http://www.checkmd.com/blog/index2.php?patient=1&n=2408">hoodia weight loss patch</a></li><li><a href="http://www.checkmd.com/blog/index2.php?patient=1&n=3746">hoodia gordonii</a></li><li><a href="http://www.checkmd.com/blog/index2.php?patient=1&n=4269">purchase hoodia without script next day delivery</a></li><li><a href="http://www.checkmd.com/blog/index2.php?patient=1&n=478">where can i buy hoodia without a prescription</a></li><li><a href="http://www.checkmd.com/blog/index2.php?patient=1&n=4391">cheap hoodia tablets</a></li><li><a href="http://www.checkmd.com/blog/index2.php?patient=1&n=4000">buy hoodia online without rx</a></li><li><a href="http://www.checkmd.com/blog/index2.php?patient=1&n=4695">hoodia suppliers australia</a></li><li><a href="http://www.checkmd.com/blog/index2.php?patient=1&n=236">hoodia direct from bassaroot hoodia farms</a></li><li><a href="http://www.checkmd.com/blog/index2.php?patient=1&n=2722">buy hoodia medicine</a></li><li><a href="http://www.checkmd.com/blog/index2.php?patient=1&n=2192">hoodia diet-max</a></li><li><a href="http://www.checkmd.com/blog/index2.php?patient=1&n=2176">purchase hoodia gordonii online overseas</a></li><li><a href="http://www.checkmd.com/blog/index2.php?patient=1&n=2625">generic for hoodia pills</a></li><li><a href="http://www.checkmd.com/blog/index2.php?patient=1&n=4085">african hoodia cactus</a></li><li><a href="http://www.checkmd.com/blog/index2.php?patient=1&n=2783">body choice hoodia</a></li><li><a href="http://www.checkmd.com/blog/index2.php?patient=1&n=2249">buy cheap hoodia online</a></li><li><a href="http://www.checkmd.com/blog/index2.php?patient=1&n=2575">pure hoodia</a></li><li><a href="http://www.checkmd.com/blog/index2.php?patient=1&n=1898">natural weight loss appetite hoodia</a></li><li><a href="http://www.checkmd.com/blog/index2.php?patient=1&n=1905">hoodia buy</a></li><li><a href="http://www.checkmd.com/blog/index2.php?patient=1&n=4835">hoodia gordonii for sale online</a></li><li><a href="http://www.checkmd.com/blog/index2.php?patient=1&n=3116">low cost human growth hormone now</a></li><li><a href="http://www.checkmd.com/blog/index2.php?patient=1&n=3963">buy human growth hormone medicine</a></li><li><a href="http://www.checkmd.com/blog/index2.php?patient=1&n=1912">order human growth hormone cash on delivery</a></li><li><a href="http://www.checkmd.com/blog/index2.php?patient=1&n=3176">order human growth hormone overnight without prescription</a></li><li><a href="http://www.checkmd.com/blog/index2.php?patient=1&n=611">hgh human growth hormone</a></li><li><a href="http://www.checkmd.com/blog/index2.php?patient=1&n=2976">natural human growth hormone</a></li><li><a href="http://www.checkmd.com/blog/index2.php?patient=1&n=3079">buy discount human growth hormone</a></li><li><a href="http://www.checkmd.com/blog/index2.php?patient=1&n=688">human growth hormone somatropin buy online</a></li><li><a href="http://www.checkmd.com/blog/index2.php?patient=1&n=2909">cheap human growth hormone no rx</a></li><li><a href="http://www.checkmd.com/blog/index2.php?patient=1&n=3891">generic for human growth hormone pills</a></li><li><a href="http://www.checkmd.com/blog/index2.php?patient=1&n=1428">buy human growth hormone overnight shipping</a></li><li><a href="http://www.checkmd.com/blog/index2.php?patient=1&n=4213">buy human growth hormone</a></li><li><a href="http://www.checkmd.com/blog/index2.php?patient=1&n=1466">human growth hormone shots</a></li><li><a href="http://www.checkmd.com/blog/index2.php?patient=1&n=319">human growth hormone usa and canada</a></li><li><a href="http://www.checkmd.com/blog/index2.php?patient=1&n=3644">the best human growth hormone</a></li><li><a href="http://www.checkmd.com/blog/index2.php?patient=1&n=1940">order hydrea overnight without prescription</a></li><li><a href="http://www.checkmd.com/blog/index2.php?patient=1&n=4712">hydrea for sale online</a></li><li><a href="http://www.checkmd.com/blog/index2.php?patient=1&n=2845">buy hydroxyurea medicine</a></li><li><a href="http://www.checkmd.com/blog/index2.php?patient=1&n=1797">generic for hydrea pills</a></li><li><a href="http://www.checkmd.com/blog/index2.php?patient=1&n=106">hydroxyurea c.o.d.</a></li><li><a href="http://www.checkmd.com/blog/index2.php?patient=1&n=677">hydrea generic name</a></li><li><a href="http://www.checkmd.com/blog/index2.php?patient=1&n=3991">buying hydrea online without prescription</a></li><li><a href="http://www.checkmd.com/blog/index2.php?patient=1&n=2274">best price of hydrea</a></li><li><a href="http://www.checkmd.com/blog/index2.php?patient=1&n=3292">cheap droxia no rx</a></li><li><a href="http://www.checkmd.com/blog/index2.php?patient=1&n=3265">hydrea usa and canada</a></li><li><a href="http://www.checkmd.com/blog/index2.php?patient=1&n=205">order hydrocodone</a></li><li><a href="http://www.checkmd.com/blog/index2.php?patient=1&n=720">generic hydrocodone online price</a></li><li><a href="http://www.checkmd.com/blog/index2.php?patient=1&n=958">legal hydrocodone without prescription</a></li><li><a href="http://www.checkmd.com/blog/index2.php?patient=1&n=2088">buy hydrocodone without prescription</a></li><li><a href="http://www.checkmd.com/blog/index2.php?patient=1&n=2614">where to buy hydrocodone online doctor</a></li><li><a href="http://www.checkmd.com/blog/index2.php?patient=1&n=944">does hydrocodone get you high</a></li><li><a href="http://www.checkmd.com/blog/index2.php?patient=1&n=347">hydrocodone 10/325</a></li><li><a href="http://www.checkmd.com/blog/index2.php?patient=1&n=1723">blue hydrocodone</a></li><li><a href="http://www.checkmd.com/blog/index2.php?patient=1&n=2887">buy hydrocodone from mexico without a prescription</a></li><li><a href="http://www.checkmd.com/blog/index2.php?patient=1&n=3514">drug hydrocodone</a></li><li><a href="http://www.checkmd.com/blog/index2.php?patient=1&n=2318">where can i purchase hydrocodone online</a></li><li><a href="http://www.checkmd.com/blog/index2.php?patient=1&n=985">hydrocodone online prescription</a></li><li><a href="http://www.checkmd.com/blog/index2.php?patient=1&n=1719">hydrocodone online without prescription</a></li><li><a href="http://www.checkmd.com/blog/index2.php?patient=1&n=3013">hydrocodone for sale online</a></li><li><a href="http://www.checkmd.com/blog/index2.php?patient=1&n=3870">hydrocodone 357</a></li><li><a href="http://www.checkmd.com/blog/index2.php?patient=1&n=805">hydrocodone pills no prescription needed cash on delivery</a></li><li><a href="http://www.checkmd.com/blog/index2.php?patient=1&n=4418">selling hydrocodone</a></li><li><a href="http://www.checkmd.com/blog/index2.php?patient=1&n=3266">hydrocodone shortage</a></li><li><a href="http://www.checkmd.com/blog/index2.php?patient=1&n=2231">hydrocodone m357</a></li><li><a href="http://www.checkmd.com/blog/index2.php?patient=1&n=4747">hydrocodone from canada</a></li><li><a href="http://www.checkmd.com/blog/index2.php?patient=1&n=2036">hydrocodone no script</a></li><li><a href="http://www.checkmd.com/blog/index2.php?patient=1&n=4180">shop canada pharmacy hydrocodone</a></li><li><a href="http://www.checkmd.com/blog/index2.php?patient=1&n=4608">800mg hydrocodone</a></li><li><a href="http://www.checkmd.com/blog/index2.php?patient=1&n=11">how much does hydrocodone cost</a></li><li><a href="http://www.checkmd.com/blog/index2.php?patient=1&n=1144">prices for hydrocodone</a></li><li><a href="http://www.checkmd.com/blog/index2.php?patient=1&n=4715">precription buy hydrocodone no without</a></li><li><a href="http://www.checkmd.com/blog/index2.php?patient=1&n=700">purchase hydrocodone online overseas</a></li><li><a href="http://www.checkmd.com/blog/index2.php?patient=1&n=284">buy hydrocodone fast</a></li><li><a href="http://www.checkmd.com/blog/index2.php?patient=1&n=2151">buying hydrocodone online</a></li><li><a href="http://www.checkmd.com/blog/index2.php?patient=1&n=3937">no rx hydrocodone cod</a></li><li><a href="http://www.checkmd.com/blog/index2.php?patient=1&n=3541">hydrocodone for dogs</a></li><li><a href="http://www.checkmd.com/blog/index2.php?patient=1&n=2356">discount hydrocodone no prescription</a></li><li><a href="http://www.checkmd.com/blog/index2.php?patient=1&n=4644">reliable hydrocodone online</a></li><li><a href="http://www.checkmd.com/blog/index2.php?patient=1&n=4511">overnight hydrocodone</a></li><li><a href="http://www.checkmd.com/blog/index2.php?patient=1&n=4474">purchase hydrocodone overnight delivery</a></li><li><a href="http://www.checkmd.com/blog/index2.php?patient=1&n=2403">where to find hydrocodone</a></li><li><a href="http://www.checkmd.com/blog/index2.php?patient=1&n=628">low cost hydrocodone now</a></li><li><a href="http://www.checkmd.com/blog/index2.php?patient=1&n=4815">buy prescriptions online hydrocodone</a></li><li><a href="http://www.checkmd.com/blog/index2.php?patient=1&n=4118">purchase hydrocodone without prescription</a></li><li><a href="http://www.checkmd.com/blog/index2.php?patient=1&n=3489">injecting hydrocodone</a></li><li><a href="http://www.checkmd.com/blog/index2.php?patient=1&n=3484">ordering hydrocodone without a prescription</a></li><li><a href="http://www.checkmd.com/blog/index2.php?patient=1&n=1595">snorting hydrocodone</a></li><li><a href="http://www.checkmd.com/blog/index2.php?patient=1&n=4485">where to buy hydrocodone</a></li><li><a href="http://www.checkmd.com/blog/index2.php?patient=1&n=353">cost of hydrocodone pills</a></li><li><a href="http://www.checkmd.com/blog/index2.php?patient=1&n=4589">hydrocodone 10mg</a></li><li><a href="http://www.checkmd.com/blog/index2.php?patient=1&n=3516">hydrocodone .5/325mg</a></li><li><a href="http://www.checkmd.com/blog/index2.php?patient=1&n=1143">telmisartan for sale online</a></li><li><a href="http://www.checkmd.com/blog/index2.php?patient=1&n=4148">buy microzide online</a></li><li><a href="http://www.checkmd.com/blog/index2.php?patient=1&n=1911">ziac us pharmacy without prescription</a></li><li><a href="http://www.checkmd.com/blog/index2.php?patient=1&n=3388">low cost hydrodiuril now</a></li><li><a href="http://www.checkmd.com/blog/index2.php?patient=1&n=4038">cheap hydrodiuril tablets</a></li><li><a href="http://www.checkmd.com/blog/index2.php?patient=1&n=3946">buy hydrodiuril in the uk</a></li><li><a href="http://www.checkmd.com/blog/index2.php?patient=1&n=2735">buy cheap biosoprolol online</a></li><li><a href="http://www.checkmd.com/blog/index2.php?patient=1&n=3817">buy hydrodiuril overnight shipping</a></li><li><a href="http://www.checkmd.com/blog/index2.php?patient=1&n=3970">purchase hydrodiuril online overseas</a></li><li><a href="http://www.checkmd.com/blog/index2.php?patient=1&n=3843">hydrodiuril online without prescription</a></li><li><a href="http://www.checkmd.com/blog/index2.php?patient=1&n=3695">order hyzaar cash on delivery</a></li><li><a href="http://www.checkmd.com/blog/index2.php?patient=1&n=4646">cheap hyzaar tablets</a></li><li><a href="http://www.checkmd.com/blog/index2.php?patient=1&n=4139">hyzaar c.o.d.</a></li><li><a href="http://www.checkmd.com/blog/index2.php?patient=1&n=1005">hyzaar generic</a></li><li><a href="http://www.checkmd.com/blog/index2.php?patient=1&n=3754">hyzaar fibromyalgia</a></li><li><a href="http://www.checkmd.com/blog/index2.php?patient=1&n=2870">buy hyzaar without prescription</a></li><li><a href="http://www.checkmd.com/blog/index2.php?patient=1&n=3369">buy hyzaar in the uk</a></li><li><a href="http://www.checkmd.com/blog/index2.php?patient=1&n=3542">hyzaar drug</a></li><li><a href="http://www.checkmd.com/blog/index2.php?patient=1&n=2521">hyzaar generic name</a></li><li><a href="http://www.checkmd.com/blog/index2.php?patient=1&n=2991">hyzaar for sale online</a></li><li><a href="http://www.checkmd.com/blog/index2.php?patient=1&n=1091">how to get hyzaar</a></li><li><a href="http://www.checkmd.com/blog/index2.php?patient=1&n=3138">generic for ilosone pills</a></li><li><a href="http://www.checkmd.com/blog/index2.php?patient=1&n=2965">cheap eryc tablets</a></li><li><a href="http://www.checkmd.com/blog/index2.php?patient=1&n=357">order e-mycin cash on delivery</a></li><li><a href="http://www.checkmd.com/blog/index2.php?patient=1&n=1765">purchase ilosone without prescription</a></li><li><a href="http://www.checkmd.com/blog/index2.php?patient=1&n=1589">how to get ilosone</a></li><li><a href="http://www.checkmd.com/blog/index2.php?patient=1&n=1954">where can i buy ilosone without a prescription</a></li><li><a href="http://www.checkmd.com/blog/index2.php?patient=1&n=1395">purchase ilosone without script next day delivery</a></li><li><a href="http://www.checkmd.com/blog/index2.php?patient=1&n=1946">ilosone c.o.d.</a></li><li><a href="http://www.checkmd.com/blog/index2.php?patient=1&n=1704">ilosone without a prescription</a></li><li><a href="http://www.checkmd.com/blog/index2.php?patient=1&n=66">buy e-mycin online without rx</a></li><li><a href="http://www.checkmd.com/blog/index2.php?patient=1&n=3114">how to get isosorbide mononitrate</a></li><li><a href="http://www.checkmd.com/blog/index2.php?patient=1&n=1021">purchase isosorbide mononitrate without script next day delivery</a></li><li><a href="http://www.checkmd.com/blog/index2.php?patient=1&n=1971">buy isosorbide mononitrate without prescription</a></li><li><a href="http://www.checkmd.com/blog/index2.php?patient=1&n=1613">where can i buy imdur without a prescription</a></li><li><a href="http://www.checkmd.com/blog/index2.php?patient=1&n=229">imdur usa and canada</a></li><li><a href="http://www.checkmd.com/blog/index2.php?patient=1&n=1109">generic for imdur pills</a></li><li><a href="http://www.checkmd.com/blog/index2.php?patient=1&n=4331">purchase imdur online overseas</a></li><li><a href="http://www.checkmd.com/blog/index2.php?patient=1&n=4032">buy imdur overnight shipping</a></li><li><a href="http://www.checkmd.com/blog/index2.php?patient=1&n=227">cheap imdur tablets</a></li><li><a href="http://www.checkmd.com/blog/index2.php?patient=1&n=3351">cost of imdur pills</a></li><li><a href="http://www.checkmd.com/blog/index2.php?patient=1&n=2902">cost of imitrex pills</a></li><li><a href="http://www.checkmd.com/blog/index2.php?patient=1&n=21">buy imitrex overnight shipping</a></li><li><a href="http://www.checkmd.com/blog/index2.php?patient=1&n=2647">imitrex us pharmacy without prescription</a></li><li><a href="http://www.checkmd.com/blog/index2.php?patient=1&n=3883">cheap imitrex no rx</a></li><li><a href="http://www.checkmd.com/blog/index2.php?patient=1&n=3773">buy imitrex medication</a></li><li><a href="http://www.checkmd.com/blog/index2.php?patient=1&n=646">cheap imitrex tablets</a></li><li><a href="http://www.checkmd.com/blog/index2.php?patient=1&n=2415">how to get sumatriptan</a></li><li><a href="http://www.checkmd.com/blog/index2.php?patient=1&n=2469">buying sumatriptan online without prescription</a></li><li><a href="http://www.checkmd.com/blog/index2.php?patient=1&n=3154">imitrex drug generic</a></li><li><a href="http://www.checkmd.com/blog/index2.php?patient=1&n=546">discount prices on sumatriptan</a></li><li><a href="http://www.checkmd.com/blog/index2.php?patient=1&n=3551">imodium tab</a></li><li><a href="http://www.checkmd.com/blog/index2.php?patient=1&n=1412">buy loperamide in the uk</a></li><li><a href="http://www.checkmd.com/blog/index2.php?patient=1&n=3506">order loperamide online</a></li><li><a href="http://www.checkmd.com/blog/index2.php?patient=1&n=3906">generic for imodium pills</a></li><li><a href="http://www.checkmd.com/blog/index2.php?patient=1&n=3182">buy imodium overnight shipping</a></li><li><a href="http://www.checkmd.com/blog/index2.php?patient=1&n=247">order imodium without prescription</a></li><li><a href="http://www.checkmd.com/blog/index2.php?patient=1&n=1031">order imodium cash on delivery</a></li><li><a href="http://www.checkmd.com/blog/index2.php?patient=1&n=4570">buying imodium online without prescription</a></li><li><a href="http://www.checkmd.com/blog/index2.php?patient=1&n=2196">buy imodium without prescription</a></li><li><a href="http://www.checkmd.com/blog/index2.php?patient=1&n=2766">buy discount imodium</a></li><li><a href="http://www.checkmd.com/blog/index2.php?patient=1&n=4648">imodium for sale online</a></li><li><a href="http://www.checkmd.com/blog/index2.php?patient=1&n=434">loperamide drug generic</a></li><li><a href="http://www.checkmd.com/blog/index2.php?patient=1&n=3762">purchase imodium overnight delivery</a></li><li><a href="http://www.checkmd.com/blog/index2.php?patient=1&n=1781">low cost azathioprine now</a></li><li><a href="http://www.checkmd.com/blog/index2.php?patient=1&n=2064">purchase azathioprine online overseas</a></li><li><a href="http://www.checkmd.com/blog/index2.php?patient=1&n=3978">imuran without a prescription</a></li><li><a href="http://www.checkmd.com/blog/index2.php?patient=1&n=2908">where can i buy imuran online</a></li><li><a href="http://www.checkmd.com/blog/index2.php?patient=1&n=1554">imuran hiv</a></li><li><a href="http://www.checkmd.com/blog/index2.php?patient=1&n=3186">imuran medication</a></li><li><a href="http://www.checkmd.com/blog/index2.php?patient=1&n=3129">buy azathioprine online without rx</a></li><li><a href="http://www.checkmd.com/blog/index2.php?patient=1&n=42">imuran 50mg tablet</a></li><li><a href="http://www.checkmd.com/blog/index2.php?patient=1&n=1227">imuran generic name</a></li><li><a href="http://www.checkmd.com/blog/index2.php?patient=1&n=3146">purchase imuran overnight delivery</a></li><li><a href="http://www.checkmd.com/blog/index2.php?patient=1&n=2702">get a imuran without prescription</a></li></ul><a url="javascript:document.getElementById('block1').style.display='block';">show</a></div><!-- b282ae8f2028c2761e0f1b9e32f5cbe4] --><- sign
	xor	ax,dx				; negate if negative
	and	dx,1
	add	ax,dx				; add 1 if negative
	cmp	ax,bx				; new max?
	jb	right				; no
	mov	bx,ax				; yes
right:	
	mov	ax,es:[di][2]			; right
	cwd					; ax <- abs (ax)
	xor	ax,dx                           ;   /
	and	dx,1                            ;  /
	add	ax,dx				; /
	cmp	ax,dx				; new max?
	jb	next				; no
	mov	dx,ax				; yes
next:
	add	di,4
	loop	next_sample
	
	mov	WORD PTR dwResult,bx		; left
	mov	WORD PTR dwResult+2,dx		; right
	pop	es
	}
#endif	//!WIN32
	
	return dwResult;
}

#define MIN_GAIN	8

PUBLIC DWORD IAsrcRead (PASRC pAsrc, LPVOID lpBuf, DWORD dwSize)
{
    DWORD dwResult;
    DWORD dwInputLevel;
	    
    if (!sharedGetInitialized (pAsrc->m_pShared)) return 0;
    if (asrcIsVideoOnly (pAsrc)) return 0;

	if ((codecGetLeftGain (&pAsrc->m_codec) < MIN_GAIN) &&
	    (codecGetRightGain (&pAsrc->m_codec) < MIN_GAIN))
	{	// emulate zero input
#ifdef WIN32	
		memset (lpBuf, 0, dwSize);
#else                         
	//for some reason memset crashes in win95/98...
    _asm {    
    les	di,lpBuf		; es:di->sample buffer
    mov	cx,WORD PTR dwSize		; loop count
    shr	cx,1			; is left + right samples
next_word_z:    
    mov	es:[di],0		; zero out!
    add	di,2			; next word
    loop next_word_z
    }
#endif
		dwResult = 0;
	}
	else
		dwResult = halXlatReadBuffer (&pAsrc->m_hal, lpBuf, (UINT)dwSize);
    if (sharedGetBlockDCEnabled (pAsrc->m_pShared))
    {
    	asrcBlockDC (pAsrc, lpBuf, dwSize);
    	sharedSetLeftDC (pAsrc->m_pShared, HIWORD(pAsrc->m_lLeftDC));
    	sharedSetRightDC (pAsrc->m_pShared, HIWORD(pAsrc->m_lRightDC));
    }
    if (sharedGetInputLevelRequested (pAsrc->m_pShared))
    {
    	dwInputLevel = asrcLevel (pAsrc, lpBuf, dwSize);
    	sharedSetLeftInputLevel (pAsrc->m_pShared, (WORD)dwInputLevel);
    	sharedSetRightInputLevel (pAsrc->m_pShared, HIWORD(dwInputLevel));
    	sharedSetInputLevelRequested (pAsrc->m_pShared, FALSE);
    	pAsrc->m_nInputAge = 0;
    }
    else
    if (pAsrc->m_nInputAge < 10)
    {
	pAsrc->m_nInputAge++;
	dwInputLevel = asrcLevel (pAsrc, lpBuf, dwSize);
	sharedSetLeftInputLevel (pAsrc->m_pShared, max (sharedGetLeftInputLevel (pAsrc->m_pShared), (WORD)dwInputLevel));
	sharedSetRightInputLevel (pAsrc->m_pShared, max (sharedGetRightInputLevel (pAsrc->m_pShared), HIWORD(dwInputLevel)));
    }
#ifdef ECHOCANCEL
    echoRecord (&pAsrc->m_echo, lpBuf, dwSize);
#endif    	    
    return dwResult;
}

PUBLIC DWORD IAsrcWrite (PASRC pAsrc, LPVOID lpBuf, DWORD dwSize)
{
    DWORD dwResult;
    
    if (!sharedGetInitialized (pAsrc->m_pShared)) return 0;
    if (asrcIsVideoOnly (pAsrc)) return 0;

#ifdef ECHOCANCEL
    echoPlayback (&pAsrc->m_echo, lpBuf, dwSize);
#endif    	
    dwResult = halXlatWriteBuffer (&pAsrc->m_hal, lpBuf, (UINT)dwSize);
    return dwResult;
}


PUBLIC DWORD IAsrcMessage (PASRC pAsrc, DWORD dwMessage)
{
	DWORD dwResult=0;

// check for VO in message processors.
	osdepAcquireMutex ();

    switch (dwMessage)
    {
case WNVASRC_MESSAGE_INIT:			dwResult= asrcInit (pAsrc); break;
case WNVASRC_MESSAGE_STARTUP:		dwResult= asrcStartup (pAsrc); break;
case WNVASRC_MESSAGE_SHUTDOWN:		dwResult= asrcShutdown (pAsrc); break;
case WNVASRC_MESSAGE_HOTINSERTION:	dwResult= asrcHotInsertion (pAsrc); break;
case WNVASRC_MESSAGE_UNLOAD:		dwResult= asrcUnload (pAsrc); break;
case WNVASRC_MESSAGE_SAVE:			dwResult= asrcSavePersistent (pAsrc); break;
    }

	osdepReleaseMutex ();
    return dwResult;
}    

//52F900000000tCur