VB6 - Stereosound ohne Directx abspielen

Hallo

ich habe folgendes Problem:
In meinem Visual Basic 6 Programm möchte ich gerne diverse Sounds abspielen und diese auch noch an verschiedenen Positionen im Stereofeld, also den einen vielleicht im rechten und einen anderen dann im linken Lautsprecher und auch kombinationen aus beiden Möglichkeiten. Ich habe zwar eine Funktion, mit der ich sound direkt über die Windows API abspielen kann, jedoch habe ich dort keinen Einfluß auf die Stereoposition. Auf Direktx möchte ich bewust verzichten. Kann man über die Bordmittel von VB6 erreichebn, was mir vorschwebt?
Hier mal meine Soundfunktion, wär schön, wenn es das was ich suche gibt, dass dann jemand meine Funktion mit den nötigen Erweiterungen versehen würde und wieder hier reinpostet.

Private Declare Function PlaySound Lib „winmm.dll“ Alias „PlaySoundA“ _
(ByVal lpszName As String, ByVal hModule As Long, _
ByVal dwFlags As Long) As Long

Abgespielt wird dann folgendermaßen:
dim play as variant

play = PlaySound(App.Path & „\sounds\tschoe.wav“, 0, 0)

Gruß

Tschapajew

Hallo,

handelt es sich ausschliesslich um WAV Files oder auch um andere Typen?

MfG

Nur Waves, erstmal.

Hallo,

wenn du dir mal die API’s

Declare Function waveOutSetVolume Lib „MMSYSTEM.DLL“
(ByVal wDeviceID as Integer, ByVal dwVolume as Long) as Integer
Declare Function waveOutGetVolume Lib „MMSYSTEM.DLL“
(ByVal wDeviceID as Integer, dwVolume as Long) as Integer

anschaust, wird dir klar das Dir waveOutGetVolume die eingestellte Lautstaerke wiedergibt. Die API waveOutSetVolume setzt dir dagegen die Lautstaerke. Bei dieser API wird für dwVolume ein Wert vom Typ Long erwartet.

Ein Auszug aus der MSDN besagt

For the waveOutSetVloume function, this parameter specifies
the new volume setting. For the waveOutGetVolume
function, it specifies a far pointer to a location that will be
filled with the current volume setting.

The low-order word contains the left-channel volume setting,
and the high-order word contains the right-channel volume
setting.
A value of &HFFFF represents full volume, and a value of
&H0000 represents no volume.

If a device does not support both left and right volume
control, the low-order word of dwVolume specifies the volume
level, and the high-order word is ignored.

Wir sehen das sich nun das Left Volume im Low Word befindet und der rechte Volume im High Word.

Wie koennen wir uns das zu nutze machen?

Ein Long belegt 4 Bytes! Ein Integer belegt 2 Bytes.
Mit diesem wissen koennen wir doch einfach die API umstricken :wink:

Declarieren wir sie also einfach mal anders!

Declare Function waveOutSetVolume Lib "MMSYSTEM.DLL"
 (ByVal wDeviceID as Integer, ByVal dwVolumeRight as Integer
 ByVal dwVolumeLeft as Integer) as Integer

Du wirst sehen, die API funktioniert genauso :wink:

Anbei aber noch ein kleiner Hinweis den ich gerade gelesen habe

Hinweis: nicht alle Geräte unterstützen Datenträger-Änderungen oder Datenträger-Steuerung auf beiden linken und rechten Kanälen. Die meist Geräte unterstützen die vollständigen 16 Bits des volume-level Steuerelements nicht und werden die höherwertigen Bit nicht verwenden. 

So nun aber mal fix ein paar kleine Demos zum Aufrufen

 Declare Function sndPlaySound Lib "MMSYSTEM.DLL"(ByVal lpszSoundName As String, ByVal wFlags As Integer) As Integer
 Declare Function waveoutSetVolume Lib "mmsystem.dll"(ByVal wDeviceID As Integer, ByVal dwVolumeRight As Integer,
 ByVal dwVolumeLeft As Integer) As Integer
 Declare Function waveOutGetVolume Lib "MMSYSTEM.DLL"(ByVal wDeviceID As Integer, lpdwvolume As Long) As Integer

 Const SND\_ASYNC = &H1
 Const SND\_NODEFAULT = &H2

 Dim VolLeft As Long
 Dim VolRight As Long

Sub Form\_Load()
Dim X as Integer
Dim BothVolume as Long
X = waveOutGetVolume(0, BothVolume)
VolLeft=BothVolume And &HFFFF&
VolRight=((BothVolume And &HFFFF0000) / &H10000)And &HFFFF&
End Sub

Sub Play ()
 Dim x As Integer
 Dim wFlags As Integer
 Dim SoundName As String
 SoundName = "Dein WAV File"
 wFlags = SND\_ASYNC Or SND\_NODEFAULT
 x = sndPlaySound(SoundName$, wFlags%)
End Sub

Sub IncreaseLeftVolume()
 Dim x As Integer
 VolLeft = VolLeft + &H1000&
 If VolLeft \> &HFFFF& Then VolLeft = &HFFFF&
 x = waveoutSetVolume(0, CInt("&H" + Hex$(VolRight)),
 CInt("&H" + Hex$(VolLeft)))
End Sub

Sub IncreaseRightVolume()
 Dim x As Integer
 VolRight = VolRight + &H1000&
 If VolRight \> &HFFFF& Then VolRight = &HFFFF&
 x = waveoutSetVolume(0, CInt("&H" + Hex$(VolRight)),
 CInt("&H" + Hex$(VolLeft)))
End Sub

Sub DecreaseLeftVolume()
 Dim x As Integer
 VolLeft = VolLeft - &H1000&
 If VolLeft 

Musst nen bissl umbasteln, dann sollte es aber deinen Anspruechen genug sein, oder?

MfG Alex
1 Like

Danke, das hilft mir auf jeden all sehr weiter.