Core/burn/snd/es5506.cpp
/**********************************************************************************************

     generate_ulaw -- general u-law decoding routine

***********************************************************************************************/
- general u-law decoding routine
- general u - law decoding routine
static void generate_ulaw(es5506_voice *voice, UINT16 *base, INT32 *lbuffer, INT32 *rbuffer, INT32 samples)
{
	UINT32 freqcount = voice->freqcount;
	UINT32 accum = voice->accum & voice->accum_mask;
	INT32 lvol = chip->volume_lookup[voice->lvol >> 4];
	INT32 rvol = chip->volume_lookup[voice->rvol >> 4];
	bprintf(PRINT_NORMAL, _T("ULAW\n"));
	base += voice->exbank;
	while (samples > 0 && !(voice->control & CONTROL_STOPMASK))
	{
reverse:
		if (!(voice->control & CONTROL_DIR))
		{
			while (samples--)
			{
				INT32 val1 = base[accum >> 11];
				INT32 val2 = base[((accum + (1 << 11)) & voice->accum_mask) >> 11];
				val1 = chip->ulaw_lookup[val1 >> (16 - ULAW_MAXBITS)];
				val2 = chip->ulaw_lookup[val2 >> (16 - ULAW_MAXBITS)];
				val1 = interpolate(val1, val2, accum);
				accum = (accum + freqcount) & voice->accum_mask;
				apply_filters(voice, val1);
				if (voice->ecount != 0)
				{
					update_envelopes(voice, 1);
					lvol = chip->volume_lookup[voice->lvol >> 4];
					rvol = chip->volume_lookup[voice->rvol >> 4];
				}
				*lbuffer++ += (val1 * lvol) >> 11;
				*rbuffer++ += (val1 * rvol) >> 11;
				check_for_end_forward(voice, accum);
			}
		}
		else
		{
			while (samples--)
			{
				INT32 val1 = base[accum >> 11];
				INT32 val2 = base[((accum + (1 << 11)) & voice->accum_mask) >> 11];
				val1 = chip->ulaw_lookup[val1 >> (16 - ULAW_MAXBITS)];
				val2 = chip->ulaw_lookup[val2 >> (16 - ULAW_MAXBITS)];
				val1 = interpolate(val1, val2, accum);
				accum = (accum - freqcount) & voice->accum_mask;
				apply_filters(voice, val1);
				if (voice->ecount != 0)
				{
					update_envelopes(voice, 1);
					lvol = chip->volume_lookup[voice->lvol >> 4];
					rvol = chip->volume_lookup[voice->rvol >> 4];
				}
				*lbuffer++ += (val1 * lvol) >> 11;
				*rbuffer++ += (val1 * rvol) >> 11;
				check_for_end_reverse(voice, accum);
			}
		}
	}
alldone:
	voice->accum = accum;
	if (samples > 0)
		update_envelopes(voice, samples);
}
static void generate_ulaw ( es5506_voice * voice , UINT16 * base , INT32 * lbuffer , INT32 * rbuffer , INT32 samples ) { UINT32 freqcount = voice -> freqcount ; UINT32 accum = voice -> accum & voice -> accum_mask ; INT32 lvol = chip -> volume_lookup [ voice -> lvol >> 4 ] ; INT32 rvol = chip -> volume_lookup [ voice -> rvol >> 4 ] ; bprintf ( PRINT_NORMAL , _T ( " \n " ) ) ; base += voice -> exbank ; while ( samples > 0 && ! ( voice -> control & CONTROL_STOPMASK ) ) { reverse : if ( ! ( voice -> control & CONTROL_DIR ) ) { while ( samples -- ) { INT32 val1 = base [ accum >> 11 ] ; INT32 val2 = base [ ( ( accum + ( 1 << 11 ) ) & voice -> accum_mask ) >> 11 ] ; val1 = chip -> ulaw_lookup [ val1 >> ( 16 - ULAW_MAXBITS ) ] ; val2 = chip -> ulaw_lookup [ val2 >> ( 16 - ULAW_MAXBITS ) ] ; val1 = interpolate ( val1 , val2 , accum ) ; accum = ( accum + freqcount ) & voice -> accum_mask ; apply_filters ( voice , val1 ) ; if ( voice -> ecount != 0 ) { update_envelopes ( voice , 1 ) ; lvol = chip -> volume_lookup [ voice -> lvol >> 4 ] ; rvol = chip -> volume_lookup [ voice -> rvol >> 4 ] ; } * lbuffer ++ += ( val1 * lvol ) >> 11 ; * rbuffer ++ += ( val1 * rvol ) >> 11 ; check_for_end_forward ( voice , accum ) ; } } else { while ( samples -- ) { INT32 val1 = base [ accum >> 11 ] ; INT32 val2 = base [ ( ( accum + ( 1 << 11 ) ) & voice -> accum_mask ) >> 11 ] ; val1 = chip -> ulaw_lookup [ val1 >> ( 16 - ULAW_MAXBITS ) ] ; val2 = chip -> ulaw_lookup [ val2 >> ( 16 - ULAW_MAXBITS ) ] ; val1 = interpolate ( val1 , val2 , accum ) ; accum = ( accum - freqcount ) & voice -> accum_mask ; apply_filters ( voice , val1 ) ; if ( voice -> ecount != 0 ) { update_envelopes ( voice , 1 ) ; lvol = chip -> volume_lookup [ voice -> lvol >> 4 ] ; rvol = chip -> volume_lookup [ voice -> rvol >> 4 ] ; } * lbuffer ++ += ( val1 * lvol ) >> 11 ; * rbuffer ++ += ( val1 * rvol ) >> 11 ; check_for_end_reverse ( voice , accum ) ; } } } alldone : voice -> accum = accum ; if ( samples > 0 ) update_envelopes ( voice , samples ) ; }
generate_ulaw -- general u-law decoding routine
generate_ulaw -- general u - law decoding routine
/* pre-add the bank offset */ /* outer loop, in case we switch directions */ /* two cases: first case is forward direction */ /* loop while we still have samples to generate */ /* fetch two samples */ /* decompress u-law */ /* interpolate */ /* apply filters */ /* update filters/volumes */ /* apply volumes and add */ /* check for loop end */ /* two cases: second case is backward direction */ /* loop while we still have samples to generate */ /* fetch two samples */ /* decompress u-law */ /* interpolate */ /* apply filters */ /* update filters/volumes */ /* apply volumes and add */ /* check for loop end */ /* if we stopped, process any additional envelope */