Results 1 to 2 of 2

Thread: VB6 check for sound on speakers

  1. #1

    Thread Starter
    New Member
    Join Date
    Apr 2021
    Posts
    11

    VB6 check for sound on speakers

    Hi,

    looking at some old code to 'test for silence' on the speakers...

    https://www.vbforums.com/showthread....Sound-Tutorial

    Comment #4 to 'record sound', although I'm not looking to save anything, just to report if there's sound or not (I'll modify it later).

    I've downloaded the zip files and I'm running the code from there, in part:
    Code:
    Private Sub cmdStartRec_Click()
        Dim ErrReturn As String
        Dim WaveFmt As WaveFormat
        
        ' fill in the Wave Format
        With WaveFmt
            .wFormatTag = 1 ' PCM
            
            .nChannels = 2
            .nSamplesPerSec = 48000   ' from my sound card, was 44100
            .wBitsPerSample = 24          'from my sound card, was16
            
            .nBlockAlign = .wBitsPerSample * .nChannels / 8
            .nAvgBytesPerSec = .nBlockAlign * .nSamplesPerSec
        End With
        
        ' Create the wave tile
        FileNum = FreeFile
        Open "D:\Recording Test.WAV" For Binary Access Write Lock Write As FileNum
        
        WaveWriteHeader FileNum, WaveFmt ' write the wave headers
        
        With DirectSoundRecord
            ' initialize DirectSound with exactly the same sound format as you expect to write in the file
            ErrReturn = .Initialize(WaveFmt.nSamplesPerSec, WaveFmt.wBitsPerSample, WaveFmt.nChannels)
            
            If Len(ErrReturn) = 0 Then
                ' if there was no error
                ' start recording
                .SoundPlay
                
                cmdStopRec.Enabled = True
                cmdStartRec.Enabled = False
            Else
                MsgBox ErrReturn, vbExclamation, "DirectSound Error"
            End If
        End With
    End Sub
    fails at:
    With DirectSoundRecord
    ErrReturn = .Initialize(WaveFmt.nSamplesPerSec, WaveFmt.wBitsPerSample, WaveFmt.nChannels)

    and reports:
    Error: -2147221164
    Desription: Class not registered

    I have dx8vb.dll registered...any ideas please?

    Regards
    Peter

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

    Re: VB6 check for sound on speakers

    For anyone else that comes across this, Peter asked in the thread for one of my Core Audio demos and I provided this solution:

    I believe you could make a few queries to the peak meter... if you continuously got zero that would mean no audio playing (but of course could also mean a stretch of silence in playing audio).

    https://docs.microsoft.com/en-us/win...io/peak-meters

    Edit: Turns out you can do exactly that. See this new demo:
    [VB6, Vista+] Core Audio - Peak Meter

    In the timer, you'll see where it sets the audio/no audio label by checking if the peak is zero.

    You'll probably want to check a couple times... the demo doesn't wait to change the status but does include the set up to do so:
    Code:
    Private nCount As Long
    'Then modify the Timer1_Timer routine:
        If snValue = 0 Then
            Label4.Caption = "No audio."
            nCount = nCount + 1
            If nCount > 5 Then
                'definitely not playing
            End If
        Else
            nCount = 0
            Label4.Caption = "Audio detected"
        End If

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