QB64 Phoenix Edition
Make your keyboard flash with music - Printable Version

+- QB64 Phoenix Edition (https://qb64phoenix.com/forum)
+-- Forum: QB64 Rising (https://qb64phoenix.com/forum/forumdisplay.php?fid=1)
+--- Forum: Prolific Programmers (https://qb64phoenix.com/forum/forumdisplay.php?fid=26)
+---- Forum: Petr (https://qb64phoenix.com/forum/forumdisplay.php?fid=52)
+---- Thread: Make your keyboard flash with music (/showthread.php?tid=2835)



Make your keyboard flash with music - Petr - 06-28-2024

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



RE: Make your keyboard flash with music - Pete - 06-28-2024

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.