#include "tn_tfm.h"

static BOOL detect_silence (int16 *buf, uint32 len) {
	while (len--) {
		if (*buf > 512 || *buf < -512) return FALSE;
		buf++;
	}
	return TRUE;
}

int32 TNPlug_DecodeFramePlayer (struct TNPlugIFace *Self, struct TuneNet *inTuneNet,
	int16 *outbuffer)
{
	struct TNDecHandle *handle = inTuneNet->handle;

	if (handle->silence > 200) return 0;

	tfm_player_render(&handle->TFM, inTuneNet->pcm[0], handle->pcm_size);
	if (detect_silence(inTuneNet->pcm[0], handle->pcm_size))
		handle->silence++;
	else
		handle->silence = 0;

	return handle->pcm_size;
}

int32 TNPlug_SeekPlayer (struct TNPlugIFace *Self, struct TuneNet *inTuneNet, uint32 seconds) {
	return 0;
}
