Example #1
0
AS3_Val initializeSkeletalChannel( void* self, AS3_Val args )
{
	int channelType;
	int length;
	Animation* animation;
	float* times;
	float** param;
	Matrix4x4* matrices;
	float* interpolations;
	Vector* inTangent;
	Vector* outTangent;
	SkeletalChannel* channel;

	AS3_ArrayValue(args, "IntType, IntType, PtrType, PtrType, PtrType, PtrType, PtrType, PtrType, PtrType", 
		&channelType, &length, &animation, &times, &param, &matrices,&interpolations, &inTangent, &outTangent);

	channel = newSkeletalChannel(animation, length, channelType, times, param, matrices, interpolations, inTangent, outTangent);

	return AS3_Ptr(channel);
}
Example #2
0
AS3_Val getWorldPositionFromSreen( void* self, AS3_Val args )
{
	Viewport* viewport;
	double x, y, z;
	int autoDepth;
	Vector3D output;

	AS3_ArrayValue( args, "PtrType, DoubleType, DoubleType, DoubleType, IntType", &viewport, &x, &y, &z, &autoDepth );

	if( viewport_getWorldPositionFromView(&output, viewport, (float)x, (float)y, (float)z, autoDepth) )
	{
		x = output.x;
		y = output.y;
		z = output.z;

		return AS3_Array( "DoubleType, DoubleType, DoubleType", x, y, z);
	}

	return 0;
}
Example #3
0
static AS3_Val thunk_InitPeerDownloadInfo(void *gg_clientData, AS3_Val gg_args) {
	AS3_Val info;
	AS3_Val bytes;
	AS3_ArrayValue(gg_args, "AS3ValType, AS3ValType",  &info,  &bytes);	
	AS3_Val isDownloadingVal = AS3_CallTS("readUnsignedByte", bytes, "");
	
	if (AS3_IntValue(isDownloadingVal) == 1)
	{
		AS3_Val true = AS3_True();
		AS3_SetS(info, "isDownloading", true);
		AS3_Release(true);
	}
	else
	{
		AS3_Val false = AS3_False();
		AS3_SetS(info, "isDownloading", false);
		AS3_Release(false);
	}
	
	AS3_Val onLineTimeVal = AS3_CallTS("readUnsignedInt", bytes, "");
	AS3_Val avgDownloadVal = AS3_CallTS("readUnsignedShort", bytes, "");
	AS3_Val nowDownloadVal = AS3_CallTS("readUnsignedShort", bytes, "");
	AS3_Val avgUploadVal = AS3_CallTS("readUnsignedShort", bytes, "");
	AS3_Val nowUploadVal = AS3_CallTS("readUnsignedShort", bytes, "");
	AS3_SetS(info, "onLineTime", onLineTimeVal);
	AS3_SetS(info, "avgDownload", avgDownloadVal);
	AS3_SetS(info, "nowDownload", nowDownloadVal);
	AS3_SetS(info, "avgUpload", avgUploadVal);
	AS3_SetS(info, "nowUpload", nowUploadVal);
	AS3_ByteArray_seek(bytes, 3, 1);	// ignore 3 byte reserved bytes	
	
	AS3_Release(isDownloadingVal);
	AS3_Release(onLineTimeVal);
	AS3_Release(avgDownloadVal);
	AS3_Release(nowDownloadVal);
	AS3_Release(avgUploadVal);
	AS3_Release(nowUploadVal);	
	AS3_Release(bytes);
	AS3_Release(info);
	return NULL;
}
/* Загрузка состояния из памяти */
AS3_Val QSPOpenSavedGameFromData(void *param, AS3_Val args)
{
	AS3_Val data;
	int dataSize, dataLen;
	QSP_BOOL isRefresh;
	QSP_CHAR *ptr;
	AS3_ArrayValue(args, "AS3ValType, IntType, IntType", &data, &dataSize, &isRefresh);
	if (qspIsExitOnError && qspErrorNum) return AS3_False();
	qspPrepareExecution();
	if (qspIsDisableCodeExec) return AS3_False();
	dataLen = dataSize / sizeof(QSP_CHAR);
	ptr = (QSP_CHAR *)malloc((dataLen + 1) * sizeof(QSP_CHAR));
	AS3_ByteArray_seek(data, 0, SEEK_SET);
	AS3_ByteArray_readBytes(ptr, data, dataSize);
	ptr[dataLen] = 0;
	qspOpenGameStatusFromString(ptr);
	free(ptr);
	if (qspErrorNum) return AS3_False();
	if (isRefresh) qspCallRefreshInt(QSP_FALSE);
	return AS3_True();
}
Example #5
0
/**
 * Returns a pointer to the memory allocated for this sample.
 * Every frame value is a float, as Flash's native sound format is a 32bit float
 *  and we don't want to waste time converting back and forth to doubles.
 * The sample is zeroed.
 * Stereo samples are interleaved.
 */ 
static AS3_Val allocateSampleMemory(void* self, AS3_Val args)
{
	int frames;
	int channels;
	int size;
	int zero;
	float *buffer;
	
	AS3_ArrayValue(args, "IntType, IntType, IntType", &frames, &channels, &zero);
 
	size = frames * channels * sizeof(float);
	buffer = (float *) malloc(size); 
	
	// If zero is true, then we must zero out this sample
	// Otherwise, it is more efficient to leave it full of junk, if it's going to be overwritten
	if (buffer && zero) {
		memset(buffer, 0, size);
	}
	
	// Return the sample pointer
	return AS3_Int((int)buffer);  
}
Example #6
0
AS3_Val doDecode(void* data,AS3_Val args)
{
	AS3_Val input = NULL;
	int in_len;
	char * ar;
	AS3_ArrayValue(args,"AS3ValType,IntType",&input,&in_len);
	ar = (char*)malloc(in_len);

	AS3_ByteArray_readBytes((void*)ar,input,in_len);

	char * decryptData;
	char * key="kael";
	decryptData = dofileEx(ar, key, in_len);
	//make a new as3 byteArray var
	AS3_Val baNS = AS3_String("flash.utils");
	AS3_Val baClass = AS3_NSGetS(baNS, "ByteArray");
	AS3_Val emptyParams = AS3_Array("");
	AS3_Val byteArray2 = AS3_New(baClass, emptyParams);
	
	AS3_ByteArray_writeBytes(byteArray2, decryptData, in_len);
	return byteArray2;
}
/* Показ / скрытие окон */
AS3_Val QSPShowWindow(void *param, AS3_Val args)
{
	int type;
	QSP_BOOL isShow;
	AS3_ArrayValue(args, "IntType, IntType", &type, &isShow);
	switch (type)
	{
	case QSP_WIN_ACTS:
		qspCurIsShowActs = isShow;
		break;
	case QSP_WIN_OBJS:
		qspCurIsShowObjs = isShow;
		break;
	case QSP_WIN_VARS:
		qspCurIsShowVars = isShow;
		break;
	case QSP_WIN_INPUT:
		qspCurIsShowInput = isShow;
		break;
	}
	return AS3_True();
}
/* Загрузка новой игры из памяти */
AS3_Val QSPLoadGameWorldFromData(void *param, AS3_Val args)
{
	char *ptr;
	AS3_Val data;
	int dataSize;
	char *fileName;
	QSP_CHAR *fileNameWC;
	AS3_ArrayValue(args, "AS3ValType, IntType, StrType", &data, &dataSize, &fileName);
	if (qspIsExitOnError && qspErrorNum) return AS3_False();
	qspResetError();
	if (qspIsDisableCodeExec) return AS3_False();
	ptr = (char *)malloc(dataSize + 3);
	AS3_ByteArray_seek(data, 0, SEEK_SET);
	AS3_ByteArray_readBytes(ptr, data, dataSize);
	ptr[dataSize] = ptr[dataSize + 1] = ptr[dataSize + 2] = 0;
	fileNameWC = qspC2W(fileName);
	qspOpenQuestFromData(ptr, dataSize + 3, fileNameWC, QSP_FALSE);
	free(fileNameWC);
	free(ptr);
	if (qspErrorNum) return AS3_False();
	return AS3_True();
}
Example #9
0
static AS3_Val thunk_CreatePacketFromByteArray(void *gg_clientData, AS3_Val gg_args) {
	AS3_Val bytes;
	AS3_ArrayValue(gg_args, "AS3ValType",  &bytes);
	AS3_Val actionVal = AS3_CallTS("readUnsignedByte", bytes, "");
	AS3_Val transactionIdVal = AS3_CallTS("readUnsignedInt", bytes, "");	
	AS3_Val protocolVersionVal = AS3_CallTS("readUnsignedShort", bytes, "");
	
	AS3_Val pplive_protocol_namespace = AS3_String("com.pplive.p2p.network.protocol");
	AS3_Val PacketClass = AS3_NSGetS(pplive_protocol_namespace, "Packet");
	AS3_Val paramArray = AS3_Array("IntType, IntType, IntType",  AS3_IntValue(actionVal), AS3_IntValue(transactionIdVal), AS3_IntValue(protocolVersionVal));
	AS3_Val packet = AS3_New(PacketClass, paramArray);
	
	AS3_Release(paramArray);
	AS3_Release(PacketClass);
	AS3_Release(pplive_protocol_namespace);
	AS3_Release(protocolVersionVal);
	AS3_Release(transactionIdVal);
	AS3_Release(actionVal);
	AS3_Release(bytes);
	
	return packet;
}
static AS3_Val getPrice(void* self, AS3_Val args)
{
    double N, T, S, K, v, r, price;
    AS3_ArrayValue( args, "DoubleType, DoubleType, DoubleType, DoubleType, DoubleType, DoubleType", &N, &T, &S, &K, &v, &r);
 
    double dt = T/N; //one time step
 
    double u = 1 + v*sqrt(dt); //up-tick
    double d = 1 - v*sqrt(dt); //down-tick
    double p = 0.5 + r*sqrt(dt)/(2*v); //risk-neutral probability of up-tick
    double df = 1/(1+r*dt); //discount factor over 1 time step, dt
 
    double* optionValues = malloc((N+1) * sizeof(double));
 
    //populate the tree (for N-steps there will be N+1 values)
    int i, j;
    double ST;
    for (i=0; i < N+1; i++) 
    {
        ST = S * pow(u, i) * pow(d, N-i);
        optionValues[i] = (ST > K)? ST - K : 0;
    }
 
    //now work backwards to get expected 
    //option value at each previous stage
    for (i=N; i >= 0; i--)
    {
        for(j=0; j<i; j++)
        {
            optionValues[j] = (p*optionValues[j+1] + (1-p)*optionValues[j])*df;
        }
    }
 
    price = optionValues[0];
    free(optionValues);
 
    return AS3_Number(price);
}
Example #11
0
/**
 * Set every sample in the range to a fixed value.
 * Useful for function generators of different types, or erasing audio.
 */ 
static AS3_Val setSamples(void *self, AS3_Val args)
{
	float *buffer; int bufferPosition; int channels; int frames;
	double valueArg; float value;	
	int count, count16, remainder;
	
	AS3_ArrayValue(args, "IntType, IntType, IntType, DoubleType", &bufferPosition, &channels, &frames, &valueArg);
	buffer = (float *) bufferPosition;
	value = (float) valueArg;
	
	count = frames * channels;
	count16 = count / 16;
	remainder = count % 16;
	
	while (count16--) {
		*buffer++ = value;
		*buffer++ = value;
		*buffer++ = value;
		*buffer++ = value;
		*buffer++ = value;
		*buffer++ = value;
		*buffer++ = value;
		*buffer++ = value;
		*buffer++ = value;
		*buffer++ = value;
		*buffer++ = value;
		*buffer++ = value;
		*buffer++ = value;
		*buffer++ = value;
		*buffer++ = value;
		*buffer++ = value;
	} 
	while (remainder--) {
		*buffer++ = value;
	}

	return 0;
} 
Example #12
0
/**
 * Writes a sample out to an as3 byte array in wav file format.
 * Writes as fixed point 16 bit.
 */
static AS3_Val writeWavBytes(void *self, AS3_Val args) 
{
	int bufferPosition; int channels; int frames;
	float *buffer;
	AS3_Val dst;
	int count;
	short *wavOut;
	int framesToWrite; int theseFramesToWrite;
	
	AS3_ArrayValue(args, "IntType, AS3ValType, IntType, IntType", &bufferPosition, &dst, &channels, &frames);
	buffer = (float *) bufferPosition;
	
	framesToWrite = frames * channels;
	
	// Convert and output wav bytes in 16k chunks
	// Convert each buffer into scratch memory, and then writeBytes 
	
	while (framesToWrite > 0) {
		
		theseFramesToWrite = framesToWrite;
		if (theseFramesToWrite > 16384) {
			theseFramesToWrite = 16384;
		}
		framesToWrite -= theseFramesToWrite;
		count = theseFramesToWrite;
		
		wavOut = scratch5; // scratch buffer 5 is 16k of shorts
		while (count--)  {
			*wavOut++ = (short) (*buffer++ * 32768 + 0.5 ); 
		}
		wavOut = scratch5;
	
		AS3_ByteArray_writeBytes(dst, wavOut, theseFramesToWrite * 2 ); // 2 bytes per short
	
	}
	
	return 0;
} 
Example #13
0
AS3_Val initializeFog( void* self, AS3_Val args )
{
	Fog * fog;

	AS3_Val color;

	double a, r, g, b, density, start, end;

	int mode;

	AS3_ArrayValue( args, "AS3ValType, DoubleType, DoubleType, DoubleType, IntType", & color, & start, & end, & density, & mode );

	r = AS3_NumberValue( AS3_GetS( color, "redMultiplier" ) );
	g = AS3_NumberValue( AS3_GetS( color, "greenMultiplier" ) );
	b = AS3_NumberValue( AS3_GetS( color, "blueMultiplier" ) );
	a = AS3_NumberValue( AS3_GetS( color, "alphaMultiplier" ) );

	fog = newFog( newColorValue( (float)r, (float)g, (float)b, (float)a ), (float)start, (float)end, (float)density, mode );

	AS3_Release( color );

	return AS3_Array( "PtrType, PtrType, PtrType, PtrType, PtrType, PtrType", fog, fog->global, & fog->start, & fog->end, & fog->density, & fog->mode );
}
Example #14
0
/**
 * Hard clipper stage
 */
static AS3_Val clip(void *self, AS3_Val args)
{
	int bufferPosition, channels, frames;
	float *buffer; 
	int count; 
	float x;
	
	AS3_ArrayValue(args, "IntType, IntType, IntType", &bufferPosition, &channels, &frames);
	buffer = (float *) bufferPosition;
	count = frames*channels;
	
	while (count--) {
		x = *buffer;
		if( x < -1 ) {
			*buffer++ = -1.0;
		} else if( x > 1 ) {
			*buffer++ = 1.0;
		} else {
			buffer++;
		}
	}
	
	return 0;
}
Example #15
0
static AS3_Val thunk_InitAnnounceResponsePacket(void *gg_clientData, AS3_Val gg_args) {
	AS3_Val packet;
	AS3_Val bytes;
	AS3_ArrayValue(gg_args, "AS3ValType, AS3ValType",  &packet,  &bytes);
	
	AS3_Val paramArray = AS3_Array("AS3ValType", bytes);
	AS3_Val p2p_struct_namespace = AS3_String("com.pplive.p2p.struct");
	AS3_Val PeerDownloadInfoClass = AS3_NSGetS(p2p_struct_namespace, "PeerDownloadInfo");
	AS3_Val BlockMapClass = AS3_NSGetS(p2p_struct_namespace, "BlockMap");
	AS3_Val peerDownloadInfo = AS3_New(PeerDownloadInfoClass, paramArray);	
	AS3_Val blockMapInfo = AS3_New(BlockMapClass, paramArray);
	AS3_SetS(packet, "peerDownloadInfo", peerDownloadInfo);
	AS3_SetS(packet, "blockMap", blockMapInfo);
	
	AS3_Release(blockMapInfo);
	AS3_Release(peerDownloadInfo);
	AS3_Release(BlockMapClass);
	AS3_Release(PeerDownloadInfoClass);
	AS3_Release(p2p_struct_namespace);
	AS3_Release(paramArray);
	AS3_Release(bytes);
	AS3_Release(packet);
	return NULL;
}
Example #16
0
AS3_Val cloneMesh( void * self, AS3_Val args )
{
	Mesh* src, *mesh;

	Material* material;

	Texture* texture;

	int render_mode, i;

	Vector3D** vp;

	AS3_ArrayValue( args, "PtrType, PtrType, PtrType, IntType",& src, & material, & texture, & render_mode);

	mesh = mesh_clone(src, material, texture, render_mode);

	mesh_updateFaces(mesh);
	mesh_updateVertices(mesh);

	if( ( vp = ( Vector3D * *   )malloc( sizeof( Vector3D * ) * mesh -> nVertices ) ) == NULL )
	{
		return AS3_Array( "PtrType, PtrType, PtrType, PtrType, PtrType, PtrType, PtrType, PtrType, PtrType, PtrType, PtrType, PtrType, PtrType",
							mesh,
							& mesh->lightEnable,
							& mesh->fogEnable,
							& mesh->useMipmap,
							//& mesh->terrainTrace,
							& mesh->mip_dist,
							& mesh->v_dirty, 
							& mesh->octree_depth,
							& mesh->addressMode,
							& mesh->texTransform->rotation,
							mesh->texTransform->offset,
							mesh->texTransform->scale,
							& mesh->texTransformDirty,
							& mesh->hit,
							& mesh->skinMeshController,
							& mesh->octree->data->aabb);
	}

	for( i = 0; i < mesh -> nVertices; i ++ )
	{
		vp[i] = mesh -> vertices[i]->position;
	}

	return AS3_Array( "PtrType, PtrType, PtrType, PtrType, PtrType, PtrType, PtrType, PtrType, PtrType, PtrType, PtrType, PtrType, PtrType, PtrType",
						mesh,
						& mesh->lightEnable,
						& mesh->fogEnable,
						& mesh->useMipmap,
						//& mesh->terrainTrace,
						& mesh->mip_dist,
						& mesh->v_dirty,
						& mesh->octree_depth,
						& mesh->addressMode,
						& mesh->texTransform->rotation, 
						mesh->texTransform->offset,
						mesh->texTransform->scale,
						& mesh->texTransformDirty,
						& mesh->hit,
						& mesh->skinMeshController,
						& mesh->octree->data->aabb,
						& vp );
}
Example #17
0
AS3_Val initializeMesh( void * self, AS3_Val args )
{
	Mesh         * mesh;

	Texture      * * tp;
	Material     * * mp;

	unsigned int   vl, fl, i, * fs;

	int          * rmp;

	float        * vs;

	Vector3D     * * vp;

	Vector       * uvp;

	AS3_ArrayValue( args, "PtrType, PtrType, PtrType, PtrType, PtrType, PtrType, IntType, IntType",& vs, & fs, & uvp, & mp, & tp, & rmp, & vl, & fl );

	mesh = newMesh( vl, fl );

	for( i = 0; i < vl; i ++ )
	{
		mesh_push_vertex( mesh, vs[i * 3], vs[i * 3 + 1], vs[i * 3 + 2] );
	}

	//free( vs );

	for( i = 0; i < fl; i ++ )
	{
		mesh_push_triangle( 
			mesh,
			(* mesh -> vertices) + fs[i * 3], 
			(* mesh -> vertices) + fs[i * 3 + 1], 
			(* mesh -> vertices) + fs[i * 3 + 2],
			uvp + i * 3    ,
			uvp + i * 3 + 1,
			uvp + i * 3 + 2,
			mp[i],
			tp[i],
			rmp[i] );
	}

	mesh_updateFaces(mesh);
	mesh_updateVertices(mesh);
	//free( fs );

	//free( rmp );

	if( ( vp = ( Vector3D * *   )malloc( sizeof( Vector3D * ) * mesh -> nVertices ) ) == NULL )
	{
		return AS3_Array( "PtrType, PtrType, PtrType, PtrType, PtrType, PtrType, PtrType, PtrType, PtrType, PtrType, PtrType, PtrType, PtrType",
							mesh,
							& mesh->lightEnable,
							& mesh->fogEnable,
							& mesh->useMipmap,
							//& mesh->terrainTrace,
							& mesh->mip_dist,
							& mesh->v_dirty, 
							& mesh->octree_depth,
							& mesh->addressMode,
							& mesh->texTransform->rotation,
							mesh->texTransform->offset,
							mesh->texTransform->scale,
							& mesh->texTransformDirty,
							& mesh->hit,
							& mesh->skinMeshController,
							mesh->octree->data->aabb);
	}

	for( i = 0; i < mesh -> nVertices; i ++ )
	{
		vp[i] = mesh -> vertices[i]->position;
	}

	return AS3_Array( "PtrType, PtrType, PtrType, PtrType, PtrType, PtrType, PtrType, PtrType, PtrType, PtrType, PtrType, PtrType, PtrType, PtrType, PtrType",
						mesh,
						& mesh->lightEnable,
						& mesh->fogEnable,
						& mesh->useMipmap,
						//& mesh->terrainTrace,
						& mesh->mip_dist,
						& mesh->v_dirty,
						& mesh->octree_depth,
						& mesh->addressMode,
						& mesh->texTransform->rotation, 
						mesh->texTransform->offset,
						mesh->texTransform->scale,
						& mesh->texTransformDirty,
						& mesh->hit,
						& mesh->skinMeshController,
						mesh->octree->data->aabb,
						& vp);
}
Example #18
0
AS3_Val testFunction(void* data, AS3_Val args) {
	AS3_Val test;
	AS3_ArrayValue(args, "AS3ValType", &test);
	return AS3_Ptr(test);
}
Example #19
0
/**
 * Converts a Sample at a lower rate (22050 Hz) or lower number of channels (mono)
 *  to the standard Flash sound format (44.1k stereo interleaved).
 * The descriptor in this case represents the sourceBuffer, not the targetBuffer, which is stereo/44.1
 */
static AS3_Val standardize(void *self, AS3_Val args) 
{
	int bufferPosition; int rate; int channels; int frames;
	float *buffer;
	int sourceBufferPosition;
	float *sourceBuffer;
	int count;
	
	AS3_ArrayValue(args, "IntType, IntType, IntType, IntType, IntType", &bufferPosition, &sourceBufferPosition, &channels, &frames, &rate);
	buffer = (float *) bufferPosition;
	sourceBuffer = (float *) sourceBufferPosition;

	if (rate == 44100 && channels == 2) {
		// We're already standardized. Just copy the memory
		memcpy(buffer, sourceBuffer, frames * channels * sizeof(float));
	} else if (rate == 22050 && channels == 1) {
		// Upsample and stereoize with cubic interpolation
		// First set hold first sample
		*buffer++ = *sourceBuffer;
		*buffer++ = *sourceBuffer;
		*buffer++ = cubicInterpolate(*(sourceBuffer), *(sourceBuffer), *(sourceBuffer+1), *(sourceBuffer+2), 0.5); 
		*buffer = *(buffer-1);
		buffer++; sourceBuffer++;
		// Loop
		count = (frames/2) - 2;
		while (--count) {
			*buffer++ = *sourceBuffer;
			*buffer++ = *sourceBuffer;
			*buffer++ = cubicInterpolate(*(sourceBuffer-1), *sourceBuffer, *(sourceBuffer+1), *(sourceBuffer+2), 0.5); 
			*buffer = *(buffer-1);
			buffer++; sourceBuffer++;
		}		
		// Last set hold 2 samples
		*buffer++ = *sourceBuffer;
		*buffer++ = *sourceBuffer;
		*buffer++ = cubicInterpolate(*(sourceBuffer-1), *sourceBuffer, *(sourceBuffer+1), *(sourceBuffer+1), 0.5); 
		*buffer = *(buffer-1);
		buffer++; sourceBuffer++;
		*buffer++ = *sourceBuffer;
		*buffer++ = *sourceBuffer;
		*buffer++ = cubicInterpolate(*(sourceBuffer-1), *sourceBuffer, *sourceBuffer, *sourceBuffer, 0.5); 
		*buffer = *(buffer-1);
		// Done
	} else if (rate == 22050 && channels == 2) {
		// Upsample with cubic interpolation 
		// First set hold sample
		*buffer++ = *sourceBuffer;
		*buffer++ = *(sourceBuffer+1);
		*buffer++ = cubicInterpolate(*sourceBuffer, *sourceBuffer, *(sourceBuffer+2), *(sourceBuffer+4), 0.5); 
		*buffer = cubicInterpolate(*(sourceBuffer+1), *(sourceBuffer+1), *(sourceBuffer+3), *(sourceBuffer+5), 0.5); 
		buffer++;
		sourceBuffer += 2;
		count = frames/2 - 2;
		while (--count) {
			*buffer++ = *sourceBuffer; // left
			*buffer++ = *(sourceBuffer+1); // right
			*buffer++ = cubicInterpolate(*(sourceBuffer-2), *sourceBuffer, *(sourceBuffer+2), *(sourceBuffer+4), 0.5); 
			*buffer++ = cubicInterpolate(*(sourceBuffer-1), *(sourceBuffer+1), *(sourceBuffer+3), *(sourceBuffer+5), 0.5);
			sourceBuffer += 2;
		}
		// second to last set		
		*buffer++ = *sourceBuffer; // left
		*buffer++ = *(sourceBuffer+1); // right
		*buffer++ = cubicInterpolate(*(sourceBuffer-2), *sourceBuffer, *(sourceBuffer+2), *(sourceBuffer+2), 0.5); 
		*buffer++ = cubicInterpolate(*(sourceBuffer-1), *(sourceBuffer+1), *(sourceBuffer+3), *(sourceBuffer+3), 0.5);
		sourceBuffer += 2;
		// last set
		*buffer++ = *sourceBuffer; // left
		*buffer++ = *(sourceBuffer+1); // right
		*buffer++ = cubicInterpolate(*(sourceBuffer-2), *sourceBuffer, *sourceBuffer, *sourceBuffer, 0.5); 
		*buffer= cubicInterpolate(*(sourceBuffer-1), *(sourceBuffer+1), *(sourceBuffer+1), *(sourceBuffer+1), 0.5);
		// Done
	} else if (rate == 44100 && channels == 1) {
		// Stereoize
		count = frames;
		while (--count) {
			*buffer++ = *sourceBuffer;
			*buffer++ = *sourceBuffer++;
		}
	}
	return 0;
}
Example #20
0
// Mix one buffer into another
static AS3_Val mixIn(void *self, AS3_Val args)
{
	int bufferPosition; int channels; int frames;
	float *buffer;
	int sourceBufferPosition;
	float *sourceBuffer;
	double leftGainArg;
	double rightGainArg;
	float leftGain;
	float rightGain;
	int count, count8, remainder;
	
	AS3_ArrayValue(args, "IntType, IntType, IntType, IntType, DoubleType, DoubleType", 
		&bufferPosition, &sourceBufferPosition, &channels, &frames, &leftGainArg, &rightGainArg);
	buffer = (float *) bufferPosition;
	sourceBuffer = (float *) sourceBufferPosition; // this can be passed with an offset to easily mix offset slices of samples
	leftGain = (float) leftGainArg;
	rightGain = (float) rightGainArg;	
	
	count = frames;
	count8 = count / 8;
	remainder = count % 8;
	
	if (channels == 1) {
		while (count8--) {
			*buffer++ += *sourceBuffer++ * leftGain;
			*buffer++ += *sourceBuffer++ * leftGain;
			*buffer++ += *sourceBuffer++ * leftGain;
			*buffer++ += *sourceBuffer++ * leftGain;
			*buffer++ += *sourceBuffer++ * leftGain;
			*buffer++ += *sourceBuffer++ * leftGain;
			*buffer++ += *sourceBuffer++ * leftGain;
			*buffer++ += *sourceBuffer++ * leftGain; 
		}			
		while (remainder--) {
			*buffer++ += *sourceBuffer++ * leftGain; 
		}
	} else if (channels == 2) {
		while (count8--) {
			*buffer++ += *sourceBuffer++ * leftGain; 		
			*buffer++ += *sourceBuffer++ * rightGain;
			*buffer++ += *sourceBuffer++ * leftGain; 		
			*buffer++ += *sourceBuffer++ * rightGain;
			*buffer++ += *sourceBuffer++ * leftGain; 		
			*buffer++ += *sourceBuffer++ * rightGain;
			*buffer++ += *sourceBuffer++ * leftGain; 		
			*buffer++ += *sourceBuffer++ * rightGain;
			*buffer++ += *sourceBuffer++ * leftGain; 		
			*buffer++ += *sourceBuffer++ * rightGain;
			*buffer++ += *sourceBuffer++ * leftGain; 		
			*buffer++ += *sourceBuffer++ * rightGain;
			*buffer++ += *sourceBuffer++ * leftGain; 		
			*buffer++ += *sourceBuffer++ * rightGain;
			*buffer++ += *sourceBuffer++ * leftGain; 		
			*buffer++ += *sourceBuffer++ * rightGain;
		}
		while (remainder--) {
			*buffer++ += *sourceBuffer++ * leftGain; 		
			*buffer++ += *sourceBuffer++ * rightGain;
		}
		
	}
	return 0;
}
Example #21
0
/**
 * Mix a mono sample into a stereo sample.
 * Buffer is stereo, and source buffer is mono.
 */
static AS3_Val mixInPan(void *self, AS3_Val args)
{
	int bufferPosition;  int frames;
	float *buffer;
	int sourceBufferPosition;
	float *sourceBuffer;
	double leftGainArg;
	double rightGainArg;
	float leftGain;
	float rightGain;
	int count, count16, remainder;
	
	AS3_ArrayValue(args, "IntType, IntType, IntType, DoubleType, DoubleType", 
		&bufferPosition, &sourceBufferPosition, &frames, &leftGainArg, &rightGainArg);
	buffer = (float *) bufferPosition;
	sourceBuffer = (float *) sourceBufferPosition; 
	leftGain = (float) leftGainArg;
	rightGain = (float) rightGainArg;	
	
	count = frames;
	count16 = count / 16;
	remainder = count % 16;
	
	while (count16--) {
		*buffer++ += *sourceBuffer * leftGain; 		
		*buffer++ += *sourceBuffer++ * rightGain;
		*buffer++ += *sourceBuffer * leftGain; 		
		*buffer++ += *sourceBuffer++ * rightGain;
		*buffer++ += *sourceBuffer * leftGain; 		
		*buffer++ += *sourceBuffer++ * rightGain;
		*buffer++ += *sourceBuffer * leftGain; 		
		*buffer++ += *sourceBuffer++ * rightGain;
		*buffer++ += *sourceBuffer * leftGain; 		
		*buffer++ += *sourceBuffer++ * rightGain;
		*buffer++ += *sourceBuffer * leftGain; 		
		*buffer++ += *sourceBuffer++ * rightGain;
		*buffer++ += *sourceBuffer * leftGain; 		
		*buffer++ += *sourceBuffer++ * rightGain;
		*buffer++ += *sourceBuffer * leftGain; 		
		*buffer++ += *sourceBuffer++ * rightGain;
		*buffer++ += *sourceBuffer * leftGain; 		
		*buffer++ += *sourceBuffer++ * rightGain;
		*buffer++ += *sourceBuffer * leftGain; 		
		*buffer++ += *sourceBuffer++ * rightGain;
		*buffer++ += *sourceBuffer * leftGain; 		
		*buffer++ += *sourceBuffer++ * rightGain;
		*buffer++ += *sourceBuffer * leftGain; 		
		*buffer++ += *sourceBuffer++ * rightGain;
		*buffer++ += *sourceBuffer * leftGain; 		
		*buffer++ += *sourceBuffer++ * rightGain;
		*buffer++ += *sourceBuffer * leftGain; 		
		*buffer++ += *sourceBuffer++ * rightGain;
		*buffer++ += *sourceBuffer * leftGain; 		
		*buffer++ += *sourceBuffer++ * rightGain;
		*buffer++ += *sourceBuffer * leftGain; 		
		*buffer++ += *sourceBuffer++ * rightGain;
	}
	while (remainder--) {
		*buffer++ += *sourceBuffer * leftGain; 		
		*buffer++ += *sourceBuffer++ * rightGain;
	}

	return 0;
}
Example #22
0
/**
 * Scan in a wavetable. Wavetable should be at least one longer than the table size.
 */
static AS3_Val wavetableIn(void *self, AS3_Val args)
{
	AS3_Val settings;
	int bufferPosition; int channels; int frames;
	float *buffer; 
	int sourceBufferPosition;
	float *sourceBuffer;
	double phaseArg; float phase;
	double phaseAddArg; float phaseAdd;
	double phaseResetArg; float phaseReset;
	int tableSize;
	int count; 
	int intPhase;
	float *wavetablePosition;
	float *scratch;
	double y1Arg, y2Arg;
	float y1, y2;
	float fractional, fractionalIncrement, instantBend;
	
	
	
	AS3_ArrayValue(args, "IntType, IntType, IntType, IntType, AS3ValType", &bufferPosition, &sourceBufferPosition, &channels, &frames, &settings);
	AS3_ObjectValue(settings, "tableSize:IntType, phase:DoubleType, phaseAdd:DoubleType, phaseReset:DoubleType, y1:DoubleType, y2:DoubleType",
		&tableSize, &phaseArg, &phaseAddArg, &phaseResetArg, &y1Arg, &y2Arg);

	buffer = (float *) bufferPosition;
	sourceBuffer = (float *) sourceBufferPosition; 
	phaseAdd = (float) phaseAddArg * tableSize; // num source frames to add per output frames
	phase = (float) phaseArg * tableSize; // translate into a frame count into the table
	phaseReset = (float) phaseResetArg * tableSize;
	y1 = (float) y1Arg;
	y2 = (float) y2Arg;
	
	// Expand the pitch modulation into scratch
	// expandLine(scratch1, y1, y2, frames); // draws spline segment into scratch1
	// scratch = (float *) scratch1;	
		
	// Make sure we got everything right
	//sprintf(trace, "Wavetable size=%d phase=%f phaseAdd=%f y1=%f y2=%f", tableSize, phase, phaseAdd, y1, y2);
	//sztrace(trace);	
				
	count=frames;
	fractional = 0.0;
	fractionalIncrement = 1 / (float) frames;
	
	if (channels == 1) {
		while (count--) {
			while (phase >= tableSize) {
				if (phaseReset == -1) {
					// no looping!
					return 0; 
				} else {
					// wrap phase to the loop point
					phase -= tableSize; 
					phase += phaseReset;
				}
			}
			intPhase = (int) phase; // int phase
			wavetablePosition = sourceBuffer + intPhase;
			*buffer++ = interpolate(*wavetablePosition, *(wavetablePosition+1), phase - intPhase);
			// Increment phase by adjusting phaseAdd for instantaneous pitch bend 
			instantBend = interpolate(y1, y2, fractional);
			fractional += fractionalIncrement;
			phase +=  phaseAdd * shiftToFreq(instantBend); 
		}		
	} else if (channels == 2 ) {
		while (count--) {
			while (phase >= tableSize) {
				if (phaseReset == -1) {
					// no looping!
					return 0; 
				} else {
					// wrap phase to the loop point
					phase -= tableSize; 
					phase += phaseReset;
				}
			}
			intPhase = ((int)(phase*0.5))*2; // int phase, round to even frames, for each stereo frame pair
			wavetablePosition = sourceBuffer + intPhase;
			*buffer++ = interpolate(*wavetablePosition, *(wavetablePosition+2), phase - intPhase);
			*buffer++ = interpolate(*(wavetablePosition+1), *(wavetablePosition+3), phase - intPhase);
			// Increment phase by adjusting phaseAdd for instantaneous pitch bend 
			instantBend = interpolate(y1, y2, fractional);
			fractional += fractionalIncrement;
			phase +=  phaseAdd * shiftToFreq(instantBend);
		}
	}
	
	// Scale back down to a factor, and write the final phase value back to AS3
	phase /= tableSize;
	AS3_Set(settings, AS3_String("phase"), AS3_Number(phase));
	
	return 0;
}
Example #23
0
static AS3_Val delay(void *self, AS3_Val args)
{
	int bufferPosition; int channels; int frames; int count; 
	float *buffer; 
	int ringBufferPosition;
	float *ringBuffer;
	AS3_Val settings;
	int length;
	double feedbackArg; float feedback;
	double dryMixArg; float dryMix;
	double wetMixArg; float wetMix;
	int offset = 0;
	float echo;
	float *echoPointer;
	
	// Extract	args
	AS3_ArrayValue(args, "IntType, IntType, IntType, IntType, AS3ValType", 
	    &bufferPosition, &ringBufferPosition, &channels, &frames,  &settings);
	AS3_ObjectValue(settings, "length:IntType, dryMix:DoubleType, wetMix:DoubleType, feedback:DoubleType",
		&length, &dryMixArg, &wetMixArg, &feedbackArg);
	// Cast arguments to the needed types
	buffer = (float *) bufferPosition;
	ringBuffer = (float *) ringBufferPosition;
	dryMix = (float) dryMixArg;
	wetMix = (float) wetMixArg;
	feedback = (float) feedbackArg;
	
	// Show params
	// sprintf(trace, "Echo length=%d, dry=%f, wet=%f, fb=%f", length, dryMix, wetMix, feedback); 
	// sztrace(trace);
	
	count = frames * channels;
	while (count--) {
		if (offset > length) { 
			offset = 0; 
		}
		echoPointer = ringBuffer + offset;
		echo = *echoPointer;
		*echoPointer = *buffer + echo*feedback;
		*buffer = *buffer * dryMix + echo * wetMix + 1e-15 - 1e-15;
		buffer++; offset++;
	}		
	
	
	// Shift the memory so that the echo pointer offset is the start of the buffer
	
	int ringSize = length * channels * sizeof(float);
	int firstChunkSize = offset * channels * sizeof(float);
	int secondChunkSize = ringSize - firstChunkSize;
	float *temp = (float *) malloc(ringSize);
	
	// copy offset-end -> start of temp buffer	
	memcpy(temp, ringBuffer + offset, secondChunkSize);

	// copy start-offset -> second half of temp buffer
	memcpy(temp + offset, ringBuffer, firstChunkSize);
	
	// copy temp buffer back to ringbuffer
	memcpy(ringBuffer, temp, ringSize); 
	free(temp);
	
	return 0;
	
}
Example #24
0
static AS3_Val biquad(void *self, AS3_Val args)
{
	int bufferPosition;  int channels; int frames; int count; 
	float *buffer; 
	int stateBufferPosition;
	float *stateBuffer;
	
	AS3_Val coeffs; // coefficients object
	double a0d, a1d, a2d, b0d, b1d, b2d; // doubles from object
	float a0, a1, a2, b0, b1, b2; // filter coefficients
	float lx, ly, lx1, lx2, ly1, ly2; // left delay line 
	float rx, ry, rx1, rx2, ry1, ry2; // right delay line 
	
	// Extract args
	AS3_ArrayValue(args, "IntType, IntType, IntType, IntType, AS3ValType", 
		&bufferPosition, &stateBufferPosition, &channels, &frames, &coeffs);
	buffer = (float *) bufferPosition;
	stateBuffer = (float *) stateBufferPosition;	
		
	// Extract filter coefficients from object	
	AS3_ObjectValue(coeffs, "a0:DoubleType, a1:DoubleType, a2:DoubleType, b0:DoubleType, b1:DoubleType, b2:DoubleType",
		&a0d, &a1d, &a2d, &b0d, &b1d, &b2d);
	// Cast to floats
	a0 = (float) a0d; a1 = (float) a1d; a2 = (float) a2d; 	
	b0 = (float) b0d; b1 = (float) b1d; b2 = (float) b2d; 	

	// Make sure we recieved all the correct coefficients 
	// sprintf(trace, "Biquad a0=%f a1=%f a2=%f b0=%f b1=%f b2=%f", a0, a1, a2, b0, b1, b2);
	// sztrace(trace);
		
	count = frames;

	if (channels == 1) {
		lx1 = *stateBuffer;
		lx2 = *(stateBuffer+1);
		ly1 = *(stateBuffer+2);
		ly2 = *(stateBuffer+3);
		while (count--) {
			lx = *buffer + 1e-15 - 1e-15; // input with denormals zapped
            ly = lx*b0 + lx1*b1 + lx2*b2 - ly1*a1 - ly2*a2;
			lx2 = lx1;
			lx1 = lx;
			ly2 = ly1;
			ly1 = ly;
            *buffer++ = ly; // output
		}
		*stateBuffer = lx1;
		*(stateBuffer+1) = lx2;
		*(stateBuffer+2) = ly1;
		*(stateBuffer+3) = ly2;
	} else if (channels == 2) {
		lx1 = *stateBuffer;
		rx1 = *(stateBuffer+1);
		lx2 = *(stateBuffer+2);
		rx2 = *(stateBuffer+3);
		ly1 = *(stateBuffer+4);
		ry1 = *(stateBuffer+5);
		ly2 = *(stateBuffer+6);
		ry2 = *(stateBuffer+7);
		while (count--) {
			lx = *buffer + 1e-15 - 1e-15; // left input
            ly = lx*b0 + lx1*b1 + lx2*b2 - ly1*a1 - ly2*a2;
			lx2 = lx1;
			lx1 = lx;
			ly2 = ly1;
			ly1 = ly;
            *buffer++ = ly; // left output
			rx = *buffer + 1e-15 - 1e-15; // right input
            ry = rx*b0 + rx1*b1 + rx2*b2 - ry1*a1 - ry2*a2;
			rx2 = rx1;
			rx1 = rx;
			ry2 = ry1;
			ry1 = ry;
            *buffer++ = ry; // right output
		}
		*stateBuffer = lx1;
		*(stateBuffer+1) = rx1;
		*(stateBuffer+2) = lx2;
		*(stateBuffer+3) = rx2;
		*(stateBuffer+4) = ly1;
		*(stateBuffer+5) = ry1;
		*(stateBuffer+6) = ly2;
		*(stateBuffer+7) = ry2;
	}

	return 0;
}
Example #25
0
static AS3_Val setFilterType(void* self, AS3_Val args)
{
	AS3_ArrayValue(args, "StrType", &filterType);
	return 0;
}
Example #26
0
//FLASH: Camera parameters setup
static AS3_Val setFrameParams(void* self, AS3_Val args)
{
	AS3_ArrayValue(args,"IntType, IntType, IntType",&frameWidth,&frameHeight,&frameChannels);
	//fprintf(stderr, "[OPENCV] setFrameParams: %d - %d - %d", frameWidth, frameHeight, frameChannels);
	return 0;
}
Example #27
0
AS3_Val call(void* thiz, AS3_Val args)
{
	AS3_Val is;
	AS3_Val os;
	uint8_t* bufIn;
	uint8_t* bufOut;

	int i = 0;
	int j = 0;
	uint32_t color;
	uint32_t* bufDst;

	int w = 0;
	int h = 0;
	int len;
	int type;

	struct
	{
		uint16_t w;
		uint16_t h;
	} size;


	AS3_ArrayValue(args, "AS3ValType,IntType,IntType,AS3ValType", &is, &len, &type, &os);


	for(;;)
	{
		bufIn = malloc(len);
		if(!bufIn)
			break;

		AS3_ByteArray_readBytes(bufIn, is, len);
		bufOut = WebPDecodeRGB(bufIn, len, &w, &h);
		free(bufIn);

		if(!bufOut || w <= 0 || h <= 0)
			break;

		bufDst = (uint32_t*)malloc(w * h * 4);
		if(!bufDst)
			break;

		len = w * h * 3;
		while(i < len)
		{
			color = *(uint32_t*)(bufOut + i);
			color = (color << 8) | 0x000000FF;

			bufDst[j++] = color;
			i += 3;
		}

		free(bufOut);

		size.w = w;
		size.h = h;

		AS3_ByteArray_writeBytes(os, &size, sizeof(size));
		AS3_ByteArray_writeBytes(os, bufDst, w * h * 4);

		free(bufDst);
		break;
	}

	return AS3_Undefined();
}
static AS3_Val benchmark(void* self, AS3_Val args)
{
	/* used in the FORTRAN version */
	long I;
	long N1, N2, N3, N4, N6, N7, N8, N9, N10, N11;
	double X1,X2,X3,X4,X,Y,Z;
	long LOOP;
	int II, JJ;

	/* added for this version */
	long loopstart;
	long startsec, finisec;
	float KIPS;
	int continuous;

	loopstart = 1000;		/* see the note about LOOP below */
	continuous = 1;

	printf("[WHETSTONE] benchmark\n");
	AS3_ArrayValue( args, "IntType", &loopstart);
	printf("[WHETSTONE] benchmark : %s\n", loopstart);

LCONT:
/*
C
C	Start benchmark timing at this point.
C
*/
	startsec = time(0);

/*
C
C	The actual benchmark starts here.
C
*/
	T  = .499975;
	T1 = 0.50025;
	T2 = 2.0;
/*
C
C	With loopcount LOOP=10, one million Whetstone instructions
C	will be executed in EACH MAJOR LOOP..A MAJOR LOOP IS EXECUTED
C	'II' TIMES TO INCREASE WALL-CLOCK TIMING ACCURACY.
C
	LOOP = 1000;
*/
	LOOP = loopstart;
	II   = 1;

	JJ = 1;

IILOOP:
	N1  = 0;
	N2  = 12 * LOOP;
	N3  = 14 * LOOP;
	N4  = 345 * LOOP;
	N6  = 210 * LOOP;
	N7  = 32 * LOOP;
	N8  = 899 * LOOP;
	N9  = 616 * LOOP;
	N10 = 0;
	N11 = 93 * LOOP;
/*
C
C	Module 1: Simple identifiers
C
*/
	X1  =  1.0;
	X2  = -1.0;
	X3  = -1.0;
	X4  = -1.0;

	for (I = 1; I <= N1; I++) {
	    X1 = (X1 + X2 + X3 - X4) * T;
	    X2 = (X1 + X2 - X3 + X4) * T;
	    X3 = (X1 - X2 + X3 + X4) * T;
	    X4 = (-X1+ X2 + X3 + X4) * T;
	}
#ifdef PRINTOUT
	IF (JJ==II)POUT(N1,N1,N1,X1,X2,X3,X4);
#endif

/*
C
C	Module 2: Array elements
C
*/
	E1[1] =  1.0;
	E1[2] = -1.0;
	E1[3] = -1.0;
	E1[4] = -1.0;

	for (I = 1; I <= N2; I++) {
	    E1[1] = ( E1[1] + E1[2] + E1[3] - E1[4]) * T;
	    E1[2] = ( E1[1] + E1[2] - E1[3] + E1[4]) * T;
	    E1[3] = ( E1[1] - E1[2] + E1[3] + E1[4]) * T;
	    E1[4] = (-E1[1] + E1[2] + E1[3] + E1[4]) * T;
	}

#ifdef PRINTOUT
	IF (JJ==II)POUT(N2,N3,N2,E1[1],E1[2],E1[3],E1[4]);
#endif

/*
C
C	Module 3: Array as parameter
C
*/
	for (I = 1; I <= N3; I++)
		PA(E1);

#ifdef PRINTOUT
	IF (JJ==II)POUT(N3,N2,N2,E1[1],E1[2],E1[3],E1[4]);
#endif

/*
C
C	Module 4: Conditional jumps
C
*/
	J = 1;
	for (I = 1; I <= N4; I++) {
		if (J == 1)
			J = 2;
		else
			J = 3;

		if (J > 2)
			J = 0;
		else
			J = 1;

		if (J < 1)
			J = 1;
		else
			J = 0;
	}

#ifdef PRINTOUT
	IF (JJ==II)POUT(N4,J,J,X1,X2,X3,X4);
#endif

/*
C
C	Module 5: Omitted
C 	Module 6: Integer arithmetic
C
*/

	J = 1;
	K = 2;
	L = 3;

	for (I = 1; I <= N6; I++) {
	    J = J * (K-J) * (L-K);
	    K = L * K - (L-J) * K;
	    L = (L-K) * (K+J);
	    E1[L-1] = J + K + L;
	    E1[K-1] = J * K * L;
	}

#ifdef PRINTOUT
	IF (JJ==II)POUT(N6,J,K,E1[1],E1[2],E1[3],E1[4]);
#endif

/*
C
C	Module 7: Trigonometric functions
C
*/
	X = 0.5;
	Y = 0.5;

	for (I = 1; I <= N7; I++) {
		X = T * DATAN(T2*DSIN(X)*DCOS(X)/(DCOS(X+Y)+DCOS(X-Y)-1.0));
		Y = T * DATAN(T2*DSIN(Y)*DCOS(Y)/(DCOS(X+Y)+DCOS(X-Y)-1.0));
	}

#ifdef PRINTOUT
	IF (JJ==II)POUT(N7,J,K,X,X,Y,Y);
#endif

/*
C
C	Module 8: Procedure calls
C
*/
	X = 1.0;
	Y = 1.0;
	Z = 1.0;

	for (I = 1; I <= N8; I++)
		P3(X,Y,&Z);

#ifdef PRINTOUT
	IF (JJ==II)POUT(N8,J,K,X,Y,Z,Z);
#endif

/*
C
C	Module 9: Array references
C
*/
	J = 1;
	K = 2;
	L = 3;
	E1[1] = 1.0;
	E1[2] = 2.0;
	E1[3] = 3.0;

	for (I = 1; I <= N9; I++)
		P0();

#ifdef PRINTOUT
	IF (JJ==II)POUT(N9,J,K,E1[1],E1[2],E1[3],E1[4]);
#endif

/*
C
C	Module 10: Integer arithmetic
C
*/
	J = 2;
	K = 3;

	for (I = 1; I <= N10; I++) {
	    J = J + K;
	    K = J + K;
	    J = K - J;
	    K = K - J - J;
	}

#ifdef PRINTOUT
	IF (JJ==II)POUT(N10,J,K,X1,X2,X3,X4);
#endif

/*
C
C	Module 11: Standard functions
C
*/
	X = 0.75;

	for (I = 1; I <= N11; I++)
		X = DSQRT(DEXP(DLOG(X)/T1));

#ifdef PRINTOUT
	IF (JJ==II)POUT(N11,J,K,X,X,X,X);
#endif

/*
C
C      THIS IS THE END OF THE MAJOR LOOP.
C
*/
	if (++JJ <= II)
		goto IILOOP;

/*
C
C      Stop benchmark timing at this point.
C
*/
	finisec = time(0);

/*
C----------------------------------------------------------------
C      Performance in Whetstone KIP's per second is given by
C
C	(100*LOOP*II)/TIME
C
C      where TIME is in seconds.
C--------------------------------------------------------------------
*/
	printf("\n");
	if (finisec-startsec <= 0) {
		printf("Insufficient duration- Increase the LOOP count\n");
		//return(1);
		return 0;
	}

	printf("Loops: %ld, Iterations: %d, Duration: %ld sec.\n",
			LOOP, II, finisec-startsec);

	KIPS = (100.0*LOOP*II)/(float)(finisec-startsec);
	if (KIPS >= 1000.0)
		printf("C Converted Double Precision Whetstones: %.1f MIPS\n", KIPS/1000.0);
	else
		printf("C Converted Double Precision Whetstones: %.1f KIPS\n", KIPS);

	if (continuous)
		goto LCONT;
	
	//return(0);
	return 0;
}
static AS3_Val prediction(void* self, AS3_Val args) {
	AS3_Val	in_arr = AS3_Undefined(), out_arr = AS3_Array(0);
	float *tmp, d, e;
	int i,j,k,l, n,x,y, newx,newy, il, dx,dy;
	LAYER *pL;

	AS3_ArrayValue( args, "AS3ValType", &in_arr );

	for(i=0; i < 1024; ++i)
    	data[i] = AS3_IntValue(AS3_Get(in_arr, AS3_Int(4*i+1))) /255.0;
    	
    n = 1;
    x = 32;
    y = 32;
    
    #define DATA(l,j,i) data[((l)*y + (j))*x + (i)]
    #define O(k,dy,dx) o[((k)*newy + (dy))*newx + (dx)]
    #define W(k,l,j,i) pL->w[(((k)*n + (l))*pL->y + (j))*pL->x + (i)]
    
    for (il=0; il < nl; ++il) {
        flyield();
        pL = L+il;
        newx = x+1-pL->x;
        newy = y+1-pL->y;

        for (dx=0; dx < newx; ++dx)
        for (dy=0; dy < newy; ++dy)
        for (k=0; k < pL->n; ++k) {
            d = pL->b[k];
            for (l=0; l < n; ++l)
            for(j=0; j < pL->y; ++j)
            for(i=0; i < pL->x; ++i)
                d += DATA(l,j+dy,i+dx)*W(k,l,j,i);
            O(k,dy,dx) = d;
        }

        if(pL->maxpool) {
            for (k=0; k < pL->n; ++k)
            for (dx=0; dx < newx; dx+=2)
            for (dy=0; dy < newy; dy+=2) {
                d=O(k,dy,dx);
                e=O(k,dy,dx+1); if(e>d) d=e;
                e=O(k,dy+1,dx); if(e>d) d=e;
                e=O(k,dy+1,dx+1); if(e>d) d=e;
                O(k,dy/2,dx/2)=d;
            }
            newx /= 2;
            newy /= 2;
        }

        for (dx=0; dx < newx; ++dx)
        for (dy=0; dy < newy; ++dy) {
            e = 0;
            for (k=0; k < pL->n; ++k) {
                d = O(k,dy,dx);
                if(pL->nonlin==1) d=1.0/(1.0 + exp(-d));
                else if(pL->nonlin==2) d=tanh(d);
                else if(pL->nonlin==3) { d=exp(d); e += d; }
                O(k,dy,dx) = d;
            }
            if(pL->nonlin==3 && e)
            for (k=0; k < pL->n; ++k)
                O(k,dy,dx) /= e;
        }
        
        tmp = data;
        data = o;
        o = tmp;
        
        x = newx;
        y = newy;
        n = pL->n;
    }

	for(i=0; i < n*x*y; ++i)
        AS3_Set(out_arr, AS3_Int(i), AS3_Number(data[i]));

	return out_arr;
}