Csound Csound-dev Csound-tekno Search About

[Cs-dev] EQ band amplitude adjustment with PVS opcodes

Date2011-02-02 09:36
From4g63gsx
Subject[Cs-dev] EQ band amplitude adjustment with PVS opcodes
I am working on a application that connects an equalizer to a real-time graph
of a song's amplitude and frequency values. I am having a problem because I
have not been successful in getting the two parts to interface correctly.
The equalizer section works fine and changes to the equalizer result in
audible changes to the output audio stream. The graph accurately displays
the values from the pvsbin opcode. However the problem is that as the
equalizer is changed, the values from the pvsbin opcode do not reflect these
changes. Even though the sound is changing in the speakers, the graphic
representation does not move.

Here is the basic structure of the code (abbreviated):

instr 1
asigL asigR diskin2 "Song.wav", 1, 0, 1

iq		=	4.318
icmpamp 	= 	ampdb(-10) ;Global amplification.

;BAND FREQUENCIES
kfrq1	=	100 	
.
.
.
kfrq8	= 	12800	

;GET FADER VALUES
kfpos1 zkr 0	;100Hz BAND
.
.
.
kfpos8 zkr 7	;12.8KHz BAND

kSwitch1		changed	kfpos1
.
.
.
kSwitch8		changed	kfpos8	

if	kSwitch1=1	then		
reinit	START1			
endif
.
.
.
if	kSwitch8=1	then		
reinit	START8			
endif

START1:

asig1L butterbp asigL,kfrq1,kfrq1/iq 
asig1R butterbp asigR,kfrq1,kfrq1/iq
asig1L = asig1L * kfpos1 
asig1R = asig1R * kfpos1 
FLprintk2	kfpos1, gid1
rireturn
.
.
.
asig8L butterbp asigL,kfrq8,kfrq8/iq 
asig8R butterbp asigR,kfrq8,kfrq8/iq 
asig8L = asig8L * kfpos8 
asig8R = asig8R * kfpos8 
FLprintk2	kfpos8, gid8
rireturn	

aoutL	=	asig1L + asig2L + asig3L + asig4L + asig5L + asig6L + asig7L +
asig8L
aoutR	=	asig1R + asig2R + asig3R + asig4R + asig5R + asig6R + asig7R +
asig8R

fsigL pvsanal aoutL, 1024, 256, 1024, 1
fsigR pvsanal aoutR, 1024, 256, 1024, 1

kampL, kfrqL pvsbin fsigL, 2
kampR, kfrqR pvsbin fsigR, 2

chn_k "amplitudeL", 2
chn_k "amplitudeR", 2
chn_k "frequencyL", 2
chn_k "frequencyR", 2

chnset kampL, "amplitudeL"
chnset kampR, "amplitudeR"
chnset kfrqL, "frequencyL"
chnset kfrqR, "frequencyR"

outs aoutL*icmpamp, aoutR*icmpamp 
endin

If I print the output from the pvsbin opcodes, they don't change when the
equalizer is adjusted. I figured that the problem might be due to the fact
that I am using butterbp opcodes to create the equalizer bands, and that
maybe the pvs opcodes cannot work with them, so I tried another version
using pvsbandp opcodes as follows:

givoltable ftgen 3, 0, 1024, 7, 1, 1024, 0

instr 2

asigL asigR diskin2 "Song.wav", 1, 0, 1

fsigglobL pvsanal asigL, 1024, 256, 1024, 1
fsigglobR pvsanal asigR, 1024, 256, 1024, 1

iq		=	4.318
ilq = iq * 2
ihq = iq * 3
icmpamp 	= 	ampdb(-10) ;Global amplification.

;BAND FREQUENCIES
kfrq1	=	100 	
.
.
.
kfrq8	= 	12800	

;BAND SHAPE VARIABLES
kfrqlwid1 = kfrq1 / ilq
.
.
.
kfrqlwid8 = kfrq8 / ilq

kfrqhwid1 = kfrq1 / ihq
.
.
.
kfrqhwid8 = kfrq8 / ihq

klowcut1 = kfrq1 - kfrqlwid1
klowfull1 = kfrq1 - kfrqhwid1
khighfull1 = kfrq1 + kfrqlwid1
khighcut1 = kfrq1 + kfrqhwid1
.
.
.
klowcut8 = kfrq8 - kfrqlwid8
klowfull8 = kfrq1 - kfrqhwid8
khighfull8 = kfrq8 + kfrqlwid8
khighcut8 = kfrq1 + kfrqhwid8

;GET FADER VALUES
kfpos1 zkr 0	;100Hz BAND
.
.
.
kfpos8 zkr 7	;12.8KHz BAND

kSwitch1		changed	kfpos1
.
.
.
kSwitch8		changed	kfpos8	

if	kSwitch1=1	then		
reinit	START1			
endif
.
.
.
if	kSwitch8=1	then		
reinit	START8			
endif

START1:

fsig1L pvsbandp fsigglobL, klowcut1, klowfull1, khighfull1, khighcut1, 0
fsig1R pvsbandp fsigglobR, klowcut1, klowfull1, khighfull1, khighcut1, 0
fsigadj1L pvsmaska fsig1L, givoltable, 1 - kfpos1
fsigadj1R pvsmaska fsig1R, givoltable, 1 - kfpos1
FLprintk2	kfpos1, gid1
rireturn
.
.
.
	START8:

fsig8L pvsbandp fsigglobL, klowcut8, klowfull8, khighfull8, khighcut8, 0
fsig8R pvsbandp fsigglobR, klowcut8, klowfull8, khighfull8, khighcut8, 0
fsigadj8L pvsmaska fsig8L, givoltable, 1 - kfpos8
fsigadj8R pvsmaska fsig8R, givoltable, 1 - kfpos8
FLprintk2	kfpos8, gid8
rireturn

asig1L pvsynth fsig1L
.
.
.
asig8L pvsynth fsig8L

asig1R pvsynth fsig1R
.
.
.
asig8R pvsynth fsig8R

asigposteqL	=	asig1L + asig2L + asig3L + asig4L + asig5L + asig6L + asig7L +
asig8L
asigposteqR=	asig1R + asig2R + asig3R + asig4R + asig5R + asig6R + asig7R +
asig8R

fsigposteqL pvsanal asigposteqL, 1024, 256, 1024, 1
fsigposteqR pvsanal asigposteqR, 1024, 256, 1024, 1

kampL, kfrqL pvsbin fsigposteqL, 2
kampR, kfrqR pvsbin fsigposteqR, 2

chn_k "amplitudeL", 2
chn_k "amplitudeR", 2
chn_k "frequencyL", 2
chn_k "frequencyR", 2

chnset kampL, "amplitudeL"
chnset kampR, "amplitudeR"
chnset kfrqL, "frequencyL"
chnset kfrqR, "frequencyR"

outs asigposteqL, asigposteqR
endin

Basically, in the second version I split the song into 8 bands using the
pvsbandp opcode. Then I use the pvsmaska opcode to adjust each band's
amplitude according to the ftable givoltable, which is a straight line
starting at one and ending at zero. The fader position is then subtracted
from 1 to give the kdepth, so that it will be full volume at fader position
1, and full attenuation at fader position 0.

Some things about this version. It sounds like garbage. There is a whole lot
of noise introduced, so I'm sure I'm making some mistakes. The main problem
I have with using the pvsbandp opcodes is that I don't know how to perform
operations on the amplitude using the fader position value. I tried directly
mutliplying it with the fsig of each band, but that was illegal. So I used
pvsynth on all the bands, converting them to asigs, then multiplied each one
by its fader position, finally summing them together. After that I used
pvsanal again to get the amplitude and frequency values. This method did not
work either, and there is a whole lot more computational complexity in this
version.

Is there a simpler way to adjust the amplitude of an fsig? What am I doing
wrong in my method?
-- 
View this message in context: http://csound.1045644.n5.nabble.com/EQ-band-amplitude-adjustment-with-PVS-opcodes-tp3367551p3367551.html
Sent from the Csound - Dev mailing list archive at Nabble.com.

------------------------------------------------------------------------------
Special Offer-- Download ArcSight Logger for FREE (a $49 USD value)!
Finally, a world-class log management solution at an even better price-free!
Download using promo code Free_Logger_4_Dev2Dev. Offer expires 
February 28th, so secure your free ArcSight Logger TODAY! 
http://p.sf.net/sfu/arcsight-sfd2d
_______________________________________________
Csound-devel mailing list
Csound-devel@lists.sourceforge.net