[Gambas-user] Current Volume Output
Rob
sourceforge-raindog2 at ...94...
Tue Mar 15 17:03:09 CET 2005
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
More information about the User
mailing list