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


Messages In This Thread
Make your keyboard flash with music - by Petr - 06-28-2024, 06:33 PM
RE: Make your keyboard flash with music - by Pete - 06-28-2024, 09:26 PM



Users browsing this thread: 1 Guest(s)