Пример #1
0
zchar os_read_line (int max, zchar *buf, int timeout, int width, int continued)
{
  char c;
  int x,y;
  int i=0;
  int t=timeout*100;
  uint32 s,ms,tm;
  set_timeout(timeout);
  timer_ms_gettime(&s,&ms);

  i=strlen(buf);
  do {
    c=os_read_key(-1,1);
    if(c>=32 && c <= 176) c99_printf("%c",c);
    switch(c) {
    case 0:
    case 13:
      break;
    case 8:
      if(i>0) {
        i--;
        buf[i]='\0';
        getxy(&x,&y);
        locate(x-1,y);
      }
      break;
    default:
      buf[i]=c;
      i++;
      break;
    }
  } while (c!=13&&c!=0);
  buf[i]='\0';
  return c;
}
Пример #2
0
/* This is kind of approximate and works only with "localtime" */
int _gettimeofday_r(void * re, struct timeval *tv, struct timezone *tz) {
	uint32	m, s;
	
	assert( tv != NULL );

	timer_ms_gettime(&s, &m);
	tv->tv_sec = rtc_boot_time() + s;
	tv->tv_usec = m * 1000;

	return 0;
}
Пример #3
0
/* *callback(...)
 *
 * this procedure is called by the streaming server when it needs more PCM data
 * for internal buffering
 */
static void *callback(snd_stream_hnd_t hnd, int size, int * size_out)
{
#ifdef TIMING_TESTS
	int decoded_bytes = 0;
	uint32 s_s, s_ms, e_s, e_ms;
#endif

	// printf("sndoggvorbis: callback requested %d bytes\n",size);

	/* Check if the callback requests more data than our buffer can hold */
	if (size > BUF_SIZE)
		size = BUF_SIZE;

#ifdef TIMING_TESTS
	timer_ms_gettime(&s_s, &s_ms);
#endif

	/* Shift the last data the AICA driver took out of the PCM Buffer */
	if (last_read > 0) {
		pcm_count -= last_read;
		if (pcm_count < 0)
			pcm_count=0; /* Don't underrun */
		/* printf("memcpy(%08x, %08x, %d (%d - %d))\n",
			pcm_buffer, pcm_buffer+last_read, pcm_count-last_read, pcm_count, last_read); */
		memcpy(pcm_buffer, pcm_buffer+last_read, pcm_count);
		pcm_ptr = pcm_buffer + pcm_count;
	}

	/* If our buffer has not enough data to fulfill the callback decode 4 KB
	 * chunks until we have enough PCM samples buffered
	 */
	// printf("sndoggvorbis: fill buffer if not enough data\n");
	long pcm_decoded = 0;
	while(pcm_count < size) {
		//int pcm_decoded =  VorbisFile_decodePCMint8(v_headers, pcm_ptr, 4096);
		pcm_decoded = ov_read(&vf, pcm_ptr, 4096, &current_section);

		/* Are we at the end of the stream? If so and looping is
		   enabled, then go ahead and seek back to the first. */
		if (pcm_decoded == 0 && sndoggvorbis_loop) {
			/* Seek back */
			if (ov_raw_seek(&vf, 0) < 0) {
				dbglog(DBG_ERROR, "sndoggvorbis: can't ov_raw_seek to the beginning!\n");
			} else {
				/* Try again */
				pcm_decoded = ov_read(&vf, pcm_ptr, 4096, &current_section);
			}
		}

#ifdef TIMING_TESTS
		decoded_bytes += pcm_decoded;
#endif
		// printf("pcm_decoded is %d\n", pcm_decoded);
		pcm_count += pcm_decoded;
		pcm_ptr += pcm_decoded;

		//if (pcm_decoded == 0 && check_for_reopen() < 0)
		//	break;
		if (pcm_decoded == 0)
			break;
	}
	if (pcm_count > size)
		*size_out = size;
	else
		*size_out = pcm_count;

	/* Let the next callback know how many bytes the last callback grabbed
	 */
	last_read = *size_out;

#ifdef TIMING_TESTS
	if (decoded_bytes != 0) {
		int t;
		timer_ms_gettime(&e_s, &e_ms);
		t = ((int)e_ms - (int)s_ms) + ((int)e_s - (int)s_s) * 1000;
		printf("%dms for %d bytes (%.2fms / byte)\n", t, decoded_bytes, t*1.0f/decoded_bytes);
	}
#endif

	// printf("sndoggvorbis: callback: returning\n");

	if (pcm_decoded == 0)
		return NULL;
	else
		return pcm_buffer;
}