void render_slide(int num, float stime, int bcolor, float state) { int scolor = (VANISH - fabsf(cubepos)) / VANISH * 400; if (fabsf(cubepos) < VANISH) { olSetPixelShader(NULL); olSetVertex3Shader(NULL); olLoadIdentity(); olLoadIdentity3(); olResetColor(); if (scolor < 255) olMultColor(C_GREY(scolor)); if (bcolor > 0) { // make sure the corners of the slide-rect are always nice and sharp // even when the whole frame gets resampled to maintain framerate OLRenderParams old, params; olGetRenderParams(&old); params = old; params.start_dwell = 40; params.corner_dwell = 40; params.end_dwell = 40; olSetRenderParams(¶ms); olRect(-1, -ASPECT, 1, ASPECT, C_GREY(bcolor > 255 ? 255 : bcolor)); olSetRenderParams(&old); } slides[num].render(slides[num].context, stime, state * ST_VANISH); } }
void openlase_initialize(t_jit_openlase_trace *x, int width, int height) { if (x->initialized) { return; } //object_post((t_object *)x, "openlase_initialize enter"); if(olInit(FRAMES_BUF, 300000) < 0) { object_post((t_object *)x, "failed to initialize OpenLase"); return; } float overscan = x->overscan; float aspect = x->aspect; float snap_pix = x->snap_pix; //float framerate = 30; x->tparams.mode = OL_TRACE_THRESHOLD; x->tparams.sigma = 0; x->tparams.threshold2 = 50; //x->tparams.mode = OL_TRACE_CANNY; x->tparams.sigma = 1; if (aspect == 0) aspect = (float)width / height; // if (framerate == 0) // framerate = (float)pFormatCtx->streams[videoStream]->r_frame_rate.num / (float)pFormatCtx->streams[videoStream]->r_frame_rate.den; float iaspect = 1/aspect; if (aspect > 1) { olSetScissor(-1, -iaspect, 1, iaspect); olScale(1, iaspect); } else { olSetScissor(-aspect, -1, aspect, 1); olScale(aspect, 1); } olScale(1+overscan, 1+overscan); olTranslate(-1.0f, 1.0f); olScale(2.0f/width, -2.0f/height); int maxd = width > height ? width : height; x->params.snap = (snap_pix*2.0)/(float)maxd; //float frametime = 1.0f/framerate; olSetRenderParams(&x->params); x->tparams.width = width, x->tparams.height = height, olTraceInit(&x->trace_ctx, &x->tparams); //object_post((t_object *)x, "openlase initialized"); x->initialized = true; }
void DoEuskal(void) { IldaFile *ild; ild = olLoadIlda("euskal18.ild"); params.off_speed = 2.0/20.0; params.start_wait = 8; params.end_wait = 1; params.render_flags |= RENDER_NOREORDER; olSetRenderParams(¶ms); include_dark_points = 0; int count = count_active_points(ild); float cur_draw = 0; olSetVertexShader(cutoff); while(1) { int obj; float w; points_left = cur_draw; olDrawIlda(ild); render(); cur_draw += ftime * count / 5.0; if (cur_draw > count) { break; } } olSetVertexShader(NULL); float bright = 300.0f; while(1) { uint32_t col; if (bright > 255.0f) col = C_WHITE; else col = C_GREY((int)bright); olPushColor(); olMultColor(col); olDrawIlda(ild); olPopColor(); render(); bright -= ftime * 40.0; if (bright < 0) break; } }
void DoCubes(float limit) { float ctime = 0; params.on_speed = 2.0/90.0; params.off_speed = 2.0/30.0; params.start_wait = 8; params.start_dwell = 6; params.curve_dwell = 0; params.corner_dwell = 8; params.end_dwell = 6; params.end_wait = 2; params.render_flags |= RENDER_NOREORDER; olSetRenderParams(¶ms); float xpos = -2.0; while(audiotime < limit) { if (ctime*AB < 1.5) xpos = -2.0 +2*sinf(ctime*AB * M_PI * 0.5 / 1.5); else if (audiotime > (limit-1.5)) xpos = 2-2*sinf((limit-audiotime) * M_PI * 0.5 / 1.5); else xpos = 0; olLoadIdentity(); olTranslate(xpos, 0); render_cubes(ctime*AB); olSetPixelShader(hfade); ctime -= 15.0; olDrawString(font, -1.2*(ctime-1.0), 0.35, 0.3, C_WHITE, "Spontz"); olDrawString(font, -1.5*(ctime-2.0), -0.60, 0.3, C_WHITE, "BiXo"); olDrawString(font, -1.3*(ctime-3.0), 0.70, 0.3, C_WHITE, "Xplsv"); olDrawString(font, -1.7*(ctime-4.0), 0.40, 0.3, C_WHITE, "Software Failure"); olDrawString(font, -1.4*(ctime-5.0), -0.75, 0.3, C_WHITE, "Nocturns"); olDrawString(font, -1.2*(ctime-6.0), -0.45, 0.3, C_WHITE, "Purple Studios"); olDrawString(font, -1.7*(ctime-7.0), 0.35, 0.3, C_WHITE, "Masca Team"); olDrawString(font, -1.2*(ctime-8.0), 0.60, 0.3, C_WHITE, "Glenz"); olDrawString(font, -1.3*(ctime-9.0), -0.40, 0.3, C_WHITE, "Napalm Core"); olDrawString(font, -1.5*(ctime-10.0), -0.75, 0.3, C_WHITE, "TDA"); olDrawString(font, -1.3*(ctime-11.0), 0.45, 0.3, C_WHITE, "ASD"); ctime += 15.0; olSetPixelShader(NULL); ctime += render(); } }
int main (int argc, char *argv[]) { OLRenderParams params; memset(¶ms, 0, sizeof params); params.rate = 48000; params.on_speed = 2.0/100.0; params.off_speed = 2.0/30.0; params.start_wait = 4; params.start_dwell = 3; params.curve_dwell = 0; params.corner_dwell = 4; params.curve_angle = cosf(30.0*(M_PI/180.0)); // 30 deg params.end_dwell = 2; params.end_wait = 5; params.snap = 1/100000.0; params.render_flags = RENDER_GRAYSCALE; if(olInit(3, 30000) < 0) return 1; olSetRenderParams(¶ms); float time = 0; float ftime; int i; int frames = 0; int points = 25; while(1) { olLoadIdentity(); int total_y = (points / 12.0 * 7.0 + 1); for (i=0; i<points; i++) { int octave = i/12; float y = (octave * 7 + pos[i%12]) * 2.0 / (total_y) - 1.0; float x = offs[i%12] * 0.1; olDot(x, y, 30, C_WHITE); } ftime = olRenderFrame(60); frames++; time += ftime; printf("Frame time: %f, FPS:%f\n", ftime, frames/time); } olShutdown(); exit (0); }
void DoMetaballs(float limit) { float ctime = 0; memset(mbuf, 0, sizeof mbuf); params.off_speed = 2.0/30.0; params.start_wait = 8; params.start_dwell = 2; params.end_dwell = 2; params.end_wait = 3; params.render_flags |= RENDER_NOREORDER; olSetRenderParams(¶ms); float xpos = 6; while(audiotime < limit) { params.start_dwell = 7; params.end_dwell = 7; olSetRenderParams(¶ms); render_metaballs(ctime * AB, limit-audiotime); params.start_dwell = 3; params.end_dwell = 3; olSetRenderParams(¶ms); olSetVertexShader(sinescroller); olDrawString(font, xpos, -0.5, 0.4, C_WHITE, "WARNING: Laser Radiation. Do not stare into beam with remaining eye!"); olSetVertexShader(NULL); ctime += render(); xpos -= ftime*1.2; } }
void go(int delta) { if (next_slide != -1) { //olLog("WARNING: attempted to change slide while transition active\n"); return; } next_slide = (cur_slide + NUM_SLIDES + delta) % NUM_SLIDES; next_stime = 0; trans_time = 0; OLRenderParams params = master_params; if (slides[next_slide].init) { slides[next_slide].init(&slides[next_slide].context, slides[next_slide].arg, ¶ms); } olSetRenderParams(¶ms); }
static VALUE ol_setRenderParams(VALUE self, VALUE v) { OLRenderParams params; params.rate = NUM2INT(rb_iv_get(v, "@rate")); params.on_speed = NUM2DBL(rb_iv_get(v, "@on_speed")); params.off_speed = NUM2DBL(rb_iv_get(v, "@off_speed")); params.start_dwell = NUM2INT(rb_iv_get(v, "@start_dwell")); params.curve_dwell = NUM2INT(rb_iv_get(v, "@curve_dwell")); params.corner_dwell = NUM2INT(rb_iv_get(v, "@corner_dwell")); params.end_dwell = NUM2INT(rb_iv_get(v, "@end_dwell")); params.end_wait = NUM2INT(rb_iv_get(v, "@end_wait")); params.curve_angle = NUM2DBL(rb_iv_get(v, "@curve_angle")); params.flatness = NUM2DBL(rb_iv_get(v, "@flatness")); params.snap = NUM2DBL(rb_iv_get(v, "@snap")); params.render_flags = NUM2INT(rb_iv_get(v, "@render_flags")); params.min_length = NUM2INT(rb_iv_get(v, "@min_length")); params.max_framelen = NUM2INT(rb_iv_get(v, "@max_framelen")); olSetRenderParams(¶ms); }
void initol() { // from examples/simple.c OLRenderParams params; memset(¶ms, 0, sizeof params); params.rate = 48000; params.on_speed = 2.0/100.0; params.off_speed = 2.0/20.0; params.start_wait = 20; params.start_dwell = 3; params.curve_dwell = 0; params.corner_dwell = 8; params.curve_angle = cosf(30.0*(M_PI/180.0)); // 30 deg params.end_dwell = 3; params.end_wait = 7; params.snap = 1/100000.0; params.render_flags = RENDER_GRAYSCALE; if(olInit(3, 30000) < 0) throw "hest"; olSetRenderParams(¶ms); }
int main (int argc, char *argv[]) { OLRenderParams params; memset(¶ms, 0, sizeof params); params.rate = 48000; params.on_speed = 2.0/100.0; params.off_speed = 2.0/20.0; params.start_wait = 8; params.start_dwell = 3; params.curve_dwell = 0; params.corner_dwell = 8; params.curve_angle = cosf(30.0*(M_PI/180.0)); // 30 deg params.end_dwell = 3; params.end_wait = 7; params.snap = 1/100000.0; params.render_flags = RENDER_GRAYSCALE; if(olInit(3, 30000) < 0) return 1; olSetRenderParams(¶ms); float time = 0; float ftime; int i,j; int frames = 0; while(1) { olLoadIdentity3(); olLoadIdentity(); olPerspective(60, 1, 1, 100); olTranslate3(0, 0, -3); for(i=0; i<2; i++) { if (i == 1) olColor3(0.0,1.0,0.0); else olColor3(0.0,1.0,0.0); olScale3(0.6, 0.6, 0.6); olRotate3Z(time * M_PI * 0.1); olRotate3Y(time * M_PI * 0.8); olRotate3X(time * M_PI * 0.73); olBegin(OL_LINESTRIP); olVertex3(-1, -1, -1); olVertex3( 1, -1, -1); olVertex3( 1, 1, -1); olVertex3(-1, 1, -1); olVertex3(-1, -1, -1); olVertex3(-1, -1, 1); olEnd(); olBegin(OL_LINESTRIP); olVertex3( 1, 1, 1); olVertex3(-1, 1, 1); olVertex3(-1, -1, 1); olVertex3( 1, -1, 1); olVertex3( 1, 1, 1); olVertex3( 1, 1, -1); olEnd(); olBegin(OL_LINESTRIP); olVertex3( 1, -1, -1); olVertex3( 1, -1, 1); olEnd(); olBegin(OL_LINESTRIP); olVertex3(-1, 1, 1); olVertex3(-1, 1, -1); olEnd(); } ftime = olRenderFrame(60); frames++; time += ftime; printf("Frame time: %f, FPS:%f\n", ftime, frames/time); } olShutdown(); exit (0); }
int main (int argc, char *argv[]) { snd_seq_t *seq_handle; int npfd; struct pollfd *pfd; seq_handle = open_seq(); npfd = snd_seq_poll_descriptors_count(seq_handle, POLLIN); pfd = malloc(npfd * sizeof(*pfd)); snd_seq_poll_descriptors(seq_handle, pfd, npfd, POLLIN); if (argc >= 2) { snd_seq_addr_t addr; if (snd_seq_parse_address(seq_handle, &addr, argv[1]) == 0) { if (snd_seq_connect_from(seq_handle, portid, addr.client, addr.port) == 0) { printf("Connected to %s\n", argv[1]); } } } int i; for (i=2; i<argc; i++) channels |= 1<<(atoi(argv[i])-1); OLRenderParams params; memset(¶ms, 0, sizeof params); params.rate = 48000; params.on_speed = 2.0/50.0; params.off_speed = 2.0/35.0; params.start_wait = 6; params.start_dwell = 1; params.curve_dwell = 0; params.corner_dwell = 0; params.curve_angle = cosf(30.0*(M_PI/180.0)); // 30 deg params.end_dwell = 0; params.end_wait = 7; params.flatness = 0.00001; params.snap = 1/100000.0; params.render_flags = RENDER_GRAYSCALE; if(olInit(3, 30000) < 0) return 1; olSetRenderParams(¶ms); float time = 0; float ftime; int frames = 0; float nps = 0; avgnotes = 5; while(1) { olLoadIdentity(); int drawn = draw(); if (drawn < 2) draw(); ftime = olRenderFrame(100); float t = powf(0.3, ftime); avgnotes = avgnotes * t + (nps+2) * (1.0f-t); animate(ftime); int notes = 0; if (poll(pfd, npfd, 0) > 0) notes = midi_action(seq_handle); int pnotes = (notes+2)/3; nps = pnotes / ftime * 1.2; frames++; time += ftime; printf("Frame time: %f, Avg FPS:%f, Cur FPS:%f, %d, nps:%3d, avgnotes:%f\n", ftime, frames/time, 1/ftime, notes, (int)nps, avgnotes); } olShutdown(); exit (0); }
int main(int argc, char** argv) { int opt, i, result = 0; const char* path = NULL; const char* serial_number = NULL; int exit_code = EXIT_SUCCESS; struct timeval time_now; float time_diff; float sweep_rate; unsigned int lna_gain=16, vga_gain=20; uint32_t freq_min = 0; uint32_t freq_max = 6000; uint32_t requested_fft_bin_width; while( (opt = getopt(argc, argv, "a:f:p:l:g:d:n:w:1BILr:h?")) != EOF ) { result = HACKRF_SUCCESS; switch( opt ) { case 'd': serial_number = optarg; break; case 'a': amp = true; result = parse_u32(optarg, &_enable); break; case 'f': result = parse_u32_range(optarg, &freq_min, &freq_max); if(freq_min >= freq_max) { fprintf(stderr, "argument error: freq_max must be greater than freq_min.\n"); usage(); return EXIT_FAILURE; } if(FREQ_MAX_MHZ <freq_max) { fprintf(stderr, "argument error: freq_max may not be higher than %u.\n", FREQ_MAX_MHZ); usage(); return EXIT_FAILURE; } if(MAX_SWEEP_RANGES <= num_ranges) { fprintf(stderr, "argument error: specify a maximum of %u frequency ranges.\n", MAX_SWEEP_RANGES); usage(); return EXIT_FAILURE; } frequencies[2*num_ranges] = (uint16_t)freq_min; frequencies[2*num_ranges+1] = (uint16_t)freq_max; num_ranges++; break; case 'p': antenna = true; result = parse_u32(optarg, &antenna_enable); break; case 'l': result = parse_u32(optarg, &lna_gain); break; case 'g': result = parse_u32(optarg, &vga_gain); break; case 'n': result = parse_u32(optarg, &num_samples); break; case 'w': result = parse_u32(optarg, &requested_fft_bin_width); fftSize = DEFAULT_SAMPLE_RATE_HZ / requested_fft_bin_width; break; case '1': one_shot = true; break; case 'B': binary_output = true; break; case 'I': ifft_output = true; break; case 'L': openlase_output = true; break; case 'r': path = optarg; break; case 'h': case '?': usage(); return EXIT_SUCCESS; default: fprintf(stderr, "unknown argument '-%c %s'\n", opt, optarg); usage(); return EXIT_FAILURE; } if( result != HACKRF_SUCCESS ) { fprintf(stderr, "argument error: '-%c %s' %s (%d)\n", opt, optarg, hackrf_error_name(result), result); usage(); return EXIT_FAILURE; } } if (lna_gain % 8) fprintf(stderr, "warning: lna_gain (-l) must be a multiple of 8\n"); if (vga_gain % 2) fprintf(stderr, "warning: vga_gain (-g) must be a multiple of 2\n"); if (num_samples % SAMPLES_PER_BLOCK) { fprintf(stderr, "warning: num_samples (-n) must be a multiple of 8192\n"); return EXIT_FAILURE; } if (num_samples < SAMPLES_PER_BLOCK) { fprintf(stderr, "warning: num_samples (-n) must be at least 8192\n"); return EXIT_FAILURE; } if( amp ) { if( amp_enable > 1 ) { fprintf(stderr, "argument error: amp_enable shall be 0 or 1.\n"); usage(); return EXIT_FAILURE; } } if (antenna) { if (antenna_enable > 1) { fprintf(stderr, "argument error: antenna_enable shall be 0 or 1.\n"); usage(); return EXIT_FAILURE; } } if (0 == num_ranges) { frequencies[0] = (uint16_t)freq_min; frequencies[1] = (uint16_t)freq_max; num_ranges++; } if(binary_output + ifft_output + openlase_output > 1) { fprintf(stderr, "argument error: binary output (-B), IFFT output (-I) and openlase output (-L) are mutually exclusive.\n"); return EXIT_FAILURE; } if(ifft_output && (1 < num_ranges)) { fprintf(stderr, "argument error: only one frequency range is supported in IFFT output (-I) mode.\n"); return EXIT_FAILURE; } if(4 > fftSize) { fprintf(stderr, "argument error: FFT bin width (-w) must be no more than one quarter the sample rate\n"); return EXIT_FAILURE; } if(8184 < fftSize) { fprintf(stderr, "argument error: FFT bin width (-w) too small, resulted in more than 8184 FFT bins\n"); return EXIT_FAILURE; } /* In interleaved mode, the FFT bin selection works best if the total * number of FFT bins is equal to an odd multiple of four. * (e.g. 4, 12, 20, 28, 36, . . .) */ while((fftSize + 4) % 8) { fftSize++; } fft_bin_width = (double)DEFAULT_SAMPLE_RATE_HZ / fftSize; fftwIn = (fftwf_complex*)fftwf_malloc(sizeof(fftwf_complex) * fftSize); fftwOut = (fftwf_complex*)fftwf_malloc(sizeof(fftwf_complex) * fftSize); fftwPlan = fftwf_plan_dft_1d(fftSize, fftwIn, fftwOut, FFTW_FORWARD, FFTW_MEASURE); pwr = (float*)fftwf_malloc(sizeof(float) * fftSize); window = (float*)fftwf_malloc(sizeof(float) * fftSize); for (i = 0; i < fftSize; i++) { window[i] = (float) (0.5f * (1.0f - cos(2 * M_PI * i / (fftSize - 1)))); } result = hackrf_init(); if( result != HACKRF_SUCCESS ) { fprintf(stderr, "hackrf_init() failed: %s (%d)\n", hackrf_error_name(result), result); usage(); return EXIT_FAILURE; } result = hackrf_open_by_serial(serial_number, &device); if( result != HACKRF_SUCCESS ) { fprintf(stderr, "hackrf_open() failed: %s (%d)\n", hackrf_error_name(result), result); usage(); return EXIT_FAILURE; } if((NULL == path) || (strcmp(path, "-") == 0)) { fd = stdout; } else { fd = fopen(path, "wb"); } if(NULL == fd) { fprintf(stderr, "Failed to open file: %s\n", path); return EXIT_FAILURE; } /* Change fd buffer to have bigger one to store or read data on/to HDD */ result = setvbuf(fd , NULL , _IOFBF , FD_BUFFER_SIZE); if( result != 0 ) { fprintf(stderr, "setvbuf() failed: %d\n", result); usage(); return EXIT_FAILURE; } #ifdef _MSC_VER SetConsoleCtrlHandler( (PHANDLER_ROUTINE) sighandler, TRUE ); #else signal(SIGINT, &sigint_callback_handler); signal(SIGILL, &sigint_callback_handler); signal(SIGFPE, &sigint_callback_handler); signal(SIGSEGV, &sigint_callback_handler); signal(SIGTERM, &sigint_callback_handler); signal(SIGABRT, &sigint_callback_handler); #endif fprintf(stderr, "call hackrf_sample_rate_set(%.03f MHz)\n", ((float)DEFAULT_SAMPLE_RATE_HZ/(float)FREQ_ONE_MHZ)); result = hackrf_set_sample_rate_manual(device, DEFAULT_SAMPLE_RATE_HZ, 1); if( result != HACKRF_SUCCESS ) { fprintf(stderr, "hackrf_sample_rate_set() failed: %s (%d)\n", hackrf_error_name(result), result); usage(); return EXIT_FAILURE; } fprintf(stderr, "call hackrf_baseband_filter_bandwidth_set(%.03f MHz)\n", ((float)DEFAULT_BASEBAND_FILTER_BANDWIDTH/(float)FREQ_ONE_MHZ)); result = hackrf_set_baseband_filter_bandwidth(device, DEFAULT_BASEBAND_FILTER_BANDWIDTH); if( result != HACKRF_SUCCESS ) { fprintf(stderr, "hackrf_baseband_filter_bandwidth_set() failed: %s (%d)\n", hackrf_error_name(result), result); usage(); return EXIT_FAILURE; } result = hackrf_set_vga_gain(device, vga_gain); result |= hackrf_set_lna_gain(device, lna_gain); /* * For each range, plan a whole number of tuning steps of a certain * bandwidth. Increase high end of range if necessary to accommodate a * whole number of steps, minimum 1. */ for(i = 0; i < num_ranges; i++) { step_count = 1 + (frequencies[2*i+1] - frequencies[2*i] - 1) / TUNE_STEP; frequencies[2*i+1] = (uint16_t) (frequencies[2*i] + step_count * TUNE_STEP); fprintf(stderr, "Sweeping from %u MHz to %u MHz\n", frequencies[2*i], frequencies[2*i+1]); } if(ifft_output) { ifftwIn = (fftwf_complex*)fftwf_malloc(sizeof(fftwf_complex) * fftSize * step_count); ifftwOut = (fftwf_complex*)fftwf_malloc(sizeof(fftwf_complex) * fftSize * step_count); ifftwPlan = fftwf_plan_dft_1d(fftSize * step_count, ifftwIn, ifftwOut, FFTW_BACKWARD, FFTW_MEASURE); } if (openlase_output) { openlaseBuf = (float*)malloc(sizeof(float) * fftSize * step_count); OLRenderParams params; memset(¶ms, 0, sizeof params); params.rate = 48000; params.on_speed = 2.0/100.0; params.off_speed = 2.0/20.0; params.start_wait = 8; params.start_dwell = 3; params.curve_dwell = 0; params.corner_dwell = 8; params.curve_angle = cosf(30.0*(M_PI/180.0)); // 30 deg params.end_dwell = 3; params.end_wait = 7; params.snap = 1/100000.0; params.render_flags = RENDER_GRAYSCALE; if(olInit(3, 30000) < 0) return EXIT_FAILURE; olSetRenderParams(¶ms); olBegin(OL_LINESTRIP); } result |= hackrf_start_rx(device, rx_callback, NULL); if (result != HACKRF_SUCCESS) { fprintf(stderr, "hackrf_start_rx() failed: %s (%d)\n", hackrf_error_name(result), result); usage(); return EXIT_FAILURE; } result = hackrf_init_sweep(device, frequencies, num_ranges, num_samples * 2, TUNE_STEP * FREQ_ONE_MHZ, OFFSET, INTERLEAVED); if( result != HACKRF_SUCCESS ) { fprintf(stderr, "hackrf_init_sweep() failed: %s (%d)\n", hackrf_error_name(result), result); return EXIT_FAILURE; } if (amp) { fprintf(stderr, "call hackrf_set_amp_enable(%u)\n", amp_enable); result = hackrf_set_amp_enable(device, (uint8_t)amp_enable); if (result != HACKRF_SUCCESS) { fprintf(stderr, "hackrf_set_amp_enable() failed: %s (%d)\n", hackrf_error_name(result), result); usage(); return EXIT_FAILURE; } } if (antenna) { fprintf(stderr, "call hackrf_set_antenna_enable(%u)\n", antenna_enable); result = hackrf_set_antenna_enable(device, (uint8_t)antenna_enable); if (result != HACKRF_SUCCESS) { fprintf(stderr, "hackrf_set_antenna_enable() failed: %s (%d)\n", hackrf_error_name(result), result); usage(); return EXIT_FAILURE; } } gettimeofday(&t_start, NULL); fprintf(stderr, "Stop with Ctrl-C\n"); while((hackrf_is_streaming(device) == HACKRF_TRUE) && (do_exit == false)) { float time_difference; sleep(1); gettimeofday(&time_now, NULL); time_difference = TimevalDiff(&time_now, &t_start); sweep_rate = (float)sweep_count / time_difference; fprintf(stderr, "%" PRIu64 " total sweeps completed, %.2f sweeps/second\n", sweep_count, sweep_rate); if (byte_count == 0) { exit_code = EXIT_FAILURE; fprintf(stderr, "\nCouldn't transfer any data for one second.\n"); break; } byte_count = 0; } result = hackrf_is_streaming(device); if (do_exit) { fprintf(stderr, "\nExiting...\n"); } else { fprintf(stderr, "\nExiting... hackrf_is_streaming() result: %s (%d)\n", hackrf_error_name(result), result); } gettimeofday(&time_now, NULL); time_diff = TimevalDiff(&time_now, &t_start); fprintf(stderr, "Total sweeps: %" PRIu64 " in %.5f seconds (%.2f sweeps/second)\n", sweep_count, time_diff, sweep_rate); if(device != NULL) { result = hackrf_stop_rx(device); if(result != HACKRF_SUCCESS) { fprintf(stderr, "hackrf_stop_rx() failed: %s (%d)\n", hackrf_error_name(result), result); } else { fprintf(stderr, "hackrf_stop_rx() done\n"); } result = hackrf_close(device); if(result != HACKRF_SUCCESS) { fprintf(stderr, "hackrf_close() failed: %s (%d)\n", hackrf_error_name(result), result); } else { fprintf(stderr, "hackrf_close() done\n"); } hackrf_exit(); fprintf(stderr, "hackrf_exit() done\n"); } if(fd != NULL) { fclose(fd); fd = NULL; fprintf(stderr, "fclose(fd) done\n"); } if (openlase_output) olShutdown(); fftwf_free(fftwIn); fftwf_free(fftwOut); fftwf_free(pwr); fftwf_free(window); fftwf_free(ifftwIn); fftwf_free(ifftwOut); fprintf(stderr, "exit\n"); return exit_code; }
void DoStars(float limit) { int i; float ctime = 0; float lctime = 0; params.start_wait = 7; params.off_speed = 2.0/20.0; params.end_wait = 3; params.render_flags &= ~RENDER_NOREORDER; olSetRenderParams(¶ms); for (i=0; i<NUM_STARS; i++) { stars[i][0] = randf(1.5); stars[i][1] = randf(2*M_PI); stars[i][2] = 0; stars[i][3] = 0; stars[i][4] = randf(255); } ftime = 0; int id = 0; while (!apassed(STAR_ST1)) { for (i=0; i<NUM_PRESETS; i++) { if(apassed(star_deps[i][0]/4.0f)) { printf("%d\n", i); cart_rnd_star(id); stars[id][2] = star_deps[i][1]; stars[id][3] = 1; id = (id+1)%NUM_STARS; } } render_stars(); ctime += render(); for (i=0; i<NUM_STARS; i++) { stars[i][3] -= ftime*0.3; if (stars[i][3] < 0) stars[i][3] = 0; } } int ct = 0; int max; ctime = 0; while (!apassed(STAR_ST2)) { max = ctime * 100.0 / 0x10; while(ct < max) { stars[id][0] = 0.05 + randf(1.50); stars[id][1] = randf(2*M_PI); stars[id][2] = randf(20); stars[id][3] = 1; id = (id+1)%NUM_STARS; ct++; } render_stars(); ctime += render()*AB; } float speed = 0.3; params.start_wait = 6; params.end_wait = 1; olSetRenderParams(¶ms); while (audiotime < limit) { render_stars(); for (i=0; i<NUM_STARS; i++) { stars[i][0] *= (1+speed*ftime); stars[i][3] += speed*ftime; if (stars[i][3] > 1.0) stars[i][3] = 1.0; if (stars[i][0] > 1.5 && audiotime < (limit-2.2*AB)) { stars[i][0] = 0.05 + randf(0.1); stars[i][1] = randf(2*M_PI); stars[i][2] = randf(20); stars[i][3] = 0; } } ctime += render(); if (speed < 2) { speed += 1.2f * ftime; if (speed > 2) speed = 2; } } }
void DoTitle(float limit) { IldaFile *ild; ild = olLoadIlda("lase_title.ild"); include_dark_points = 1; int count = count_active_points(ild); float cur_draw = 0; float ctime = 0; olSetVertexShader(cutoff); params.render_flags |= RENDER_NOREORDER; olSetRenderParams(¶ms); while(1) { int obj; float w; points_left = cur_draw; olDrawIlda(ild); ctime += render(); cur_draw += ftime * count / 3.0; if (cur_draw > count) { break; } } olSetVertexShader(NULL); while(AB*ctime < 8) { olDrawIlda(ild); ctime += render(); } wipe_center = -1.0; wipe_w = 0.4; wipe_inv = 1; const char *s="A realtime laser demo"; float s_x = -olGetStringWidth(font, 0.2, s) / 2; float s_y = -0.5; float s_h = 0.2; while(1) { olDrawIlda(ild); olSetPixelShader(hwipe); olDrawString(font, s_x, s_y, s_h, C_WHITE, s); olSetPixelShader(NULL); ctime += render(); wipe_center += 1.7*ftime; if(wipe_center > 1.0f) break; } float bright = 300.0f; while(audiotime < limit) { uint32_t col; if (bright > 255.0f) col = C_WHITE; else col = C_GREY((int)bright); olPushColor(); olMultColor(col); olDrawIlda(ild); olDrawString(font, s_x, s_y, s_h, C_WHITE, s); olPopColor(); render(); bright -= ftime * 130.0; if (bright < 0) bright = 0; } }
void render_cubes(float time) { int i; OLRenderParams mpar; memcpy(&mpar, ¶ms, sizeof(OLRenderParams)); if (time > 32) { time += 1.0; mpar.on_speed = 0.022 + (1-usin(time, 2.0)) * 0.02; mpar.corner_dwell = 8*usin(time, 2.0); mpar.start_dwell = 2+3*usin(time, 2.0); mpar.start_wait = 3+5*usin(time, 2.0); mpar.end_dwell = 2+3*usin(time, 2.0); mpar.end_wait = 2*usin(time, 2.0); olSetRenderParams(&mpar); time -= 1.0; } printf("%f %d %d %d %d %d\n", mpar.on_speed, mpar.corner_dwell, mpar.start_dwell, mpar.start_wait, mpar.end_dwell, mpar.end_wait); olLoadIdentity3(); olPerspective(60, 1, 1, 100); olTranslate3(0, 0, -2.1); for(i=0; i<3; i++) { if (i>0) olPushMatrix3(); olScale3(0.6, 0.6, 0.6); if (i>0) { float tx = sinf(time + (i-1)*M_PI); float ty = cosf(time + (i-1)*M_PI); float tz = sinf(time + (i-1)*M_PI); float s = sinf(0.6*time); olTranslate3(tx*s,ty*s,tz*s); //olScale3(s,s,s); olScale3(0.3,0.3,0.3); } float mult; if (i==0) mult = 1; else if (i==1) mult = 1.5; else if (i==2) mult = -1.5; if (i==0) olMultColor(C_GREY(120)); else olResetColor(); olRotate3Z(mult*time * M_PI * 0.1 / 3.0); olRotate3Y(mult*time * M_PI * 0.8 / 3.0); olRotate3X(mult*time * M_PI * 0.73 / 3.0); olBegin(OL_LINESTRIP); olVertex3(-1, -1, -1, C_RED); olVertex3( 1, -1, -1, C_RED); olVertex3( 1, 1, -1, C_RED); olVertex3(-1, 1, -1, C_RED); olVertex3(-1, -1, -1, C_RED); olVertex3(-1, -1, 1, C_RED); olEnd(); olBegin(OL_LINESTRIP); olVertex3( 1, 1, 1, C_GREEN); olVertex3(-1, 1, 1, C_GREEN); olVertex3(-1, -1, 1, C_GREEN); olVertex3( 1, -1, 1, C_GREEN); olVertex3( 1, 1, 1, C_GREEN); olVertex3( 1, 1, -1, C_GREEN); olEnd(); olBegin(OL_LINESTRIP); olVertex3( 1, -1, -1, C_RED); olVertex3( 1, -1, 1, C_RED); olEnd(); olBegin(OL_LINESTRIP); olVertex3(-1, 1, 1, C_GREEN); olVertex3(-1, 1, -1, C_GREEN); olEnd(); /*olBegin(OL_BEZIERSTRIP); olVertex3(-1, 1, 0, C_WHITE); olVertex3(0, -1, 0, C_WHITE); olVertex3(0, -1, 0, C_WHITE); olVertex3(1, 1, 0, C_WHITE); olVertex3(-1, 0, 0, C_WHITE); olVertex3(-1, 0, 0, C_WHITE); olVertex3(1, -1, 0, C_WHITE); olVertex3(0, 1, 0, C_WHITE); olVertex3(0, 1, 0, C_WHITE); olVertex3(-1, -1, 0, C_WHITE); olVertex3(1, 0, 0, C_WHITE); olVertex3(1, 0, 0, C_WHITE); olVertex3(-1, 1, 0, C_WHITE); olEnd();*/ if (i>0) olPopMatrix3(); } olLoadIdentity3(); olLoadIdentity(); olSetRenderParams(¶ms); olResetColor(); }
int main (int argc, char *argv[]) { void *mod_data; FILE *mod_fd; size_t mod_size; mod_fd = fopen("GLOS-pope.xm","r"); fseek(mod_fd, 0, SEEK_END); mod_size = ftell(mod_fd); fseek(mod_fd, 0, SEEK_SET); mod_data = malloc(mod_size); fread(mod_data, 1, mod_size, mod_fd); fclose(mod_fd); ModPlug_Settings cfg; ModPlug_GetSettings(&cfg); cfg.mChannels = 2; cfg.mBits = 16; cfg.mFrequency = 48000; cfg.mResamplingMode = MODPLUG_RESAMPLE_SPLINE; cfg.mFlags = MODPLUG_ENABLE_OVERSAMPLING; ModPlug_SetSettings(&cfg); module = ModPlug_Load(mod_data, mod_size); srandom(0); memset(¶ms, 0, sizeof params); params.rate = 48000; params.on_speed = 2.0/100.0; params.off_speed = 2.0/30.0; params.start_wait = 8; params.start_dwell = 2; params.curve_dwell = 0; params.corner_dwell = 2; params.curve_angle = cosf(30.0*(M_PI/180.0)); // 30 deg params.end_dwell = 2; params.end_wait = 1; params.snap = 1/100000.0; params.flatness = 0.000005; params.max_framelen = params.rate / 24; params.render_flags = RENDER_GRAYSCALE; if(olInit(10, 30000) < 0) return 1; olSetRenderParams(¶ms); olSetAudioCallback(gen_audio); float time = 0; float ftime; int i,j; int frames = 0; memset(mbuf, 0, sizeof mbuf); font = olGetDefaultFont(); float xpos = 1.0; DoStars(96); DoTitle(111); DoMetaballs(143); DoFire(174); DoTunnel(175+32); DoCubes(175+32+64); DoEuskal(); #if 0 while(1) { int obj; float w; points_left = cur_draw; olPushColor(); //olMultColor(C_GREY((int)(255.0f * cur_draw / count))); olSetVertexShader(cutoff); olDrawIlda(ild); olSetVertexShader(NULL); olPopColor(); /* olSetVertexShader(sinescroller); w = olDrawString(font, xpos, 0.35, 0.4, C_WHITE, "Hello, World! This is a test message displayed using the OpenLase text functions. Sine scrollers FTW!"); if (xpos < (-w-1.5)) xpos = 1.0; olSetVertexShader(NULL);*/ /* olDrawString(font, -1, 0.35, 0.4, C_WHITE, "Hello, World!"); olDrawString(font, -1, -0, 0.4, C_WHITE, "How are you?"); olDrawString(font, -1, -0.35, 0.4, C_WHITE, " (-; :-)");*/ //render_cubes(time); //render_metaballs(time); //ender_fire(); /* olBegin(OL_BEZIERSTRIP); olVertex(0,1,C_WHITE); olVertex(1,1,C_WHITE); olVertex(1,1,C_WHITE); olVertex(1,0,C_WHITE); olVertex(1,-1,C_WHITE); olVertex(1,-1,C_WHITE); olVertex(0,-1,C_WHITE); olEnd();*/ ftime = olRenderFrame(150); frames++; gbl_time += ftime; xpos -= ftime; cur_draw += ftime * count / 5.0; if (cur_draw > count) cur_draw = count; printf("Frame time: %f, FPS:%f\n", ftime, frames/time); } #endif olShutdown(); exit (0); }
int main (int argc, char *argv[]) { initscr(); cbreak(); curs_set(0); keypad(stdscr, TRUE); nodelay(stdscr, TRUE); int wh = (LINES - WINSTART)/2; attron(A_BOLD); render_win = newwin(wh-1, COLS, WINSTART + 1, 0); scrollok(render_win, TRUE); mvprintw(WINSTART, 0, "Render messages:"); misc_win = newwin(wh-1, COLS, WINSTART + wh + 1, 0); scrollok(misc_win, TRUE); mvprintw(WINSTART + wh, 0, "Misc messages:"); attroff(A_BOLD); mvprintw(0, 0, "Keys: NEXT: -> or space PREV: <- QUIT: q\n"); refresh(); cur_win = misc_win; olSetLogCallback(logger); memset(&master_params, 0, sizeof master_params); master_params.rate = 48000; master_params.on_speed = 2.0/100.0; master_params.off_speed = 2.0/55.0; master_params.start_wait = 12; master_params.start_dwell = 3; master_params.curve_dwell = 0; master_params.corner_dwell = 8; master_params.curve_angle = cosf(30.0*(M_PI/180.0)); // 30 deg master_params.end_dwell = 3; master_params.end_wait = 7; master_params.snap = 1/100000.0; master_params.max_framelen = master_params.rate / 30; master_params.flatness = 0.000001; master_params.render_flags = RENDER_GRAYSCALE; if(olInit(4, 100000) < 0) return 1; atexit(reset_term); olSetVertexShader(shader_cube); olSetScissor (-1, -ASPECT, 1, ASPECT); //olLog("\e[6H"); OLRenderParams params = master_params; if (slides[0].init) slides[0].init(&slides[0].context, slides[0].arg, ¶ms); olSetRenderParams(¶ms); int done = 0; while (!done) { if (next_slide == -1) { mvprintw(1, 0, "Slide %d/%d", cur_slide+1, NUM_SLIDES); } else { mvprintw(1, 0, "Slide %d/%d -> %d/%d", cur_slide+1, NUM_SLIDES, next_slide+1, NUM_SLIDES); } clrtoeol(); refresh(); fd_set rfds; struct timeval tv; tv.tv_sec = tv.tv_usec = 0; FD_ZERO(&rfds); FD_SET(0, &rfds); while(1) { int ch = getch(); if (ch == ERR) break; switch (ch) { case KEY_LEFT: go(-1); break; case KEY_RIGHT: case ' ': go(1); break; case 'q': done = 1; } } cur_win = render_win; render_slides(); cur_win = misc_win; } olShutdown(); exit (0); }
void DoTunnel(float limit) { params.on_speed = 2.0/100.0; params.start_dwell = 2; params.curve_dwell = 0; params.corner_dwell = 2; params.curve_angle = cosf(30.0*(M_PI/180.0)); // 30 deg params.end_dwell = 2; params.snap = 1/100000.0; params.flatness = 0.000005; params.start_wait = 6; params.off_speed = 2.0/30.0; params.end_wait = 3; params.render_flags &= ~RENDER_NOREORDER; olSetRenderParams(¶ms); float ctime = 0; int i,j; olLoadIdentity(); float z = 0.0f; float rz = 0.0f; float dz=1.2; int id=0; while (audiotime < limit) { float left = (limit-audiotime)/AB; olResetColor(); if (ctime < 2.0) olMultColor(C_GREY((int)(255*ctime/2))); else if (left < 2.0) olMultColor(C_GREY((int)(255*left/2))); olLoadIdentity3(); olPerspective(45, 1, 1, 100); while(z > dz) { z -= dz; id++; } olScale3(0.6, 0.6, 1.0); olTranslate3(0, 0, 1.5); olTranslate3(0, 0, -z); tunnel_revxform(rz); for(i=0;i<10;i++) { if ((id+i) > 5) { olPushMatrix3(); olTranslate3(0,0,dz*i); tunnel_xform(rz+dz*(i+id)); olBegin(OL_LINESTRIP); for(j=0;j<11;j++) { float theta = j/5.0*M_PI; uint32_t c = C_RED; if(i==9) { c = C_RED_I((int)(255 * z/dz)); } olVertex3(sinf(theta), cosf(theta), 0, c); //olVertex3(j/11.0,0,0,C_WHITE); } olEnd(); olPopMatrix3(); } } for(j=0;j<10;j++) { float theta = j/5.0*M_PI; olBegin(OL_LINESTRIP); for(i=0;i<9;i++) { if ((id+i) > 5) { olPushMatrix3(); olTranslate3(0,0,dz*i); tunnel_xform(rz+dz*(i+id)); olVertex3(sinf(theta), cosf(theta), 0, C_GREEN_I((int)(255 * i/8.0)) | C_BLUE_I((int)(255 * (1-(i/8.0))))); olPopMatrix3(); } } olEnd(); } ctime += render(); z += ftime*3.2; rz += ftime*3.2; } }
int main (int argc, char *argv[]) { OLRenderParams params; AVFrame *frame; int i; // Register all formats and codecs av_register_all(); memset(¶ms, 0, sizeof params); params.rate = 48000; params.on_speed = 2.0/100.0; params.off_speed = 2.0/15.0; params.start_wait = 8; params.end_wait = 3; params.snap = 1/120.0; params.render_flags = RENDER_GRAYSCALE; params.min_length = 4; params.start_dwell = 2; params.end_dwell = 2; float snap_pix = 3; float aspect = 0; float framerate = 0; float overscan = 0; int thresh_dark = 60; int thresh_light = 160; int sw_dark = 100; int sw_light = 256; int decimate = 2; int edge_off = 0; int optchar; OLTraceParams tparams = { .mode = OL_TRACE_THRESHOLD, .sigma = 0, .threshold2 = 50 }; while ((optchar = getopt(argc, argv, "hct:T:b:w:B:W:O:d:m:S:E:D:g:s:p:a:r:R:o:v:")) != -1) { switch (optchar) { case 'h': case '?': usage(argv[0]); return 0; case 'c': tparams.mode = OL_TRACE_CANNY; tparams.sigma = 1; break; case 't': thresh_dark = thresh_light = atoi(optarg); break; case 'T': tparams.threshold2 = atoi(optarg); break; case 'b': thresh_dark = atoi(optarg); break; case 'w': thresh_light = atoi(optarg); break; case 'B': sw_dark = atoi(optarg); break; case 'W': sw_light = atoi(optarg); break; case 'O': edge_off = atoi(optarg); break; case 'd': decimate = atoi(optarg); break; case 'm': params.min_length = atoi(optarg); break; case 'S': params.start_wait = atoi(optarg); break; case 'E': params.end_wait = atoi(optarg); break; case 'D': params.start_dwell = atoi(optarg); params.end_dwell = atoi(optarg); break; case 'g': tparams.sigma = atof(optarg); break; case 's': params.off_speed = 2.0f/atof(optarg); break; case 'p': snap_pix = atof(optarg); break; case 'a': aspect = atof(optarg); break; case 'r': framerate = atof(optarg); break; case 'R': params.max_framelen = params.rate/atof(optarg); break; case 'o': overscan = atof(optarg); break; case 'v': volume = atof(optarg); break; } } if (optind == argc) { usage(argv[0]); return 1; } if (av_vid_init(argv[optind]) != 0) { printf("Video open/init failed\n"); return 1; } if (av_aud_init(argv[optind]) != 0) { printf("Audio open/init failed\n"); return 1; } if(olInit(FRAMES_BUF, 300000) < 0) { printf("OpenLase init failed\n"); return 1; } if (aspect == 0) aspect = pCodecCtx->width / (float)pCodecCtx->height; if (framerate == 0) framerate = (float)pFormatCtx->streams[videoStream]->r_frame_rate.num / (float)pFormatCtx->streams[videoStream]->r_frame_rate.den; float iaspect = 1/aspect; if (aspect > 1) { olSetScissor(-1, -iaspect, 1, iaspect); olScale(1, iaspect); } else { olSetScissor(-aspect, -1, aspect, 1); olScale(aspect, 1); } printf("Aspect is %f %f\n", aspect, iaspect); printf("Overscan is %f\n", overscan); olScale(1+overscan, 1+overscan); olTranslate(-1.0f, 1.0f); olScale(2.0f/pCodecCtx->width, -2.0f/pCodecCtx->height); int maxd = pCodecCtx->width > pCodecCtx->height ? pCodecCtx->width : pCodecCtx->height; params.snap = (snap_pix*2.0)/(float)maxd; float frametime = 1.0f/framerate; printf("Framerate: %f (%fs per frame)\n", framerate, frametime); olSetAudioCallback(moreaudio); olSetRenderParams(¶ms); float vidtime = 0; int inf=0; int bg_white = -1; float time = 0; float ftime; int frames = 0; OLFrameInfo info; OLTraceCtx *trace_ctx; OLTraceResult result; memset(&result, 0, sizeof(result)); tparams.width = pCodecCtx->width, tparams.height = pCodecCtx->height, olTraceInit(&trace_ctx, &tparams); while(GetNextFrame(pFormatCtx, pCodecCtx, videoStream, &frame)) { if (inf == 0) printf("Frame stride: %d\n", frame->linesize[0]); inf+=1; if (vidtime < time) { vidtime += frametime; printf("Frame skip!\n"); continue; } vidtime += frametime; int thresh; int obj; int bsum = 0; int c; for (c=edge_off; c<(pCodecCtx->width-edge_off); c++) { bsum += frame->data[0][c+edge_off*frame->linesize[0]]; bsum += frame->data[0][c+(pCodecCtx->height-edge_off-1)*frame->linesize[0]]; } for (c=edge_off; c<(pCodecCtx->height-edge_off); c++) { bsum += frame->data[0][edge_off+c*frame->linesize[0]]; bsum += frame->data[0][(c+1)*frame->linesize[0]-1-edge_off]; } bsum /= (2*(pCodecCtx->width+pCodecCtx->height)); if (bg_white == -1) bg_white = bsum > 128; if (bg_white && bsum < sw_dark) bg_white = 0; if (!bg_white && bsum > sw_light) bg_white = 1; if (bg_white) thresh = thresh_light; else thresh = thresh_dark; tparams.threshold = thresh; olTraceReInit(trace_ctx, &tparams); olTraceFree(&result); obj = olTrace(trace_ctx, frame->data[0], frame->linesize[0], &result); do { int i, j; for (i = 0; i < result.count; i++) { OLTraceObject *o = &result.objects[i]; olBegin(OL_POINTS); OLTracePoint *p = o->points; for (j = 0; j < o->count; j++) { if (j % decimate == 0) olVertex(p->x, p->y, C_WHITE); p++; } olEnd(); } ftime = olRenderFrame(200); olGetFrameInfo(&info); frames++; time += ftime; printf("Frame time: %.04f, Cur FPS:%6.02f, Avg FPS:%6.02f, Drift: %7.4f, " "In %4d, Out %4d Thr %3d Bg %3d Pts %4d", ftime, 1/ftime, frames/time, time-vidtime, inf, frames, thresh, bsum, info.points); if (info.resampled_points) printf(" Rp %4d Bp %4d", info.resampled_points, info.resampled_blacks); if (info.padding_points) printf(" Pad %4d", info.padding_points); printf("\n"); } while ((time+frametime) < vidtime); } olTraceDeinit(trace_ctx); for(i=0;i<FRAMES_BUF;i++) olRenderFrame(200); olShutdown(); av_deinit(); exit (0); }
void *display_thread(void *arg) { PlayerCtx *ctx = arg; int i; OLRenderParams params; memset(¶ms, 0, sizeof params); params.rate = 48000; params.on_speed = 2.0/100.0; params.off_speed = 2.0/15.0; params.start_wait = 8; params.end_wait = 3; params.snap = 1/120.0; params.render_flags = RENDER_GRAYSCALE; params.min_length = 20; params.start_dwell = 2; params.end_dwell = 2; params.max_framelen = 48000/20.0; if(olInit(OL_FRAMES_BUF, 300000) < 0) { printf("OpenLase init failed\n"); return NULL; } float aspect = ctx->width / (float)ctx->height; float sample_aspect = av_q2d(ctx->v_stream->sample_aspect_ratio); if (sample_aspect != 0) aspect *= sample_aspect; printf("Aspect: %f\n", aspect); float iaspect = 1/aspect; int maxd = ctx->width > ctx->height ? ctx->width : ctx->height; int mind = ctx->width < ctx->height ? ctx->width : ctx->height; g_ctx = ctx; olSetAudioCallback(get_audio); olSetRenderParams(¶ms); OLTraceCtx *trace_ctx; OLTraceParams tparams; OLTraceResult result; memset(&result, 0, sizeof(result)); ctx->settings_changed = 1; tparams.sigma = ctx->settings.blur / 100.0; if (ctx->settings.canny) tparams.mode = OL_TRACE_CANNY; else tparams.mode = OL_TRACE_THRESHOLD; tparams.width = ctx->width; tparams.height = ctx->height; printf("Resolution: %dx%d\n", ctx->width, ctx->height); olTraceInit(&trace_ctx, &tparams); VideoFrame *last = NULL; pthread_mutex_lock(&ctx->display_mode_mutex); DisplayMode display_mode = ctx->display_mode; pthread_mutex_unlock(&ctx->display_mode_mutex); int inf = 0; int bg_white = -1; float time = 0; int frames = 0; while (display_mode != STOP) { pthread_mutex_lock(&ctx->settings_mutex); PlayerSettings settings = ctx->settings; int settings_changed = ctx->settings_changed; ctx->settings_changed = 0; pthread_mutex_unlock(&ctx->settings_mutex); if (ctx->audio_idx == -1) { drop_all_video(ctx); next_video_frame(ctx); } params.min_length = settings.minsize; params.end_dwell = params.start_dwell = settings.dwell; params.off_speed = settings.offspeed * 0.002; params.snap = (settings.snap*2.0)/(float)maxd; params.start_wait = settings.startwait; params.end_wait = settings.endwait; if (settings.minrate == 0) params.max_framelen = 0; else params.max_framelen = params.rate / settings.minrate; olSetRenderParams(¶ms); olLoadIdentity(); if (aspect > 1) { olSetScissor(-1, -iaspect, 1, iaspect); olScale(1, iaspect); } else { olSetScissor(-aspect, -1, aspect, 1); olScale(aspect, 1); } olScale(1 + settings.overscan/100.0, 1 + settings.overscan/100.0); olTranslate(-1.0f, 1.0f); olScale(2.0f/ctx->width, -2.0f/ctx->height); if (!ctx->cur_frame || ctx->cur_frame->seekid < 0) { printf("Dummy frame\n"); float ftime = olRenderFrame(80); pthread_mutex_lock(&ctx->display_mode_mutex); display_mode = ctx->display_mode; pthread_mutex_unlock(&ctx->display_mode_mutex); if (ctx->cur_frame && ctx->cur_frame->seekid < 0) deliver_event(ctx, time, ftime, frames, 1); else deliver_event(ctx, time, ftime, frames, 0); continue; } if (last != ctx->cur_frame || settings_changed) { tparams.sigma = settings.blur / 100.0; if (settings.canny) { tparams.mode = OL_TRACE_CANNY; tparams.threshold = settings.threshold; tparams.threshold2 = settings.threshold2; bg_white = -1; } else { tparams.mode = OL_TRACE_THRESHOLD; if (settings.splitthreshold) { int edge_off = mind * settings.offset / 100; int bsum = 0; int cnt = 0; int c; for (c = edge_off; c < (ctx->width-edge_off); c++) { bsum += ctx->cur_frame->data[c+edge_off*ctx->cur_frame->stride]; bsum += ctx->cur_frame->data[c+(ctx->height-edge_off-1)*ctx->cur_frame->stride]; cnt += 2; } for (c = edge_off; c < (ctx->height-edge_off); c++) { bsum += ctx->cur_frame->data[edge_off+ctx->cur_frame->stride]; bsum += ctx->cur_frame->data[(c+1)*ctx->cur_frame->stride-1-edge_off]; cnt += 2; } bsum /= cnt; if (bg_white == -1) bg_white = bsum > ((settings.darkval + settings.lightval)/2); if (bg_white && bsum < settings.darkval) bg_white = 0; if (!bg_white && bsum > settings.lightval) bg_white = 1; if (bg_white) tparams.threshold = settings.threshold2; else tparams.threshold = settings.threshold; } else { tparams.threshold = settings.threshold; } } olTraceReInit(trace_ctx, &tparams); olTraceFree(&result); printf("Trace\n"); olTrace(trace_ctx, ctx->cur_frame->data, ctx->cur_frame->stride, &result); printf("Trace done\n"); inf++; last = ctx->cur_frame; } int i, j; for (i = 0; i < result.count; i++) { OLTraceObject *o = &result.objects[i]; olBegin(OL_POINTS); OLTracePoint *p = o->points; for (j = 0; j < o->count; j++) { if (j % settings.decimation == 0) olVertex(p->x, p->y, C_WHITE); p++; } olEnd(); } float ftime = olRenderFrame(80); OLFrameInfo info; olGetFrameInfo(&info); frames++; time += ftime; printf("Frame time: %.04f, Cur FPS:%6.02f, Avg FPS:%6.02f, Drift: %7.4f, " "In %4d, Out %4d Thr %3d/%3d Bg %3d Pts %4d", ftime, 1/ftime, frames/time, 0.0, inf, frames, tparams.threshold, tparams.threshold2, 0, info.points); if (info.resampled_points) printf(" Rp %4d Bp %4d", info.resampled_points, info.resampled_blacks); if (info.padding_points) printf(" Pad %4d", info.padding_points); printf("\n"); deliver_event(ctx, time, ftime, frames, 0); pthread_mutex_lock(&ctx->display_mode_mutex); display_mode = ctx->display_mode; pthread_mutex_unlock(&ctx->display_mode_mutex); } olTraceDeinit(trace_ctx); for(i = 0; i < OL_FRAMES_BUF; i++) olRenderFrame(80); olShutdown(); return NULL; }