예제 #1
0
파일: pll.cpp 프로젝트: happycube/ld-decode
// This method performs interpolated zero-crossing detection and stores the
// result a sample deltas (the number of samples between each
// zero-crossing).  Interpolation of the zero-crossing point provides a
// result with sub-sample resolution.
//
// Since the EFM data is NRZ-I (non-return to zero inverted) the polarity of the input
// signal is not important (only the frequency); therefore we can simply
// store the delta information.  The resulting delta information is fed to the
// phase-locked loop which is responsible for correcting jitter errors from the ZC
// detection process.
QByteArray Pll::process(QByteArray buffer)
{
    // Input data is really qint16 wrapped in a byte array
    qint16 *inputBuffer = reinterpret_cast<qint16*>(buffer.data());

    // Clear the PLL result buffer
    pllResult.clear();

    // In order to hold state over buffer read boundaries, we keep
    // global track of the direction and delta information
    if (zcFirstRun) {
        zcFirstRun = false;

        zcPreviousInput = 0;
        prevDirection = false; // Down
        delta = 0;
    }

    for (qint32 i = 0; i < (buffer.size() / 2); i++) {
        qint16 vPrev = zcPreviousInput;
        qint16 vCurr = inputBuffer[i];

        bool xup = false;
        bool xdn = false;

        // Possing zero-cross up or down?
        if (vPrev < 0 && vCurr >= 0) xup = true;
        if (vPrev > 0 && vCurr <= 0) xdn = true;

        // Check ZC direction against previous
        if (prevDirection && xup) xup = false;
        if (!prevDirection && xdn) xdn = false;

        // Store the current direction as the previous
        if (xup) prevDirection = true;
        if (xdn) prevDirection = false;

        if (xup || xdn) {
            // Interpolate to get the ZC sub-sample position fraction
            qreal prev = static_cast<qreal>(vPrev);
            qreal curr = static_cast<qreal>(vCurr);
            qreal fraction = (-prev) / (curr - prev);

            // Feed the sub-sample accurate result to the PLL
            pushEdge(delta + fraction);

            // Offset the next delta by the fractional part of the result
            // in order to maintain accuracy
            delta = 1.0 - fraction;
        } else {
            // No ZC, increase delta by 1 sample
            delta += 1.0;
        }

        // Keep the previous input (so we can work across buffer boundaries)
        zcPreviousInput = inputBuffer[i];
    }

    return pllResult;
}
예제 #2
0
파일: search.c 프로젝트: vickytu/cs223
/* and bfs if useQueue == 1 */
static void
genericSearch(struct searchInfo *r, int root, int useQueue)
{
    /* queue/stack */
    struct queue q;

    /* edge we are working on */
    struct edge cur;

    /* start with empty q */
    /* we need one space per edge */
    /* plus one for the fake (root, root) edge */
    q.e = malloc(sizeof(*q.e) * (graphEdgeCount(r->graph) + 1));
    assert(q.e);

    q.bottom = q.top = 0;

    /* push the root */
    pushEdge(r->graph, root, root, &q);

    /* while q.e not empty */
    while(q.bottom < q.top) {
        if(useQueue) {
            cur = q.e[q.bottom++];
        } else {
            cur = q.e[--q.top];
        }


        /* did we visit sink already? */
        if(r->parent[cur.v] != SEARCH_INFO_NULL) continue; 
        
        /* no */
        assert(r->reached < graphVertexCount(r->graph));
        r->parent[cur.v] = cur.u;
        r->time[cur.v] = r->reached;
        r->preorder[r->reached++] = cur.v;
        if(cur.u == cur.v) {
            /* we could avoid this if we were certain SEARCH_INFO_NULL */
            /* would never be anything but -1 */
            r->depth[cur.v] = 0;
        } else {
            r->depth[cur.v] = r->depth[cur.u] + 1;
        }

        /* push all outgoing edges */
        graphForeach(r->graph, cur.v, pushEdge, &q);
    }

    free(q.e);
}
예제 #3
0
파일: search.c 프로젝트: vickytu/cs223
/* returns endpoints of a cycle */
static int *
genericSearchModified(struct searchInfo *r, int root, int useQueue)
{
    /* queue/stack */
    struct queue q;

    /* edge we are working on */
    struct edge cur;

    int node;

    int *cycle;
    cycle = malloc(sizeof(int) * 2);

    /* start with empty q */
    /* we need one space per edge */
    /* plus one for the fake (root, root) edge */
    q.e = malloc(sizeof(*q.e) * (graphEdgeCount(r->graph) + 1));
    assert(q.e);

    q.bottom = q.top = 0;

    /* push the root */
    pushEdge(r->graph, root, root, &q);

    /* while q.e not empty */
    while(q.bottom < q.top) {
        if(useQueue) {
            cur = q.e[q.bottom++];
        } else {
            cur = q.e[--q.top];
        }
        node = 0;

        /* did we visit sink already? */
        if(r->parent[cur.v] != SEARCH_INFO_NULL) {
            /* yes. we know that cur.u is the not the parent of cur.v. but is this a cycle? */
            while(r->preorder[node] != cur.v) {
            //if(r->preorder[node] != r->parent[cur.u] && r->preorder[node] != cur.v) {
                if(graphHasEdge(r->graph, cur.u, r->preorder[node])) {
                /*printf("cycle found containing %d and %d\n", cur.u, r->preorder[node]);*/
                cycle[0] = cur.u;
                cycle[1] = r->preorder[node];
                goto out;
            }
           // }
            node++;
        }
            continue; 
        }
        

        /* no */
        assert(r->reached < graphVertexCount(r->graph));
        r->parent[cur.v] = cur.u;
        r->time[cur.v] = r->reached;
        r->preorder[r->reached++] = cur.v;
        if(cur.u == cur.v) {
            /* we could avoid this if we were certain SEARCH_INFO_NULL */
            /* would never be anything but -1 */
            r->depth[cur.v] = 0;
        } else {
            r->depth[cur.v] = r->depth[cur.u] + 1;
        }

        /* push all outgoing edges */
        graphForeach(r->graph, cur.v, pushEdge, &q);
    }
    out:
    free(q.e);
    return cycle;
}
예제 #4
0
void generateMapMesh(Map *map)
{
	static int divisor = 1;
	int x;
	int y;
	int z;
	// = map->depth;
	//int zlevel = map->depth;
	//float fx;
	//float fy;
	//float fz;
	//float normalize;
	//if (z < 0) z = 0;
	//if (z > MAP_LEVELS) z = MAP_LEVELS-1;
	gamePointi location;
	//gamePointi testPoint;
	
	
	clock_t starttime;
	clock_t endtime;

	starttime = clock();

	//tileInfo result;
	tileInfo thisPoint;

	//map->Vertices()->clear();
	map->tempVertices->clear();

	//float r=0;
	//float g=0;
	//bool exist;
	vertex_t vertex;
	for (x = -1; x <= map->width; x++) 
	{
		for (y = -1; y <= map->height; y++)
		{
			for(z = -1; z <= map->depth; z++)
			{

			location.x = x;
			location.y = y;
			location.z = z;
			//eximap->getTileInfo(location).status;
			//if (false)
			thisPoint = map->getTileAdjacencyInfo(location);
			if (thisPoint.status == success) //Tile is Empty or out of scope
			{
				/*
				testPoint = location;
				testPoint.z++;
				result = map->getTileInfo(testPoint);*/
				/*fx = (float)x/map->width;
				fy = (float)y/map->height;
				fz = (float)z/map->depth;
				normalize = sqrt(fx*fx+fy*fy+fz*fz);*/
				vertex.normal[0] = 0.577f;
				vertex.normal[1] = 0.577f;
				vertex.normal[2] = 0.577f;
				vertex.color[0] = thisPoint.r;
				vertex.color[1] = thisPoint.g;
				vertex.color[2] = thisPoint.b;
				vertex.color[3] = 1.0f;
					
					//vertex.normal[0] = 0.0f;
					//vertex.normal[1] = 0.0f;
					//vertex.normal[2] = 1.0f;
					
				vertex.position[0] = location.x;
				vertex.position[1] = location.y;
				vertex.position[2] = location.z;

				if (thisPoint.top == false)
				{/*
					vertex.color[0] = thisPoint.r;
					vertex.color[1] = thisPoint.g;
					vertex.color[2] = thisPoint.b;
					vertex.color[3] = 1.0f;
					
					vertex.normal[0] = 0.0f;
					vertex.normal[1] = 0.0f;
					/vertex.normal[2] = 1.0f;
					
					vertex.position[0] = location.x;
					vertex.position[1] = location.y;
					vertex.position[2] = location.z;*/
					pushEdge(0, vertex, map->tempVertices);
				}
				/*
				testPoint = location;
				testPoint.z--;
				result = map->getTileInfo(testPoint);
				*/
				if (thisPoint.bottom == false)
				{/*
					vertex.color[0] = thisPoint.r;
					vertex.color[1] = thisPoint.g;
					vertex.color[2] = thisPoint.b;
					vertex.color[3] = 1.0f;
					//vertex.normal[0] = 1.0f;
					//vertex.normal[1] = 0.0f;
					//vertex.normal[2] = 0.0f;
					vertex.position[0] = location.x;
					vertex.position[1] = location.y;
					vertex.position[2] = location.z;*/
					pushEdge(1, vertex, map->tempVertices);
				}
				/*
				testPoint = location;
				testPoint.x++;
				result = map->getTileInfo(testPoint);
				*/
				if (thisPoint.right == false)
				{/*
					vertex.color[0] = thisPoint.r;
					vertex.color[1] = thisPoint.g;
					vertex.color[2] = thisPoint.b;
					vertex.color[3] = 1.0f;
					//vertex.normal[0] = -1.0f;
					//vertex.normal[1] = 0.0f;
					//vertex.normal[2] = 0.0f;
					vertex.position[0] = location.x;
					vertex.position[1] = location.y;
					vertex.position[2] = location.z;*/
					pushEdge(2, vertex, map->tempVertices);
				}
				/*
				testPoint = location;
				testPoint.x--;
				result = map->getTileInfo(testPoint);
				*/
				if (thisPoint.left == false)
				{/*
					vertex.color[0] = thisPoint.r;
					vertex.color[1] = thisPoint.g;
					vertex.color[2] = thisPoint.b;
					vertex.color[3] = 1.0f;
					//vertex.normal[0] = 0.0f;
					//vertex.normal[1] = 1.0f;
					//vertex.normal[2] = 0.0f;
					vertex.position[0] = location.x;
					vertex.position[1] = location.y;
					vertex.position[2] = location.z;*/
					pushEdge(3, vertex, map->tempVertices);
				}
				/*
				testPoint = location;
				testPoint.y++;
				result = map->getTileInfo(testPoint);
				*/
				if (thisPoint.back == false)
				{/*
					vertex.color[0] = thisPoint.r;
					vertex.color[1] = thisPoint.g;
					vertex.color[2] = thisPoint.b;
					vertex.color[3] = 1.0f;
					//vertex.normal[0] = 0.0f;
					//vertex.normal[1] = -1.0f;
					//vertex.normal[2] = 0.0f;
					vertex.position[0] = location.x;
					vertex.position[1] = location.y;
					vertex.position[2] = location.z;*/
					pushEdge(4, vertex, map->tempVertices);
				}
				/*
				testPoint = location;
				testPoint.y--;
				result = map->getTileInfo(testPoint);
				*/
				if (thisPoint.front == false)
				{/*
					vertex.color[0] = thisPoint.r;
					vertex.color[1] = thisPoint.g;
					vertex.color[2] = thisPoint.b;
					vertex.color[3] = 1.0f;
					//vertex.normal[0] = 0.0f;
					//vertex.normal[1] = 0.0f;
					//vertex.normal[2] = 1.0f;
					vertex.position[0] = location.x;
					vertex.position[1] = location.y;
					vertex.position[2] = location.z;*/
					pushEdge(5, vertex, map->tempVertices);
				}
				}
			}
			//else
		
		}
	}
	std::vector<vertex_t> *temp = map->vertex_data;
	map->vertex_data = map->tempVertices;
	map->tempVertices = temp;
	endtime;
	/*
	endtime = clock();
	clock_t dif = (endtime - starttime) * 1000 / CLOCKS_PER_SEC;
	printf ("\n buffer generated in %i ms\n", dif );
	*/

}