int main(int argc, char **argv) { /* 模块初始化 */ exc_init(); /* 中断初始化 */ sys_timer_init(); /* 系统时钟初始化 */ light_init(); /* LED灯初始化 */ switch_init(); /* 开关初始化 */ speaker_init(); /* 蜂鸣器初始化 */ motor_init(); /* 电机初始化 */ steer_init(); /* 舵机初始化 */ decoder_init(); /* 编码器初始化 */ serial_initialize((intptr_t)(NULL)); /* 初始化串口 */ //sd_init(&Fatfs); /* 初始化SD卡,并创建文件 */ //sd_create_file(&test_data, test_data_name); /* 命令注册 */ help_cmd_initialize((intptr_t)(NULL)); light_cmd_initialize((intptr_t)(NULL)); switch_cmd_initialize((intptr_t)(NULL)); speaker_cmd_initialize((intptr_t)(NULL)); motor_cmd_initialize((intptr_t)(NULL)); decoder_cmd_initialize((intptr_t)(NULL)); control_cmd_initialize((intptr_t)(NULL)); //sd_cmd_initialize((intptr_t)(NULL)); printf("\n Welcome to k60 software platform!"); printf("\n Press 'help' to get the help! \n"); //light_open(LIGHT4); /* ntshell测试 */ task_ntshell((intptr_t)(NULL)); }
void stride_init(void) { #ifdef APE detect_init(); #else decoder_init(); #endif }
int main(int argc, char **argv) { struct stat sb; decoder_context decoder; const char *in_file_path = NULL; const char *out_file_path = NULL; FILE *fp_out; void *data_ptr; int fd; int c; while ((c = getopt(argc, argv, "i:o:")) != -1) { switch (c) { case 'i': in_file_path = optarg; break; case 'o': out_file_path = optarg; break; default: break; } } if (in_file_path == NULL || out_file_path == NULL) { fprintf(stderr, "-i h264 input file path\n"); fprintf(stderr, "-o decoded i420 frames output file path\n"); exit(EXIT_FAILURE); } fd = open(in_file_path, O_RDONLY); assert(fd != -1); assert(fstat(fd, &sb) != -1); fp_out = fopen(out_file_path, "w+"); assert(fp_out != NULL); data_ptr = mmap(NULL, sb.st_size, PROT_READ, MAP_PRIVATE, fd, 0); assert(data_ptr != MAP_FAILED); assert(madvise(data_ptr, sb.st_size, MADV_SEQUENTIAL) == 0); decoder_init(&decoder, data_ptr, sb.st_size); if (out_file_path) { decoder_set_notify(&decoder, save_decoded_frame, fp_out); } if (!parse_mp4(&decoder)) { parse_annex_b(&decoder); } return 0; }
int playvid_open(PlayerCtx **octx, const char *filename) { PlayerCtx *ctx = malloc(sizeof(PlayerCtx)); if (decoder_init(ctx, filename) < 0) return -1; ctx->display_mode = STOP; ctx->cur_frame = NULL; ctx->last_frame_pts = -1; ctx->ev_cb = NULL; *octx = ctx; return 0; }
int main(int argc, char *argv[]) { float *buffer; unsigned int len; unsigned int frate; FILE *f; decoder_handle handle; if(argc != 3) { printf("USAGE: %s <MP3 File> <Output file>\n", argv[0]); exit(-1); } f = fopen(argv[2], "w"); if(!f) { printf("Cannot create %s\n", argv[2]); exit(-1); } if(decoder_init(&handle)) { printf("Cound not initialize decoder\n"); goto init_failed; } if(decoder_open(handle, argv[1])) { printf("Could not open %s to decode\n", argv[1]); goto open_failed; } if(decoder_start(handle)) { printf("Could not start decoding\n"); goto start_failed; } while(1) { decoder_data_pull(handle, &buffer, &len, &frate); if(len == 0) break; if(write(fileno(f), buffer, len * sizeof(float)) != len * sizeof(float)) { printf("Write failed\n"); } free(buffer); } init_failed: fclose(f); start_failed: if(decoder_close(handle)) { printf("Closing decoder handle failed\n"); } open_failed: decoder_exit(handle); return 0; }
Decoder* init_decoder() { Decoder* obj = decoder_new(); char *filename = FILENAME; FILE *pF = fopen( filename, "rb" ); obj->pOpaqueSource = (void*) pF; decoder_reg_read( obj, read_fp ); decoder_reg_seek( obj, seek_fp ); decoder_init( obj ); decoder_load_info( obj ); return obj; }
int main(int argc, char *argv[]) { if (argc == 3 && argv[1][0] == '-' && argv[1][1] == 'l') { g_ip = NULL; g_port = atoi(argv[2]); } else if (argc == 3) { g_ip = argv[1]; g_port = atoi(argv[2]); } else { usage(argc, argv); return 1; } load_settings(); if (!decoder_init(g_webcam_w, g_webcam_h)) { return 2; } stream_video(); decoder_fini(); return 0; }
int main(int argc, char **argv) { int robot_state = FORWARD; int last_robot_state = FORWARD; int front_infrared_value = 0; int back_infrared_value = 0; int front_infrared_num = 0; int back_infrared_num = 0; int front_infrared_amount = 0; int back_infrared_amount = 0; int front_infrared_weight = 0; int back_infrared_weight = 0; uint32_t car_distence = 0; uint8_t get_char = 0; int change_num = 0; bool_t switch_state = 0; int detect_num = 0; int angle = 0; /* 模块初始化 */ exc_init(); /* 中断初始化 */ sys_timer_init(); /* 系统时钟初始化 */ light_init(); /* 灯初始化 */ switch_init(); /* 开关初始化 */ serial_initialize((intptr_t) (NULL)); /* 初始化串口 */ motor_init(); /* 电机初始化 */ steer_init(); /* 舵机初始化 */ decoder_init((intptr_t) (NULL)); /* 编码器初始化 */ infrared_init(); /* 红外初始化 */ while(1) { light_open(LIGHT2); light_open(LIGHT3); } // gpio_init(PORT_NO_GET(PTC0), PIN_NO_GET(PTC0), OUT_PUT, 0); // gpio_init(PORT_NO_GET(PTC2), PIN_NO_GET(PTC2),OUT_PUT, 1); // while(1) // { // motor_output(MOTOR_LEFT, 50); // motor_output(MOTOR_RIGHT, 50); // } while((get_char != 's') && (switch_state != SWITCH_ON)) { light_open_some(0x0f); get_char = serial_get_char(UART_NO_GET(UART_NO)); switch_state = switch_read(SWITCH0); } while (1) { get_char = serial_get_char(UART_NO_GET(UART_NO)); if(get_char == 'p') { last_robot_state = robot_state; robot_state = STOP; } /* 读取光电管的数据 */ front_infrared_value = infrared_read_loc(INFRARED_FRONT); back_infrared_value = infrared_read_loc(INFRARED_BACK); /* 读取红外从右第一个亮灯的位置 */ front_infrared_num = infrared_read_num(front_infrared_value); back_infrared_num = infrared_read_num(back_infrared_value); /* 读取传感器亮灯的总数 */ front_infrared_amount = infrared_read_amount(front_infrared_value); back_infrared_amount = infrared_read_amount(back_infrared_value); /* 读取权值 */ front_infrared_weight = infrared_read_weight(front_infrared_value); back_infrared_weight = infrared_read_weight(back_infrared_value); switch (robot_state) { /**********************************前进*************************************/ case FORWARD: light_open_some(0x01); light_bar_open(LIGHT_BAR0); light_bar_close(LIGHT_BAR1); if (front_infrared_amount == 1) { if (front_infrared_weight == 3) { angle = 40; //motor_output2(13, 13); } else if (front_infrared_weight == -3) { angle = -40; //motor_output2(13, 13); } else if (front_infrared_weight == 2) { angle = 20; //motor_output2(13, 13); } else if (front_infrared_weight == -2) { angle = -20; //motor_output2(13, 13); } else if (front_infrared_weight == 1) { angle = 5; //motor_output2(13, 13); } else if (front_infrared_weight == -1) { angle = -5; //motor_output2(13, 13); } } else if (front_infrared_amount == 2) { if (front_infrared_weight == 5) { angle = 30; //motor_output2(13, 13); } else if (front_infrared_weight == -5) { angle = -30; //motor_output2(13, 13); } else if (front_infrared_weight == 3) { angle = 10; //motor_output2(13, 13); } else if (front_infrared_weight == -3) { angle = -10; //motor_output2(13, 13); } else if (front_infrared_weight == 0) { angle = 0; //motor_output2(13, 13); } } steer_output_angle(STEER_DIR, angle); speed_control_forward(30,angle); if (front_infrared_amount > 4) { if(change_num == 4) { robot_state = STOP; } detect_num ++; if(detect_num > 2) { detect_num = 0; robot_state = FORWARD_CHANGE; car_distence = gl_distanceTotal; } } else { detect_num = 0; } break; /**********************************前进转换1*************************************/ case FORWARD_CHANGE: light_bar_open(LIGHT_BAR0); light_bar_open(LIGHT_BAR1); light_open_some(0x02); steer_output_angle(STEER_DIR, 40); //motor_output2(-25, -10); speed_control_backward(30,angle); if((gl_distanceTotal - car_distence)>9) { robot_state = FORWARD_CHANGE2; } break; /**********************************前进转换2*************************************/ case FORWARD_CHANGE2: light_bar_open(LIGHT_BAR0); light_bar_open(LIGHT_BAR1); light_open_some(0x02); steer_output_angle(STEER_DIR, 40); //motor_output2(-25, -10); speed_control_backward(30,angle); if((back_infrared_value & 0x30) && (!(back_infrared_value & 0x03)) && (front_infrared_amount < 3)) { robot_state = BACKWARD; car_distence = gl_distanceTotal; change_num ++; } break; /************************************后退****************************************/ case BACKWARD: light_bar_open(LIGHT_BAR1); light_bar_close(LIGHT_BAR0); light_open_some(0x04); if (back_infrared_amount == 1) { if (back_infrared_weight == 3) { angle = -40; //motor_output2(-5, -22); } else if (back_infrared_weight == -3) { angle = 40; //motor_output2(-22, -5); } else if (back_infrared_weight == 2) { angle = -40; //motor_output2(-5, -20); } else if (back_infrared_weight == -2) { angle = 40; //motor_output2(-20, -5); } else if (back_infrared_weight == 1) { angle = -5; //motor_output2(-14, -14); } else if (back_infrared_weight == -1) { angle = 5; //motor_output2(-14, -14); } } else if (back_infrared_amount == 2) { if (back_infrared_weight == 5) { angle = -40; //motor_output2(-5, -20); } else if (back_infrared_weight == -5) { angle = 40; //motor_output2(-20, -5); } else if (back_infrared_weight == 3) { angle = -20; //motor_output2(-5, -20); } else if (back_infrared_weight == -3) { angle = 20; //motor_output2(-20, -5); } else if (back_infrared_weight == 0) { angle = 0; //motor_output2(-14, -14); } } steer_output_angle(STEER_DIR, angle); speed_control_backward(30,angle); if(back_infrared_amount > 4) { detect_num ++; if(detect_num > 2) { detect_num = 0; robot_state = BACKWARD_CHANGE; car_distence = gl_distanceTotal; } } else { detect_num = 0; } break; /************************************后退转换1****************************************/ case BACKWARD_CHANGE: light_bar_open(LIGHT_BAR0); light_bar_open(LIGHT_BAR1); light_open_some(0x8); steer_output_angle(STEER_DIR, -35); speed_control_forward(30,angle); if((gl_distanceTotal - car_distence)>7) { robot_state = BACKWARD_CHANGE2; } break; /************************************后退转换2****************************************/ case BACKWARD_CHANGE2: light_bar_open(LIGHT_BAR0); light_bar_open(LIGHT_BAR1); light_open_some(0x8); steer_output_angle(STEER_DIR, -35); speed_control_forward(30,angle); if((front_infrared_value & 0x38) && (!(front_infrared_value & 0x03)) && (back_infrared_amount < 3)) { robot_state = FORWARD; change_num ++; } break; /************************************停车****************************************/ case STOP: light_open_some(0x03); light_bar_close(LIGHT_BAR0); light_bar_close(LIGHT_BAR1); motor_output2(0, 0); steer_output_angle(STEER_DIR, 0); if(get_char == 's') { robot_state = last_robot_state; } break; } } }
static inline spectgen_session_t *spectgen_session_create(unsigned int window_size, scale_t scale, spect_method_t method, unsigned int nbands) { spectgen_session_t *session; int i; unsigned int num_bands = nbands; if(method == CEPSTOGRAM) num_bands = (nbands - 1) * 2; if(num_bands > (1 + (window_size / 2))) return NULL; session = (spectgen_session_t *)malloc(sizeof(spectgen_session_t)); if(!session) return NULL; session->window_size = window_size; session->numfreqs = (window_size / 2) + 1; session->nbands = nbands; session->scale = scale; session->method = method; session->window = (float *)malloc(sizeof(float) * window_size); if(!session->window) goto window_creation_failed; for(i = 0; i < window_size; i++) { session->window[i] = 0.5 * (1 - cos(2 * M_PI * (float)i / (float)(window_size - 1))); } session->scale_table = generate_scale_table(num_bands, scale); if(!session->scale_table) goto scale_generation_failed; session->norm_table = generate_scale_norm_table(session->scale_table, num_bands); if(!session->norm_table) goto norm_generation_failed; session->fft_in_pre = (float *)fftwf_malloc(sizeof(float) * window_size); if(!session->fft_in_pre) goto fft_in_pre_failed; session->fft_out_pre = (fftwf_complex *) fftwf_malloc(sizeof(fftwf_complex) * session->numfreqs); if(!session->fft_out_pre) goto fft_out_pre_failed; /* Even though we are thread safe, the planner is not. so * serialize the calls to fftwf plan create */ pthread_mutex_lock(&planner_lock); session->plan_pre = fftwf_plan_dft_r2c_1d(window_size, session->fft_in_pre, session->fft_out_pre, FFTW_MEASURE | FFTW_DESTROY_INPUT); pthread_mutex_unlock(&planner_lock); if(!session->plan_pre) goto plan_pre_creation_failed; session->fft_in_post = NULL; session->fft_out_post = NULL; session->plan_post = 0; if(method == CEPSTOGRAM) { unsigned int len_out_post = nbands; unsigned int len_in_post = num_bands; session->fft_in_post = (float *)fftwf_malloc(sizeof(float) * len_in_post); if(!session->fft_in_post) goto fft_in_post_failed; session->fft_out_post = (fftwf_complex *) fftwf_malloc(sizeof(fftwf_complex) * len_out_post); if(!session->fft_out_post) goto fft_out_post_failed; pthread_mutex_lock(&planner_lock); session->plan_post = fftwf_plan_dft_r2c_1d(len_in_post, session->fft_in_post, session->fft_out_post, FFTW_MEASURE | FFTW_DESTROY_INPUT); pthread_mutex_unlock(&planner_lock); if(!session->plan_post) goto plan_post_creation_failed; } /* The reason we create is for it to be taken! */ session->busy = 1; session->next = NULL; pthread_mutex_init(&session->lock, NULL); SIGNAL_INIT(&session->start_signal); SIGNAL_INIT(&session->finished_signal); session->active = 1; if(decoder_init(&session->d_handle)) goto decoder_init_failed; /* The thread will wait on the start signal */ pthread_create(&session->thread, 0, spectgen_session_thread, session); if(!session->thread) goto thread_creation_failed; return session; thread_creation_failed: decoder_exit(session->d_handle); decoder_init_failed: pthread_mutex_destroy(&session->lock); SIGNAL_DEINIT(&session->start_signal); SIGNAL_DEINIT(&session->finished_signal); if(session->plan_post) fftwf_destroy_plan(session->plan_post); plan_post_creation_failed: if(session->fft_out_post) fftwf_free(session->fft_out_post); fft_out_post_failed: if(session->fft_in_post) fftwf_free(session->fft_in_post); fft_in_post_failed: fftwf_destroy_plan(session->plan_pre); plan_pre_creation_failed: fftwf_free(session->fft_out_pre); fft_out_pre_failed: fftwf_free(session->fft_in_pre); fft_in_pre_failed: free(session->norm_table); norm_generation_failed: free(session->scale_table); scale_generation_failed: free(session->window); window_creation_failed: free(session); return NULL; }
static void prepare_decoder(trigger_type type) { config.trigger = type; decoder_init(&config.decoder); }
static GstFlowReturn gst_tta_dec_chain (GstPad * pad, GstBuffer * in) { GstTtaDec *ttadec; GstBuffer *outbuf, *buf = GST_BUFFER (in); guchar *data, *p; decoder *dec; unsigned long outsize; unsigned long size; guint32 frame_samples; long res; long *prev; ttadec = GST_TTA_DEC (GST_OBJECT_PARENT (pad)); data = GST_BUFFER_DATA (buf); size = GST_BUFFER_SIZE (buf); ttadec->tta_buf.bit_count = 0; ttadec->tta_buf.bit_cache = 0; ttadec->tta_buf.bitpos = ttadec->tta_buf.buffer_end; ttadec->tta_buf.offset = 0; decoder_init (ttadec->tta, ttadec->channels, ttadec->bytes); if (GST_BUFFER_DURATION_IS_VALID (buf)) { frame_samples = ceil ((gdouble) (GST_BUFFER_DURATION (buf) * ttadec->samplerate) / (gdouble) GST_SECOND); } else { frame_samples = ttadec->samplerate * FRAME_TIME; } outsize = ttadec->channels * frame_samples * ttadec->bytes; dec = ttadec->tta; p = ttadec->decdata; prev = ttadec->cache; for (res = 0; p < ttadec->decdata + frame_samples * ttadec->channels * ttadec->bytes;) { unsigned long unary, binary, depth, k; long value, temp_value; fltst *fst = &dec->fst; adapt *rice = &dec->rice; long *last = &dec->last; // decode Rice unsigned get_unary (&ttadec->tta_buf, data, size, &unary); switch (unary) { case 0: depth = 0; k = rice->k0; break; default: depth = 1; k = rice->k1; unary--; } if (k) { get_binary (&ttadec->tta_buf, data, size, &binary, k); value = (unary << k) + binary; } else value = unary; switch (depth) { case 1: rice->sum1 += value - (rice->sum1 >> 4); if (rice->k1 > 0 && rice->sum1 < shift_16[rice->k1]) rice->k1--; else if (rice->sum1 > shift_16[rice->k1 + 1]) rice->k1++; value += bit_shift[rice->k0]; default: rice->sum0 += value - (rice->sum0 >> 4); if (rice->k0 > 0 && rice->sum0 < shift_16[rice->k0]) rice->k0--; else if (rice->sum0 > shift_16[rice->k0 + 1]) rice->k0++; } /* this only uses a temporary variable to silence a gcc warning */ temp_value = DEC (value); value = temp_value; // decompress stage 1: adaptive hybrid filter hybrid_filter (fst, &value); // decompress stage 2: fixed order 1 prediction switch (ttadec->bytes) { case 1: value += PREDICTOR1 (*last, 4); break; // bps 8 case 2: value += PREDICTOR1 (*last, 5); break; // bps 16 case 3: value += PREDICTOR1 (*last, 5); break; // bps 24 case 4: value += *last; break; // bps 32 } *last = value; if (dec < ttadec->tta + ttadec->channels - 1) { *prev++ = value; dec++; } else { *prev = value; if (ttadec->channels > 1) { long *r = prev - 1; for (*prev += *r / 2; r >= ttadec->cache; r--) *r = *(r + 1) - *r; for (r = ttadec->cache; r < prev; r++) WRITE_BUFFER (r, ttadec->bytes, p); } WRITE_BUFFER (prev, ttadec->bytes, p); prev = ttadec->cache; res++; dec = ttadec->tta; } } outbuf = gst_buffer_new_and_alloc (outsize); memcpy (GST_BUFFER_DATA (outbuf), ttadec->decdata, outsize); GST_BUFFER_TIMESTAMP (outbuf) = GST_BUFFER_TIMESTAMP (buf); GST_BUFFER_DURATION (outbuf) = GST_BUFFER_DURATION (buf); gst_buffer_set_caps (outbuf, GST_PAD_CAPS (ttadec->srcpad)); return gst_pad_push (ttadec->srcpad, outbuf); }
int main (int argc, char *argv[]) { struct parameters params; lists_t_strs *deferred_overrides; lists_t_strs *args; #ifdef HAVE_UNAME_SYSCALL int rc; struct utsname uts; #endif #ifdef PACKAGE_REVISION logit ("This is Music On Console (revision %s)", PACKAGE_REVISION); #else logit ("This is Music On Console (version %s)", PACKAGE_VERSION); #endif #ifdef CONFIGURATION logit ("Configured:%s", CONFIGURATION); #endif #ifdef HAVE_UNAME_SYSCALL rc = uname (&uts); if (rc == 0) logit ("Running on: %s %s %s", uts.sysname, uts.release, uts.machine); #endif log_command_line (argc, argv); files_init (); if (get_home () == NULL) fatal ("Could not determine user's home directory!"); memset (¶ms, 0, sizeof(params)); options_init (); deferred_overrides = lists_strs_new (4); /* set locale according to the environment variables */ if (!setlocale(LC_ALL, "")) logit ("Could not set locale!"); args = process_command_line (argc, argv, ¶ms, deferred_overrides); if (params.dont_run_iface && params.only_server) fatal ("-c, -a and -p options can't be used with --server!"); if (!params.config_file) params.config_file = xstrdup (create_file_name ("config")); options_parse (params.config_file); if (params.config_file) free (params.config_file); params.config_file = NULL; process_deferred_overrides (deferred_overrides); lists_strs_free (deferred_overrides); deferred_overrides = NULL; check_moc_dir (); io_init (); rcc_init (); decoder_init (params.debug); srand (time(NULL)); if (!params.only_server && params.dont_run_iface) server_command (¶ms, args); else start_moc (¶ms, args); lists_strs_free (args); options_free (); decoder_cleanup (); io_cleanup (); rcc_cleanup (); files_cleanup (); compat_cleanup (); exit (EXIT_SUCCESS); }