Esempio n. 1
0
wavfile::wavfile(const char * fname)
{
	auto file = fopen(fname, "rb");
	ready = false;
	
	if (file == NULL)
		puts("Could not open file.");
		
	fseek(file, 0, SEEK_END);
	auto filesize = ftell(file);
	fseek(file, 0, SEEK_SET);

	char riff[16];
	fread(riff, 4, 3, file);
	
	if(*(Uint32*)(riff) != 0x46464952) //'RIFF'
		puts("Not a RIFF file!");
	if(*(Uint32*)(riff+8) != 0x45564157) //'WAVE'
		puts("Not a WAVE file!");
	
	int havefmt = 0;
	while(!ferror(file) and !feof(file))
	{
		char subchunk[4];
		fread(subchunk, 4, 1, file);
		switch(*(Uint32*)(subchunk))
		{
		case 0x20746d66: // 'fmt '
			do_fmt(file);
			havefmt = 1;
			break;
		case 0x61746164: //'data'
			if(!havefmt)
				puts("NO FORMAT!!!");
			do_data(file);
			break;
		default:
			Uint32 len;
			fread(&len, 4, 1, file);
			if (len%2)
				len++;
			printf("Unknown chunk 0x%08X, seeking by 0x%08X\n", *(Uint32*)(subchunk), len);
			fseek(file, len, SEEK_CUR);
			if(ftell(file) >= filesize)
				goto out; // double break pls
		}
	}
	out:
	
	fclose(file);
	
	if(isfloatingpoint)
	{
		SDL_CreateThread(&normalize_float, "faucet\20mixer.cpp:normalize_float", this);
	}
	else
		ready = true;
}
Esempio n. 2
0
 void do_token(char *token,int token_type,int state,int level) {
   if (token_type==0 && level>last_level && last_type==0 && !level_array[level]) {
     strcpy(keys[level],token); // store current key, as we are going deeper...
   }
   if (token_type==0) {
     if (!level_array[level]) {
       strcpy(key,token);
       strcpy(keys[level],token); //
     } else {
       sprintf(key,"%d",level_index[level]);
       sprintf(keys[level],"%d",level_index[level]++);
       do_data(level,token,state);
     }
   } else if (token_type==1 && last_type!=0)
     printf("Error: no value for %s\n",key);
   else if (token_type==1 && last_type==0) {
     do_data(level,token,state);
   }
   last_type=token_type;
   last_level=level;
 }
Esempio n. 3
0
void *thread_fun(void *arg)
{
	PK_COMMON    pack;
	PK_REQUEST   rrq;
	PK_DATA      data;
	PK_ACK       ack;
	PK_ERROR     err;
	PK_IFLIVE    live;
	LOG_LIST     *loglist;
	MSG_ERROR    ero;
	int rdret=-1;
	int wrret=-1;
	int ret=-1;
	int maxfd;
	int recvpack=-1;

	maxfd=*((int *)arg);
	do{
		rdret=read(maxfd,&pack,sizeof(struct pk_common));
		if(rdret<0)
		{
			perror("error read - ");
			return;
		}
		//printf("%d\n",pack.opt_code);
		//printf("%s\n",pack.datas);
		switch(pack.opt_code)
		{
			case 1:
				do_request(pack,maxfd,&ero,&loglist);
				break;
			case 2:
				do_data(&pack,NULL);
				break;
			case 3:
				do_ack(&pack);
				break;
			case 4:
				do_error(&pack,&ero,&loglist);
				break;
			case 5:
				do_iflive(&pack);
				break;
		}
	}while(rdret>0);
	close(*(int*)arg);
}
Esempio n. 4
0
void do_container(void *data, unsigned len, int dir_in)
{
    struct generic_container *cont = data;
    if(cont->length != len)
        printf("DIE (%d <> %d)\n", cont->length, len);
    /*
    printf("container: len=%d type=%d (%s) code=0x%x id=%d dir_in=%d\n", cont->length,
        cont->type, cont_type_str(cont->type), cont->code, cont->transaction_id, dir_in);
    //*/
    unsigned nr_param = (cont->length - sizeof(struct generic_container)) / sizeof(uint32_t);
    if(nr_param > 5)
        nr_param = 5;
    uint32_t param[5];
    for(unsigned i = 0; i < nr_param; i++)
        param[i] = *(i + (uint32_t *)(cont + 1));

    if(cont->type == CONTAINER_COMMAND_BLOCK)
        do_cmd(cont->code, nr_param, param);
    else if(cont->type == CONTAINER_RESPONSE_BLOCK)
        do_resp(cont->code, nr_param, param);
    else if(cont->type == CONTAINER_DATA_BLOCK)
        do_data(cont->code, cont + 1, cont->length - sizeof(struct generic_container), dir_in);
}