Sign in to follow this  
Followers 0
59FIFTY

Visualize Sound

10 posts in this topic

Hi there

I've got a question to ask. I need a little Program that visualizes the current sound output in bars (like a synthesizer). That means even if I play an mp3 in wmplayer it should display it with AutoIt.

Is that even possible? And I mean very simple, like volume output or frequencies.

Share this post


Link to post
Share on other sites



Did you look at Bass.au3?


Giggity

Share this post


Link to post
Share on other sites

This works fine for a soundfile, but I want to read out the current system sound ("stereo mix")

Share this post


Link to post
Share on other sites

This works fine for a soundfile, but I want to read out the current system sound ("stereo mix")

It's possible to open a recording device in Bass as well.

If you want to see how you can visualize the data from Bass you can check the Audio Viz in my sig.

:)


Broken link? PM me and I'll send you the file!

Share this post


Link to post
Share on other sites

#5 ·  Posted (edited)

I've downloaded your zip-file but it's a bit difficult to read/understand. Can you post an example of how to open stereo mix and get _BASS_ChannelGetLevel for the input? caus' I'm really struggeling here :) even to get just the value of the peak's

I tried this but only returns 0 on both channels

#include <Bass.au3>
#include <BassConstants.au3>
$bass_dll = DllOpen("BASS.dll")
_BASS_Init ($bass_dll, 0, -1, 44100, 0, "")
$HRECORD = _BASS_RecordStart($bass_dll, 44100, 2, $BASS_SAMPLE_FLOAT)
$levels = _BASS_ChannelGetLevel ($bass_dll, $HRECORD)
$right = _LoWord ($levels)
$left = _HiWord ($levels)

While 1
    ConsoleWrite("R ["&$right&"] L ["&$left&"]"&@CRLF)
    Sleep(500)
Wend
Edited by 59FIFTY

Share this post


Link to post
Share on other sites

I've got to solve this fast :\

Share this post


Link to post
Share on other sites

No suggestions? I'm trying the whole day now and it won't work :)

Share this post


Link to post
Share on other sites

I haven't got time to write code for you, but are you sure you're actually recording the stereomix and not the microphone? Also check that the levels for the device are high enough.


Broken link? PM me and I'll send you the file!

Share this post


Link to post
Share on other sites

#9 ·  Posted (edited)

ok it works now, the only problem is that if I play a sound the level get's to 32768 even if i reduce the stereo mix volume, that's why?

This is my current Script

#include <GUIConstants.au3>
#include <Bass.au3>
#include <BassConstants.au3>
AutoItSetOption("TrayIconHide", TRUE)
AutoItSetOption("GUIOnEventMode", 1)

; BASS.DLL Init
$bass_dll = DllOpen("BASS.dll")
_BASS_Init ($bass_dll, 0, -1, 44100, 0, "")

; Create GUI
$StereoMixer = GUICreate("RecordPeakVol", 457, 123, 199, 116)
$prg_left = GUICtrlCreateProgress(8, 80, 438, 32)
$prg_right = GUICtrlCreateProgress(8, 40, 438, 32)
$btn_start = GUICtrlCreateButton("start", 8, 8, 75, 25, 0)
$btn_stop = GUICtrlCreateButton("stop", 88, 8, 75, 25, 0)
GUISetOnEvent($GUI_EVENT_CLOSE, "GUIClose")
GUICtrlSetOnEvent($btn_stop, "btn_stopClick")
GUICtrlSetOnEvent($btn_start, "btn_startClick")
GUISetState(@SW_SHOW)

; Variables
Dim $File, $mhnd, $play = FALSE, $device = 0

While 1
    If $play Then
        $peaks = _BASS_ChannelGetLevel($bass_dll, $mhnd) ;get volume peaks
        $right = Round((_LoWord($peaks)/32768)*100, 0) ;round to percent
        $left = Round((_HiWord($peaks)*-1/32768)*100, 0)
        GUICtrlSetData($prg_left, $left)
        GUICtrlSetData($prg_right, $right)
        ConsoleWrite('L ['&_HiWord($peaks)*-1&'] - R ['&_LoWord($peaks)&']' & @CRLF)
        Sleep(50)
    EndIf
WEnd

Func btn_startClick()
    ;start recording sound from stereo mixer
    _BASS_RecordInit($bass_dll, $device) ;init record to stereo mixer
    $RecDevice = _BASS_RecordGetInputName($bass_dll, $device) ;check if input is Stereo Mixer
    ConsoleWrite('Start recording from: ' & $RecDevice & @CRLF)
    
    _BASS_RecordSetInput($bass_dll, $device, $BASS_INPUT_ON, 1)
    
    $mhnd = _BASS_RecordStart($bass_dll, 44100, 5, 0) ;start record stereo
    _BASS_ChannelPlay($bass_dll, $mhnd, FALSE) ;play channel
    $play = TRUE
EndFunc

Func btn_stopClick()
    ;stop recording sound from stereo mixer
    _BASS_ChannelStop($bass_dll, $mhnd)
    $play = FALSE
EndFunc

Func GUIClose()
    ;quit app
    Exit
EndFunc
Edited by 59FIFTY

Share this post


Link to post
Share on other sites

ok I had to change _BASS_RecordSetInput($bass_dll, $device, $BASS_INPUT_ON, -1) because I set the volume to 1, now I leave it.

Full working script (reading from device 0)

#include <GUIConstants.au3>
#include <Bass.au3>
#include <BassConstants.au3>
AutoItSetOption("TrayIconHide", TRUE)
AutoItSetOption("GUIOnEventMode", 1)

; BASS.DLL Init
$bass_dll = DllOpen("BASS.dll")
_BASS_Init ($bass_dll, 0, -1, 44100, 0, "")

; Create GUI
$StereoMixer = GUICreate("RecordPeakVol", 457, 123, 199, 116)
$prg_left = GUICtrlCreateProgress(8, 80, 438, 32)
$prg_right = GUICtrlCreateProgress(8, 40, 438, 32)
$btn_start = GUICtrlCreateButton("start", 8, 8, 75, 25, 0)
$btn_stop = GUICtrlCreateButton("stop", 88, 8, 75, 25, 0)
GUISetOnEvent($GUI_EVENT_CLOSE, "GUIClose")
GUICtrlSetOnEvent($btn_stop, "btn_stopClick")
GUICtrlSetOnEvent($btn_start, "btn_startClick")
GUISetState(@SW_SHOW)

; Variables
Dim $File, $mhnd, $play = FALSE, $device = 0

While 1
    If $play Then
        $peaks = _BASS_ChannelGetLevel($bass_dll, $mhnd) ;get volume peaks
        $right = Round((_LoWord($peaks)/32768)*100, 0) ;round to percent
        $left = Round((_HiWord($peaks)/32768)*100, 0)
        GUICtrlSetData($prg_left, $left)
        GUICtrlSetData($prg_right, $right)
        ConsoleWrite('L ['&_HiWord($peaks)&'] - R ['&_LoWord($peaks)&']' & @CRLF)
        Sleep(50)
    EndIf
WEnd

Func btn_startClick()
    ;start recording sound from stereo mixer
    _BASS_RecordInit($bass_dll, $device) ;init record to stereo mixer
    $RecDevice = _BASS_RecordGetInputName($bass_dll, $device) ;check if input is Stereo Mixer
    ConsoleWrite('Start recording from: ' & $RecDevice & @CRLF)
    
    _BASS_RecordSetInput($bass_dll, $device, $BASS_INPUT_ON, -1)
    
    $mhnd = _BASS_RecordStart($bass_dll, 44100, 5, 0) ;start record stereo
    _BASS_ChannelPlay($bass_dll, $mhnd, FALSE) ;play channel
    $play = TRUE
EndFunc

Func btn_stopClick()
    ;stop recording sound from stereo mixer
    _BASS_ChannelStop($bass_dll, $mhnd)
    $play = FALSE
EndFunc

Func GUIClose()
    ;quit app
    Exit
EndFunc

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0