[Gambas-user] Current Volume Output

Daniel Oxley oxleyd at ...699...
Wed Mar 16 09:20:58 CET 2005


This looks good.  I have 1 question though Rob.  What is "buf" in the line
"read #soundin, buf"?

Daniel
 

-----Original Message-----
From: gambas-user-admin at lists.sourceforge.net
[mailto:gambas-user-admin at lists.sourceforge.net] On Behalf Of Rob
Sent: 15 March 2005 17:03
To: gambas-user at lists.sourceforge.net
Subject: Re: [Gambas-user] Current Volume Output

On Tuesday 15 March 2005 09:38, Daniel Oxley wrote:
> Is there an easy way to interface with this from Gambas?

I think you're the first to ask.  I don't think dcop and kmix are gonna do
the trick, though.  I think you'll need to find a program that outputs
current levels (maybe something like 'rec' from the sox
package) and SHELL to it, reading its output and interpreting it to
determine the amplitude.

Maybe something like:

dim soundin as process
shell "sox -t ossdsp -u -r 8000 -c 1 -b /dev/dsp -u -r 8000 -c 1 -b -t raw
-" for read as soundin

and then in Process_Read (this is pseudocode, no idea if it'll work and all
the dim's are up to you)

if last.id = soundin.id then
	read #soundin, buf, lof(soundin)
        for i = 1 to len(buf)
        	val = abs(asc(mid(buf, 1, 1)) - 128)
        	if val > 120 then
                	' do something
                endif
        next
endif

I don't know how to force sox to monitor the output rather than the mic or
line input.... it may be that you need to use a mixer program to do that
(but I don't think kmix will do it, I think kmix works at the KDE sound
system (arts) level, not at the hardware level.) Basically, it's doable, but
there's some pitfalls to watch out for.  
Using that sox command line I was at least able to get a whole lot of 7F's
and 80's dumped to stdout (I was watching by piping it into xxd, but I
didn't have a mic hooked up or anything.)  Since you were treating it as
data to analyze and not audio to play, I made sox give us unsigned 8-bit
samples.... I don't even know if gambas will be able to keep up with 8000
samples per second with that for loop in there.  If need be, you can add
STEP 16 or STEP 100 or something to that for loop and I don't think it'll be
any less effective.

Obviously, there'll be a component to do audio analysis eventually, just not
yet ;)

Rob




-------------------------------------------------------
SF email is sponsored by - The IT Product Guide Read honest & candid reviews
on hundreds of IT Products from real users.
Discover which products truly live up to the hype. Start reading now.
http://ads.osdn.com/?ad_id=6595&alloc_id=14396&op=click
_______________________________________________
Gambas-user mailing list
Gambas-user at lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/gambas-user





More information about the User mailing list