static void process_buffer_2(char *buf, int bufsize) { fprintf(stderr,"Got %d bytes from buffer 2\n",bufsize); process_buffer(buf,bufsize); }
static void input_sound(unsigned int sample_rate, unsigned int overlap, const char *ifname) { int sndparam; int fd; union { short s[8192]; unsigned char b[8192]; } b; float fbuf[16384]; unsigned int fbuf_cnt = 0; int i; short *sp; unsigned char *bp; int fmt = 0; if ((fd = open(ifname ? ifname : "/dev/dsp", O_RDONLY)) < 0) { perror("open"); exit (10); } sndparam = AFMT_S16_NE; /* we want 16 bits/sample signed */ if (ioctl(fd, SNDCTL_DSP_SETFMT, &sndparam) == -1) { perror("ioctl: SNDCTL_DSP_SETFMT"); exit (10); } if (sndparam != AFMT_S16_NE) { fmt = 1; sndparam = AFMT_U8; if (ioctl(fd, SNDCTL_DSP_SETFMT, &sndparam) == -1) { perror("ioctl: SNDCTL_DSP_SETFMT"); exit (10); } if (sndparam != AFMT_U8) { perror("ioctl: SNDCTL_DSP_SETFMT"); exit (10); } } sndparam = 0; /* we want only 1 channel */ if (ioctl(fd, SNDCTL_DSP_STEREO, &sndparam) == -1) { perror("ioctl: SNDCTL_DSP_STEREO"); exit (10); } if (sndparam != 0) { fprintf(stderr, "soundif: Error, cannot set the channel " "number to 1\n"); exit (10); } sndparam = sample_rate; if (ioctl(fd, SNDCTL_DSP_SPEED, &sndparam) == -1) { perror("ioctl: SNDCTL_DSP_SPEED"); exit (10); } if ((10*abs(sndparam-sample_rate)) > sample_rate) { perror("ioctl: SNDCTL_DSP_SPEED"); exit (10); } if (sndparam != sample_rate) { fprintf(stderr, "Warning: Sampling rate is %u, " "requested %u\n", sndparam, sample_rate); } #if 0 sndparam = 4; if (ioctl(fd, SOUND_PCM_SUBDIVIDE, &sndparam) == -1) { perror("ioctl: SOUND_PCM_SUBDIVIDE"); } if (sndparam != 4) { perror("ioctl: SOUND_PCM_SUBDIVIDE"); } #endif for (;;) { if (fmt) { i = read(fd, bp = b.b, sizeof(b.b)); if (i < 0 && errno != EAGAIN) { perror("read"); exit(4); } if (!i) break; if (i > 0) { for (; i >= sizeof(b.b[0]); i -= sizeof(b.b[0]), sp++) fbuf[fbuf_cnt++] = ((int)(*bp)-0x80) * (1.0/128.0); if (i) fprintf(stderr, "warning: noninteger number of samples read\n"); if (fbuf_cnt > overlap) { process_buffer(fbuf, fbuf_cnt-overlap); memmove(fbuf, fbuf+fbuf_cnt-overlap, overlap*sizeof(fbuf[0])); fbuf_cnt = overlap; } } } else { i = read(fd, sp = b.s, sizeof(b.s)); if (i < 0 && errno != EAGAIN) { perror("read"); exit(4); } if (!i) break; if (i > 0) { for (; i >= sizeof(b.s[0]); i -= sizeof(b.s[0]), sp++) fbuf[fbuf_cnt++] = (*sp) * (1.0/32768.0); if (i) fprintf(stderr, "warning: noninteger number of samples read\n"); if (fbuf_cnt > overlap) { process_buffer(fbuf, fbuf_cnt-overlap); memmove(fbuf, fbuf+fbuf_cnt-overlap, overlap*sizeof(fbuf[0])); fbuf_cnt = overlap; } } } } close(fd); }
static void input_file(unsigned int sample_rate, unsigned int overlap, const char *fname, const char *type) { struct stat statbuf; int pipedes[2]; int pid = 0, soxstat; int fd; int i; short buffer[8192]; float fbuf[16384]; unsigned int fbuf_cnt = 0; short *sp; /* * if the input type is not raw, sox is started to convert the * samples to the requested format */ if (!strcmp(fname, "-")) { // read from stdin and force raw input fd = 0; type = "raw"; } else if (!type || !strcmp(type, "raw")) { #ifdef WINDOWS if ((fd = open(fname, O_RDONLY | O_BINARY)) < 0) { #else if ((fd = open(fname, O_RDONLY)) < 0) { #endif perror("open"); exit(10); } } #ifndef ONLY_RAW else { if (stat(fname, &statbuf)) { perror("stat"); exit(10); } if (pipe(pipedes)) { perror("pipe"); exit(10); } if (!(pid = fork())) { char srate[8]; /* * child starts here... first set up filedescriptors, * then start sox... */ sprintf(srate, "%d", sample_rate); close(pipedes[0]); /* close reading pipe end */ close(1); /* close standard output */ if (dup2(pipedes[1], 1) < 0) perror("dup2"); close(pipedes[1]); /* close writing pipe end */ execlp("sox", "sox", "-t", type, fname, "-t", "raw", "-esigned-integer", "-b16", "-r", srate, "-", NULL); perror("execlp"); exit(10); } if (pid < 0) { perror("fork"); exit(10); } close(pipedes[1]); /* close writing pipe end */ fd = pipedes[0]; } #endif /* * demodulate */ for (;;) { i = read(fd, sp = buffer, sizeof(buffer)); if (i < 0 && errno != EAGAIN) { perror("read"); exit(4); } if (!i) break; if (i > 0) { for (; i >= sizeof(buffer[0]); i -= sizeof(buffer[0]), sp++) fbuf[fbuf_cnt++] = (*sp) * (1.0f/32768.0f); if (i) fprintf(stderr, "warning: noninteger number of samples read\n"); if (fbuf_cnt > overlap) { process_buffer(fbuf, fbuf_cnt-overlap); memmove(fbuf, fbuf+fbuf_cnt-overlap, overlap*sizeof(fbuf[0])); fbuf_cnt = overlap; } } } close(fd); #ifndef ONLY_RAW waitpid(pid, &soxstat, 0); #endif } void quit(void) { int i = 0; for (i = 0; i < NUMDEMOD; i++) { if(MASK_ISSET(i)) if (dem[i]->de_init) { dem[i]->de_init(); } } }
static void input_sound(unsigned int sample_rate, unsigned int overlap, const char *ifname) { audio_info_t audioinfo; audio_info_t audioinfo2; audio_device_t audiodev; int fd; short buffer[8192]; float fbuf[16384]; unsigned int fbuf_cnt = 0; int i; short *sp; if ((fd = open(ifname ? ifname : "/dev/audio", O_RDONLY)) < 0) { perror("open"); exit (10); } if (ioctl(fd, AUDIO_GETDEV, &audiodev) == -1) { perror("ioctl: AUDIO_GETDEV"); exit (10); } AUDIO_INITINFO(&audioinfo); audioinfo.record.sample_rate = sample_rate; audioinfo.record.channels = 1; audioinfo.record.precision = 16; audioinfo.record.encoding = AUDIO_ENCODING_LINEAR; /*audioinfo.record.gain = 0x20; audioinfo.record.port = AUDIO_LINE_IN; audioinfo.monitor_gain = 0;*/ if (ioctl(fd, AUDIO_SETINFO, &audioinfo) == -1) { perror("ioctl: AUDIO_SETINFO"); exit (10); } if (ioctl(fd, I_FLUSH, FLUSHR) == -1) { perror("ioctl: I_FLUSH"); exit (10); } if (ioctl(fd, AUDIO_GETINFO, &audioinfo2) == -1) { perror("ioctl: AUDIO_GETINFO"); exit (10); } fprintf(stdout, "Audio device: name %s, ver %s, config %s, " "sampling rate %d\n", audiodev.name, audiodev.version, audiodev.config, audioinfo.record.sample_rate); for (;;) { i = read(fd, sp = buffer, sizeof(buffer)); if (i < 0 && errno != EAGAIN) { perror("read"); exit(4); } if (!i) break; if (i > 0) { for (; i >= sizeof(buffer[0]); i -= sizeof(buffer[0]), sp++) fbuf[fbuf_cnt++] = (*sp) * (1.0/32768.0); if (i) fprintf(stderr, "warning: noninteger number of samples read\n"); if (fbuf_cnt > overlap) { process_buffer(fbuf, fbuf_cnt-overlap); memmove(fbuf, fbuf+fbuf_cnt-overlap, overlap*sizeof(fbuf[0])); fbuf_cnt = overlap; } } } close(fd); }
void done () { if (_buffer_curr > _buffer) { process_buffer(); } }
void done () { if (_buffer_curr > _buffer) { assert(_hr_curr > _hr_buffer, "_hr_curr should be consistent with _buffer_curr"); process_buffer(); } }
int main(void) { static int cog; static char tbuf[_TOKEN_BUFFER]; char c; /************************ initializations ****************************/ sleep(1); //wait for the serial terminal to start /* display system info on serial terminal */ printf("\n*** Pcon %i.%i ***\n\n",_major_version,_minor_version); #if _DRIVEN == _DIOB printf("system is configured to drive a Parallax Digital IO Board\n"); #else printf("system is configured to drive 5 IO pins\n"); #endif /* build file set prefix */ strcat(file_set_prefix,_F_PREFIX); strcat(file_set_prefix,_FILE_SET_ID); printf("file set prefix <%s>\n",file_set_prefix); /* check out the SD card */ if(sd_setup()) { printf("**** sd_setup aborted application ****\n"); return 1; } /* start monitoring the real time clock DS3231 */ rtc_cb.rtc.tdb_lock = locknew(); lockclr(rtc_cb.rtc.tdb_lock); cog = start_rtc(&rtc_cb.rtc); if(cog == -1) { printf("** error attempting to start rtc cog\n cognew returned %i\n\n",cog); return 1; } printf(" DS3231 monitored by code running on cog %i\n",cog); /* setup the dio control block */ dio_cb.dio.tdb_lock = rtc_cb.rtc.tdb_lock; dio_cb.dio.cca_lock = locknew(); lockclr(dio_cb.dio.cca_lock); dio_cb.dio.sch_lock = locknew(); lockclr(dio_cb.dio.sch_lock); dio_cb.dio.update_ptr = &(rtc_cb.rtc.update); dio_cb.dio.td_ptr = &(rtc_cb.rtc.td_buffer); *dio_cb.dio.update_ptr = 0; dio_cb.dio.sch_ptr = bbb; /* start the dio cog */ cog = start_dio(&dio_cb.dio); if(cog == -1) { printf("** error attempting to start dio cog\n cognew returned %i\n\n",cog); return 1; } #if _DRIVEN == _DIOB printf(" DIO Board controlled by code running on cog %i\n",cog); #else printf(" relays controlled by code running on cog %i\n",cog); #endif /* set up unbuffered nonblocking io */ setvbuf(stdin, NULL, _IONBF, 0); setvbuf(stdout, NULL, _IONBF, 0); stdin->_flag &= ~_IOCOOKED; stdin->_flag |= _IONONBLOCK; /* initialize fsm(s) parameters */ input_buffer_ptr = input_buffer;//setup so actions routines can mess the buffer cmd_state = 0; //set initial command parser state char_state = 0; //set initial caracter parser state // hold_day = -1; //force schedule load first time through the main loop *input_buffer = ' '; //load a a blank into the buffer to force first prompt process_buffer(); printf("initialization complete\n"); /************************************************************/ /********************** main processing loop ****************/ /************************************************************/ while(1) { /* check for problems */ if(ckeck_abort()) return 1; /* check the token stack */ while(pop_cmd_q(tbuf)) { cmd_fsm(tbuf,&cmd_state); //cycle cmd fsm until queue is empty } /* grab a character from the keyboard if one is present */ c = fgetc(stdin); //nonblocking read /* process input char */ if(c!=_NO_CHAR) { fputc(c, stdout); // echo char if(c==_CR) fputc(_CR, stdout); //second CR after uer input char_fsm(char_type(c),&char_state,&c); //cycle fsm } }; printf("\nnormal termination\n\n"); return 0; }
static void on_depth_frame (GFreenectDevice *kinect, gpointer user_data) { gboolean smoothing_enabled; gint width, height; gint dimension_factor; guchar *grayscale_buffer; guint16 *depth; BufferInfo *buffer_info; gsize len; GError *error = NULL; GFreenectFrameMode frame_mode; ClutterContent *content; depth = (guint16 *) gfreenect_device_get_depth_frame_raw (kinect, &len, &frame_mode); width = frame_mode.width; height = frame_mode.height; g_object_get (skeleton, "dimension-reduction", &dimension_factor, NULL); buffer_info = process_buffer (depth, width, height, dimension_factor, THRESHOLD_BEGIN, THRESHOLD_END); skeltrack_skeleton_track_joints (skeleton, buffer_info->reduced_buffer, buffer_info->reduced_width, buffer_info->reduced_height, NULL, on_track_joints, buffer_info); content = clutter_actor_get_content (depth_tex); if (!SHOW_SKELETON) { grayscale_buffer = create_grayscale_buffer (buffer_info, dimension_factor); if (depth_image == NULL) depth_image = clutter_image_new (); /* ref because we don't want it to be freed */ if (depth_canvas == content) g_object_ref (depth_canvas); clutter_actor_set_content (depth_tex, depth_image); if (! clutter_image_set_data (CLUTTER_IMAGE (depth_image), grayscale_buffer, COGL_PIXEL_FORMAT_RGB_888, width, height, 0, &error)) { g_debug ("Error setting texture area: %s", error->message); g_error_free (error); } g_slice_free1 (width * height * sizeof (guchar) * 3, grayscale_buffer); } else { /* ref because we don't want it to be freed */ if (depth_image && depth_image == content) g_object_ref (depth_image); clutter_actor_set_content (depth_tex, depth_canvas); } }