Results 1 to 20 of 20

Thread: Capture audio and visualize it

  1. #1

    Thread Starter
    Addicted Member beic's Avatar
    Join Date
    Jun 2012
    Posts
    150

    Question Capture audio and visualize it

    Hi there,

    Do someone has a simple audio capturing and visualization snippet?

    I need something simplest ever, to visualize audio in Picturebox with dark gray background and with orange spectrum wave.

    Any starting point is welcome!

    Thanks!

  2. #2
    PowerPoster
    Join Date
    Jul 2010
    Location
    NYC
    Posts
    5,719

    Re: Capture audio and visualize it

    I have a basic intro to it with a simple peak meter, then The trick has some really cool more advanced ones.

  3. #3

    Thread Starter
    Addicted Member beic's Avatar
    Join Date
    Jun 2012
    Posts
    150

    Re: Capture audio and visualize it

    Thank you for the fast response!

    1. It has an external additional library
    2. It's over complicated for my needs (but it's epic)

    What I need is like this simple example:

    Attachment 190567
    Last edited by beic; Feb 25th, 2024 at 04:25 PM.

  4. #4
    PowerPoster Elroy's Avatar
    Join Date
    Jun 2014
    Location
    Near Nashville TN
    Posts
    9,942

    Re: Capture audio and visualize it

    Yeah, I'd recommend looking in the CodeBank for some of The Trick's work.

    As an alternative, Audacity is some very nice software for visualizing and manipulating audio files. Not sure if it's open-source or not, but it's definitely not VB6, if that's what you were looking for.
    Any software I post in these forums written by me is provided "AS IS" without warranty of any kind, expressed or implied, and permission is hereby granted, free of charge and without restriction, to any person obtaining a copy. To all, peace and happiness.

  5. #5
    PowerPoster
    Join Date
    Jul 2010
    Location
    NYC
    Posts
    5,719

    Re: Capture audio and visualize it

    Quote Originally Posted by beic View Post
    Thank you for the fast response!

    1. It has an external additional library
    2. It's over complicated for my needs (but it's epic)

    What I need is like this simple example:

    Attachment 190567
    For 1, the 'external library' is for the IDE only. You do not need to distribute it with your compiled exe; it doesn't need to be present anywhere except the machine you use to compile the exe.

    For 2, it's really not, for what you're asking. There's nothing in between the more simple core audio and direct wavein that isn't a 3rd party library too (and often an ocx you *would* need to distribute).

  6. #6

  7. #7

    Thread Starter
    Addicted Member beic's Avatar
    Join Date
    Jun 2012
    Posts
    150

    Re: Capture audio and visualize it

    Hi Trick,

    Thank you for your support!

    I downloaded it, unzipped, loaded the Recorder project and after running it, I got an error saying "Invalid property value" in Form_Load, line:
    Code:
    cboCaptureDevices.ListIndex = 0
    I just really wish for a simplest solution to listen/sniff the default audio output and visualize it (I don't need any recording, or similar fancy things...)

  8. #8
    Addicted Member ISAWHIM's Avatar
    Join Date
    Jan 2023
    Posts
    181

    Re: Capture audio and visualize it

    You may be able to use "bass.dll" for something you desire.
    https://www.un4seen.com/

    I believe you can obtain various levels of an audio-stream. Then you just have to "visualize" it in some way.
    - global-volume (used for DB output displays)
    - frequency-volumes (used for EQ output displays)

    DB-volume is easy to display, because even windows offers some "volume output level", in some form. The frequency-volumes are harder, because you have to do heavy "math" to detect the various frequencies on frequencies on frequencies. (waves on waves on waves), which sum-up to the singular "wave" that makes whole "volume".

    The DLL allows streaming/playing and streaming/recording, in multiple formats and various qualities of play and recording.

    There should still be some VB6 examples there. There are many online, in the forums.
    Please, chime-in on my latest WIP.
    I can use all the help I can get.
    [VB6 Game], (In Development), "Galactic-Bondsman"

  9. #9

    Thread Starter
    Addicted Member beic's Avatar
    Join Date
    Jun 2012
    Posts
    150

    Re: Capture audio and visualize it

    Quote Originally Posted by ISAWHIM View Post
    You may be able to use "bass.dll" for something you desire.
    https://www.un4seen.com/

    I believe you can obtain various levels of an audio-stream. Then you just have to "visualize" it in some way.
    - global-volume (used for DB output displays)
    - frequency-volumes (used for EQ output displays)

    DB-volume is easy to display, because even windows offers some "volume output level", in some form. The frequency-volumes are harder, because you have to do heavy "math" to detect the various frequencies on frequencies on frequencies. (waves on waves on waves), which sum-up to the singular "wave" that makes whole "volume".

    The DLL allows streaming/playing and streaming/recording, in multiple formats and various qualities of play and recording.

    There should still be some VB6 examples there. There are many online, in the forums.
    Hi there, thank you for your input, but the issue is that is a 3rd party control (separate file), so I would need a simple implementation.

    Just to listen to the default playback device and draw the audio peak as a wave visualization (orange) into a single Picturebox (black background).

  10. #10
    PowerPoster
    Join Date
    Jun 2013
    Posts
    7,259

    Re: Capture audio and visualize it

    Quote Originally Posted by beic View Post
    Hi there, thank you for your input, but the issue is that is a 3rd party control (separate file), so I would need a simple implementation.

    Just to listen to the default playback device and draw the audio peak as a wave visualization (orange) into a single Picturebox (black background).
    Here is an vbRichClient-based example, which does PeakMeter- and FFT-visualization
    (with a low amount of VB6-code).

    https://www.vbforums.com/showthread....a-and-onwards)

    The zipped Project currently wants a reference to a registered vbRichClient5,
    but is easily switchable to a registered RC6-Ref in the appropriate Dialog.

    Also note, that the example "out of the box" tries to capture and visualize "sound from the Microphone-device"...

    To switch that to your "default-sound-output-device" you will have to change in Form_Load the line:

    Set CapDev = New_c.MMDeviceEnumerator.GetDefaultAudioEndpoint(eCapture, eCommunications)
    to:
    Set CapDev = New_c.MMDeviceEnumerator.GetDefaultAudioEndpoint(eRender, eMultimedia)

    HTH

    Olaf

  11. #11

    Thread Starter
    Addicted Member beic's Avatar
    Join Date
    Jun 2012
    Posts
    150

    Re: Capture audio and visualize it

    Quote Originally Posted by Schmidt View Post
    Here is an vbRichClient-based example, which does PeakMeter- and FFT-visualization
    (with a low amount of VB6-code).

    https://www.vbforums.com/showthread....a-and-onwards)

    The zipped Project currently wants a reference to a registered vbRichClient5,
    but is easily switchable to a registered RC6-Ref in the appropriate Dialog.

    Also note, that the example "out of the box" tries to capture and visualize "sound from the Microphone-device"...

    To switch that to your "default-sound-output-device" you will have to change in Form_Load the line:

    Set CapDev = New_c.MMDeviceEnumerator.GetDefaultAudioEndpoint(eCapture, eCommunications)
    to:
    Set CapDev = New_c.MMDeviceEnumerator.GetDefaultAudioEndpoint(eRender, eMultimedia)

    HTH

    Olaf
    Hi Olaf,

    Oh, I really like the Peak meter in your linked post, but the issue is with it that I can't afford to include 4Mb library with 150Kb single file executable.

    Is there any in-code solution? I really need only a basic single channel Spectrum wave audio visualization in Picturebox, nothing else.

    Thank you!

  12. #12
    PowerPoster Zvoni's Avatar
    Join Date
    Sep 2012
    Location
    To the moon and then left
    Posts
    4,444

    Re: Capture audio and visualize it

    Quote Originally Posted by beic View Post
    Is there any in-code solution? I really need only a basic single channel Spectrum wave audio visualization in Picturebox, nothing else.
    Thank you!
    Then make yourself familiar with FFT-Computation/Calculations, because that's at the core of all those Spectrum visualizations
    Last edited by Zvoni; Tomorrow at 31:69 PM.
    ----------------------------------------------------------------------------------------

    One System to rule them all, One Code to find them,
    One IDE to bring them all, and to the Framework bind them,
    in the Land of Redmond, where the Windows lie
    ---------------------------------------------------------------------------------
    People call me crazy because i'm jumping out of perfectly fine airplanes.
    ---------------------------------------------------------------------------------
    Code is like a joke: If you have to explain it, it's bad

  13. #13
    PowerPoster
    Join Date
    Jun 2013
    Posts
    7,259

    Re: Capture audio and visualize it

    Quote Originally Posted by beic View Post
    Oh, I really like the Peak meter in your linked post,
    but the issue is with it that I can't afford to include 4Mb library with 150Kb single file executable.
    Hmm, ...you are aware, that RC6 allows regfree distribution (without any setup) -
    along with your executable (in a ca. 4MB-zip...which then occupies about 0,0004% of your End-Users disk)?

    Quote Originally Posted by beic View Post
    Is there any in-code solution?
    Several were already posted, I think...

    Olaf

  14. #14
    PowerPoster
    Join Date
    Jul 2010
    Location
    NYC
    Posts
    5,719

    Re: Capture audio and visualize it

    The typelib-based solutions don't requiring including anything at all with your exe.

    You're going to have to make a choice buddy. Nobody can give you a solution that's easier than any given so far *and* has zero external dependencies even for the IDE that you don't need to include with your exe; you'd have to look outside VB6 for that, but even then the reduction in complexity would be minimal and would be just as likely to need a 3rd party library.

  15. #15

    Thread Starter
    Addicted Member beic's Avatar
    Join Date
    Jun 2012
    Posts
    150

    Re: Capture audio and visualize it

    Quote Originally Posted by Zvoni View Post
    Then make yourself familiar with FFT-Computation/Calculations, because that's at the core of all those Spectrum visualizations
    The logic say, that if I would know to make it myself, I wouldn't asked on forum/here.

  16. #16
    Addicted Member ISAWHIM's Avatar
    Join Date
    Jan 2023
    Posts
    181

    Re: Capture audio and visualize it

    Your only option then, is to use built-in windows PCM/WAV or MP3 audio streams.

    All three will offer some form of potential visualization, if you hand-code some basic math to get the "levels" you are looking for. You will have to become familiar with the formats, or find someone who has already done the work for you.

    It will not be fast, but it will function.

    PCM/WAV is quite literal, once you know the format. The values are literally just a relation to a wave-form shape. At the lowest level, it is only a matter of reading the value, related to the "current location in the stream", and displaying the value on a chart. The harder part is figuring out the current time-position, since audio is all managed by third-party drivers that windows has used to replace the original drivers they once used. (All use Direct-Sound streams now)

    The alternative to reading live-streams, is to read the whole file, in advance. Then place that data into an array, formatted as needed, for visualization. Then just monitor the "time position", of the stream and show that chunk of visualized data. (That removes any form of "active display")

    MP3 will be a bit different, due to compression. You have to read the associated time-block-container, math the MIN/MAX/Compression, and then calculate the uncompressed "values", which will always be janky and slower. (In a roll-your-own math reader).

    If you want live visualization, while capturing audio, within VB6, you are really pushing the bounds of reality. VB6 has no real way to directly interface audio-components, without some third-party device. The ones that windows uses, which VB6 gives you access to, have a real limited VB6 interaction. (Part of the reason is that VB6 is 32-bit and all current audio-drivers are all 64-bit, as is most new audio formats.)

    Your last potential alternative is "DirectSound" or "DirectX". (DirectSound has since expired and been incorporated into DirectX, which is what windows uses for ALL audio that you physically hear from the OS, currently.) However, DirectSound still exists, due to legacy support, within DirectX.
    https://en.wikipedia.org/wiki/DirectSound
    Please, chime-in on my latest WIP.
    I can use all the help I can get.
    [VB6 Game], (In Development), "Galactic-Bondsman"

  17. #17
    Addicted Member ISAWHIM's Avatar
    Join Date
    Jan 2023
    Posts
    181

    Re: Capture audio and visualize it

    The logic say, that if I would know to make it myself, I wouldn't asked on forum/here.
    You are welcome, is the more appropriate response, to many of these replies.

    If you wanted someone to code it for you, there is another way to ask. That is not "Help", that is "do it for me".

    There were MANY great and informed replies offered-up for you to digest and USE directly. All, to some point, clearly state that what you "dream of doing yourself", can not be done easily, and now you bluntly state that you don't want to "do it", but "have it done for you".

    VB6 has no direct access to any audio. Audio, like video and inputs, are all "data streams". Windows offers, by third-party, access to those streams data, in various forms of API calls and SOMETIMES the use of "Callbacks". VB6, can tap into the streams by way of API calls, or obtain bits of info from a callback. VB6 is not fast enough to directly manage audio itself. You are 100% at the mercy of some external sources for audio like this. The OLD audio devices that VB6 has adopted as OCX's and old DLLs, is not up to the task. Even less now, since they ALL depend on DirectX, which is another layer behind them, attempting to keep them "functioning" for VB6 now.

    Unlike an audio FILE, which VB6 can easily process, if you know the math and the formats to read them. That is going to demand someone's third-party code, which is really going to be limited by many factors now. The math is basic, but the chances that they have isolated the code to ONLY what you want, is going to be rare. It is going to include many more, useful things within the code and you will have to figure out what things to NOT use. (They also will probably be using file-streams, because it is audio, and that often requires "skipping", for timing. Few will be setup for "static file access", as that is more about editing and manipulating raw audio data. Though I am sure that exists too, in a more limited crowd of ambitious people who resist using the appropriate language and tools to do what has been done for the past 30+ years.)

    Your options are...
    1: Learn the math and do the math, or find one of the MANY who have already done it.
    - Another good, limited resource. https://en.wikipedia.org/wiki/Pulse-code_modulation
    - Working with PCM a "Class". https://www.vbforums.com/showthread....WAVE-PCM-files
    2: Use third-party devices, which are really NEEDED for this. (Be it a new DLL or some already existing DLLs, like DirectX)
    3: Ask someone to code it for you, your way, since you don't like the way it has been coded already and can't code it yourself, as you stated.

    Few have attempted to do this, as a DIY, with VB6, because it's really just not possible. VB6 is not a DAW or an audio-program, it barely even has the ability to play sounds, well, with what the CREATORS of VB6/MS offered.

    BASS.dll at that site, actually offers a FULL AUDIO PROGRAM with full examples. It is as seasoned as DirectX, but with less learning involved. You literally just have to include the DLL in the programs folder and use it! (DirectX will NOT be as easy to setup and run, and be more involved than just dropping in a DLL and calling a simple API.)

    Other things you will NEED to know, for visualization...
    - GDI point drawing API programming, for drawing the visualization, fast enough to display. (Or DirectX)
    - Line drawing, and manipulation, if not using just "points" to visualize the waves.
    - GDI BitBlt API, if you are going to use "images" or "rectangles", to visualize the waves like an EQ.

    NOTE: VB6 does not have any built-in "visualization" ability that is fast enough to match audio. The refresh rates are horrible within the IDE, and close to around 15 FPS, without directly drawing things, yourself, with GDI commands, on VB6 forms. Audio data comes in at around 20,000 Hz, which is 20,000 FPS. Up to 160,000 Hz of data, for newer audio, which is reduced to 20,000 Hz audible frequencies, with more "wave-form accuracy". (198,000 Hz is the highest I think. I forget. Though I am 90% sure that is 64-bit audio only.) Also note that is "per channel". Stereo is those numbers x2. 5.1 surround sound is those numbers x6.

    Final note... Bass.dll was made, originally, due to VB4, VB5 and VB6's inability to manage MP3 audio compression streams. It was a core foundation for WinAmp, which has since broken away and now been adopted by Microsoft. (WinAmp still exists) Later, with DirectSound, bass.dll offered NON-DX games, that same speed and ability with bonus frills that DirectSound never had. Later, DirectSound was abandoned and replaced with an integrated DirectX version known later as DirectSound3D. That allowed Audio to be matched to Video, as opposed to running side by side and "falling out of sync". That will be your only real flaw with bass.dll, is a visual-lag, due to VB6 attempting to display a visual representation for audio that is currently playing ahead of the visualization potential. (That is why DirectX is really the "better solution". Because the streams can be directly linked, in a sense. They share the same single timing values, optionally.)
    Last edited by ISAWHIM; Mar 4th, 2024 at 09:11 AM.
    Please, chime-in on my latest WIP.
    I can use all the help I can get.
    [VB6 Game], (In Development), "Galactic-Bondsman"

  18. #18

    Thread Starter
    Addicted Member beic's Avatar
    Join Date
    Jun 2012
    Posts
    150

    Re: Capture audio and visualize it

    No, no, no, don't get me wrong here...

    I tough that it can be still done over APIs:
    Code:
    Private Declare Function waveInOpen Lib "winmm" (phwi As Long, ByVal uDeviceID As Long, pwfx As Any, ByVal dwCallback As Long, ByVal dwCallbackInstance As Long, ByVal fdwOpen As Long) As Long
    Private Declare Function waveInClose Lib "winmm" (ByVal hwi As Long) As Long
    Private Declare Function waveInAddBuffer Lib "winmm" (ByVal hwi As Long, pwh As Any, ByVal cbwh As Long) As Long
    Private Declare Function waveInGetDevCaps Lib "winmm" Alias "waveInGetDevCapsA" (ByVal hwi As Long, pwic As Any, ByVal cbwic As Long) As Long
    Private Declare Function waveInGetNumDevs Lib "winmm" () As Long
    etc...
    Sorry for misunderstanding!

  19. #19
    Addicted Member ISAWHIM's Avatar
    Join Date
    Jan 2023
    Posts
    181

    Re: Capture audio and visualize it

    Quote Originally Posted by beic View Post
    The logic say, that if I would know to make it myself, I wouldn't asked on forum/here.
    Quote Originally Posted by beic View Post
    No, no, no, don't get me wrong here...

    I tough that it can be still done over APIs:
    Code:
    Private Declare Function waveInOpen Lib "winmm" (phwi As Long, ByVal uDeviceID As Long, pwfx As Any, ByVal dwCallback As Long, ByVal dwCallbackInstance As Long, ByVal fdwOpen As Long) As Long
    Private Declare Function waveInClose Lib "winmm" (ByVal hwi As Long) As Long
    Private Declare Function waveInAddBuffer Lib "winmm" (ByVal hwi As Long, pwh As Any, ByVal cbwh As Long) As Long
    Private Declare Function waveInGetDevCaps Lib "winmm" Alias "waveInGetDevCapsA" (ByVal hwi As Long, pwic As Any, ByVal cbwic As Long) As Long
    Private Declare Function waveInGetNumDevs Lib "winmm" () As Long
    etc...
    Sorry for misunderstanding!
    It can, with APIs and "bass.dll", instead of "winmm.dll".

    https://en.wikipedia.org/wiki/Window...dio_components

    The MME API or the Windows Multimedia API (also known as WinMM) was the first universal and standardized Windows audio API. Wave sound events played in Windows (up to Windows XP) and MIDI I/O use MME. The devices listed in the Multimedia/Sounds and Audio control panel applet represent the MME API of the sound card driver.
    Yes, that is the janky, garbage that VB6's OCX's use to play audio, if you use the media/sound device OCX's. The same garbage that "Windows media player" used, and quickly abandoned, when they "acquired" WinAmp. The new SDK's no longer use that horrible DLL for anything, other than legacy support. You may be able to get the "values" you need, to do the MATH you need, to visualize the audio-stream, possibly.

    Look for an older SDK set of examples that has VB6 examples. They may have gutted them for VB.NET. There may even be old threads here for that. However, those I usually got from the old website for VB-Code, which no longer exists. But I know someone has the whole website archived.
    https://learn.microsoft.com/en-us/wi...dia-player-sdk

    "Windows Media Player" has API you can use. Look at the SDK. However, that was replaced by "MediaPlayer", in win-10/win-11, which has better ability and stability, but still garbage. WMP can still be used and may be better for compatibility. Both have the MS version of bass.dll as the core now, but it is not "bass.dll", itself. It is the WinAmp version.

    Possible searching phrase...
    vb6 wmp.dll api

    mpvis.DLL (Windows media player visualization dll)
    ??? http://dll.fyicenter.com/1643_mpvis_...alization.html

    I am not sure if that will give you access to the actual "visualization" code too. (Media player has a "visualization" component, which it uses to display audio in various ways, like a psychedelic screensaver. I do not know if the API will offer access to the same data that the visualizer uses too. It is the same one from WinAmp. Since you can display the "screen" from media player, you may be able to display the built-in "visualization", which actually uses DirectX for the display, but YOU would not have to mess with DX code, just show the screen, pick a visualization, and start streaming or recording audio.)
    Last edited by ISAWHIM; Mar 4th, 2024 at 10:02 AM.
    Please, chime-in on my latest WIP.
    I can use all the help I can get.
    [VB6 Game], (In Development), "Galactic-Bondsman"

  20. #20

    Thread Starter
    Addicted Member beic's Avatar
    Join Date
    Jun 2012
    Posts
    150

    Re: Capture audio and visualize it

    First of all, thank you for those beautiful explanation and directions described above!

    Quote Originally Posted by ISAWHIM View Post
    It can, with APIs and "bass.dll", instead of "winmm.dll".
    "Windows Media Player" has API you can use. Look at the SDK. However, that was replaced by "MediaPlayer", in win-10/win-11, which has better ability and stability, but still garbage. WMP can still be used and may be better for compatibility. Both have the MS version of bass.dll as the core now, but it is not "bass.dll", itself. It is the WinAmp version.
    Yes, I'm using Windows Media Player control (wmp.dll), it's working just perfectly for my needs, also it has a built-in visualization, I could use it any time, but the spectrum wave inside is blue color (by default).

    You mentioned "MediaPlayer" in win-10/win-11, I tried to run my compiled application on Windows 11, unfortunately it's not working, can't find wmp.dll component.

    So, ... (my brain stopped, right here...)

    p.s. The compiled application is backward compatible "tested and working" on Windows Vista, 7, 8, 10 (VirtualBox - Fresh System installs)

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width