1

I was trying to make music by purely using python's winsound module. However, almost every single pitch (frequency) pulsates. A few that doesn't are like A 440 or anything higher than around 2000 hertz. Is this just how winsound works or is this just my pc because the same problem occurred when I tried this on my friend's pc. It even happened when I played it through a guitar amp.

And here is a piece of my coding, ... Note: I am trying to make a tuner for my piano.

Just play the notes in order.

import winsound

while True:
    octv = input("Enter 4: ")
    octv.strip()
    octv = int(octv)

    press = input("Press a note: ")
    press.lower()
    press.strip()

    if octv == 4:
        if press == "c":
            winsound.Beep(262, 5000)
        elif press == "d":
            winsound.Beep(294, 5000)
        elif press == "e":
            winsound.Beep(330, 5000)
        elif press == "f":
            winsound.Beep(349, 5000)
        elif press == "g":
            winsound.Beep(392, 5000)
        elif press == "a":
            winsound.Beep(440, 5000)
        elif press == "b":
            winsound.Beep(494, 5000)
Rational
  • 19
  • 2
  • 5
    Wow. Strange behavior for sure. Can you post a small sample program that demonstrates this? I bet it would help a lot if others could try to reproduce what you're hearing. – CryptoFool Aug 22 '20 at 21:52
  • The [**`winsound.beep`**](https://docs.python.org/3/library/winsound.html) function delegates to the Windows API function: [**`Beep`**](https://learn.microsoft.com/en-us/windows/win32/api/utilapiset/nf-utilapiset-beep) – Peter Wood Aug 22 '20 at 22:12
  • You can get exactly the same effect calling: `from ctypes import windll; windll.Kernel32.Beep(1000, 5000)`. Does that pulse (or beat)? If so you need to take it up as a question about windows, not [tag:python]. – Peter Wood Aug 22 '20 at 22:19
  • WinAPI `Beep` depends on the system audio device that's used to generate the tone. The problem here, whatever it turns out to be, is not a programming question. Maybe there's a bug in the device driver, which could be fixed maybe by updating to a newer version. – Eryk Sun Aug 23 '20 at 04:12

0 Answers0