void test_assignment(void)
{
        printf("\ntest_assignment\n");

        {
                struct Node* f0 = node_new(__ASSIGNMENT);

                struct Node* n0 = create_declarator_scalar();

                struct Complex* n1val = complex_new(111,222);
                struct Node* n1 = node_new_leaf(__CONST_FLOAT, (void*)n1val);

                node_link(f0, n0);
                node_link(f0, n1);

                calcnode(f0);
        }

        {
                struct Node* f0 = node_new(__ASSIGNMENT);

                struct Node* n0 = create_declarator_array();

                struct Complex* n1val = complex_new(333,444);
                struct Node* n1 = node_new_leaf(__CONST_FLOAT, (void*)n1val);

                node_link(f0, n0);
                node_link(f0, n1);

                calcnode(f0);
        }

        g();
}
Beispiel #2
0
int main(int argc, char **argv)
{
	lock = malloc(sizeof(unsigned char));
	*lock = 0;

	FILE *fp = fopen("music.wav", "rb");

	if(fp == NULL)
	{
		fprintf(stderr, "failed to load music.wav\n");
		return -1;
	}

	mixer = mixer_create();

	struct node_s * n_sine = node_oscillator_create(oscillator_create(waveshape_sine_create(512)));
	struct node_s * n_music = node_oscillator_create(oscillator_create(waveshape_wav_create(fp)));
	//struct node_s * n_reverb = node_reverb_create(256, 0.5f);

	((struct oscillator_s *)n_sine->extra)->frequency = 10.0f;

	node_link(&n_sine->outputs[0], &n_music->inputs[0]);
	//node_link(&n_music->outputs[0], &n_reverb->inputs[0]);
	node_link(&n_music->outputs[0], &mixer->output_node->inputs[0]);
	node_link(&n_music->outputs[0], &mixer->output_node->inputs[1]);

	PaStream *stream;

	assert_pa_error(Pa_Initialize(), "initializing portaudio");
	assert_pa_error(Pa_OpenDefaultStream(&stream, 0, 2, paFloat32, SAMPLE_RATE, FRAMES_PER_BUFFER, callback, NULL), "opening default stream");
	assert_pa_error(Pa_StartStream(stream), "starting stream");

	for(unsigned char running=1; running;)
	{
		char c = fgetc(stdin);

		switch(c)
		{
			case 'q':
				running = 0;
		}
	}

	assert_pa_error(Pa_Terminate(), "terminating portaudio");

	return 0;
}
Beispiel #3
0
/**
 * Find a location of the suffix in the tree.
 * @param st the suffixtree in question
 * @param j the extension number counting from 0
 * @param i the current phase - 1
 * @param log the log to record errors in
 * @return the position (combined node and edge-offset)
 */ 
static pos *find_beta( suffixtree *st, int j, int i, plugin_log *log )
{
    pos *p;
    if ( st->old_j > 0 && st->old_j == j )
    {
        p = pos_create();
        p->loc = st->old_beta.loc;
        p->v = st->old_beta.v;
    }
    else if ( j>i )  // empty string
    {
        p = pos_create();
        p->loc = 0;
        p->v = st->root;
    }
    else if ( j==0 )    // entire string
    {
        p = pos_create();
        p->loc = i;
        p->v = st->f;
    }
    else // walk across tree
    {
        node *v = st->last.v;
        int len = st->last.loc-node_start(st->last.v)+1;
        path *q = path_create( node_start(v), len, log );
        v = node_parent( v );
        while ( v != st->root && node_link(v)==NULL )
        {
            path_prepend( q, node_len(v) );
            v = node_parent( v );
        }
        if ( v != st->root )
        {
            v = node_link( v );
            p = walk_down( st, v, q );
        }
        else
        {
            path_dispose( q );
            p = walk_down( st, st->root, path_create(j,i-j+1,log) );
        }
    }
    st->last = *p;
    return p;
}
Beispiel #4
0
/**
 * Find a location of the suffix in the tree.
 * @param j the extension number counting from 0
 * @param i the current phase - 1
 * @return the position (combined node and edge-offset)
 */
static pos *find_beta( int j, int i )
{
    pos *p;
    if ( old_j > 0 && old_j == j )
    {
        p = pos_create();
        p->loc = old_beta.loc;
        p->v = old_beta.v;
    }
    else if ( j>i )  // empty string
    {
        p = pos_create();
        p->loc = 0;
        p->v = root;
    }
    else if ( j==0 )    // entire string
    {
        p = pos_create();
        p->loc = i;
        p->v = f;
    }
    else // walk across tree
    {
        node *v = last.v;
        int len = last.loc-node_start(last.v)+1;
        path *q = path_create( node_start(v), len );
        v = node_parent( v );
        while ( v != root && node_link(v)==NULL )
        {
            path_prepend( q, node_len(v) );
            v = node_parent( v );
        }
        if ( v != root )
        {
            v = node_link( v );
            p = walk_down( v, q );
        }
        else
        {
            path_dispose( q );
            p = walk_down( root, path_create(j,i-j+1) );
        }
    }
    last = *p;
    return p;
}
struct Node* create_declarator_array(void)
{
        struct Node* f0 = node_new(__DECLARATOR);

        const char* str = "kakikukeko";
        char* iden = malloc(sizeof(*iden));
        strcpy(iden, str);
        struct Node* n0 = node_new_leaf(__IDENTIFIER, (void*)iden);

        struct Complex* index = complex_new(10, 0);
        struct Node* n1 = node_new_leaf(__CONST_FLOAT, (void*)index);

        node_link(f0, n0);
        node_link(f0, n1);

        return f0;
}
struct Node* create_selection_if(void)
{
        struct Node* f0 = node_new(__SELECTION_IF);

        struct Complex* n0val = complex_new(1, 0);
        struct Node* n0 = node_new_leaf(__CONST_FLOAT, (void*)n0val);

        struct Complex* n1val = complex_new(2, 0);
        struct Node* n1 = node_new_leaf(__CONST_FLOAT, (void*)n1val);

        struct Complex* n2val = complex_new(3, 0);
        struct Node* n2 = node_new_leaf(__CONST_FLOAT, (void*)n2val);

        node_link(f0, n0);
        node_link(f0, n1);
        node_link(f0, n2);

        return f0;
}
struct Node* create_declarator_scalar(void)
{
        struct Node* f0 = node_new(__DECLARATOR);

        const char* str = "aiueo";
        char* iden = malloc(sizeof(*iden));
        strcpy(iden, str);
        struct Node* n0 = node_new_leaf(__IDENTIFIER, (void*)iden);

        node_link(f0, n0);

        return f0;
}
struct arch_header *delete_arch(char *entry, char *arch_name)
{
	int arch_fd;
	int len, header_read, data_read[BUF_SIZE], check = 0;
	struct arch_header *head;
	struct arch_header *node = NULL;
	struct arch_header *temp = NULL;
	int count = 0, match = 0, unmatch = 0;
	struct arch_data data[BUF_SIZE];

	arch_fd = open(arch_name, O_RDONLY, 0664);

	head = (struct arch_header *) malloc(sizeof(struct arch_header));

	while((header_read = read(arch_fd, head, sizeof(struct arch_header))) > 0)
	{		
		if(strcmp(head->name, entry) != 0)
		{
			if(node->name == NULL)
			{
				node = (struct arch_header *) malloc(sizeof(struct arch_header));
				strcpy(node->name, head->name);
				node->file_info = head->file_info;
				node->next = NULL;

			}
			else
			{
				temp = (struct arch_header *) malloc(sizeof(struct arch_header));
				strcpy(temp->name, head->name);
				temp->file_info = head->file_info;
				temp->next = NULL;

				node_link(&node, temp);
			}

			check = lseek(arch_fd, head->file_info.st_size, SEEK_CUR);
			unmatch++;
		}
		else
		{
			check = lseek(arch_fd, head->file_info.st_size, SEEK_CUR);
			match++;
		}
		count++;
	}

	printf("read / count : %d, unmatch : %d, match : %d\n", count, unmatch, match);

	check = lseek(arch_fd, 0, SEEK_SET);
	count = unmatch;
	unmatch = 0;
	temp = node;

	while((header_read = read(arch_fd, head, sizeof(struct arch_header))) > 0)
	{		
		if(strcmp(head->name, temp->name) == 0 && unmatch<=count)
		{
			data[unmatch].buf = (char *)malloc(head->file_info.st_size);
			data_read[unmatch] = read(arch_fd, data[unmatch].buf, head->file_info.st_size);
			temp = temp->next;
			unmatch++;
		}
		else
		{
			check = lseek(arch_fd, head->file_info.st_size, SEEK_CUR);
		}
	}

	close(arch_fd);

	arch_fd = open(arch_name, O_WRONLY | O_TRUNC, 0664);
	temp = node;

	for(unmatch = 0; unmatch < count; unmatch++)
	{
		len = write(arch_fd, temp, sizeof(struct arch_header));
		len = write(arch_fd, data[unmatch].buf, data_read[unmatch]);
		temp = temp->next;
	}
	close(arch_fd);

	return node;
}