Ejemplo n.º 1
0
Archivo: ui.cpp Proyecto: paulyc/asr
void UITrack::set_fine(double v)
{
    fine_val = 800.0 -	1600.*v;
//	printf("fine_val %f\n", fine_val);
    update_frequency(coarse_val+fine_val);
    _ui->_io->GetTrack(id)->set_output_sampling_frequency(coarse_val+fine_val);
}
Ejemplo n.º 2
0
Archivo: ui.cpp Proyecto: paulyc/asr
void UITrack::set_coarse(double v)
{
    coarse_val = 48000.0 / (1.0 + .4 * v -0.2);
//	printf("coarse_val %f\n", _track2.coarse_val);
    update_frequency(coarse_val+fine_val);
    _ui->_io->GetTrack(id)->set_output_sampling_frequency(coarse_val+fine_val);
}
Ejemplo n.º 3
0
// Fills the output buffer.
static void audio_cb(void *, uint8_t *stream, int len)
{
  uint16_t *audio = reinterpret_cast<uint16_t *>(stream);

  for (int i = 0; i < len / 2; i++) {
    if (symbol_position >= SYMBOL_LENGTH) {
      symbol_position -= SYMBOL_LENGTH;
      update_frequency();
    }

    audio[i] = 32768;
    if (period_length) {
      audio[i] += 20000 * sinf(2*PI * symbol_position / period_length);
    }

    symbol_position += 1.0 / SAMPLE_RATE;
  }
}
Ejemplo n.º 4
0
	/*!
	 * \internal
	 *
	 * Add \a event with \a time occurence of this event to update statistics.
	 * Complexity: O(log N) on average, where N - number of containing events
	 */
	void add_event(const E &event, time_t time)
	{
		std::unique_lock<std::mutex> locker(m_lock);
		auto it = m_treap.find(event.get_key());
		if (it) {
			update_weight(*it, time, m_period, event.get_weight());
			update_frequency(*it, time, m_period, 1.);
			it->set_time(time);
			m_treap.decrease_key(it);
		} else {
			if (m_num_events < m_max_events) {
				m_treap.insert(new E(event));
				++m_num_events;
			} else {
				auto t = m_treap.top();
				m_treap.erase(t);
				*t = event;
				m_treap.insert(t);
			}
		}
	}
Ejemplo n.º 5
0
int main(int argc, char *argv[]){

  // 1. Initialization
  int c;
  symbol *root;
  root=init_symbol(ROOT_NODE);
  root->frequency=NON_EXISTENT;
  root->parent=root;
  
  // 1.a. init: file pointers
  FILE *inputfile;
  FILE *outputfile;
  inputfile=NULL;
  outputfile=NULL;

  if (argc >=2)
    inputfile = fopen(argv[1],"r");
  
  if (argc >=3)
    outputfile = fopen(argv[2],"w");
  
  if (inputfile == NULL) {
    fprintf(stderr, "Can't open input file. \n");
    exit(1);
  }

  if (outputfile == NULL) {
    outputfile=stdout;
  }
  
  // 2. count the frequency of each character in inputfile 
  while((c=fgetc(inputfile))!=EOF){
    update_frequency(root,c);
  }
  update_frequency(root,-1);


  // 3. Make the huffman tree
  while(count_parentless_nodes(root) > 1){
    symbol *node1,*node2, *newnode;
    node1 = get_rarest_parentless_node(root);
    node1->parent=node1; //temporarily
    node2 = get_rarest_parentless_node(root);
    node2->parent=node2; //temporarily
    newnode = new_node(node1, node2);
    insert_symbol(root,newnode);
  }


  // 4. Output symbol mappings
  for(c=-1;c<256;c++){
    char *encodingstring;
    encodingstring=get_encoding(root,c);
    int freq=get_frequency(root,c);
    if (freq > 0){
      /*if (c <=127 && c>=32 )
	fprintf(outputfile,"%c\t%d\t%s\n", c, freq, encodingstring);    
      else */
	fprintf(outputfile,"%d\t%d\t%s\n", c, freq, encodingstring);    
    }
    free(encodingstring);
  }
  fprintf(outputfile,"\n");    

  
  // 5. Output encoding of inputfile
  rewind(inputfile);
  while((c=fgetc(inputfile))!=EOF){
    char *encodingstring;
    encodingstring=get_encoding(root,c);
    fprintf(outputfile, "%s", encodingstring);
    free(encodingstring);
  }
  char *encodingstring;
  encodingstring=get_encoding(root,EOF);
  fprintf(outputfile, "%s", encodingstring);
  free(encodingstring);
  fprintf(outputfile,"\n");    

  free_symbol(root);
  
  
  // 6. Close file pointers
  fclose(inputfile);
  fclose(outputfile);
}
Ejemplo n.º 6
0
void settings_menu() {

	unsigned char *fbuffer,fin;
	unsigned char texto[41];
	int ancho=screen->w;

	fbuffer=screen->pixels;

	fin=1;

	texto[0]=0;

	do {
		clean_screen();

		print_string(fbuffer,"Current settings",-1,20,15,0,ancho);
		switch(ordenador.mode128k) {
		case 0:
			if(ordenador.issue==2)
				sprintf(texto,"Mode: 48K issue2");
			else
				sprintf(texto,"Mode: 48K issue3");
		break;
		case 1:
			sprintf(texto,"Mode: Sinclair 128K");
		break;
		case 2:
			sprintf(texto,"Mode: Amstrad +2");
		break;
		case 3:
			sprintf(texto,"Mode: Amstrad +2A/+3");
		break;
		case 4:
			sprintf(texto,"Mode: Spanish 128K");
		break;
		}
  
		print_string(fbuffer,texto,-1,45,14,0,ancho);

		switch(ordenador.joystick[0]) {
		case 0:
			sprintf(texto,"Joystick emulation: Cursor");
			break;
		case 1:
			sprintf(texto,"Joystick emulation: Kempston");
			break;
		case 2:
			sprintf(texto,"Joystick emulation: Sinclair (1)");
			break;
		case 3:
			sprintf(texto,"Joystick emulation: Sinclair (2)");
			break;
		}
		print_string(fbuffer,texto,-1,65,13,0,ancho);

		if(ordenador.ay_emul)
			sprintf(texto,"AY-3-8912 Emulation: enabled");
		else
			sprintf(texto,"AY-3-8912 Emulation: disabled");

		print_string(fbuffer,texto,-1,85,11,0,ancho);

		if(ordenador.mdr_active)
			sprintf(texto,"Interface I Emulation: enabled");
		else
			sprintf(texto,"Interface I Emulation: disabled");

		print_string(fbuffer,texto,-1,105,15,0,ancho);
	
		if(ordenador.dblscan)
			sprintf(texto,"Double scan: enabled");
		else
			sprintf(texto,"Double scan: disabled");

		print_string(fbuffer,texto,-1,125,12,0,ancho);

		if(ordenador.turbo)
			sprintf(texto,"TURBO auto mode: enabled");
		else
			sprintf(texto,"TURBO auto mode: disabled");
		print_string(fbuffer,texto,-1,145,14,0,ancho);

		switch (ordenador.bw) {
			case 0:
			default:
			print_string(fbuffer,"TV Set: \001\012C\001\014o\001\011l\001\016o\001\013r",-1,165,15,0,ancho);
			break;
			case 1:
			print_string(fbuffer,"TV Set: \001\011B\001\012&\001\014W",-1,165,15,0,ancho);
			break;
			case 2:
			print_string(fbuffer,"TV Set: \001\014Green",-1,165,15,0,ancho);
			break;
		}
	
		print_string(fbuffer,"1:",30,190,12,0,ancho);
		print_string(fbuffer,"48K issue2",78,190,15,0,ancho);

		print_string(fbuffer,"2:",350,190,12,0,ancho);
		print_string(fbuffer,"48K issue3",398,190,15,0,ancho);

		print_string(fbuffer,"3:",30,220,12,0,ancho);
		print_string(fbuffer,"Sinclair 128K",78,220,15,0,ancho);

		print_string(fbuffer,"4:",350,220,12,0,ancho);
		print_string(fbuffer,"Amstrad +2",398,220,15,0,ancho);

		print_string(fbuffer,"5:",30,250,12,0,ancho);
		print_string(fbuffer,"Amstrad +2A/+3",78,250,15,0,ancho);

		print_string(fbuffer,"6:",350,250,12,0,ancho);
		print_string(fbuffer,"Spanish 128K",398,250,15,0,ancho);

		print_string(fbuffer,"7:",30,280,12,0,ancho);
		print_string(fbuffer,"Cursor",78,280,15,0,ancho);

		print_string(fbuffer,"8:",350,280,12,0,ancho);
		print_string(fbuffer,"Kempston",398,280,15,0,ancho);

		print_string(fbuffer,"9:",30,310,12,0,ancho);
		print_string(fbuffer,"Sinclair (1)",78,310,15,0,ancho);

		print_string(fbuffer,"0:",350,310,12,0,ancho);
		print_string(fbuffer,"Sinclair (2)",398,310,15,0,ancho);

		print_string(fbuffer,"I:",30,340,12,0,ancho);
		print_string(fbuffer,"Interface I",78,340,15,0,ancho);

		print_string(fbuffer,"D:",350,340,12,0,ancho);
		print_string(fbuffer,"Double Scan",398,340,15,0,ancho);

		print_string(fbuffer,"A:",350,370,12,0,ancho);
		print_string(fbuffer,"AY emulation",398,370,15,0,ancho);
		print_string(fbuffer,"T:",30,370,12,0,ancho);
		print_string(fbuffer,"TURBO mode",78,370,15,0,ancho);

		print_string(fbuffer,"V:",30,400,12,0,ancho);
		print_string(fbuffer,"TV Set mode",78,400,15,0,ancho);
		
		#ifndef GEKKO
		print_string(fbuffer,"F:",350,400,12,0,ancho);
		print_string(fbuffer,"Full screen",398,400,15,0,ancho);
		#endif
		
		print_string(fbuffer,"ESC:",168,450,12,0,ancho);
		print_string(fbuffer,"return emulator",232,450,15,0,ancho);

		switch(wait_key()) {
		case SDLK_ESCAPE:
		case SDLK_RETURN:
			fin=0;
		break;
		case SDLK_1:
			ordenador.issue=2;
			ordenador.mode128k=0;
			ordenador.ay_emul=0;
			ResetComputer();
		break;
		case SDLK_2:
			ordenador.issue=3;
			ordenador.mode128k=0;
			ordenador.ay_emul=0;
			ResetComputer();
		break;
		case SDLK_3:
			ordenador.issue=3;
			ordenador.mode128k=1;
			ordenador.ay_emul=1;
			ordenador.videosystem=0;
			ordenador.currah_active = 0;
			ResetComputer();
		break;
		case SDLK_4:
			ordenador.issue=3;
			ordenador.mode128k=2;
			ordenador.ay_emul=1;
			ordenador.videosystem=0;
			ordenador.currah_active = 0;
			ResetComputer();
		break;
		case SDLK_5:
			ordenador.issue=3;
			ordenador.mode128k=3;
			ordenador.ay_emul=1;
			ordenador.videosystem=0;
			ordenador.mdr_active=0;
			ordenador.currah_active = 0;
			ResetComputer();
		break;
		case SDLK_6:
			ordenador.issue=3;
			ordenador.mode128k=4;
			ordenador.ay_emul=1;
			ordenador.videosystem=0;
			ordenador.currah_active = 0;
			ResetComputer();
		break;
		case SDLK_7:
			ordenador.joystick[0]=0;
		break;
		case SDLK_8:
			ordenador.joystick[0]=1;
		break;
		case SDLK_9:
			ordenador.joystick[0]=2;
		break;
		case SDLK_0:
			ordenador.joystick[0]=3;
		break;
		case SDLK_i:
			if(ordenador.mode128k!=3) {
				ordenador.mdr_active=1-ordenador.mdr_active;
				ResetComputer();
			}
		break;
		case SDLK_d:
			ordenador.dblscan=1-ordenador.dblscan;
			update_npixels();
		break;
		case SDLK_a:
			ordenador.ay_emul=1-ordenador.ay_emul;
		break;
		case SDLK_v:
			ordenador.bw=(ordenador.bw+1)%3;
			computer_set_palete();
		break;
		case SDLK_t:
			curr_frames=0;
			update_frequency(0); //set deafult machine frequency
			jump_frames=0;
			ordenador.turbo_state = 0;
			if(ordenador.turbo){
				ordenador.turbo = 0;	
			} else {
				ordenador.turbo = 1; //Auto mode	
			}
		break;
		#ifndef GEKKO
		case SDLK_f:
			SDL_Fullscreen_Switch();
		break;
		#endif
		}
	} while(fin);

	clean_screen();
}