We are about to switch to a new forum software. Until then we have removed the registration on this forum.
I'm trying to self teach the Processing language, and struggling with something I'm trying to do for university.
This is probably quite simple for someone who knows what they're doing... I'm trying to use sound input to change the opacity of text. The louder the sound, the greater the opacity. Could someone help with the coding?
Many thanks hope someone can help!
Answers
hello,
great idea!
are you using minim?
see here
http://code.compartmental.net/minim/audioplayer_method_play.html
you can easily use
getvolume
http://code.compartmental.net/minim/audioplayer_method_getvolume.html
then for text use e.g.
I don't know whether getVolume gives values from 0 to 1 or from 0 to 100 or so. But map can re-calculate this range of values to another range (0 to 255).
I think the opacity range is from 0 to 255 (or maybe 0 to 100).
Once you have the opacity calculated as myOpacity you can use it with fill.
Hey,
Yeah I have the Minim library installed Great!! Very grateful for this, a big help. Will try this out.
Sam
Chrisir
Apologies - I think I might almost be there. Any pointers from this point though?
Sam
you need background(255); in setup() and at the beginning of draw()
I would put the size()-command always at the start of setup()
at the end of setup() you need to load a file and play it?
see my 1st link above.
Greetings, Chrisir
is not needed
Sorry Im trying to say If any audio input at all, opacity is at 100%, if none, then opacity is at 0% - So the text will appear and disappear with sound. Does this make sense?
Sam
Sorry Im trying to say If any audio input at all, opacity is at 100%, if none, then opacity is at 0% - So the text will appear and disappear with sound. Does this make sense?
Sam
don't mark a thread as answered when it's not...
as said, you need background
and check this line:
I don't know the ranges
myOpacity = map (player.getVolume(), 0,100, 0,255);
when getVolume delivers values between 0 and 100 - fine
when it gives something between 0 and 1 change it!!!!
same for opacity:
when its getting evaluated between 0 and 255 - fine
when its getting stuff between 0 and 100 - change it please....
map (player.getVolume(), 0,100, 0,255);
means
map (player.getVolume(), 0,100, 0,255);
ok, convert the value of getVolume to another value so that if
it has a certain percentage of the range from 0 to 100 , my new value
should have the same percentage on the range of 0 to 255
so it's mapping the value from one range to another range
this is working
// I replaced getvolume with abs(player.mix.get(i))
// I replaced the for-loop with a loop that uses the // looping of draw() itself. // Disavantage: pretty fast; advantage: pretty accurate.
// Alternatively: use for but with myOpacity = map ( abs(player.mix.get(i)), 0, 100, 0, 255); // 100 instead of .7 because then they got printed all over one another.
// Alternatively: use for-loop but only till 10 and not i < player.bufferSize() - 1
Hi,
I am trying to follow the existing code above, but I would like to use two separate instances of text, one which reduces to an opacity of 0% with sound input and one which increases to an opacity of 100%.
I am trying to add another int ii=100 and another float myOpacit1 and duplicating the relevant section son the code but not working, can anyone offer any help to me?
my change to the code below - after line 47 mostly - thanks..
make sure size(1200, 800); is the first line in setup(). There is quite a bit going on behind the scenes in
size
.This makes no sense I think:
Instead
you have this now
just add the same differently with
myOpacity2
and with different parameters formap
!!!!!! :Thanks, seems to be a much neater way of achieving this process thanks.. I can see what you are doing with the values in the map, I have tweaked my parameters and all is good.
What happens if
you println abs(in.mix.get(ii))
?
The code is aimed on a mic input afaik. Do you have mic input?
The code to monitor a song you play on your computer is different afaik