Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Make your keyboard flash with music
#1
Big Grin 
THE FOLLOWING PROGRAM IS THE REASON WHY I HAD TO BORROW A KEYBOARD WITH ALL THE LED DIODES THAT CAN BE CONTROLLED BY PHOENIX DIRECTLY Smile NOBODY EXPECTED THIS USAGE...

Code: (Select All)

_Title "Make your keyboard flash with music"
Dim As Long s, d, Sam
Dim As _MEM m
Dim As _Float Volume, Position

s = _SndOpen("10.mp3") 'liquido - narcotic
m = _MemSound(s, 0)
If m.ELEMENTSIZE <> 8 Then Print "try another mp3 sound file": _SndClose s: End
_SndPlay s
T = Timer
DetectTime = .005
Samples = _SndRate * DetectTime

'detect maximal volume level in record (left channel)
Do Until d = m.SIZE - 8
    CurrentVolLevel = Abs(_MemGet(m, m.OFFSET + d, Single))
    If VolLevel < CurrentVolLevel Then VolLevel = CurrentVolLevel
    d = d + 8
Loop

Do While _SndPlaying(s)
    Position = 8 * (_SndGetPos(s) * _SndRate)
    If Position Mod 8 = 0 Then
        Sam = Sam + 1
        Volume = Volume + Abs(_MemGet(m, m.OFFSET + Position, Single))
    End If

    If T + DetectTime < Timer Then
        Volume = Volume / Sam
        Locate 1
        Print "Listen to music while watching numlock, capslock and scrolllock"
        Print
        Print "Current volume level: "; Int((Volume / VolLevel) * 100); "%"; "  "
        Select Case Volume / VolLevel
            Case Is < .05 * VolLevel: _Scrolllock Off: _Numlock Off: _CapsLock Off
            Case .051 * VolLevel To .3 * VolLevel: _Numlock On: _Scrolllock Off: _CapsLock Off
            Case .3 * VolLevel To .6 * VolLevel: _Numlock On: _CapsLock On: _Scrolllock Off
            Case Is > .6 * VolLevel: _Scrolllock On: _Numlock On: _CapsLock On
        End Select
        T = Timer
        Volume = 0
        Sam = 0
   End If
Loop
_MemFree m
_SndClose s
System


Reply
#2
How do I reverse the effect? The reason I ask is because my keyboard just flashed my floppy drive and turned it into a hard drive.

Pete Big Grin

- I have an IQ of 160 because I took the test twice.
Reply




Users browsing this thread: 2 Guest(s)