Skip to content

Commit

Permalink
Wave mode 5, untested
Browse files Browse the repository at this point in the history
  • Loading branch information
lekernel committed Aug 19, 2009
1 parent 5a0d425 commit 1ff9911
Show file tree
Hide file tree
Showing 11 changed files with 176 additions and 78 deletions.
14 changes: 12 additions & 2 deletions milkymist-core/software/demo/apipe.c
Expand Up @@ -144,12 +144,19 @@ static void pfv_callback(struct pfpu_td *td)
rpipe_frame = (struct rpipe_frame *)td->user;

rpipe_frame->brightness = 63.0f*eval_read_pfv(eval, pfv_decay);

rpipe_frame->wave_mode = eval_read_pfv(eval, pfv_wave_mode);
rpipe_frame->wave_scale = eval_read_pfv(eval, pfv_wave_scale);
rpipe_frame->wave_additive = eval_read_pfv(eval, pfv_wave_additive) != 0.0f;
rpipe_frame->wave_usedots = eval_read_pfv(eval, pfv_wave_usedots) != 0.0f;
rpipe_frame->wave_maximize_color = eval_read_pfv(eval, pfv_wave_maximize_color) != 0.0f;
rpipe_frame->wave_thick = eval_read_pfv(eval, pfv_wave_thick) != 0.0f;
rpipe_frame->wave_x = eval_read_pfv(eval, pfv_wave_x);
rpipe_frame->wave_y = eval_read_pfv(eval, pfv_wave_y);
rpipe_frame->wave_r = eval_read_pfv(eval, pfv_wave_r);
rpipe_frame->wave_g = eval_read_pfv(eval, pfv_wave_g);
rpipe_frame->wave_b = eval_read_pfv(eval, pfv_wave_b);
rpipe_frame->wave_a = eval_read_pfv(eval, pfv_wave_a);
rpipe_frame->wave_additive = eval_read_pfv(eval, pfv_wave_additive) != 0.0f;
rpipe_frame->wave_usedots = eval_read_pfv(eval, pfv_wave_usedots) != 0.0f;

eval_pfv_to_pvv(eval);
eval_pvv_fill_td(eval, &pfpu_td, &rpipe_frame->vertices[0][0], pvv_callback, rpipe_frame);
Expand Down Expand Up @@ -206,6 +213,9 @@ static void analyzer_bottom_half()
eval_write_pfv(eval, pfv_mid_att, mid_att);
eval_write_pfv(eval, pfv_treb_att, treb_att);

rpipe_frame->time = time;
rpipe_frame->treb = ftreb;

eval_pfv_fill_td(eval, &pfpu_td, pfv_callback, rpipe_frame);
pfpu_submit_task(&pfpu_td);
}
Expand Down
2 changes: 1 addition & 1 deletion milkymist-core/software/demo/ast.h
Expand Up @@ -21,7 +21,7 @@

#define NDEBUG

#define IDENTIFIER_SIZE 16
#define IDENTIFIER_SIZE 24

struct preset_equation;

Expand Down
2 changes: 1 addition & 1 deletion milkymist-core/software/demo/brd.c
Expand Up @@ -22,7 +22,7 @@

#include "brd.h"

struct board_desc *brd_desc;
const struct board_desc *brd_desc;

void brd_init()
{
Expand Down
2 changes: 1 addition & 1 deletion milkymist-core/software/demo/brd.h
Expand Up @@ -19,7 +19,7 @@
#ifndef __BRD_H
#define __BRD_H

extern struct board_desc *brd_desc;
extern const struct board_desc *brd_desc;

void brd_init();

Expand Down
3 changes: 3 additions & 0 deletions milkymist-core/software/demo/eval.c
Expand Up @@ -44,6 +44,8 @@ static const char pfv_names[EVAL_PFV_COUNT][IDENTIFIER_SIZE] = {
"wave_scale",
"wave_additive",
"wave_usedots",
"bMaximizeWaveColor",
"wave_thick",
"wave_x",
"wave_y",
"wave_r",
Expand All @@ -70,6 +72,7 @@ static int pfv_from_name(const char *name)
if(strcmp(name, "fWaveScale") == 0) return pfv_wave_scale;
if(strcmp(name, "bAdditiveWaves") == 0) return pfv_wave_additive;
if(strcmp(name, "bWaveDots") == 0) return pfv_wave_usedots;
if(strcmp(name, "bWaveThick") == 0) return pfv_wave_thick;
if(strcmp(name, "fWaveAlpha") == 0) return pfv_wave_a;
return -1;
}
Expand Down
2 changes: 2 additions & 0 deletions milkymist-core/software/demo/eval.h
Expand Up @@ -41,6 +41,8 @@ enum {
pfv_wave_scale,
pfv_wave_additive,
pfv_wave_usedots,
pfv_wave_maximize_color,
pfv_wave_thick,
pfv_wave_x,
pfv_wave_y,
pfv_wave_r,
Expand Down
169 changes: 136 additions & 33 deletions milkymist-core/software/demo/rpipe.c
Expand Up @@ -20,6 +20,7 @@
#include <console.h>
#include <irq.h>
#include <system.h>
#include <math.h>
#include <hw/interrupts.h>

#include "renderer.h"
Expand Down Expand Up @@ -124,70 +125,172 @@ int rpipe_input(struct rpipe_frame *frame)
return 1;
}

static void rpipe_bottom_half()
/* TODO: implement missing wave modes */

static int wave_mode_0(struct wave_vertex *vertices)
{
struct wave_vertex vertices[100];
struct wave_params params;
return 0;
}

static int wave_mode_1(struct wave_vertex *vertices)
{
return 0;
}

static int wave_mode_2(struct wave_vertex *vertices)
{
return 0;
}

static int wave_mode_3(struct wave_vertex *vertices)
{
return 0;
}

static int wave_mode_4(struct wave_vertex *vertices)
{
return 0;
}

static int wave_mode_5(struct wave_vertex *vertices)
{
int nvertices;
int i;
unsigned int oldmask;
float s1, s2;
float x0, y0;
float cos_rot, sin_rot;
int x, y;

nvertices = 256-64;

cos_rot = cosf(bh_frame->time*0.3f);
sin_rot = sinf(bh_frame->time*0.3f);

for(i=0;i<nvertices;i++) {
s1 = bh_frame->samples[4*i ]/32768.0;
s2 = bh_frame->samples[4*i+64+1]/32768.0;
x0 = 2.0*s1*s2;
y0 = s1*s1 - s2*s2;

x = (float)vga_hres*((x0*cos_rot - y0*sin_rot)*bh_frame->wave_scale*0.5 + bh_frame->wave_x);
y = (float)vga_vres*((x0*sin_rot + y0*cos_rot)*bh_frame->wave_scale*0.5 + bh_frame->wave_y);

if(x < 0) x = 0;
if(x >= vga_hres) x = vga_hres - 1;
if(y < 0) y = 0;
if(y >= vga_vres) y = vga_vres - 1;

vertices[i].x = x;
vertices[i].y = y;
}

return nvertices;
}

static int wave_mode_6(struct wave_vertex *vertices)
{
return 0;
}

static int wave_mode_7(struct wave_vertex *vertices)
{
return 0;
}

static void rpipe_draw_waves()
{
struct wave_params params;
struct wave_vertex vertices[256];
int nvertices;

/*
* We assume that the VGA back buffer is not in any cache
* (such a cached copy would be incoherent because the TMU
* has just written it, straight to SDRAM).
*/

/* Draw waves */
params.wave_mode = 5;
params.wave_mode = bh_frame->wave_mode;
params.wave_additive = bh_frame->wave_additive;
params.wave_dots = bh_frame->wave_usedots;
params.wave_maximize_color = bh_frame->wave_maximize_color;
params.wave_thick = bh_frame->wave_thick;

params.wave_r = bh_frame->wave_r;
params.wave_g = bh_frame->wave_g;
params.wave_b = bh_frame->wave_b;
params.wave_alpha = bh_frame->wave_a;
params.maximize_wave_color = 1;
params.wave_dots = bh_frame->wave_usedots;
params.wave_thick = 1;
params.additive_waves = bh_frame->wave_additive;
params.wave_loop = 0;
params.treb = 0.2;

for(i=0;i<40;i++) {
int a;
vertices[i].x = 639*i/39;
a = 240 + 200*(int)bh_frame->samples[16*i]/32768;
if(a < 0) a = 0;
if(a > 479) a = 479;
vertices[i].y = a;
params.wave_a = bh_frame->wave_a;

params.treb = bh_frame->treb;

switch(bh_frame->wave_mode) {
case 0:
nvertices = wave_mode_0(vertices);
break;
case 1:
nvertices = wave_mode_1(vertices);
break;
case 2:
nvertices = wave_mode_2(vertices);
break;
case 3:
nvertices = wave_mode_3(vertices);
break;
case 4:
nvertices = wave_mode_4(vertices);
break;
case 5:
nvertices = wave_mode_5(vertices);
break;
case 6:
nvertices = wave_mode_6(vertices);
break;
case 7:
nvertices = wave_mode_7(vertices);
break;
default:
nvertices = 0;
break;
}

wave_draw(vga_backbuffer, vga_hres, vga_vres, &params, vertices, 40);

/* Draw spam */
wave_draw(vga_backbuffer, vga_hres, vga_vres, &params, vertices, nvertices);
}

static void rpipe_draw_spam()
{
int dx, dy;
int x, y;

spam_counter++;
if(spam_counter > SPAM_PERIOD) {
int dx, dy;
int x, y;

dx = (vga_hres-SPAM_W)/2;
dy = vga_vres/2-SPAM_H;

for(y=0;y<SPAM_H;y++)
for(x=0;x<SPAM_W;x++) {
if(spam_xpm[y+3][x] == SPAM_ON)
vga_backbuffer[vga_hres*(dy+y)+dx+x] = 0xffff;
}

spam_counter = 0;
}
}

static void rpipe_bottom_half()
{
unsigned int oldmask;

rpipe_draw_waves();
rpipe_draw_spam();

/* Update display */
flush_bridge_cache();
vga_swap_buffers();

/* Update statistics */
oldmask = irq_getmask();
irq_setmask(oldmask & ~(IRQ_TIMER0));
frames++;
irq_setmask(oldmask);

/* Update display */
flush_bridge_cache();
vga_swap_buffers();
}

void rpipe_service()
Expand Down
10 changes: 9 additions & 1 deletion milkymist-core/software/demo/rpipe.h
Expand Up @@ -28,8 +28,16 @@ typedef void (*rpipe_callback)(struct rpipe_frame *frame);
struct rpipe_frame {
struct tmu_vertex vertices[TMU_MESH_MAXSIZE][TMU_MESH_MAXSIZE];
unsigned int brightness;
unsigned int wave_mode;
float wave_scale;
int wave_additive;
int wave_usedots;
int wave_maximize_color;
int wave_thick;
float wave_x, wave_y;
float wave_r, wave_b, wave_g, wave_a;
int wave_additive, wave_usedots;
float treb;
float time;
unsigned int nsamples; /* < audio samples */
short *samples;
rpipe_callback callback;
Expand Down
30 changes: 1 addition & 29 deletions milkymist-core/software/demo/shell.c
Expand Up @@ -363,33 +363,6 @@ static void echo()
}
}

static void wavetest()
{
int i;
struct wave_vertex vertices[100];
struct wave_params params;

params.wave_mode = 5;
params.wave_r = 0.5;
params.wave_g = 0.5;
params.wave_b = 0.8;
params.wave_alpha = 3.299999;
params.maximize_wave_color = 1;
params.wave_dots = 1;
params.wave_thick = 1;
params.additive_waves = 1;
params.wave_loop = 0;
params.treb = 0.2;

for(i=0;i<100;i++) {
vertices[i].x = 640*i/100;
vertices[i].y = 240 + 200.0*cosf(4.0*6.28*(float)i/100.0f);
}

wave_draw(vga_frontbuffer, vga_hres, vga_vres, &params, vertices, 100);
flush_bridge_cache();
}

static char *get_token(char **str)
{
char *c, *d;
Expand Down Expand Up @@ -425,8 +398,7 @@ static void do_command(char *c)
else if(strcmp(token, "pfputest") == 0) pfputest();
else if(strcmp(token, "tmutest") == 0) tmutest();
else if(strcmp(token, "echo") == 0) echo();
else if(strcmp(token, "wavetest") == 0) wavetest();


else if(strcmp(token, "") != 0) printf("Command not found: '%s'\n", token);
}

Expand Down
9 changes: 5 additions & 4 deletions milkymist-core/software/demo/wave.c
Expand Up @@ -40,7 +40,7 @@ void wave_draw(unsigned short *framebuffer, unsigned int hres, unsigned int vres
line_init_context(&ctx, framebuffer, hres, vres);

//TODO: implement modulate_opacity_by_volume
wave_o = params->wave_alpha;
wave_o = params->wave_a;
// Original code: maximize_colors
wave_r = params->wave_r;
wave_g = params->wave_g;
Expand All @@ -63,7 +63,7 @@ void wave_draw(unsigned short *framebuffer, unsigned int hres, unsigned int vres
wave_o *= params->treb*params->treb;
}

if(params->maximize_wave_color) {
if(params->wave_maximize_color) {
// WARNING: softfloat ">=" operator is broken (says 0.5 >= 0.8)
// ">" works fine
if((wave_r > wave_g) && (wave_r > wave_b)) {
Expand Down Expand Up @@ -112,7 +112,7 @@ void wave_draw(unsigned short *framebuffer, unsigned int hres, unsigned int vres
// glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
// else
// glBlendFunc(GL_SRC_ALPHA, GL_ONE);
if(params->additive_waves)
if(params->wave_additive)
ctx.additive = 1;

// Original code:
Expand All @@ -125,7 +125,8 @@ void wave_draw(unsigned short *framebuffer, unsigned int hres, unsigned int vres
for(i=0;i<(nvertices-1);i++)
line(&ctx, vertices[i].x, vertices[i].y, vertices[i+1].x, vertices[i+1].y);

if(params->wave_loop)
// draw_wave_as_loop
if(params->wave_mode == 0)
line(&ctx, vertices[0].x, vertices[0].y, vertices[nvertices-1].x, vertices[nvertices-1].y);

// TODO: implement two_waves
Expand Down

0 comments on commit 1ff9911

Please sign in to comment.