Skip to content

pygame.mixer.Sound play speed doesn't work with frequency setting when playing the bytes array cut from wave module (2597) #1338

Open
@GalacticEmperor1

Description

@GalacticEmperor1

Issue №2597 opened by plr0201 at 2021-05-22 04:51:02

import wave
from pygame import mixer
bgm = wave.open('cf.wav', 'rb')
bgm.setpos(345778)
freq = bgm.getframerate()
fragment = bgm.readframes(500000)
bgm.close()
mixer.init(frequency = freq)
sound = mixer.Sound(buffer= fragment)
sound.play()

Code works good, however, the play speed is significantly lower (~0.6-0.7?) than it needs to be. I wonder why. Look forward to help!


Comments

# # plr0201 commented at 2021-05-26 05:18:22

The reason I used wave instead of mixer to get the bytes array is that wave can precisely operate the samples/frames like in audacity. The len(raw_array) in mixer.Sound doesn't match the frames in audacity.


# # plr0201 commented at 2021-05-26 14:44:52

No, it is slow for most if not all music. for the same wave file, the byte length for wav is longer than pygame.mixer... wonder why? If only wave could play audio...

Metadata

Metadata

Assignees

No one assigned

    Labels

    mixerpygame.mixer

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions