From 4d64e4cd434426234a5c313c151cd79b6afc299e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Juha=20Vehvil=C3=A4inen?= Date: Sat, 6 Jul 2002 17:50:18 +0000 Subject: *** empty log message *** svn path=/trunk/Framestein/; revision=27 --- Plugins/sonogram.cpp | 82 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 82 insertions(+) create mode 100644 Plugins/sonogram.cpp (limited to 'Plugins/sonogram.cpp') diff --git a/Plugins/sonogram.cpp b/Plugins/sonogram.cpp new file mode 100644 index 0000000..821b94a --- /dev/null +++ b/Plugins/sonogram.cpp @@ -0,0 +1,82 @@ +// +// sonogram.cpp +// +// use with fs.sonogram +// +// see example-sonogram.pd +// + +#include +#include +#include +#include +#include +#include "plugin.h" +#include "pixels.h" + +#define SONOSIZE 128 +#define SONOMAXVAL 500 +#define sonotype float + +int callcount=-1; + +void perform_effect(_frame f, _args a) +{ + if(!a.s) return; + + if(++callcount>=f.width) callcount=0; + + FILE *inf; + if((inf = fopen(a.s, "rb"))==NULL) + { + printf("sonogram: error opening %s\n", a.s); + return; + } + + char buf[80]; + sonotype sono[SONOSIZE]; + int i=0; + + while(!feof(inf)) + { + if(!fgets(buf, 80, inf)) + { + printf("sonogram: read error.\n"); + return; + } + sono[i] = atof(buf); + if(++i>=SONOSIZE) break; + } + fclose(inf); + + int y; + + for(i=0; iSONOMAXVAL) sono[i]=SONOMAXVAL; + sono[i] = (sonotype)((sono[i] / (float)SONOMAXVAL)*255); + // white = no sound + sono[i] = abs(sono[i]-255); + + y = (int)((i / (float)SONOSIZE) * (float)f.height); + // bottom = bass + y = abs((f.height-1) - y); + + switch(f.pixelformat) + { + case 16: + scanline16(f, y)[callcount] = + rgbtocolor16(sono[i], sono[i], sono[i]); + break; + case 24: + scanline24(f, y)[callcount] = + rgbtocolor24(sono[i], sono[i], sono[i]); + break; + case 32: + scanline32(f, y)[callcount] = + rgbtocolor32(sono[i], sono[i], sono[i]); + break; + } + } +} -- cgit v1.2.1