1 /* vi:set ts=8 sts=8 sw=8 noexpandtab: */
10 #include "filetypes.h"
12 void audiocb(void *userdata
, Uint8
*buf
, int len
) {
15 for(i
= 0; i
< len
; i
++) {
16 buf
[i
] = interrupthandler();
20 int main(int argc
, char **argv
){
21 SDL_AudioSpec requested
, obtained
;
28 static char chars
[10] =
30 '+', '-', '*', '#', 'X', '@', '%', '$', 'M', 'W'
35 caca_canvas_t
*pineapple
;
37 if(SDL_Init( SDL_INIT_AUDIO
) < 0){
38 err(1, "Couldnt initialize SDL\n");
42 cv
= caca_create_canvas(80, 24);
43 pineapple
= caca_create_canvas(0, 0);
44 if((cv
== NULL
) || (pineapple
== NULL
)){
45 printf("failed to create canvas\n");
48 dp
= caca_create_display(cv
);
49 caca_set_display_time(dp
, 20000);
51 printf("Failed to create display\n");
55 caca_import_file(pineapple
, "./pineapple", "");
59 requested
.freq
= 48000;
60 requested
.format
= AUDIO_U8
;
61 requested
.samples
= 4096;
62 requested
.callback
= audiocb
;
63 requested
.channels
= 1;
65 if(SDL_OpenAudio(&requested
, &obtained
) == -1){
66 err(1, "SDL_OpenAudio");
71 lft_loadfile(argv
[1]);
81 caca_set_color_ansi(cv
, CACA_DEFAULT
, CACA_DEFAULT
);
82 caca_clear_canvas(cv
);
83 xo
= caca_get_canvas_width(cv
);
84 yo
= caca_get_canvas_height(cv
);
85 //caca_blit(cv, 0, 0, pineapple, NULL);
86 caca_blit(cv
, 55, 0, pineapple
, NULL
);
87 caca_set_color_ansi(cv
, caca_rand(0, 16), caca_rand(0, 16));
88 caca_put_str(cv
, (xo
- strlen("pineapple player")) / 2, (yo
/ 2) - 5, "pineapple player");
89 caca_set_color_ansi(cv
, caca_rand(0, 16), caca_rand(0, 16));
90 caca_printf(cv
, (xo
- strlen("song pos -> ")) / 2, (yo
/ 2) - 3, "song pos -> %x", songpos
);
92 for(i
= 0; i
< 4; i
++)
93 meter
[i
] = (osc
[i
].volume
*20)/255;
96 for(j
= 0; j
< 25; j
=j
+6){
97 for(k
= 0; k
< 4; k
++){
98 caca_draw_line(cv
, (((xo
/2)+10)-j
)-k
, yo
, (((xo
/2)+10)-j
)-k
, yo
- meter
[i
],
99 chars
[caca_rand(0, 9)]);
104 for(i
= 0; i
< 4; i
++)
105 caca_printf(cv
, 0, i
, "%0x", osc
[i
].volume
);
107 while(caca_get_event(dp
, CACA_EVENT_ANY
, &ev
, 0))
109 if(caca_get_event_type(&ev
) & CACA_EVENT_KEY_PRESS
)
111 switch(caca_get_event_key_ch(&ev
))
115 case CACA_KEY_ESCAPE
:
121 caca_refresh_display(dp
);
124 caca_free_display(dp
);
125 caca_free_canvas(cv
);