Set Master-Volume

Just starting out? Need help? Post your questions and find answers here.
BackupUser
PureBasic Guru
PureBasic Guru
Posts: 16777133
Joined: Tue Apr 22, 2003 7:42 pm

Post by BackupUser »

Restored from previous forum. Originally posted by GPI.

Like the same as in the Systemtry (loudspeaker).

And how to mute, would be nice too.

I have found out, that the API-Mixer function can do this, but i don't check the description and a VB-Example i don't get to work.

GPI

PII 333, 256MB, Asus TNT2Ultra 32MB, AWE Gold 64 4MB
BackupUser
PureBasic Guru
PureBasic Guru
Posts: 16777133
Joined: Tue Apr 22, 2003 7:42 pm

Post by BackupUser »

Restored from previous forum. Originally posted by PB.

> a VB-Example i don't get to work.

Post the example and we may be able to convert it to PureBasic for you. :)
BackupUser
PureBasic Guru
PureBasic Guru
Posts: 16777133
Joined: Tue Apr 22, 2003 7:42 pm

Post by BackupUser »

Restored from previous forum. Originally posted by GPI.

Ok, i got the Example out of API-Guide 3.7
(Mixeropen)

Code: Select all

'This project needs a module and a form
'The form must contain two labels, two progressbars, a timer and a checkbox

'Paste this code into the form
Dim hmixer As Long                  ' mixer handle
Dim inputVolCtrl As MIXERCONTROL    ' waveout volume control
Dim outputVolCtrl As MIXERCONTROL   ' microphone volume control
Dim rc As Long                      ' return code
Dim ok As Boolean                   ' boolean return code

Dim mxcd As MIXERCONTROLDETAILS         ' control info
Dim vol As MIXERCONTROLDETAILS_SIGNED   ' control's signed value
Dim volume As Long                      ' volume value
Dim volHmem As Long                     ' handle to volume memory
Private Sub Form_Load()
   'KPD-Team 1999
   'URL: [url]http://www.allapi.net/[/url]
   'E-Mail: [url]mailto:KPDTeam@Allapi.net[/url]
   Me.ScaleMode = vbTwips
   Me.Caption = "Volume meter"
   Label1.Move 0, 0
   Label1.AutoSize = True
   Label1.Caption = "Input level"
   Label2.Move 0, 4 * Label1.Height
   Label2.AutoSize = True
   Label2.Caption = "Output level"
   ProgressBar1.Move Label1.Width * 2, 0, 3375
   ProgressBar2.Move Label1.Width * 2, Label2.Top, 3375
   Check1.Move ProgressBar1.Left, ProgressBar1.Height
   Check1.Caption = "Get Input"
   Me.Move Me.Left, Me.Top, ProgressBar1.Width + ProgressBar1.Left + 10 * Screen.TwipsPerPixelX, ProgressBar2.Top + ProgressBar2.Height + 30 * Screen.TwipsPerPixelY
   Timer1.Interval = 50
   Timer1.Enabled = True

   ' Open the mixer specified by DEVICEID
   rc = mixerOpen(hmixer, DEVICEID, 0, 0, 0)

   If ((MMSYSERR_NOERROR  rc)) Then
       MsgBox "Couldn't open the mixer."
       Exit Sub
   End If

   ' Get the input volume meter
   ok = GetControl(hmixer, MIXERLINE_COMPONENTTYPE_DST_WAVEIN, MIXERCONTROL_CONTROLTYPE_PEAKMETER, inputVolCtrl)

   If (ok  True) Then
       ok = GetControl(hmixer, MIXERLINE_COMPONENTTYPE_SRC_MICROPHONE, MIXERCONTROL_CONTROLTYPE_PEAKMETER, inputVolCtrl)
   End If

   If (ok = True) Then
      ProgressBar1.Min = 0
      ProgressBar1.Max = inputVolCtrl.lMaximum
   Else
      ProgressBar1.Enabled = False
      MsgBox "Couldn't get wavein meter"
   End If

   ' Get the output volume meter
   ok = GetControl(hmixer, MIXERLINE_COMPONENTTYPE_SRC_WAVEOUT, MIXERCONTROL_CONTROLTYPE_PEAKMETER, outputVolCtrl)

   If (ok = True) Then
      ProgressBar2.Min = 0
      ProgressBar2.Max = outputVolCtrl.lMaximum
   Else
      ProgressBar2.Enabled = False
      MsgBox "Couldn't get waveout meter"
   End If

   ' Initialize mixercontrol structure
   mxcd.cbStruct = Len(mxcd)
   volHmem = GlobalAlloc(&H0, Len(volume))  ' Allocate a buffer for the volume value
   mxcd.paDetails = GlobalLock(volHmem)
   mxcd.cbDetails = Len(volume)
   mxcd.cChannels = 1

End Sub
Private Sub Check1_Click()
   If (Check1.Value = 1) Then
      StartInput  ' Start receiving audio input
   Else
      StopInput   ' Stop receiving audio input
   End If
End Sub
Private Sub Timer1_Timer()

   On Error Resume Next

   ' Process sound buffer if recording
   If (fRecording) Then
      For i = 0 To (NUM_BUFFERS - 1)
         If inHdr(i).dwFlags And WHDR_DONE Then
            rc = waveInAddBuffer(hWaveIn, inHdr(i), Len(inHdr(i)))
         End If
      Next
   End If

   ' Get the current input level
   If (ProgressBar1.Enabled = True) Then
      mxcd.dwControlID = inputVolCtrl.dwControlID
      mxcd.item = inputVolCtrl.cMultipleItems
      rc = mixerGetControlDetails(hmixer, mxcd, MIXER_GETCONTROLDETAILSF_VALUE)
      CopyStructFromPtr volume, mxcd.paDetails, Len(volume)
      If (volume  0 Then
        waveInGetErrorText rc, msg, Len(msg)
        MsgBox msg
        StartInput = False
        Exit Function
    End If

    For i = 0 To NUM_BUFFERS - 1
        rc = waveInPrepareHeader(hWaveIn, inHdr(i), Len(inHdr(i)))
        If (rc  0) Then
            waveInGetErrorText rc, msg, Len(msg)
            MsgBox msg
        End If
    Next

    For i = 0 To NUM_BUFFERS - 1
        rc = waveInAddBuffer(hWaveIn, inHdr(i), Len(inHdr(i)))
        If (rc  0) Then
            waveInGetErrorText rc, msg, Len(msg)
            MsgBox msg
        End If
    Next

    fRecording = True
    rc = waveInStart(hWaveIn)
    StartInput = True
End Function
' Stop receiving audio input on the soundcard
Sub StopInput()

    fRecording = False
    waveInReset hWaveIn
    waveInStop hWaveIn
    For i = 0 To NUM_BUFFERS - 1
        waveInUnprepareHeader hWaveIn, inHdr(i), Len(inHdr(i))
        GlobalFree hmem(i)
    Next
    waveInClose hWaveIn
End Sub
and my translation

Code: Select all

Structure  MIXERCONTROL
  cbStruct.l
  dwControlID.l
  dwControlType.l
  fdwControl.l
  cMultipleItems.l
  szShortName.b[#MIXER_SHORT_NAME_CHARS]
  szName.b[#MIXER_LONG_NAME_CHARS]
  lMinimum.l
  lMaximum.l
  Reserved.l[10]
EndStructure
Structure MIXERLINE
  cbStruct.l
  dwDestination.l
  dwSource.l
  dwLineID.l
  fdwLine.l
  dwUser.l
  dwComponentType.l
  cChannels.l
  cConnections.l
  cControls.l
  szShortName.b[#MIXER_SHORT_NAME_CHARS]
  szName.b[#MIXER_LONG_NAME_CHARS]
  dwType.l
  dwDeviceID.l
  wMid.l
  wPid.l
  vDriverVersion.l
  szPname.b[#MAXPNAMELEN]
EndStructure
Structure MIXERLINECONTROLSx
  cbStruct.l
  dwLineID.l
  dwControl.l
  cControls.l
  cbmxctrl.l
  pamxctrl.l
EndStructure
hmixer.l
outputVolCtrl.MIXERCONTROL  

Procedure GetControl(hmixer,componentType,ctrlType,*mxc.MIXERCONTROL)

 ;This function attempts To obtain a mixer control. Returns True If successful.
 mxlc.MIXERLINECONTROLSx
 mxl.MIXERLINE
 hmem.l
 rc.l
 
 mxl\cbStruct = SizeOf(mixerline)
 mxl\dwComponentType = componentType
 ;Obtain a line corresponding To the component type
 
 rc = mixerGetLineInfo_(hmixer, mxl, #MIXER_GETLINEINFOF_COMPONENTTYPE)
 If (#MMSYSERR_NOERROR = rc) 
   mxlc\cbStruct = SizeOf(mixerlinecontrolsx)
   mxlc\dwLineID = mxl\dwLineID
   mxlc\dwControl = ctrlType
   mxlc\cControls = 1
   mxlc\cbmxctrl = SizeOf(mixercontrol)     
   ; Allocate a buffer For the control
   ; hmem = GlobalAlloc(&H40, Len(mxc))
   ;hmem = GlobalAlloc(GMEM_FIXED, Len(mxc))
   ;mixercontrol_in_memory.mixercontrol
   ;hmem=@mixercontrol_in_memory
   mxlc\pamxctrl = *mxc
   *mxc\cbStruct = SizeOf(mixercontrol)
   
   ; Get the control
   rc = mixerGetLineControls_(hmixer, mxlc,#MIXER_GETLINECONTROLSF_ONEBYTYPE)
   If (#MMSYSERR_NOERROR = rc) 
     GetControl = -1
     ;' Copy the control into the destination structure
     ;CopyMemory(mxlc\pamxctrl,*mxc,SizeOf(mixercontrol))
   Else
     GetControl = 0
   EndIf
   ProcedureReturn getcontrol
 EndIf
 ProcedureReturn -2
EndProcedure         

rc = mixerOpen_(@hmixer, 0, 0, 0, 0)
If ((#MMSYSERR_NOERROR  rc))
  Debug "Fehler"
  End
EndIf

ok = GetControl(hmixer, #MIXERLINE_COMPONENTTYPE_SRC_WAVEOUT, #MIXERCONTROL_CONTROLTYPE_PEAKMETER, outputVolCtrl)
Debug "getcontorl"+Str(ok)

mxcd.MIXERCONTROLDETAILS
mxcd\cbStruct = SizeOf(MIXERCONTROLDETAILS)
volume_in_mem=0
mxcd\paDetails=@volume_in_mem
mxcd\cbDetails=4
mxcd\cChannels=1

;get the current outputlevel
mxcd\dwControlID = outputVolCtrl\dwControlID
mxcd\item = outputVolCtrl\cMultipleItems
rc = mixerGetControlDetails_(hmixer, @mxcd, #MIXER_GETCONTROLDETAILSF_VALUE)

volume=PeekL(mxcd\paDetails)
Debug "volume:"+Str(volume)
I get allways return, that the volume is 0

PII 333, 256MB, Asus TNT2Ultra 32MB, AWE Gold 64 4MB
BackupUser
PureBasic Guru
PureBasic Guru
Posts: 16777133
Joined: Tue Apr 22, 2003 7:42 pm

Post by BackupUser »

Restored from previous forum. Originally posted by PB.

Hmm, I didn't know the example would be so long... :cry:

It looks like the example is using a MixerControl for Visual Basic, so I don't think
this can be converted to PureBasic. Maybe someone else knows otherwise?
Post Reply