imported>Veyron |
imported>Veyron No edit summary |
||
Line 5: | Line 5: | ||
== Quellcode == |
== Quellcode == |
||
Den Quellcode für das XMMS-Plugin habe ich mit Hilfe von [http://dev.webreeze.de/portal/modules.php5?name=OnlineArticle&pid=5 Workshop: Vis-Plugins in XMMS] und [http://www.nobugs.org/developer/xmms/xmms-nobugs.html XMMS Plugin tutorial at nobugs.org] erstellen können. Desweiteren waren Informationen zum [http://wiki.blinkenarea.org/bin/view/Blinkenarea/BlinkenlightsProtocol BLP - Blinkenlights Protokoll] sehr nützlich. Der "Rechen-Kern" für die Visualisierung entspricht dem des [http://cvs.xmms.org/cvsweb.cgi/xmms/Visualization/sanalyzer/ spectrum] Plugins. |
Den Quellcode für das XMMS-Plugin habe ich mit Hilfe von [http://dev.webreeze.de/portal/modules.php5?name=OnlineArticle&pid=5 Workshop: Vis-Plugins in XMMS] und [http://www.nobugs.org/developer/xmms/xmms-nobugs.html XMMS Plugin tutorial at nobugs.org] erstellen können. Desweiteren waren Informationen zum [http://wiki.blinkenarea.org/bin/view/Blinkenarea/BlinkenlightsProtocol BLP - Blinkenlights Protokoll] sehr nützlich. Der "Rechen-Kern" für die Visualisierung entspricht dem des [http://cvs.xmms.org/cvsweb.cgi/xmms/Visualization/sanalyzer/ spectrum] Plugins. |
||
Jetzt mit Gaustufen! |
|||
[[:Image:Blinken_xmms.c.txt | blinken_xmms.c]] ! Beim Speichern --> Dateiname: blinken_xmms.c ! |
[[:Image:Blinken_xmms.c.txt | blinken_xmms.c]] ! Beim Speichern --> Dateiname: blinken_xmms.c ! |
||
<HighlightSyntax> |
<HighlightSyntax> |
||
/* XMMS - Cross-platform multimedia player |
|||
/* XMMS - Cross-platform multimedia player |
|||
* Copyright (C) 1998-2000 Peter Alm, Mikael Alm, Olle Hallnas, Thomas Nilsson and 4Front Technologies |
|||
* Copyright (C) 1998-2000 Peter Alm, Mikael Alm, Olle Hallnas, Thomas Nilsson and 4Front Technologies |
|||
* |
|||
* |
|||
* This program is free software; you can redistribute it and/or modify |
|||
* This program is free software; you can redistribute it and/or modify |
|||
* it under the terms of the GNU General Public License as published by |
|||
* it under the terms of the GNU General Public License as published by |
|||
* the Free Software Foundation; either version 2 of the License, or |
|||
* (at your option) any later version. |
|||
* |
|||
* |
|||
* This program is distributed in the hope that it will be useful, |
|||
* This program is distributed in the hope that it will be useful, |
|||
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
|||
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
|||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|||
* GNU General Public License forore details. |
|||
* GNU General Public License forore details. |
|||
* |
|||
* |
|||
* You should have received a copy of the GNU General Public License |
|||
* You should have received a copy of the GNU General Public License |
|||
* along with this program; if not, write to the Free Software |
|||
* along with this program; if not, write to the Free Software |
|||
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
|||
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
|||
*/ |
*/ |
||
/ |
/* Compile: |
||
* gcc -Wall --shared `xmms-config --cflags` -o blinken_xmms.so blinken_xmms.c |
|||
* Install: |
|||
//install blinken_plugin.so `xmms-config --visualization-plugin-dir` |
|||
* install blinken_plugin.so `xmms-config --visualization-plugin-dir` |
|||
*/ |
|||
#include <stdio.h> |
#include <stdio.h> |
||
#include <xmms/plugin.h> |
#include <xmms/plugin.h> |
||
#include <stdio.h> |
#include <stdio.h> |
||
#include <math.h> |
#include <math.h> |
||
Line 39: | Line 44: | ||
#include <sys/socket.h> |
#include <sys/socket.h> |
||
#include <netinet/in.h> |
#include <netinet/in.h> |
||
#include <stdlib.h> |
#include <stdlib.h> |
||
#include <unistd.h> |
#include <unistd.h> |
||
#include <string.h> |
#include <string.h> |
||
#include <arpa/inet.h> |
#include <arpa/inet.h> |
||
#define NUM_BANDS 18 |
#define NUM_BANDS 18 |
||
#define WIDTH 18 |
#define WIDTH 18 |
||
#define HEIGHT 8 |
#define HEIGHT 8 |
||
#define MSG { |
#define MSG {0xFE,0xED,0xBE,0xEF,0x00,0x00,0x00,0x00,0x00,0x012,0x00,0x08,\ |
||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xFF, 0xFF, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,\ |
|||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xFF, 0x00, 0x00, 0xFF, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,\ |
|||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xFF, 0x00, 0x00, 0x00, 0x00, 0xFF, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,\ |
|||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xFF, 0x00, 0x00, 0x00, 0x00, 0xFF, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,\ |
|||
0x00, 0x00, 0x00, 0x00, 0x00, 0xFF, 0xFF, 0x00, 0x00, 0x00, 0x00, 0xFF, 0xFF, 0x00, 0x00, 0x00, 0x00, 0x00,\ |
|||
0x00, 0x00, 0x00, 0x00, 0xFF, 0xFF, 0xFF, 0x00, 0x00, 0x00, 0x00, 0xFF, 0xFF, 0xFF, 0x00, 0x00, 0x00, 0x00,\ |
|||
0x00, 0x00, 0x00, 0x00, 0x00, 0xFF, 0xFF, 0x00, 0x00, 0x00, 0x00, 0xFF, 0xFF, 0x00, 0x00, 0x00, 0x00, 0x00,\ |
|||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xFF, 0x00, 0x00, 0x00, 0x00, 0xFF, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00} |
|||
unsigned char msg[156]=MSG; |
static unsigned char msg[156]=MSG; |
||
int sock; |
static int sock; |
||
static unsigned char scalmsg[10] = {0x11, 0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0xAA, 0xCC, 0x00}; |
|||
static gint16 bar_heights[NUM_BANDS]; |
static gint16 bar_heights[NUM_BANDS]; |
||
static gdouble scale; |
static gdouble scale; |
||
void our_init(); |
void our_init(); |
||
void our_cleanup(); |
void our_cleanup(); |
||
void our_playback_start(); |
void our_playback_start(); |
||
void our_playback_stop(); |
void our_playback_stop(); |
||
void our_render_freq( |
void our_render_freq(gint16 data[1][256]); |
||
VisPlugin g_our_plugin = |
VisPlugin g_our_plugin = |
||
{ |
{ |
||
NULL, /* handle */ |
|||
NULL, /* filename */ |
|||
0, /* session id */ |
|||
"blinken_xmms", /* description */ |
|||
1, /* PCM Channels */ |
|||
1, /* Freq. Channels */ |
|||
/* Callbacks ... */ |
|||
our_init, /* init */ |
|||
/* Callbacks ... */ |
|||
our_cleanup, /* cleanup */ |
|||
NULL, /* about-dialog */ |
|||
our_cleanup, /* cleanup */ |
|||
NULL, /* configure-dialog */ |
|||
NULL, /* disable-plugin */ |
|||
our_playback_start, /* playback-start */ |
|||
NULL, /* disable-plugin */ |
|||
our_playback_stop, /* playback-top */ |
|||
NULL, /* render-pcm */ |
|||
our_render_freq /* render-freq */ |
|||
our_render_freq /* render-freq */ |
|||
}; |
}; |
||
VisPlugin *get_vplugin_info(void) |
VisPlugin *get_vplugin_info(void) |
||
{ |
{ |
||
return( & g_our_plugin); |
|||
} |
} |
||
#define OUR_PREFIX "blinken-plugin:" |
#define OUR_PREFIX "blinken-plugin:" |
||
void our_init() |
void our_init() |
||
{ |
{ |
||
if ((sock = socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP)) == -1) |
|||
{ |
|||
printf("couldn't create socket"); |
|||
our_cleanup(); // programm mit fehlercode 1 beenden |
|||
exit(1); |
|||
} |
|||
// Struktur anlegen, mit Nullen initialisieren und füllen |
|||
struct sockaddr_in dest_addr; |
|||
memset(&dest_addr, 0, sizeof(dest_addr)); // alles mit Nullen füllen |
|||
dest_addr.sin_family = AF_INET; // muss hier nochmal stehen |
|||
dest_addr.sin_port = htons(2323); // auf dem Port läuft meistens HTTP |
|||
dest_addr.sin_addr.s_addr = inet_addr("127.0.0.1"); // IP Adresse von www.example.net |
|||
if (connect(sock, (struct sockaddr*) &dest_addr, sizeof(dest_addr)) == -1) |
|||
{ |
|||
printf("couldn't connect to 127.0.0.1:2323"); |
|||
our_cleanup(); |
|||
exit(2); // mit fehlercode aussteigen |
|||
} |
|||
send(sock, msg, 156, 0); // senden |
|||
scale = (HEIGHT + 1)/ log(256); |
|||
} |
} |
||
void our_cleanup() |
void our_cleanup() |
||
{ |
{ |
||
close(sock); // wir schließen den descriptor wieder |
|||
} |
} |
||
void our_playback_start() |
void our_playback_start() |
||
{ |
{ |
||
//printf( OUR_PREFIX" playback_start\n"); |
|||
} |
} |
||
void our_playback_stop() |
void our_playback_stop() |
||
{ |
{ |
||
unsigned char msg[156]=MSG; |
|||
send(sock, msg, 156, 0); |
|||
send(sock, msg, 156, 0); |
|||
} |
} |
||
void our_render_freq( gint16 data[1][256]) |
void our_render_freq( gint16 data[1][256]) |
||
{ |
{ |
||
int result,zeile,spalte; |
|||
int i,j,c; |
|||
gint y; |
|||
gint xscale[NUM_BANDS] = {0, 1, 2, 3, 5, 7, 10, 14, 20, 28, 40, 54, 74, 85, 101, 137, 140, 150}; |
|||
gint xscale[NUM_BANDS] = {0, 1, 2, 3, 5, 7, 10, 14, 20, 28, 40, 54, 74, 85, 101, 137, 140, 150}; |
|||
for(i = 0; i < NUM_BANDS; i++) |
|||
{ |
|||
for(c = xscale[i], y = 0; c < xscale[i + 1]; c++) |
|||
{ |
|||
if(data[0][c] > y) |
|||
{ |
|||
y = data[0][c]; |
|||
y = data[0][c]; |
|||
} |
|||
} |
|||
if(y != 0) |
|||
} |
|||
{ |
|||
y = (gint)(log(y) * scale); |
|||
y >>= 7; |
|||
if(y != 0) |
|||
{ |
|||
} |
|||
y = (gint)(log(y) * scale); |
|||
if(y > HEIGHT+1) |
|||
{ |
|||
bar_heights[i] = y; |
|||
y = HEIGHT+1; |
|||
else if(bar_heights[i] > 4) |
|||
} |
|||
bar_heights[i] -= 4; |
|||
else |
|||
bar_heights[i] = 0; |
|||
} |
|||
} |
|||
bar_heights[i] = -y+9; |
|||
spalte = 0; |
|||
zeile = 0; |
|||
} |
|||
for(i=12;i<=155;i++) |
|||
{ |
|||
spalte = 0; |
|||
zeile = 0; |
|||
for(i=12;i<=155;i++) |
|||
spalte = j%18; |
|||
{ |
|||
j = i-12; |
|||
if((-bar_heights[spalte]+8)<=zeile) |
|||
zeile = j/18; |
|||
{ |
|||
spalte = j%18; |
|||
msg[i]=0x01; |
|||
} |
|||
if((bar_heights[spalte])==zeile+1) |
|||
else |
|||
{ |
|||
msg[i]=0xFF; |
|||
} |
|||
else if((bar_heights[spalte])<zeile+1) |
|||
} |
|||
{ |
|||
msg[i]=scalmsg[bar_heights[spalte]]; |
|||
result = send(sock, msg, 156, 0); |
|||
} |
|||
return; |
|||
else |
|||
{ |
|||
msg[i]=0x00; |
|||
} |
|||
} |
|||
result = send(sock, msg, 156, 0); |
|||
return; |
|||
} |
} |
||
Revision as of 12:59, 25 January 2007
blinken_xmms
Das blinken_xmms ist ein Spectrum-Analyser-Plugin für den Multimedia Player Xmms. Es sendet UDP-Pakete an 127.0.0.1:2323 im BLP - Blinkenlights Protokoll mit 8x18 Pixeln. Die Ausgabe kann z.B. mit lldrv auf ein BlinkenLEDsPro umgeleitet werden.
Quellcode
Den Quellcode für das XMMS-Plugin habe ich mit Hilfe von Workshop: Vis-Plugins in XMMS und XMMS Plugin tutorial at nobugs.org erstellen können. Desweiteren waren Informationen zum BLP - Blinkenlights Protokoll sehr nützlich. Der "Rechen-Kern" für die Visualisierung entspricht dem des spectrum Plugins.
Jetzt mit Gaustufen!
blinken_xmms.c ! Beim Speichern --> Dateiname: blinken_xmms.c !
<HighlightSyntax>
/* XMMS - Cross-platform multimedia player * Copyright (C) 1998-2000 Peter Alm, Mikael Alm, Olle Hallnas, Thomas Nilsson and 4Front Technologies * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License forore details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
/* Compile: * gcc -Wall --shared `xmms-config --cflags` -o blinken_xmms.so blinken_xmms.c * Install: * install blinken_plugin.so `xmms-config --visualization-plugin-dir` */
#include <stdio.h> #include <xmms/plugin.h>
#include <stdio.h> #include <math.h> #include <sys/types.h> #include <sys/socket.h> #include <netinet/in.h> #include <stdlib.h> #include <unistd.h> #include <string.h> #include <arpa/inet.h>
#define NUM_BANDS 18 #define WIDTH 18 #define HEIGHT 8
#define MSG {0xFE,0xED,0xBE,0xEF,0x00,0x00,0x00,0x00,0x00,0x012,0x00,0x08,\ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xFF, 0xFF, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,\ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xFF, 0x00, 0x00, 0xFF, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,\ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xFF, 0x00, 0x00, 0x00, 0x00, 0xFF, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,\ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xFF, 0x00, 0x00, 0x00, 0x00, 0xFF, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,\ 0x00, 0x00, 0x00, 0x00, 0x00, 0xFF, 0xFF, 0x00, 0x00, 0x00, 0x00, 0xFF, 0xFF, 0x00, 0x00, 0x00, 0x00, 0x00,\ 0x00, 0x00, 0x00, 0x00, 0xFF, 0xFF, 0xFF, 0x00, 0x00, 0x00, 0x00, 0xFF, 0xFF, 0xFF, 0x00, 0x00, 0x00, 0x00,\ 0x00, 0x00, 0x00, 0x00, 0x00, 0xFF, 0xFF, 0x00, 0x00, 0x00, 0x00, 0xFF, 0xFF, 0x00, 0x00, 0x00, 0x00, 0x00,\ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xFF, 0x00, 0x00, 0x00, 0x00, 0xFF, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}
static unsigned char msg[156]=MSG; static int sock; static unsigned char scalmsg[10] = {0x11, 0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0xAA, 0xCC, 0x00};
static gint16 bar_heights[NUM_BANDS]; static gdouble scale;
void our_init(); void our_cleanup(); void our_playback_start(); void our_playback_stop(); void our_render_freq(gint16 data[1][256]);
VisPlugin g_our_plugin = { NULL, /* handle */ NULL, /* filename */ 0, /* session id */ "blinken_xmms", /* description */ 1, /* PCM Channels */ 1, /* Freq. Channels */ /* Callbacks ... */ our_init, /* init */ our_cleanup, /* cleanup */ NULL, /* about-dialog */ NULL, /* configure-dialog */ NULL, /* disable-plugin */ our_playback_start, /* playback-start */ our_playback_stop, /* playback-top */ NULL, /* render-pcm */ our_render_freq /* render-freq */ };
VisPlugin *get_vplugin_info(void) { return( & g_our_plugin); }
#define OUR_PREFIX "blinken-plugin:"
void our_init() { if ((sock = socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP)) == -1) { printf("couldn't create socket"); our_cleanup(); // programm mit fehlercode 1 beenden exit(1); }
// Struktur anlegen, mit Nullen initialisieren und füllen struct sockaddr_in dest_addr; memset(&dest_addr, 0, sizeof(dest_addr)); // alles mit Nullen füllen dest_addr.sin_family = AF_INET; // muss hier nochmal stehen dest_addr.sin_port = htons(2323); // auf dem Port läuft meistens HTTP dest_addr.sin_addr.s_addr = inet_addr("127.0.0.1"); // IP Adresse von www.example.net
if (connect(sock, (struct sockaddr*) &dest_addr, sizeof(dest_addr)) == -1) { printf("couldn't connect to 127.0.0.1:2323"); our_cleanup(); exit(2); // mit fehlercode aussteigen }
send(sock, msg, 156, 0); // senden scale = (HEIGHT + 1)/ log(256); }
void our_cleanup() { close(sock); // wir schließen den descriptor wieder }
void our_playback_start() { //printf( OUR_PREFIX" playback_start\n"); }
void our_playback_stop() { unsigned char msg[156]=MSG; send(sock, msg, 156, 0); }
void our_render_freq( gint16 data[1][256]) { int result,zeile,spalte; int i,j,c; gint y; gint xscale[NUM_BANDS] = {0, 1, 2, 3, 5, 7, 10, 14, 20, 28, 40, 54, 74, 85, 101, 137, 140, 150};
for(i = 0; i < NUM_BANDS; i++) { for(c = xscale[i], y = 0; c < xscale[i + 1]; c++) { if(data[0][c] > y) { y = data[0][c]; }
}
y >>= 7; if(y != 0) { y = (gint)(log(y) * scale); if(y > HEIGHT+1) { y = HEIGHT+1; }
}
bar_heights[i] = -y+9;
}
spalte = 0; zeile = 0; for(i=12;i<=155;i++) { j = i-12; zeile = j/18; spalte = j%18;
if((bar_heights[spalte])==zeile+1) { msg[i]=0xFF; } else if((bar_heights[spalte])<zeile+1) { msg[i]=scalmsg[bar_heights[spalte]]; } else { msg[i]=0x00; }
}
result = send(sock, msg, 156, 0); return; }
</HighlightSyntax>
Installation
gcc -Wall --shared `xmms-config --cflags` -o blinken_xmms.so blinken_xmms.c
install blinken_plugin.so `xmms-config --visualization-plugin-dir`
Evtl. ist das dev. Paket von xmms erforderlich.
Nun kann man mit einem Rechtsklick auf das XMMS-Fenster im Menü: Visualisierung-->Visualisierungs-Plugins
Blinken-Plugin
auswählen. Um den UDP-Stream umzuleiten kann z.B
./BlinkenOutput -l 2323 -d /dev/lldrv
benutzt werden.