예제 #1
0
void trans()
{
    Serial.println("Enter a msg (max 32 Characters)");
    while(!Serial.available());
      delay(32); // for collection
      char tx[32];
      for(int j=0;j<32;j++)
      {
       tx[j]=Serial.read();
       if(tx[j]==(char)-1)    // to avoid writing unkown char in spaces
       {
         tx[j]='\0';
         goto loop1;
       }
      }
      loop1:
     loop2: 
     bool done = radio.write(tx, sizeof(tx));  
     if(done==false)
     { 
       retx++;
       Serial.println("Tx Failed");
       if(retx<10)
       {
       goto loop2;
       }else retx=0;
     }
     radio.startListening();
     print_welcome_message();
}
예제 #2
0
파일: tetris.c 프로젝트: seL4/refos
int
main()
{
    /* Future Work 3:
       How the selfloader bootstraps user processes needs to be modified further. Changes were
       made to accomodate the new way that muslc expects process's stacks to be set up when
       processes start, but the one part of this that still needs to changed is how user processes
       find their system call table. Currently the selfloader sets up user processes so that
       the selfloader's system call table is used by user processes by passing the address of the
       selfloader's system call table to the user processes via the user process's environment
       variables. Ideally, user processes would use their own system call table.
    */

    uintptr_t address = strtoll(getenv("SYSTABLE"), NULL, 16);
    refos_init_selfload_child(address);
    int c, i, *ptr;
    int delay = INITIAL_DELAY_MS;
    refos_initialise();

    peekShape = NULL;

    /* Initialise board. */
    ptr = board;
    for (i = B_SIZE - 1; i>=0; i--) {
        *ptr++ = i < 25 || i % B_COLS < 2 ? A_BG_W : RESETATTR;
    }

    srand((unsigned int) RANDOM_SEED);

    clrscr();

    print_welcome_message();
    printf("      Press the space bar to continue...\n");
    show_online_help();

    while (1) {
        c = io_nonblock_getkey();
        rand();
        if (c == ' ') break;
    }
    clrscr();
    show_online_help();

    /* Main game loop. */
    shape = next_shape();
    while (!exitGame) {
        c = io_nonblock_getkey();
        rand();
        if (c >= 0) {
            game_frame(c);
        } else {
            game_frame(0);
            usleep((delay - level * LEVEL_DECREASE_DELAY_MS) * 1000);
        }
    }

    gotoxy (0, 25);
    printf("Game over! You reached %d points.\n", points);
}
예제 #3
0
void setup()
{
  Serial.begin(9600);
  //delay(1000);
  radio.begin();
  print_welcome_message();
  radio.openReadingPipe(1,pipe[0]);//For Receiving Operation
  radio.openWritingPipe(pipe[1]);//For Transmitting Operation
  radio.startListening();

}
예제 #4
0
void engine_start(void){
  // start ncurses screen
  initscr();
  start_color();

  // customizations
  raw();
  nodelay(stdscr, TRUE);
  noecho();
  nonl();
  curs_set(0);
  keypad(stdscr, TRUE);
  refresh();

  // render game
  draw_border();
  print_welcome_message();
}
예제 #5
0
파일: celp13k.c 프로젝트: RupW/celp13k
int main( int argc, char *argv[] )
{
  int   i;
  char  fn_inspeech[80], fn_outspeech[80];
  FILE  *fin, *fout;
  int   numread, nsamp;
  float temp[MAXSF];
  unsigned long frame_num;
  unsigned long total_frames;
  unsigned long fer_count;
  struct ENCODER_MEM     encoder_memory;
  struct DECODER_MEM     decoder_memory;
  struct PACKET          packet;
  struct CONTROL         control;
  int input_format;
  int output_format;

#if USE_CALLOC
  float *in_speech;
  float *out_speech;
#else
    float   in_speech[FSIZE+LPCSIZE-FSIZE+LPCOFFSET];
    float   out_speech[FSIZE];
#endif

  memset(&encoder_memory, 0, sizeof(encoder_memory));
  memset(&decoder_memory, 0, sizeof(decoder_memory));
  memset(&packet, 0, sizeof(packet));
  memset(&control, 0, sizeof(control));


#if USE_CALLOC
  alloc_mem_for_speech(&in_speech, &out_speech);
#endif

  for(i = 0; i < argc; i++)
    fprintf(stdout, "%s ", argv[i]);
  fprintf(stdout, "\n");

  parse_command_line(argc, argv, fn_inspeech, fn_outspeech, &control);

  initialize_encoder_and_decoder(&encoder_memory, &decoder_memory, 
				 &control);

  print_welcome_message();

  /*** Init TTY/TDD Routines and Varibles ***/

  if( tty_debug_flag )
      tty_debug();

  if( tty_option == TTY_NO_GAIN )
  {
      fprintf(stdout," TTY OPTION = NO GAIN\n");
      init_tty_enc( &tty_enc_char, &tty_enc_header, &tty_enc_baud_rate);
      init_tty_dec();
  }
  else
  {
      tty_option = 0;
      fprintf(stdout," TTY OPTION = OFF\n");
  }

  if( trans_fname != NULL )
  {
      fprintf(stdout,"FER SIMULATOR ON:  seed = %d\n",fer_sim_seed);
  }


  for(i = 0; i < LPCORDER; i++)
    packet.lsp[i] = packet.lpc[i] = 0;

  encoder_memory.frame_num = 0;
  frame_num = 0;
  fer_count = 0;

  if (control.decode_only == YES)
  {
    /* Input is a CELP file */
    switch (control.celp_file_format)
    {
    case FORMAT_PACKET:
      open_binary_input_file(&fin, fn_inspeech);
      total_frames = GetNumFrames(fin, sizeof(short)*WORDS_PER_PACKET);
      input_format = FORMAT_PACKET;
      break;
    case FORMAT_QCP:
      open_qcp_input_file(&fin, fn_inspeech);
      total_frames = get_qcp_packet_count();
      input_format = FORMAT_QCP;
      break;
    default:
      fprintf(stderr, "unsupported decode_only input format %d\n", control.celp_file_format);
      exit(-2);
    }
  }
  else
  {
    /* Input is an audio file */
    open_binary_input_file(&fin, fn_inspeech);
    input_format = FORMAT_RAW_AUDIO;
    total_frames = GetNumFrames(fin, sizeof(short)*FSIZE);
  }

  if ((control.form_res_out == YES)
    || (control.target_after_out == YES)
    || (control.cb_out == YES)
    || (control.pitch_out == YES))
  {
    /* Output is encoder state for debugging */
    open_binary_output_file(&fout, fn_outspeech);
    output_format = FORMAT_DEBUG_OUTPUT;
  }
  else if (control.encode_only == YES)
  {
    /* Output is a CELP file */
    switch (control.celp_file_format)
    {
    case FORMAT_PACKET:
      open_binary_output_file(&fout, fn_outspeech);
      output_format = FORMAT_PACKET;
      break;
    case FORMAT_QCP:
      open_qcp_output_file(&fout, fn_outspeech, total_frames);
      output_format = FORMAT_QCP;
      break;
    default:
      fprintf(stderr, "unsupported encode_only output format %d\n", control.celp_file_format);
      exit(-2);
    }
  }
  else
  {
    /* Output is an audio file */
    open_binary_output_file(&fout, fn_outspeech);
    output_format = FORMAT_RAW_AUDIO;
  }

  if(control.decode_only == NO)
  {
#if 0
    if (read_samples(fin, in_speech, LPCSIZE-FSIZE+LPCOFFSET)
	!=LPCSIZE-FSIZE+LPCOFFSET)
    {
      printf("Not even enough samples for 1 frame!\n");
      usage(&control);
    }
#else
    for( i=0 ; i < LPCSIZE-FSIZE+LPCOFFSET ; i++ )
    {
        in_speech[i] = 0;
    }
#endif
  }



  /*-----------------------------------------------
  *                   Main Loop
  *------------------------------------------------*/

  while( control.num_frames == UNLIMITED || frame_num < control.num_frames )
  {
    fprintf(stderr,"Processing %lu of %lu  FER = %.2f%%\r",
        frame_num, total_frames, 100.0*fer_count/(frame_num+1));

    if (control.decode_only==NO)
    {
        nsamp = read_samples(fin, &in_speech[LPCSIZE-FSIZE+LPCOFFSET], FSIZE);
        if( nsamp <= 0 )
        {
            break;
        }
        else if(nsamp < FSIZE)
        {
            for (i=nsamp; i<FSIZE; i++)
            {
                in_speech[LPCSIZE-FSIZE+LPCOFFSET+i]=0;
            }
        }

        encoder(in_speech, &packet, &control,
                &encoder_memory, out_speech);

        update_snr(ENCODER, in_speech, out_speech, &(control.snr));

    }

    if (control.decode_only==YES)
    {
      if (input_format == FORMAT_QCP)
      {
        numread = read_qcp_packet(fin, packet.data, WORDS_PER_PACKET);
        if (numread == 0) break;
      }
      else
      {
        /* FORMAT_PACKET */
        numread = read_packet(fin, packet.data, WORDS_PER_PACKET);
        if( numread != WORDS_PER_PACKET)
        {
            if(numread != 0)
            {
              fprintf(stderr,
                  "%s: Wrong number of words read: %d\n", argv[0], numread);
            }
            break;
        }
      }
    }

    if(control.encode_only==NO)
    {

        if (control.output_encoder_speech==NO)
        {
            decoder(out_speech, &packet, &control, &decoder_memory);

            if( packet.data[0] == ERASURE )
            {
                fer_count++;
            }

            if(control.decode_only==NO)
            {
                update_snr(DECODER, in_speech, out_speech, &(control.snr));
            }
        }
        i = write_samples(fout,out_speech,FSIZE); 
    }
    else
    {
        if( trans_fname != NULL )
        {
            fer_sim( &(packet.data[0]) );
        }
        if( packet.data[0] == ERASURE )
        {
            fer_count++;
        }

        if (output_format == FORMAT_QCP)
        {
            i = write_qcp_packet(fout, packet.data, WORDS_PER_PACKET);
        }
        else
        {
            i = write_packet(fout, packet.data, WORDS_PER_PACKET);
        }
    }


    /***** Update in_speech buffer ***************/

    for (i=0; i<LPCSIZE-FSIZE+LPCOFFSET; i++)
    {
        in_speech[i]=in_speech[i+FSIZE];
    }

    frame_num++;
    encoder_memory.frame_num = frame_num;

  } /* end main while() */

  if (output_format == FORMAT_QCP)
  {
    finish_qcp_output_file(fout);
  }

  fclose(fin);
  fclose(fout);

  if ((control.encode_only==NO)&&(control.decode_only==NO))
  {
    compute_snr(&(control.snr), &control);
  }
  if( control.decode_only == NO )
  {
      /* calculate the avg. rate for active speech for the entire file */
      temp[0] = (encoder_memory.full_cnt + encoder_memory.full_force +
	     encoder_memory.full_cnt_t + encoder_memory.full_force_t)*14.4+ 
	    (encoder_memory.half_cnt + encoder_memory.half_force +
	     encoder_memory.half_cnt_t + encoder_memory.half_force_t)*7.2+ 
	    (encoder_memory.quarter_cnt + encoder_memory.quarter_cnt_t)*3.6;
      temp[0] /= (encoder_memory.total_speech_frames+
	      (STATWINDOW-encoder_memory.block_cnt));

      if(control.reduced_rate_flag != 0)
      {
          printf("\n The target_snr_threshold at the end of the run was %f",
             encoder_memory.target_snr_thr);

          printf("\n The average rate for the entire file was %f",temp[0]);
          i = STATWINDOW-encoder_memory.block_cnt+encoder_memory.total_speech_frames;
          temp[1] = i;
          printf("\n The # of speech frames in the file is  = %d",i);

          i = encoder_memory.full_cnt+encoder_memory.full_cnt_t;
          printf("\n The percent of frames at 14.4 is %f",100.0*i/temp[1]);
          i = encoder_memory.full_force+encoder_memory.full_force_t;
          printf("\n The percent of frames forced to  14.4 is %f",100.*i/temp[1]);
          i = encoder_memory.half_cnt+encoder_memory.half_cnt_t;
          printf("\n The percent of frames at 7.2 is %f",100.*i/temp[1]);
          i = encoder_memory.half_force+encoder_memory.half_force_t;
          printf("\n The percent of frames forced to  7.2 is %f",100.*i/temp[1]);
          i = encoder_memory.quarter_cnt+encoder_memory.quarter_cnt_t;
          printf("\n The percent of frames coded at 3.6 is %f\n",100.*i/temp[1]);

      }
  }

  if(control.encode_only == NO)
    print_erasure_count();
  free_encoder_and_decoder(&encoder_memory, &decoder_memory);

#if USE_CALLOC
  free((char*) in_speech);
  free((char*) out_speech);
#endif

  print_farewell_message();

  exit(0);

}/* end of main() */