Prevent pop-ups at the end of sound in Pygame.mixer

This has been resolved - see solution below.

When using pygame.mixer every time the sound ends (regardless of whether it is queued on the channel, not queued, but still played on the channel or played directly through Sound.play()), an audible "noise" is heard. Is there any way to prevent this?

Code example:

import math
import pygame
import array

pygame.mixer.init()

rawArr=[]
for i in range(41000):
    freq1=int(math.sin(i/220.0*math.pi*2)*32767.0)
    if i>40900: freq1=int(freq1*(41000-i)/100.0) #Solution - see Final Solution
    rawArr.append(freq1)

sndArr=array.array('h',rawArr)

snd=pygame.mixer.Sound(sndArr)

snd.play()

Update: Sound attenuation does not cause a noticeable difference. Tested with mixer.fadeout(fadeTime), Sound.fadeout(fadeTime)and Sound.play(0,maxTime,fadeTime)for fadeTime=1,10,100,200,1000and maxTime=0,1,10,100,1000.

Update 2: Neither mixer.stop()will mixer.pause()not remove the sound.

3: , 0,1 . , "", , , , , "". , :

while snd.get_volume():
     snd.set_volume(snd.get_volume()-0.005)
     pygame.time.wait(5)

: msw "popping", . if i>40900: freq1=int(freq1*(41000-i)/100.0) - 0,0024 , , "popping". .

+4
1

" ".

, 0, , 0. , , ( ) . "" , .

, . , . , 2,5- , -.

+3
source

Source: https://habr.com/ru/post/1606226/


All Articles