Mercurial > touhou
diff pytouhou/lib/sdl.pyx @ 783:ec1e06402a97
Replace SDL2_mixer with the kira crate
| author | Link Mauve <linkmauve@linkmauve.fr> |
|---|---|
| date | Fri, 21 Nov 2025 10:21:59 +0100 |
| parents | 468dab1dd683 |
| children | f73e8524c045 |
line wrap: on
line diff
--- a/pytouhou/lib/sdl.pyx +++ b/pytouhou/lib/sdl.pyx @@ -62,8 +62,7 @@ class SDL: - def __init__(self, *, video=True, sound=True): - self.sound = sound + def __init__(self, *, video=True): self.video = video def __enter__(self): @@ -77,23 +76,7 @@ keyboard_state = SDL_GetKeyboardState(NULL) - if self.sound: - mix_init(0) - try: - mix_open_audio(44100, MIX_DEFAULT_FORMAT, 2, 4096) - except SDLError as error: - logger.error(u'Impossible to set up audio subsystem: %s', error) - self.sound = False - else: - # TODO: make it dependent on the number of sound files in the - # archives. - mix_allocate_channels(MAX_SOUNDS) - def __exit__(self, *args): - if self.sound: - Mix_CloseAudio() - Mix_Quit() - TTF_Quit() IMG_Quit() SDL_Quit() @@ -278,31 +261,6 @@ image[3+4*i] = alpha[3*i] -cdef class Music: - def __dealloc__(self): - if self.music != NULL: - Mix_FreeMusic(self.music) - - cdef void play(self, int loops) nogil: - Mix_PlayMusic(self.music, loops) - - cdef void set_loop_points(self, double start, double end) nogil: - #Mix_SetLoopPoints(self.music, start, end) - pass - - -cdef class Chunk: - def __dealloc__(self): - if self.chunk != NULL: - Mix_FreeChunk(self.chunk) - - cdef void play(self, int channel, int loops) nogil: - Mix_PlayChannel(channel, self.chunk, loops) - - cdef void set_volume(self, float volume) nogil: - Mix_VolumeChunk(self.chunk, int(volume * 128)) - - cdef class Font: def __init__(self, str filename, int ptsize): path = filename.encode() @@ -335,11 +293,6 @@ raise SDLError() -cdef bint mix_init(int flags) except True: - if Mix_Init(flags) != flags: - raise SDLError() - - cdef bint ttf_init() except True: if TTF_Init() < 0: raise SDLError() @@ -369,44 +322,6 @@ return surface -cdef bint mix_open_audio(int frequency, Uint16 format_, int channels, int chunksize) except True: - if Mix_OpenAudio(frequency, format_, channels, chunksize) < 0: - raise SDLError() - - -cdef bint mix_allocate_channels(int numchans) except True: - if Mix_AllocateChannels(numchans) != numchans: - raise SDLError() - - -cdef int mix_volume(int channel, float volume) nogil: - return Mix_Volume(channel, int(volume * 128)) - - -cdef int mix_volume_music(float volume) nogil: - return Mix_VolumeMusic(int(volume * 128)) - - -cdef Music load_music(str filename): - music = Music() - path = filename.encode() - music.music = Mix_LoadMUS(path) - if music.music == NULL: - raise SDLError() - return music - - -cdef Chunk load_chunk(file_): - cdef SDL_RWops *rwops - chunk = Chunk() - data = file_.read() - rwops = SDL_RWFromConstMem(<char*>data, len(data)) - chunk.chunk = Mix_LoadWAV_RW(rwops, 1) - if chunk.chunk == NULL: - raise SDLError() - return chunk - - cdef Uint32 get_ticks() nogil: return SDL_GetTicks()
