Example #1
0
		static Ref<Sound> decode_pcm16_codec (const Buffer * buf, ALint channel_count, ALint bits_per_sample, ALfloat sample_frequency)
		{
			if (host_endian() == PCM16Endian) {
				return new Sound(data_format(channel_count, bits_per_sample), sample_frequency, buf);
			} else {
				DynamicBuffer copy(buf->size(), true);

				for (unsigned i = 0; i < buf->size(); i += 2) {
					int16_t sample;
					buf->read(i, sample, PCM16Endian);
					copy.append(sample);
				}

				return new Sound(data_format(channel_count, bits_per_sample), sample_frequency, &copy);
			}
		}
Example #2
0
// Work out which data format to use for given filename
DataFormat *data_format(const char *filename)
{
  if(filename == NULL) {
    // Return default file format

#ifdef PDBF
    //output.write("\tUsing default format (PDB)\n");
    return new PdbFormat;
#else

#ifdef NCDF
    //output.write("\tUsing default format (NetCDF)\n");
    return new NcFormat;
#else

#error No file format available; aborting.

#endif // NCDF
#endif // PDBF
  }

  // Extract the file extension

  int len = strlen(filename);

  int ind = len-1;  
  while((ind != -1) && (filename[ind] != '.')) {
    ind--;
  }
  
  const char *s = filename + ind+1;

  // Match strings
  
#ifdef PDBF
  const char *pdb_match[] = {"pdb"};
  if(match_string(s, 1, pdb_match) != -1) {
    output.write("\tUsing PDB format for file '%s'\n", filename);
    return new PdbFormat;
  }
#endif

#ifdef NCDF
  const char *ncdf_match[] = {"cdl", "nc", "ncdf"};
  if(match_string(s, 3, ncdf_match) != -1) {
    output.write("\tUsing NetCDF format for file '%s'\n", filename);
    return new NcFormat;
  }
#endif

  output.write("\tFile extension not recognised for '%s'\n", filename);
  // Set to the default
  return data_format(NULL);
}
Example #3
0
		static Ref<Sound> decode_pcm8s_codec (const Buffer * buf, ALint channel_count, ALint bits_per_sample, ALfloat sample_frequency)
		{
			DynamicBuffer copy;
			copy.assign(*buf);

			int8_t *d = (int8_t *)copy.begin();
			std::size_t i;

			for (i = 0; i < copy.size(); i++)
				d[i] += (int8_t) 128;

			return new Sound(data_format(channel_count, bits_per_sample), sample_frequency, &copy);
		}
Example #4
0
/////////////////////03--30--03--30////////////////////////////
///////////////////get_status_res//////////////////////////////
////////////get  cgminer  state&& send////////////////////
int send_getstatus_res(char *cmd_server_code)
{
    char *api_len=NULL;
    char *buf_data=NULL;
    char *cuniqid;
    int len,i;
    short int port;
    int statebody_size=0;
    char ipaddr[40];
    char *cmd_server;
    char *s4_dataformat_dir;
    char *api_command;
    for(i=0;i<COMMAND_SUM;i++)
    {
        if(strcmp(cmd_server_code,server_command_code[i])==0)
        {
        	len = strlen(dataformat_conf_dir[i]) + 1;
            s4_dataformat_dir =(char *)malloc(len * sizeof(char));
            memset(s4_dataformat_dir,0,len);
            strcpy(s4_dataformat_dir,dataformat_conf_dir[i]);

        	len = strlen(server_command[i]) + 1;
            api_command = (char *)malloc(len * sizeof(char));
            memset(api_command,0,len);
            strcpy(api_command,server_command[i]);

        	len = strlen(command_code[i]) + 1;
            cmd_server = (char *)malloc(len * sizeof(char));
            memset(cmd_server,0,len);
            strcpy(cmd_server,command_code[i]);
            break;
        }
    }

    buf_data=(char*)calloc(4096,sizeof(char));
    //cuniqid= (char*)calloc(10,sizeof(char));
    len=strlen(gen_cuniqid(deal_package_cmd.pkg_nonce));

    //Get_Port
    //Get_IP
    #ifdef OPENWRT
    port=4028;
    #endif // OPENWRT
    #ifdef BB_BLACK
    char port_str[10];
    port=atoi(read_bb_black_switch(bb_black_conf_dir,"port_local",port_str));
    #endif // BB_BLACK

    if(!get_ip(ETH,ipaddr))
    {
        DEBUG_printf("get IP error\n");
    }
    #ifdef PC_IP
    port=4028;
    strcpy(ipaddr,ip_pc);
    #endif

    api_len=callapi(api_command, ipaddr,port);

    if(strlen(api_len) == 0)
    {
        DEBUG_printf("nothing returned form callapi\n\n\n ");
        return 0;
    }
    //DEBUG_printf("result of callapi:%s\n ",api_len);
    statebody_size=strlen(data_format(s4_dataformat_dir,buf_data,api_len));

    DEBUG_printf("state_len=%d\n",(statebody_size+len));
    send_head(cmd_server,(statebody_size+len));


    if ((sendbytes = senddata(ssl,sockfd,deal_package_cmd.pkg_nonce, len)) ==-1)
    {
        perror("send");
    }

    if ( (sendbytes =senddata(ssl,sockfd,buf_data, (statebody_size))) ==-1)
    {
        perror("send");
    }
    DEBUG_printf("sendbytes=%d\n",sendbytes);
    DEBUG_printf("send pakge str :%s\n",buf_data);

    if(cmd_server)
        free(cmd_server);
    if(s4_dataformat_dir)
        free(s4_dataformat_dir);
    if(api_command)
        free(api_command);
    if(api_len)
        free(api_len);
    free(buf_data);
    //free(cuniqid);
    return 1;
}
Example #5
0
		static Ref<Sound> decode_linear_codec (const Buffer * buf, ALint channel_count, ALint bits_per_sample, ALfloat sample_frequency)
		{
			return new Sound(data_format(channel_count, bits_per_sample), sample_frequency, buf);
		}
Example #6
0
Datafile::Datafile()
{
  low_prec = false;
  setFormat(data_format()); // Set default format
}
Example #7
0
char *solution_data_format(char *param, short dec_digits, char char_com)
{
    char *result = malloc(4 + pow(2, dec_digits/10) + strlen(param));
    sprintf(result, "%c %s = %s\n", char_com, param, data_format(1, dec_digits) + 1);
    return result;
}