Example #1
0
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(&params);
			olRect(-1, -ASPECT, 1, ASPECT, C_GREY(bcolor > 255 ? 255 : bcolor));
			olSetRenderParams(&old);
		}

		slides[num].render(slides[num].context, stime, state * ST_VANISH);
	}
}
Example #2
0
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(&params);

	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();
	}
}
Example #3
0
int main (int argc, char *argv[])
{
	OLRenderParams params;

	memset(&params, 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(&params);

	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);
}
Example #4
0
int rx_callback(hackrf_transfer* transfer) {
	int8_t* buf;
	uint8_t* ubuf;
	uint64_t frequency; /* in Hz */
	uint64_t band_edge;
	uint32_t record_length;
	int i, j, ifft_bins;
	struct tm *fft_time;
	char time_str[50];
	struct timeval usb_transfer_time;

	if(NULL == fd) {
		return -1;
	}

	gettimeofday(&usb_transfer_time, NULL);
	byte_count += transfer->valid_length;
	buf = (int8_t*) transfer->buffer;
	ifft_bins = fftSize * step_count;
	for(j=0; j<BLOCKS_PER_TRANSFER; j++) {
		ubuf = (uint8_t*) buf;
		if(ubuf[0] == 0x7F && ubuf[1] == 0x7F) {
			frequency = ((uint64_t)(ubuf[9]) << 56) | ((uint64_t)(ubuf[8]) << 48) | ((uint64_t)(ubuf[7]) << 40)
					| ((uint64_t)(ubuf[6]) << 32) | ((uint64_t)(ubuf[5]) << 24) | ((uint64_t)(ubuf[4]) << 16)
					| ((uint64_t)(ubuf[3]) << 8) | ubuf[2];
		} else {
			buf += BYTES_PER_BLOCK;
			continue;
		}

		if (frequency == (uint64_t)(FREQ_ONE_MHZ*frequencies[0])) {
			if(sweep_started) {
				if(ifft_output) {
					fftwf_execute(ifftwPlan);
					for(i=0; i < ifft_bins; i++) {
						ifftwOut[i][0] *= 1.0f / ifft_bins;
						ifftwOut[i][1] *= 1.0f / ifft_bins;
						fwrite(&ifftwOut[i][0], sizeof(float), 1, fd);
						fwrite(&ifftwOut[i][1], sizeof(float), 1, fd);
					}
				}
				if (openlase_output) {
					olLoadIdentity3();
					olLoadIdentity();
//					olPerspective(60, 1, 1, 100);
					olTranslate3(0, 0, -3);

					olScale3(0.6f, 0.6f, 0.6f);

					int len = fftSize * step_count;
					olBegin(OL_LINESTRIP);
					float mul = 2.0f / len;
					for (int i = 0; i < len; i++) {
						float x = i * mul - 1.0f;
						float pwr = openlaseBuf[i] / 100.0f;
						olVertex3(x, pwr, 0.0f, (255 << 16) | 255);
					}
					olEnd();
					olRenderFrame(60);

				}
				sweep_count++;
				if(one_shot) {
					do_exit = true;
				}
			}
			sweep_started = true;
			time_stamp = usb_transfer_time;
			time_stamp.tv_usec +=
					(uint64_t)(num_samples + THROWAWAY_BLOCKS * SAMPLES_PER_BLOCK)
					* j * FREQ_ONE_MHZ / DEFAULT_SAMPLE_RATE_HZ;
			if(999999 < time_stamp.tv_usec) {
				time_stamp.tv_sec += time_stamp.tv_usec / 1000000;
				time_stamp.tv_usec = time_stamp.tv_usec % 1000000;
			}
		}
		if(do_exit) {
			return 0;
		}
		if(!sweep_started) {
			buf += BYTES_PER_BLOCK;
			continue;
		}
		if((FREQ_MAX_MHZ * FREQ_ONE_MHZ) < frequency) {
			buf += BYTES_PER_BLOCK;
			continue;
		}
		/* copy to fftwIn as floats */
		buf += BYTES_PER_BLOCK - (fftSize * 2);
		for(i=0; i < fftSize; i++) {
			fftwIn[i][0] = buf[i*2] * window[i] * 1.0f / 128.0f;
			fftwIn[i][1] = buf[i*2+1] * window[i] * 1.0f / 128.0f;
		}
		buf += fftSize * 2;
		fftwf_execute(fftwPlan);
		for (i=0; i < fftSize; i++) {
			pwr[i] = logPower(fftwOut[i], 1.0f / fftSize);
		}
		if(binary_output) {
			record_length = 2 * sizeof(band_edge)
					+ (fftSize/4) * sizeof(float);

			fwrite(&record_length, sizeof(record_length), 1, fd);
			band_edge = frequency;
			fwrite(&band_edge, sizeof(band_edge), 1, fd);
			band_edge = frequency + DEFAULT_SAMPLE_RATE_HZ / 4;
			fwrite(&band_edge, sizeof(band_edge), 1, fd);
			fwrite(&pwr[1+(fftSize*5)/8], sizeof(float), fftSize/4, fd);

			fwrite(&record_length, sizeof(record_length), 1, fd);
			band_edge = frequency + DEFAULT_SAMPLE_RATE_HZ / 2;
			fwrite(&band_edge, sizeof(band_edge), 1, fd);
			band_edge = frequency + (DEFAULT_SAMPLE_RATE_HZ * 3) / 4;
			fwrite(&band_edge, sizeof(band_edge), 1, fd);
			fwrite(&pwr[1+fftSize/8], sizeof(float), fftSize/4, fd);
		} else if(ifft_output) {
			ifft_idx = (uint32_t) round((frequency - (uint64_t)(FREQ_ONE_MHZ*frequencies[0]))
					/ fft_bin_width);
			ifft_idx = (ifft_idx + ifft_bins/2) % ifft_bins;
			for(i = 0; (fftSize / 4) > i; i++) {
				ifftwIn[ifft_idx + i][0] = fftwOut[i + 1 + (fftSize*5)/8][0];
				ifftwIn[ifft_idx + i][1] = fftwOut[i + 1 + (fftSize*5)/8][1];
			}
			ifft_idx += fftSize / 2;
			ifft_idx %= ifft_bins;
			for(i = 0; (fftSize / 4) > i; i++) {
				ifftwIn[ifft_idx + i][0] = fftwOut[i + 1 + (fftSize/8)][0];
				ifftwIn[ifft_idx + i][1] = fftwOut[i + 1 + (fftSize/8)][1];
			}
		} else if (openlase_output) {
			ifft_idx = (uint32_t) round((frequency - (uint64_t)(FREQ_ONE_MHZ*frequencies[0]))
					/ fft_bin_width);
			ifft_idx = (ifft_idx + ifft_bins/2) % ifft_bins;
			for(i = 0; (fftSize / 4) > i; i++) {
				openlaseBuf[ifft_idx + i] = pwr[i + 1 + (fftSize*5)/8];
			}
			ifft_idx += fftSize / 2;
			ifft_idx %= ifft_bins;
			for(i = 0; (fftSize / 4) > i; i++) {
				openlaseBuf[ifft_idx + i] = pwr[i + 1 + (fftSize/8)];
			}
		} else {
			time_t time_stamp_seconds = time_stamp.tv_sec;
			fft_time = localtime(&time_stamp_seconds);
			strftime(time_str, 50, "%Y-%m-%d, %H:%M:%S", fft_time);
			fprintf(fd, "%s.%06ld, %" PRIu64 ", %" PRIu64 ", %.2f, %u",
					time_str,
					(long int)time_stamp.tv_usec,
					(uint64_t)(frequency),
					(uint64_t)(frequency+DEFAULT_SAMPLE_RATE_HZ/4),
					fft_bin_width,
					fftSize);
			for(i = 0; (fftSize / 4) > i; i++) {
				fprintf(fd, ", %.2f", pwr[i + 1 + (fftSize*5)/8]);
			}
			fprintf(fd, "\n");
			fprintf(fd, "%s.%06ld, %" PRIu64 ", %" PRIu64 ", %.2f, %u",
					time_str,
					(long int)time_stamp.tv_usec,
					(uint64_t)(frequency+(DEFAULT_SAMPLE_RATE_HZ/2)),
					(uint64_t)(frequency+((DEFAULT_SAMPLE_RATE_HZ*3)/4)),
					fft_bin_width,
					fftSize);
			for(i = 0; (fftSize / 4) > i; i++) {
				fprintf(fd, ", %.2f", pwr[i + 1 + (fftSize/8)]);
			}
			fprintf(fd, "\n");
		}
	}
	return 0;
}
Example #5
0
int main (int argc, char *argv[])
{
	OLRenderParams params;

	memset(&params, 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(&params);

	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);
}
Example #6
0
static VALUE
ol_loadIdentity()
{
  olLoadIdentity();
  return Qnil;
}
Example #7
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(&params);

	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;

	}
}
Example #8
0
void render_cubes(float time)
{
	int i;

	OLRenderParams mpar;

	memcpy(&mpar, &params, 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(&params);
	olResetColor();
}
Example #9
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(&params, 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(&params);

	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);
}
Example #10
0
void *display_thread(void *arg)
{
	PlayerCtx *ctx = arg;
	int i;

	OLRenderParams params;
	memset(&params, 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(&params);

	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(&params);

		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;
}