// TODO: need a "now" take it as an argument void simple_soft_render(struct simple_soft_ctx *ctx, Pixbuf *out, int64_t now, int64_t tick0) { ctx->m = (ctx->m+1)&0x1; if(tick0+(ctx->maxfrms*1000)/ctx->maxsrc_rate - now > 1000/ctx->maxsrc_rate) { maxsrc_update(ctx->maxsrc, ctx->prev_buf, ctx->nr_samp/2); ctx->maxfrms++; } if(!ctx->rational_julia) { ctx->map_func(ctx->map_surf[ctx->m], ctx->map_surf[(ctx->m+1)&0x1], ctx->im_w, ctx->im_h, ctx->pd); maxblend(ctx->map_surf[ctx->m], maxsrc_get(ctx->maxsrc), ctx->im_w, ctx->im_h); } if(ctx->rational_julia) { maxblend(ctx->map_surf[(ctx->m+1)&0x1], maxsrc_get(ctx->maxsrc), ctx->im_w, ctx->im_h); ctx->map_func(ctx->map_surf[ctx->m], ctx->map_surf[(ctx->m+1)&0x1], ctx->im_w, ctx->im_h, ctx->pd); } // rather than just audio clock if((now - ctx->lastpalstep)*256/1024 >= 1) { // want pallet switch to take ~2 seconds pal_ctx_step(ctx->pal_ctx, IMIN((now - ctx->lastpalstep)*256/1024, 32)); ctx->lastpalstep = now; } pallet_blit_Pixbuf(out, ctx->map_surf[ctx->m], ctx->im_w, ctx->im_h, pal_ctx_get_active(ctx->pal_ctx)); //pallet_blit_Pixbuf(out, maxsrc_get(ctx->maxsrc), ctx->im_w, ctx->im_h, pal_ctx_get_active(ctx->pal_ctx)); int newbeat = beat_ctx_count(ctx->beat); if(newbeat != ctx->beats) pal_ctx_start_switch(ctx->pal_ctx, newbeat); if(newbeat != ctx->beats && now - ctx->last_beat_time > 1000) { ctx->last_beat_time = now; update_points(ctx->pd, (now - tick0), 1); } else update_points(ctx->pd, (now - tick0), 0); ctx->beats = newbeat; }
static int run_map_thread(tribuf *tb) { set_threadname("render"); struct point_data *pd = new_point_data(opts.rational_julia?4:2); unsigned int beats = beat_get_count(); unsigned int tick0, fps_oldtime, frmcnt=0, last_beat_time = 0; tick0 = fps_oldtime = SDL_GetTicks(); unsigned int fpstimes[40]; for(int i=0; i<40; i++) fpstimes[i] = 0; uint16_t *map_src = tribuf_get_read_nolock(tb); while(running) { frmcnt++; if((tick0-SDL_GetTicks())*opts.maxsrc_rate + (maxfrms*1000) > 1000) { audio_data ad; audio_get_samples(&ad); maxsrc_update(maxsrc, ad.data, ad.len); audio_finish_samples(); maxfrms++; } uint16_t *map_dest = tribuf_get_write(tb); map_func(map_dest, map_src, im_w, im_h, pd); maxblend(map_dest, maxsrc_get(maxsrc), im_w, im_h); tribuf_finish_write(tb); map_src=map_dest; unsigned int now = SDL_GetTicks() - tick0; float fpsd = (now - fpstimes[frmcnt%40])/1000.0f; fpstimes[frmcnt%40] = now; map_fps = 40.0f / fpsd; unsigned int newbeat = beat_get_count(); if(newbeat != beats && now - last_beat_time > 1000) { last_beat_time = now; update_points(pd, now, 1); } else update_points(pd, now, 0); beats = newbeat; if(map_fps > 750) SDL_Delay(1); // hard limit ourselves because 1500FPS is just pointless use of CPU (except of course to say that we can do it) // also if we run at more that 1000FPS the point motion code might blow up without the microsecond accurate timers... // high threshhold because we want it high enough that we don't notice if we jitter back // and fourth across it } return 0; }