-+P -+k5
;*** SIMPLE BMSCAN
;*** shows, in a simple way, the usage of bmscan, FLsetImage, FLsetOverlay and vectorial opcodes.
;*** this is a very trivial use of such opcodes, to allow the beginner to understand their basics.
sr=44100
kr=441
ksmps=100
nchnls=1
GLfps 20, .5
#include "OpenGL.h"
giwidth,giheight,ibpp bmopen "test.png",1,2 ;*** you can use another image
FLpanel "Simple Example of BMSCAN and VECTORIAL OPCODES",830,630
FLscroll 830,630,0,0
GLpanel "OpenGL panel", giwidth, giheight
GLpanel_end
FLscroll_end
FLpanel_end
FLrun
giTex1 GLloadTexture "test.png", $PNG_ALPHA,$GL_REPEAT, $PNG_NOMIPMAPS, $GL_NEAREST
GLinsert_i $GL_INIT
glMatrixMode $GL_PROJECTION
glLoadIdentity
glOrtho -1, 1, -1, 1, -20, 20
glMatrixMode $GL_MODELVIEW
glLoadIdentity
glClearColor 0,0,0,1
glEnable $GL_TEXTURE_2D
GLinsert_i $GL_NOT_VALID
glClear $GL_COLOR_BUFFER_BIT + $GL_DEPTH_BUFFER_BIT
GLinsert_i 1
giElems init 150 ;*** number of partials.
;*** reduce this number if your
;*** computer is not fast enough
;*** must be <= to the vertical dimension of the image
;*** otherwise Csound will crash
giTabFreq1 ftgen 1,0,512,-7, 1,giElems,5,128,5 ;*** table containing frequency ratios (exponential)
giTabFreq2 ftgen 2,0,512,-5, 1,giElems,5,128,5 ;*** table containing frequency ratios (linear)
giTabRed ftgen 4,0,512,2, 0 ;*** table receiving red channel
giTaGreen ftgen 5,0,512,2, 0 ;*** table receiving green channel
giTaBlue ftgen 6,0,512,2, 0 ;*** table receiving blue channel
giTaScale ftgen 32,0,512,5, 1,giElems,.08 ;*** scale the amplutude of partials
giTemp ftgen 33,0,512,2,0 ;*** temporary buffer table
giTabSine ftgen 12,0,2048, 10,1,0,1,0,1 ;*** audio function
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
instr 1
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
iamp = 8 ;*** amplitude
iscanrate = .05 ;*** setscanning rate
kphs phasor iscanrate
;////// OPENGL BEGIN
glLoadIdentity
glBindTexture giTex1
glColor 1,1,1,1
; glScale 1,1/giratio,1
glScale 1,giheight/giwidth,1
GLtexSquare 1, 0,1, 1,1, 1,0, 0,0
glDisable $GL_TEXTURE_2D
glutCube 2,0
glLoadIdentity
glDisable $GL_TEXTURE_2D
tphs = t(kphs) * 2 - 1
glTranslate tphs,0,0
glScale 1/150, 3,1
glColor 1,0,0,1
glutCube 1,0
glEnable $GL_TEXTURE_2D
GLinsert 1.1
;////// OPENGL END
kphs = kphs*giwidth ;*** point of table scanning
;ktrig metro 10 ;*** the cursor of the image is updated 10 times per second
;*** MANUAL ktrig, kx,ky,kwidth,kheight,ihandle;
; FLsetOverlay ktrig,kphs,0,2,giheight,gih2 ;*** display moving cursor of the image
iportament= .0001 ;*** portamento time to smooth transients (you can increase this value for a reverb-like effect)
;*** IMAGE SCANNING OPCODE
;*** MANUAL kphs, ihorLines, ifn, istartLine, ifnR, ifnG, ifnB;
bmscani kphs, giheight/giElems, 1, 0, giTabRed,giTaGreen,giTaBlue
;*** VECTORIAL OPCODES PROVIDE TRANSFORMATIONS OF IMAGE VECTORS
vaddv giTabRed,giTaGreen, giElems ;*** mix Green amplitudes to Red channel
vaddv giTabRed,giTaBlue, giElems ;*** mix Blue amplitudes to Red channel
vmultv giTabRed,giTaScale, giElems ;*** scale the amplutude of high partials
vport giTabRed,iportament,giElems ;*** add portamento to smooth transients (you can reduce or increase this value)
vcopy giTemp,giTabFreq1, giElems ;*** copy the frequency table to a temporary table
vpow giTemp,4, giElems ;*** expand frequency range
kenv linsegr 0, 1 ,iamp,1,iamp,.1,0
a1 adsynt2 kenv,5,giTabSine,giTemp,giTabRed,giElems,1
a1 tone a1,1000
out a1
endin
i1 0 3600
f0 3600
e