Skip to content

directsound and xaudio2 audio drivers on Windows respond to volume differently #321

@SirGnip

Description

@SirGnip

It sounds like the directsound and xaudio2 audio drivers treat the .volume member on the Player differently.

Run the script below with xaudio2 as the driver and press the keys in order (ex: Q, W, E, R, T, Y). You should hear beeps that get gradually quieter. The "Y" key is silent.

Then, comment out the xaudio2 line and uncomment the directsound driver. Press the keys again in order. You will hear beeps that are pretty much at full loudness. Except, when you press "Y", you will hear a quiet beep.

I'd expect the volume "ramp" to be identical, regardless of what audio driver was chosen.

My environment:

  • Python 3.8.6
  • Pyglet: 1.5.11
  • OS: WIndows 10 Home (1909)
import pyglet
pyglet.options["audio"] = ("xaudio2",)
# pyglet.options["audio"] = ("directsound",)

class VolumeTest(pyglet.window.Window):
    def __init__(self):
        super(VolumeTest, self).__init__()
        self.sound = pyglet.media.StaticSource(pyglet.media.synthesis.Sine(0.3, frequency=440))
        self.player = None

    def on_key_press(self, symbol, modifiers):
        if symbol == pyglet.window.key.Q:
            self.player = self.sound.play()
            self.player.volume = 1.0
        if symbol == pyglet.window.key.W:
            self.player = self.sound.play()
            self.player.volume = 0.75
        if symbol == pyglet.window.key.E:
            self.player = self.sound.play()
            self.player.volume = 0.5
        if symbol == pyglet.window.key.R:
            self.player = self.sound.play()
            self.player.volume = 0.25
        if symbol == pyglet.window.key.T:
            self.player = self.sound.play()
            self.player.volume = 0.1
        if symbol == pyglet.window.key.Y:
            self.player = self.sound.play()
            self.player.volume = 0.0001

if __name__ == '__main__':
    print(pyglet.media.get_audio_driver())
    window = VolumeTest()
    pyglet.app.run()

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions