コード例 #1
0
ファイル: sound.c プロジェクト: carriercomm/minisphere
static duk_ret_t
js_Sound_finalize(duk_context* ctx)
{
	sound_t* sound;

	duk_get_prop_string(ctx, 0, "\xFF" "ptr"); sound = duk_get_pointer(ctx, -1); duk_pop(ctx);
	free_sound(sound);
	return 0;
}
コード例 #2
0
ファイル: mixtest.c プロジェクト: ricpelo/prometeo
void ourexitproc(void)
  {
    int i;

    for (i=0; i < NUMSOUNDS; ++i)
      if (sound[i] != NULL) free_sound(sound+i);
#ifdef SHAREDEMB
    shutdown_sharing();
#endif
  }
コード例 #3
0
ファイル: mixtest.c プロジェクト: ricpelo/prometeo
void shutdown(void)
  {
    int i;

    shutdown_mixing();
    shutdown_sb();

    for (i=0; i < NUMSOUNDS; i++)
      free_sound(sound+i);
#ifdef SHAREDEMB
    shutdown_sharing();
#endif
    printf("\n");
  }
コード例 #4
0
ファイル: sound.c プロジェクト: carriercomm/minisphere
static duk_ret_t
js_LoadSound(duk_context* ctx)
{
	duk_int_t n_args = duk_get_top(ctx);
	const char* filename = duk_require_string(ctx, 0);
	duk_bool_t is_stream = n_args >= 2 ? duk_require_boolean(ctx, 1) : true;

	sound_t* sound;
	char*    sound_path;

	sound_path = get_asset_path(filename, "sounds", false);
	sound = load_sound(sound_path, is_stream);
	free(sound_path);
	if (sound == NULL)
		duk_error_ni(ctx, -1, DUK_ERR_ERROR, "LoadSound(): Failed to load sound file '%s'", filename);
	duk_push_sphere_sound(ctx, sound);
	free_sound(sound);
	return 1;
}
コード例 #5
0
ファイル: main.c プロジェクト: metredigm/hunter
int main(int argc, char** argv) {
	init_core();
	debug_message("[hunter] initialized core");

	init_graphic();
	debug_message("[hunter] initialized graphics, mode W%d H%d", window_get_width(global_get(global_get_singleton(), GLOBAL_WINDOW)), window_get_height(global_get(global_get_singleton(), GLOBAL_WINDOW)));

	init_sound();
	debug_message("[hunter] initialized sound");

	init_systems();
	debug_message("[hunter] initialized systems");

	window* window_handle = global_get(global_get_singleton(), GLOBAL_WINDOW);
	input* input_handle = global_get(global_get_singleton(), GLOBAL_INPUT);
	syscontainer* syscontainer_handle = global_get(global_get_singleton(), GLOBAL_SYSCONTAINER);
	text* text_handle = global_get(global_get_singleton(), GLOBAL_TEXT);
	hl_render* hl_render_handle = global_get(global_get_singleton(), GLOBAL_HL_RENDER);
	shader* shader_texture_handle = global_get(global_get_singleton(), GLOBAL_SHADER_TEXTURE);
	camera* camera_handle = global_get(global_get_singleton(), GLOBAL_CAMERA);
	debug_draw* debug_draw_handle = global_get(global_get_singleton(), GLOBAL_DEBUG_DRAW);

	float delta_ref_point = time_get_elapsed(window_handle);
	float delta_accumulator = 0.0f;
	float delta_frame_time = 0.0f;

	float fps_accumulator = 0.0f;
	float fps_value = 0.0f;
	float fps_value_last = fps_value;
	unsigned int fps_counter = 0;

	unsigned int game_kill_flag = 0;

	debug_message("[hunter] posting init event to systems");
	syscontainer_post_event(syscontainer_handle, EVENT_INIT);

	while (!game_kill_flag) {
		delta_frame_time = time_get_elapsed(window_handle) - delta_ref_point;
		delta_ref_point = time_get_elapsed(window_handle);

		window_update(window_handle);

		input_state current_input_state;
		input_get_input_state(input_handle, &current_input_state);

		game_kill_flag |= window_get_should_close(window_handle);
		game_kill_flag |= current_input_state.key_dev;

		window_set_clear_color(window_handle, 1.0f, 0.0f, 1.0f, 0.0f);
		debug_draw_clear(debug_draw_handle);
		window_clear(window_handle);

		delta_accumulator += delta_frame_time;

		if (delta_accumulator < 0.0f) {
			delta_accumulator = 0.0f;
		}

		while (delta_accumulator >= 1.0f / DELTA_REFERENCE_FPS) {
			syscontainer_post_event(syscontainer_handle, EVENT_PRE_LOGIC);
			syscontainer_post_event(syscontainer_handle, EVENT_LOGIC);
			syscontainer_post_event(syscontainer_handle, EVENT_POST_LOGIC);

			delta_accumulator -= 1.0f / DELTA_REFERENCE_FPS;
		}

		syscontainer_post_event(syscontainer_handle, EVENT_DRAW);

		window_set_blend_mode(window_handle, WINDOW_BLEND_ALPHA);

		debug_draw_render_all(debug_draw_handle);

		hl_render_draw(hl_render_handle, shader_texture_handle, camera_handle);
		hl_render_clear(hl_render_handle);

		fps_counter++;
		fps_accumulator += delta_frame_time;

		if (fps_accumulator >= 1.0f) {
			fps_value_last = fps_value;
			fps_value = (float) fps_counter / fps_accumulator;
			fps_counter = 0;
			fps_accumulator = 0.0f;
		}

		text_batch fps_batch = {20, 20, 0.2f, 0.8f, 1.0f, 1.0f, "", "monospace", 12};
		sprintf(fps_batch.text_data, "FPS : %3.2f (%3.2f)", fps_value, fps_value - fps_value_last);

		text_submit_batch(text_handle, &fps_batch);

		text_render_all(text_handle);
		text_flush_batch(text_handle);

		window_swap_buffers(window_handle);
	}

	debug_message("[hunter] posting destroy event to systems");
	syscontainer_post_event(syscontainer_handle, EVENT_DESTROY);

	free_systems();
	free_sound();
	free_graphic();
	free_core();

	h_free_all();

	debug_message("[hunter] terminated cleanly");
	return 0;
}
コード例 #6
0
ファイル: atsh-files.c プロジェクト: bion/ats
void atsin(char *pointer)
{
  int sizef=0, length=0, i, x;
  float  dt=0., normfac=0.;
  double aux=0., magic=123.00;
  int n1=2, n2=0;
  FILE *pundo;

  need_byte_swap=FALSE;  
  *info=0;

  //if(filew){gtk_widget_hide(GTK_WIDGET(filew));}

  if((pundo=fopen(undo_file,"wb"))!=0) {
    fclose(pundo);    
  }
  else {
    Popup("WARNING: Could not delete the UNDO backup file, UNDO disabled");
    undo=FALSE;
  }

  view_type=SON_VIEW;
  scale_type=AMP_SCALE;

  //the contrast of display
  valexp=.5;

  *ats_tittle=0;
  strcat(ats_tittle,pointer);    

  //g_print ("%s ", pointer);

  if((atsfin=fopen(ats_tittle,"rb"))==0) {
    strcat(info, "Could not open ");
    strcat(info, ats_tittle);
    Popup(info);
    *ats_tittle=0;
    floaded=FALSE;
    draw_default();
    init_scalers(FALSE);
    show_file_name(win_main,NULL);
    return;
  }

  length=my_filelength(atsfin);
  //g_print (" (%d BYTES) \n", length);
  
  fread(atshed,sizeof(ATS_HEADER),1,atsfin);

  //here we try to deal with the BIG/LITTLE ENDIAN stuff 
  if(atshed->mag != magic) { 
    aux=atshed->mag;		
    atshed->mag =byte_swap(&aux);

    if((int)atshed->mag != (int)magic) { 
      Popup("ERROR:ATS MAGIC NUMBER NOT FOUND IN HEADER...");
      *ats_tittle=0;
      fclose(atsfin);
      floaded=FALSE;
      need_byte_swap=FALSE;
      init_scalers(FALSE);
      draw_default();
      show_file_name(win_main,NULL);
      return;
    } 
    else {
      need_byte_swap=TRUE;               //now we know that we must swap the bytes 
      byte_swap_header(atshed,FALSE);    //swap bytes of header data first
    }  
 
  }
 

  //////////////////////find out length of data and check it for consistence////////////////

  if(FILE_HAS_PHASE) {
    n1+=1;
  }
  if(FILE_HAS_NOISE) {
    n2+=1;
  }

  sizef =  sizeof(ATS_HEADER) +
    ((int)atshed->par * (int)atshed->fra * sizeof(double) * n1) +
    (sizeof(double) * (int)atshed->fra) + 
    (ATSA_CRITICAL_BANDS * (int)atshed->fra * sizeof(double) * n2);



  if(sizef != length) { //error: the file size does not match the header data
    Popup("ERROR: FILE SIZE DOES NOT MATCH HEADER DATA...");
    *ats_tittle=0;
    fclose(atsfin);
    floaded=FALSE;
    init_scalers(FALSE);
    draw_default();
    show_file_name(win_main,NULL);
    return; 
  }
  //////////////////////////
 
  //     if(!ats_sound) {
  //       Popup("Could not allocate enough memory for ATS data");
  //       *ats_tittle=0;
  //       fclose(atsfin);
  //       floaded=FALSE;
  //       init_scalers(FALSE);
  //       draw_default();
  //       return; 
  //     }

  if(ats_sound != NULL) free_sound(ats_sound);
  ats_sound=(ATS_SOUND*)malloc(sizeof(ATS_SOUND));
  init_sound(ats_sound, (int)atshed->sr, (int)atshed->fs, (int)atshed->ws, (int)atshed->fra+1, (double)atshed->dur, (int)atshed->par, FILE_HAS_NOISE);

  selected=(short*)realloc(selected, (int)atshed->par * sizeof(short) + 1);
    
  //all partials are UNselected by default
  for(i=0; i<(int)atshed->par; i++) selected[i]=FALSE;
  ////////////////////////////////////////////////////////////////////////////////////////

  normfac= 1. / atshed->ma;
  ///EVERYTHING SEEMS TO BE OK, THEN LOAD THE DATA...
    fseek(atsfin,sizeof(ATS_HEADER),SEEK_SET);
  

    for(i=0; i<(int)atshed->fra; ++i) {
   
      fread(&aux,1,sizeof(double),atsfin);  //read just one time value per frame
   
      if(need_byte_swap==TRUE) ats_sound->time[0][i]=byte_swap(&aux); 
      else ats_sound->time[0][i]=aux; 


      for (x=0; x<(int)atshed->par; ++x) {
   
	fread(&aux,1,sizeof(double),atsfin);  //read amp value for each partial 
	if(need_byte_swap==TRUE) {
	  ats_sound->amp[x][i]=byte_swap(&aux); 
	} 
	else {
	  ats_sound->amp[x][i]= aux; 
	} 
	fread(&aux,1,sizeof(double),atsfin); //read freq value for each partial 
	if(need_byte_swap==TRUE) {
	  ats_sound->frq[x][i]=byte_swap(&aux); 
	} 
	else {
	  ats_sound->frq[x][i]= aux; 
	}
   
	if(FILE_HAS_PHASE) {                 //read phase data if any...
	  fread(&aux,1,sizeof(double),atsfin); 
	  if(need_byte_swap==TRUE) {
	    ats_sound->pha[x][i]=byte_swap(&aux); 
	  } 
	  else {
	    ats_sound->pha[x][i]= aux; 
	  }
	}
      }  
   
      if (FILE_HAS_NOISE) {
	for (x=0; x<ATSA_CRITICAL_BANDS; x++) {//read residual analysis data if any...
	  fread(&aux,1,sizeof(double),atsfin);
	  if(need_byte_swap==TRUE) {
	    ats_sound->band_energy[x][i]=byte_swap(&aux);  
	  }
	  else {
	    ats_sound->band_energy[x][i]=aux;
	  }
	    
	}
      }
	
    }
    //// find out max. dt
    maxtim=0.;
					  
    for(i=0; i<(int)atshed->fra - 1; ++i) {
      dt=ats_sound->time[0][1+i] - ats_sound->time[0][i];
      if(dt > maxtim) {maxtim=dt;} //find out max. dt.
    }
    //g_print ("MAX. delta time is = %f secs.\n",maxtim );
    smr_done=FALSE;

    //the horizontal selection parameters 
    selection->from=selection->to=0;
    selection->f1=selection->f2=0;
    selection->x1=selection->y1=selection->x2=selection->y2=0;
    vertex1=vertex2=FALSE;
 

    if (FILE_HAS_PHASE) {
      sparams->upha=TRUE;
    }
    else{
      sparams->upha=FALSE;
    }
 
    //Default initialization of synthesis data...
    sparams->sr  = 44100.; 
    sparams->amp = 1.;
    if(FILE_HAS_NOISE) {
      sparams->ramp = 1.;
    }
    else {
      sparams->ramp = 0.;
    }
    sparams->frec = 1.;
    sparams->max_stretch= 1.;
    sparams->beg = 0.;
    sparams->end = ats_sound->time[0][(int)atshed->fra-1] + ats_sound->time[0][1];
    sparams->allorsel=FALSE;

    //initialization of smart selection data

    sdata->from=  1;
    sdata->to=(int)atshed->par; 
    sdata->step=  1;
    sdata->tres=  -96.;
    sdata->met =  FALSE;

    floaded=TRUE;
    init_scalers(TRUE); 
    ned=led=0;
    undo=TRUE;

    //the contrast of display
    valexp=.5;
    GTK_ADJUSTMENT(valadj)->upper=100.;
    GTK_ADJUSTMENT(valadj)->lower=1.;
    gtk_adjustment_set_value(GTK_ADJUSTMENT(valadj), valexp * 100.);  
 

    if(tWedit == NULL) {
      tWedit=create_edit_curve(TIM_EDIT, timenv);
    }
    else {
      set_time_env(timenv, TRUE);
    }
    show_file_name(win_main,pointer);
    fclose(atsfin);
    draw_pixm(); 
 
    return;
}