visplugin/actor_gizmod.c

00001 #include <stdio.h>
00002 #include <stdlib.h>
00003 #include <unistd.h>
00004 #include <fcntl.h>
00005 #include <string.h>
00006 #include <math.h>
00007 #include <sys/stat.h>
00008 #include <sys/types.h>
00009 
00010 #include <libvisual/libvisual.h>
00011 #include "GizmodLibVisualCInterface.h"
00012 
00013 #if HAVE_CONFIG_H
00014 #include <config.h>
00015 #endif
00016 #define CONFIG_FILE "/config"
00017 #define PRESETS_DIR "/presets"
00018 #define FONTS_DIR "/fonts"
00019 
00020 // function headers 
00021 int lv_gizmod_init(VisPluginData *plugin);
00022 int lv_gizmod_cleanup(VisPluginData *plugin);
00023 int lv_gizmod_requisition(VisPluginData *plugin, int *width, int *height);
00024 int lv_gizmod_dimension(VisPluginData *plugin, VisVideo *video, int width, int height);
00025 int lv_gizmod_events(VisPluginData *plugin, VisEventQueue *events);
00026 VisPalette *lv_gizmod_palette(VisPluginData *plugin);
00027 int lv_gizmod_render(VisPluginData *plugin, VisVideo *video, VisAudio *audio);
00028 
00029 // validate the version
00030 VISUAL_PLUGIN_API_VERSION_VALIDATOR
00031 
00039 const VisPluginInfo * get_plugin_info(int *count) {
00040         /* Initialize the plugin specific data structure
00041          * with pointers to the functions that represent
00042          * the plugin interface it's implementation, more info:
00043          * http://libvisual.sourceforge.net/newdocs/docs/html/struct__VisActorPlugin.html**/
00044         static VisActorPlugin actor[] = {{
00045                 .requisition =  lv_gizmod_requisition,
00046                 .palette =      lv_gizmod_palette,
00047                 .render =       lv_gizmod_render,
00048                 //.vidoptions.depth = VISUAL_VIDEO_DEPTH_GL /* We want GL clearly**/
00049         }};
00050 
00051         /* This is the non plugin specific data structure, containing
00052          * general informatie about the plugin itself, more info:
00053          * http://libvisual.sourceforge.net/newdocs/docs/html/struct__VisPluginInfo.html**/
00054         static const VisPluginInfo info[] = {{
00055                 .type =         VISUAL_PLUGIN_TYPE_ACTOR,
00056 
00057                 .plugname =     "gizmod",
00058                 .name =         "libVisual Gizmo Daemon Visualization Plugin",
00059                 .author =       "Tim Burrell",
00060                 .version =      "3.0",
00061                 .about =        "Gizmo Daemon",
00062                 .help =         "This plugin is for visualizing music on Gizmo Daemon supported Gizmos\n\t(such as LEDs on certain USB dials, etc)",
00063 
00064                 .init =         lv_gizmod_init,
00065                 .cleanup =      lv_gizmod_cleanup,
00066                 .events =       lv_gizmod_events,
00067 
00068                 .plugin = (void *) &actor[0]
00069         }};
00070 
00071         *count = sizeof (info) / sizeof (*info);
00072 
00073         /*
00074         VISUAL_VIDEO_ATTRIBUTE_OPTIONS_GL_ENTRY(actor[0].vidoptions, VISUAL_GL_ATTRIBUTE_ALPHA_SIZE, 8);
00075         VISUAL_VIDEO_ATTRIBUTE_OPTIONS_GL_ENTRY(actor[0].vidoptions, VISUAL_GL_ATTRIBUTE_DEPTH_SIZE, 16);
00076         VISUAL_VIDEO_ATTRIBUTE_OPTIONS_GL_ENTRY(actor[0].vidoptions, VISUAL_GL_ATTRIBUTE_DOUBLEBUFFER, 1);
00077 
00078         VISUAL_VIDEO_ATTRIBUTE_OPTIONS_GL_ENTRY(actor[0].vidoptions, VISUAL_GL_ATTRIBUTE_RED_SIZE, 8);
00079         VISUAL_VIDEO_ATTRIBUTE_OPTIONS_GL_ENTRY(actor[0].vidoptions, VISUAL_GL_ATTRIBUTE_GREEN_SIZE, 8);
00080         VISUAL_VIDEO_ATTRIBUTE_OPTIONS_GL_ENTRY(actor[0].vidoptions, VISUAL_GL_ATTRIBUTE_BLUE_SIZE, 8);
00081         */
00082 
00083         return info;
00084 }
00085 
00091 int lv_gizmod_init(VisPluginData *plugin) {
00092         GizmodLibVisual_Init();
00093         return 0;
00094 }
00095 
00099 int lv_gizmod_cleanup(VisPluginData *plugin) {
00100         GizmodLibVisual_CleanUp();
00101         return 0;
00102 }
00103 
00111 int lv_gizmod_requisition(VisPluginData *plugin, int *width, int *height) {
00112         *width = 0;
00113         *height = 0;
00114         return 0;
00115 }
00116 
00120 int lv_gizmod_dimension(VisPluginData *plugin, VisVideo *video, int width, int height) {
00121         return 0;
00122 }
00123 
00131 int lv_gizmod_events(VisPluginData *plugin, VisEventQueue *events) {
00132         return 0;
00133 }
00134 
00141 VisPalette *lv_gizmod_palette(VisPluginData *plugin) {
00142         return NULL;
00143 }
00144 
00151 int lv_gizmod_render(VisPluginData *plugin, VisVideo *video, VisAudio *audio) {
00152         // pcm data
00153         int lp;
00154         VisBuffer pcmb;
00155         float pcm[2][512];
00156         visual_buffer_set_data_pair (&pcmb, pcm[0], sizeof (pcm[0]));
00157         visual_audio_get_sample (audio, &pcmb, VISUAL_AUDIO_CHANNEL_LEFT);
00158         visual_buffer_set_data_pair (&pcmb, pcm[1], sizeof (pcm[1]));
00159         visual_audio_get_sample (audio, &pcmb, VISUAL_AUDIO_CHANNEL_RIGHT);
00160         
00161         float VULeft = 0.0f;
00162         float VURight = 0.0f;
00163         float VUCombined = 0.0f;
00164         for (lp = 0; lp < 512; lp ++) {
00165                 float vall = fabs(pcm[0][lp]);
00166                 float valr = fabs(pcm[1][lp]);
00167                 float valc = (vall + valr) / 2.0f;
00168                 
00169                 if (vall > VULeft)
00170                         VULeft = vall;
00171                 if (valr > VURight)
00172                         VURight = valr;
00173                 if (valc > VUCombined)
00174                         VUCombined = valc;
00175         }
00176         
00177         // send off to the server
00178         GizmodLibVisual_Render(VULeft, VURight, VUCombined);
00179         
00180         /*
00181         // freq data
00182         const int BARS = 512; // bars is the number of freqs
00183         float freq[BARS];
00184         float freqL[BARS];
00185         float freqR[BARS];
00186         float pcm[BARS * 2];
00187         VisBuffer buffer;
00188         VisBuffer pcmb;
00189         visual_buffer_set_data_pair(&buffer, freq, sizeof(freq));
00190         visual_buffer_set_data_pair(&pcmb, pcm, sizeof(pcm));
00191         visual_audio_get_sample_mixed_simple(audio, &pcmb, 2, VISUAL_AUDIO_CHANNEL_LEFT, VISUAL_AUDIO_CHANNEL_RIGHT);
00192         visual_audio_get_spectrum_for_sample(&buffer, &pcmb, TRUE);
00193         
00194         visual_buffer_set_data_pair(&buffer, freqL, sizeof(freqL));
00195         visual_audio_get_sample_simple(audio, &pcmb, 2, VISUAL_AUDIO_CHANNEL_LEFT);
00196         visual_audio_get_spectrum_for_sample(&buffer, &pcmb, TRUE);
00197         
00198         visual_buffer_set_data_pair(&buffer, freqR, sizeof(freqR));
00199         visual_audio_get_sample_simple(audio, &pcmb, 2, VISUAL_AUDIO_CHANNEL_RIGHT);
00200         visual_audio_get_spectrum_for_sample(&buffer, &pcmb, TRUE);
00201         */
00202         
00203         return 0;
00204 }

Generated on Wed Nov 7 10:04:16 2007 for gizmod by  doxygen 1.5.3