#include "Glue.h"
#include "ModUnitConversion.h"
#include "ModTypeConversion.h"
#include <SANE.h>


// REQUIRES "ModTypeConversion.c" AND THE SANE LIBRARY.


void ConvBytesToMilliseconds(unsigned long value, ModParamsPtr modInfo, double *myDouble, unsigned long *myLong)
{
	double			dblVal, dblRate;
	unsigned long	newVal;
	short			frameSize;
	
	frameSize = modInfo->bps/8 + (modInfo->bps%8 != 0);
	
	MyUnsignedFix2Double(modInfo->rate, &dblRate);
	dblVal = (double)(value/frameSize)/dblRate*1000;
	
	if (myDouble)
		*myDouble = dblVal;
	if (myLong)
		*myLong = (unsigned long)dblVal;
}


unsigned long ConvMillisecondsToBytes(double value, ModParamsPtr modInfo)
{
	double			dblVal, dblRate;
	unsigned long	newVal;
	short			frameSize;
	
	frameSize = modInfo->bps/8 + (modInfo->bps%8 != 0);
	
	MyUnsignedFix2Double(modInfo->rate, &dblRate);
	dblVal = value*dblRate/1000*frameSize;
	newVal = dblVal;
	newVal -= newVal%frameSize;
	
	return newVal;
}