Exemplo n.º 1
0
double durOfTone(int filenum,double startTime){
	
	int i;
	double toneLength = 0;
	double toneEnd = 0;
	
	char file_name[64] ;
	sprintf(file_name, "%dD", filenum) ;

	printf("\tLine counting file %s...", file_name);
	
	int mallocD;
	mallocD = filecount(file_name);
	printf("Done.\n");
	
	double* D;
	D = (double *)Malloc(mallocD * sizeof(double));
	
	printf("\tfile2array file %s...", file_name);
	
	file2array(file_name, D);
	
	printf("Done.\n");
	
	for(i =0;i<mallocD;i++)
		toneLength = toneLength + D[i];	

	Free(D);
	
	toneEnd = startTime + toneLength;
	
	return toneEnd;
}
Exemplo n.º 2
0
void file2array(char* file_name, double buffer[])
{
	double val;
	
	FILE *fp;

	fp = fopen(file_name,"r"); //read mode

	if(fp == NULL)
	{
		perror("Error while opening the file.\n");
		printf("\n\tError while opening file: %s\n", file_name);
		exit(EXIT_FAILURE);
	}
	
	int i = 0;
	while(i < filecount(file_name)){
		fscanf(fp, "%lf", &val);
		buffer[i] = val;
		++i;
	}
	
	fclose(fp);
	return ;
}
Exemplo n.º 3
0
int32_t RogueSD::filecount(const char *filemask)
{
  return filecount(NULL, filemask);
}
Exemplo n.º 4
0
////////////////////////////////////////////////////////////////////////////////
// Program main
////////////////////////////////////////////////////////////////////////////////
int
main(int argc, char **argv)
{
    printf("%s Starting...\n\n", sSDKsample);

    numParticles = NUM_PARTICLES;
    maxNumParticles = MAX_NUM_PARTICLES;
    uint gridDim = GRID_SIZE;
    numIterations = 0;
    printf("Surely I can get this far\n");

    if (argc > 1)
    {
        if (checkCmdLineFlag(argc, (const char **) argv, "n"))
        {
            numParticles = getCmdLineArgumentInt(argc, (const char **)argv, "n");
        }

        if (checkCmdLineFlag(argc, (const char **) argv, "grid"))
        {
            gridDim = getCmdLineArgumentInt(argc, (const char **) argv, "grid");
        }

        if (checkCmdLineFlag(argc, (const char **)argv, "file"))
        {
            getCmdLineArgumentString(argc, (const char **)argv, "file", &g_refFile);
            fpsLimit = frameCheckNumber;
            numIterations = 1;
        }
    }

    //*******************************************************
    // RMK Hard code for cylindrical coords (y=theta=1)
    // DomainSize
	//char Zfile[] = "/home/rkeedy/Dropbox/CFD/BuoyantStrumJet85-nothot/ZVert.txt";
	//char Rfile[] = "/home/rkeedy/Dropbox/CFD/BuoyantStrumJet85-nothot/RVert.txt";
	//char Zfile[] = "/home/rkeedy/Dropbox/CFD/BuoyantStrumJet85-nothot-big/ZVert.txt";
	//char Rfile[] = "/home/rkeedy/Dropbox/CFD/BuoyantStrumJet85-nothot-big/RVert.txt";
	//char Zfile[] = "/home/rkeedy/Dropbox/CFD/BuoyantStrumJet85-big/ZVert.txt";
	//char Rfile[] = "/home/rkeedy/Dropbox/CFD/BuoyantStrumJet85-big/RVert.txt";
	//char Zfile[] = "/home/rkeedy/Dropbox/CFD/BuoyantStrumJet85-nothot-big-refine/ZVert.txt";
	//char Rfile[] = "/home/rkeedy/Dropbox/CFD/BuoyantStrumJet85-nothot-big-refine/RVert.txt";
	char Zfile[] = "/home/rkeedy/CFD/BuoyantStrumJet85-big-refine-lighter/ZVert.txt";
	char Rfile[] = "/home/rkeedy/CFD/BuoyantStrumJet85-big-refine-lighter/RVert.txt";
	//char Zfile[] = "/home/rkeedy/Dropbox/CFD/BuoyantStrumJet62-big-refine-lighter/ZVert.txt";
	//char Rfile[] = "/home/rkeedy/Dropbox/CFD/BuoyantStrumJet62-big-refine-lighter/RVert.txt";
	//char Zfile[] = "/home/rkeedy/Dropbox/CFD/BuoyantStrumJet85-big-refine/ZVert.txt";
	//char Rfile[] = "/home/rkeedy/Dropbox/CFD/BuoyantStrumJet85-big-refine/RVert.txt";
	//char Zfile[] = "/home/rkeedy/Dropbox/CFD/BuoyantStrumJet63-big-refine/ZVert.txt";
	//char Rfile[] = "/home/rkeedy/Dropbox/CFD/BuoyantStrumJet63-big-refine/RVert.txt";
	numVelNodes.x = filecount(Rfile); //-1;
	numVelNodes.z = filecount(Zfile); //-1;
	numVelNodes.y = 1;
	numCells.x = 80; //47; //24; //29;
	numCells.y = 1;
	numCells.z = 160; //188; //95; //88;
	numParticles = numCells.x*numCells.z*20; //avgnumparticles = 40
	srand( time( NULL ) );
	//numParticles = numCells.x*numCells.z*40;
	printf("vel grid: %d x %d x %d = %d cells\n", numVelNodes.x, numVelNodes.y, numVelNodes.z, numVelNodes.x*numVelNodes.y*numVelNodes.z);
	printf("    grid: %d x %d x %d = %d cells\n", numCells.x, numCells.y, numCells.z, numCells.x*numCells.y*numCells.z);
	//printf("vel grid: %d x %d x %d = %d cells\n", gridSize.x, gridSize.y, gridSize.z, gridSize.x*gridSize.y*gridSize.z);

    bool benchmark = checkCmdLineFlag(argc, (const char **) argv, "benchmark") != 0;

    if (checkCmdLineFlag(argc, (const char **) argv, "i"))
    {
        numIterations = getCmdLineArgumentInt(argc, (const char **) argv, "i");
    }
    if (g_refFile)
    {
        cudaInit(argc, argv);
    }
    else
    {
        if (checkCmdLineFlag(argc, (const char **)argv, "device"))
        {
            printf("[%s]\n", argv[0]);
            printf("   Does not explicitly support -device=n in OpenGL mode\n");
            printf("   To use -device=n, the sample must be running w/o OpenGL\n\n");
            printf(" > %s -device=n -file=<*.bin>\n", argv[0]);
            printf("exiting...\n");
            exit(EXIT_SUCCESS);
        }

        initGL(&argc, argv);
        cudaGLInit(argc, argv);
    }

    // Moved code snippet to CellSystem
    //initCellSystem(gridSize);
    // now moved to particlesystem

    printf("Begin initialization\n");

    //initParticleSystem(numParticles, gridSize, g_refFile==NULL);
    initParticleSystem(maxNumParticles, numParticles, numVelNodes, numCells, g_refFile==NULL);
    //printf("Finished with initParticleSystem, %d\n",g_refFile==NULL);
    //cin.ignore();
    initParams();

    printf("Finished with initialization\n");

    if (!g_refFile)
    {
        initMenus();
    }

    if (benchmark || g_refFile)
    {
        if (numIterations <= 0)
        {
            numIterations = 300;
        }

        runBenchmark(numIterations, argv[0]);
    }
    else
    {
        glutDisplayFunc(display);
        glutReshapeFunc(reshape);
        glutMouseFunc(mouse);
        glutMotionFunc(motion);
        glutKeyboardFunc(key);
        glutSpecialFunc(special);
        glutIdleFunc(idle);

        atexit(cleanup);

        glutMainLoop();
    }

    if (psystem)
    {
        delete psystem;
    }

    cudaDeviceReset();
    exit(g_TotalErrors > 0 ? EXIT_FAILURE : EXIT_SUCCESS);
}
Exemplo n.º 5
0
void allocSetup(int filenum,
		int *mallocCar,
		int *mallocMod,
		int *mallocPD,
		int *mallocD,
		int *mallocAmp,
		int *mallocT,
		int *mallocA,
		int *mallocPan)
{
	char file_name[64];

	sprintf(file_name, "%dCarrier", filenum);
	printf("\tLine counting file %s...", file_name);
	*mallocCar = filecount(file_name);
	printf("%d\n",*mallocCar);
	
	sprintf(file_name, "%dModulator", filenum);
	printf("\tLine counting file %s...", file_name);
	*mallocMod = filecount(file_name);
	printf("%d\n",*mallocMod);

	sprintf(file_name, "%dPD", filenum);
	printf("\tLine counting file %s...", file_name);
	*mallocPD = filecount(file_name);
	printf("%d\n",*mallocPD);

	sprintf(file_name, "%dD", filenum);
	printf("\tLine counting file %s...", file_name);
	*mallocD = filecount(file_name);
	printf("%d\n",*mallocD);
	
	sprintf(file_name, "%dAmp", filenum);
	printf("\tLine counting file %s...", file_name);
	*mallocAmp = filecount(file_name);
	printf("%d\n",*mallocAmp);
	
	sprintf(file_name, "%dD", filenum);
	double* D;
	D = (double *)Malloc(*mallocD * sizeof(double));
	file2array(file_name, D);

	sprintf(file_name, "%dT", filenum);
	printf("\tLine counting file %s...", file_name);
	*mallocT = filecount(file_name);
	printf("%d\n",*mallocT);

	sprintf(file_name, "%dA", filenum);
	printf("\tLine counting file %s...", file_name);
	*mallocA = filecount(file_name);
	printf("%d\n",*mallocA);


	int i;
	double toneLength = 1;
	for(i = 0;i<*mallocD;i++) 
		toneLength = toneLength + D[i];

	*mallocPan = toneLength * 44100.0;
	printf("\tD[0] = %f\n", D[0]);
	printf("\ttoneLength = %f\n", toneLength);
	printf("\tmallocPan = %d\n", *mallocPan);
	
	Free(D);
}
Exemplo n.º 6
0
void loadarray(int filenum,
		double Carrier[],
		double Modulator[],
		double PD[],
		double D[],
		double Amp[],
		int *nFMTones,
		double T[],
		double A[],
		int *nPoints,
		double xpan[],
		double ypan[]){
	
	char file_name[64];
	
	sprintf(file_name, "%dCarrier", filenum);
	printf("\tfile2array file %s...\n", file_name);
	file2array(file_name, Carrier);
	
	sprintf(file_name, "%dModulator", filenum);
	printf("\tfile2array file %s...\n", file_name);
	file2array(file_name, Modulator);
	
	sprintf(file_name, "%dPD", filenum);
	printf("\tfile2array file %s...\n", file_name);
	file2array(file_name, PD);

	sprintf(file_name, "%dD", filenum);
	printf("\tfile2array file %s...\n", file_name);
	file2array(file_name, D);

	sprintf(file_name, "%dAmp", filenum);
	printf("\tfile2array file %s...\n", file_name);
	file2array(file_name, Amp);
	
	*nFMTones = filecount(file_name);
	
	int i;
	double toneLength = 0;
	printf("test\n");
	for(i =0;i<*nFMTones;i++)
		toneLength = toneLength + D[i];
	
	printf("test\n");
	//changes Modulator Multiplier to Molulating Frequency
	for(i=0;i<*nFMTones;i++)
		Modulator[i] = Modulator[i] * Carrier[i];

	sprintf(file_name, "%dT", filenum);
	printf("\tfile2array file %s...\n", file_name);
	file2array(file_name, T);

	sprintf(file_name, "%dA", filenum);
	printf("\tfile2array file %s...\n", file_name);
	file2array(file_name, A);
	
	*nPoints = filecount(file_name);
	
	//panning
	//TODO x and y panning for 8 chan
	char xpanTime[64];
	char xpanStep[64];
	sprintf(xpanTime, "%dxpantime", filenum);
	sprintf(xpanStep, "%dxpanstep", filenum);
	
	int xpanPoints = filecount(xpanTime);
	
	char ypanTime[64];
	char ypanStep[64];
	sprintf(ypanTime, "%dypantime", filenum);
	sprintf(ypanStep, "%dypanstep", filenum);
	
	int ypanPoints = filecount(ypanTime);
	
	double *xX;
	double *xY;
	double *yX;
	double *yY;
	xX = (double *)Malloc(xpanPoints * sizeof(double));
	xY = (double *)Malloc(xpanPoints * sizeof(double));
	yX = (double *)Malloc(ypanPoints * sizeof(double));
	yY = (double *)Malloc(ypanPoints * sizeof(double));
	file2array(xpanTime, xX);
	file2array(xpanStep, xY);
	file2array(ypanTime, yX);
	file2array(ypanStep, yY);
	
	int x, xIndx, xrange;
	double yrange, m, m_inc;
	double sr = 44100;
	int samples = toneLength * sr; 
	//linear panning
	double x1, y1, x2, y2;
	
	x1 = xX[0];
	y1 = xY[0];
	xIndx = 0;

	for(i = 1; i < xpanPoints; i++){
		x2 = xX[i];
		y2 = xY[i];

		xrange = (x2 - x1) * samples;
		yrange = (y2 - y1);

		m = 0;
		m_inc = 1.0 / (xrange - 1.0);

		for(x = xIndx ; x < xIndx+xrange; x++){
			xpan[x] = y1 +(m * yrange);
			m = m + m_inc;
			//printf("xpan[x] = %f\n", xpan[x]);
		}

		xIndx = xIndx + xrange;

		y1 = y2;
		x1 = x2;
	}
	
	x1 = yX[0];
	y1 = yY[0];
	xIndx = 0;
	
	for(i = 1; i < ypanPoints; i++){
		x2 = yX[i];
		y2 = yY[i];

		xrange = (x2 - x1) * samples;
		yrange = (y2 - y1);

		m = 0;
		m_inc = 1.0 / (xrange - 1.0);

		for(x = xIndx ; x < xIndx+xrange; x++){
			ypan[x] = y1 +(m * yrange);
			m = m + m_inc;
			//printf("ypan[x] = %f\n", ypan[x]);
		}

		xIndx = xIndx + xrange;

		y1 = y2;
		x1 = x2;
	}
	Free(xX);
	Free(xY);
	Free(yX);
	Free(yY);
}