/* Simple plugin for XMMS to deliver frequency and pcm data in an easy way for any program. v2.0 - Uses mmap() + error checks Written by Jonas Aaberg 2003. Released under GPL. */ #include #include #include #include #include #include #include #include #include #include static int fd_freq, fd_pcm; static unsigned char *null_data, *pcm_mem=NULL, *freq_mem=NULL; static int create_spec(char *name, char **mem) { int fd; unlink(name); fd = open(name, O_RDWR|O_CREAT|O_TRUNC, S_IRUSR|S_IWUSR|S_IRGRP|S_IWGRP|S_IROTH|S_IWOTH); if(fd == -1){ perror("Trying to create:"); return -1; } write(fd,null_data,512*2*sizeof(gint16)); close(fd); fd = open(name, O_RDWR|O_NONBLOCK); if(fd == -1){ perror("Trying to open:"); return -1; } (*mem) = mmap(0, 512*2*sizeof(gint16), PROT_WRITE,MAP_SHARED, fd, 0); if((int)mem == -1){ close(fd); perror("Mmap error:"); return -1; } return fd; } static void plugin_playback_start(void) { null_data = g_malloc0(512*2*sizeof(gint16)); fd_freq = create_spec("/tmp/spectrum-freq", (char **)&freq_mem); fd_pcm = create_spec("/tmp/spectrum-pcm", (char **)&pcm_mem); } static void plugin_playback_stop(void) { // memcpy(pcm_mem,null_data, 512*2*sizeof(gint16)); if(fd_freq != -1){ munmap(freq_mem, 512*2*sizeof(gint16)); close(fd_freq); } // memcpy(freq_mem,null_data, 512*2*sizeof(gint16)); if(fd_freq != -1){ munmap(pcm_mem, 512*2*sizeof(gint16)); close(fd_pcm); } unlink("/tmp/spectrum-freq"); unlink("/tmp/spectrum-pcm"); g_free(null_data); } static void plugin_render_freq(gint16 data[2][512]) { if(freq_mem !=NULL) memcpy(freq_mem, (const void*)data, 512*2*sizeof(gint16)); } static void plugin_render_pcm(gint16 data[2][512]) { if(pcm_mem !=NULL) memcpy(pcm_mem, (const void*)data, 512*2*sizeof(gint16)); } static VisPlugin spectrum_vp = { NULL, NULL, 0, "Freq and PCM outputs for GAI applets v2.0 - http://gai.sf.net -", 2, /* One PCM channel */ 2, /* Two freq channels */ NULL, /* init */ NULL, /* cleanup */ NULL, /* about */ NULL, /* configure */ NULL, /* disable_plugin */ plugin_playback_start, /* playback_start */ plugin_playback_stop, /* playback_stop */ plugin_render_pcm, /* render_pcm */ plugin_render_freq /* render_freq */ }; VisPlugin *get_vplugin_info(void) { return &spectrum_vp; }