remove scipy

This commit is contained in:
Yonokid
2025-05-16 18:36:53 -04:00
parent f063226711
commit 316b878516
6 changed files with 39 additions and 89 deletions

View File

@@ -41,7 +41,7 @@ jobs:
script-name: PyTaiko.py script-name: PyTaiko.py
mode: app mode: app
output-dir: . output-dir: .
include-module: raylib,moviepy,numpy,scipy,sounddevice include-module: raylib,moviepy,numpy,sounddevice
include-package: imageio_ffmpeg include-package: imageio_ffmpeg
enable-plugins: numpy enable-plugins: numpy

View File

@@ -9,11 +9,13 @@ from numpy import (
abs as np_abs, abs as np_abs,
) )
from numpy import ( from numpy import (
arange,
column_stack, column_stack,
float32, float32,
frombuffer, frombuffer,
int16, int16,
int32, int32,
interp,
mean, mean,
uint8, uint8,
zeros, zeros,
@@ -25,28 +27,42 @@ from numpy import (
os.environ["SD_ENABLE_ASIO"] = "1" os.environ["SD_ENABLE_ASIO"] = "1"
import sounddevice as sd import sounddevice as sd
from pydub import AudioSegment from pydub import AudioSegment
from scipy import signal
from libs.utils import get_config, rounded from libs.utils import get_config, rounded
def resample(data, orig_sr, target_sr): def resample(data, orig_sr, target_sr):
# Return original data if no resampling needed
ratio = target_sr / orig_sr ratio = target_sr / orig_sr
if ratio == 1.0: if ratio == 1.0:
return data return data
if len(data.shape) == 1: # Handle both mono and multi-channel audio
resampled_data = signal.resample_poly(data, target_sr, orig_sr) if len(data.shape) == 1: # Mono audio
else: return _resample_channel(data, orig_sr, target_sr)
else: # Multi-channel audio
num_channels = data.shape[1] num_channels = data.shape[1]
resampled_channels = [] resampled_channels = []
for ch in range(num_channels): for ch in range(num_channels):
channel_data = data[:, ch] channel_data = data[:, ch]
resampled_channel = signal.resample_poly(channel_data, target_sr, orig_sr) resampled_channel = _resample_channel(channel_data, orig_sr, target_sr)
resampled_channels.append(resampled_channel) resampled_channels.append(resampled_channel)
resampled_data = column_stack(resampled_channels)
return column_stack(resampled_channels)
def _resample_channel(channel_data, orig_sr, target_sr):
# Calculate number of samples in resampled audio
orig_length = len(channel_data)
new_length = int(orig_length * target_sr / orig_sr)
# Create time points for original and new sample rates
orig_time = arange(orig_length) / orig_sr
new_time = arange(new_length) / target_sr
# Perform linear interpolation
resampled_data = interp(new_time, orig_time, channel_data)
return resampled_data return resampled_data
def get_np_array(sample_width, raw_data): def get_np_array(sample_width, raw_data):
@@ -643,16 +659,12 @@ class AudioEngine:
def get_master_volume(self) -> float: def get_master_volume(self) -> float:
return self.master_volume return self.master_volume
def load_sound(self, fileName: str) -> str | None: def load_sound(self, fileName: str) -> str:
try:
sound = Sound(fileName, target_sample_rate=self.target_sample_rate) sound = Sound(fileName, target_sample_rate=self.target_sample_rate)
sound_id = f"sound_{len(self.sounds)}" sound_id = f"sound_{len(self.sounds)}"
self.sounds[sound_id] = sound self.sounds[sound_id] = sound
print(f"Loaded sound from {fileName} as {sound_id}") print(f"Loaded sound from {fileName} as {sound_id}")
return sound_id return sound_id
except Exception as e:
print(f"Error loading sound: {e}")
return None
def play_sound(self, sound): def play_sound(self, sound):
if sound in self.sounds: if sound in self.sounds:
@@ -683,16 +695,12 @@ class AudioEngine:
if sound in self.sounds: if sound in self.sounds:
self.sounds[sound].pan = max(0.0, min(1.0, pan)) self.sounds[sound].pan = max(0.0, min(1.0, pan))
def load_music_stream(self, fileName: str) -> str | None: def load_music_stream(self, fileName: str) -> str:
try:
music = Music(file_path=fileName, target_sample_rate=self.target_sample_rate) music = Music(file_path=fileName, target_sample_rate=self.target_sample_rate)
music_id = f"music_{len(self.music_streams)}" music_id = f"music_{len(self.music_streams)}"
self.music_streams[music_id] = music self.music_streams[music_id] = music
print(f"Loaded music stream from {fileName} as {music_id}") print(f"Loaded music stream from {fileName} as {music_id}")
return music_id return music_id
except Exception as e:
print(f"Error loading music stream: {e}")
return None
def is_music_valid(self, music: str) -> bool: def is_music_valid(self, music: str) -> bool:
if music in self.music_streams: if music in self.music_streams:

View File

@@ -6,63 +6,6 @@ import pyray as ray
from libs.animation import Animation from libs.animation import Animation
from libs.utils import load_all_textures_from_zip from libs.utils import load_all_textures_from_zip
'''
class Background:
class Chibi:
def __init__(self):
self.texture_index = Animation.create_texture_change(249, textures=[(0, 150, 4), (150, 183, 0), (183, 183 + 33, 1), (183 + 33, 183 + 66, 2)])
self.chibi_color = 5
self.move = Animation.create_move(1000, total_distance=1280)
def update(self):
self.chibi_color = random.choice([5, 10, 15, 20])
self.texture_index.update(get_current_ms())
self.move.update(get_current_ms())
if self.texture_index.is_finished:
self.texture_index = Animation.create_texture_change(100, textures=[(0, 150, 4), (150, 183, 0), (183, 183 + 33, 1), (183 + 33, 183 + 66, 2)])
def draw(self, textures):
ray.draw_texture(textures[self.texture_index.attribute + self.chibi_color], 200 + int(self.move.attribute), 0, ray.WHITE)
def __init__(self, width: int, height: int):
self.screen_width = width
self.screen_height = height
self.bg_fever_name = 'bg_fever_a_' + str(random.randint(1, 4)).zfill(2)
self.bg_normal_name = 'bg_nomal_a_' + str(random.randint(1, 5)).zfill(2)
self.chibi_name = 'chibi_a_' + str(random.randint(1, 14)).zfill(2)
self.dance_name = 'dance_a_' + str(random.randint(1, 22)).zfill(2)
self.donbg_name = 'donbg_a_' + str(random.randint(1, 6)).zfill(2)
self.fever_name = 'fever_a_' + str(random.randint(1, 4)).zfill(2)
self.renda_name = 'renda_a_' + str(random.randint(1, 3)).zfill(2)
self.textures = dict()
self.textures.update(load_all_textures_from_zip(Path(f'Graphics/lumendata/enso_original/{self.bg_fever_name}.zip')))
self.textures.update(load_all_textures_from_zip(Path(f'Graphics/lumendata/enso_original/{self.bg_normal_name}.zip')))
self.textures.update(load_all_textures_from_zip(Path(f'Graphics/lumendata/enso_original/{self.chibi_name}.zip')))
self.textures.update(load_all_textures_from_zip(Path(f'Graphics/lumendata/enso_original/{self.dance_name}.zip')))
self.textures.update(load_all_textures_from_zip(Path(f'Graphics/lumendata/enso_original/{self.donbg_name}_1p.zip')))
self.textures.update(load_all_textures_from_zip(Path(f'Graphics/lumendata/enso_original/{self.donbg_name}_2p.zip')))
self.textures.update(load_all_textures_from_zip(Path(f'Graphics/lumendata/enso_original/{self.fever_name}.zip')))
self.textures.update(load_all_textures_from_zip(Path(f'Graphics/lumendata/enso_original/{self.renda_name}.zip')))
self.donbg_move = Animation.create_move(2500, start_position=0, total_distance=-self.textures[self.donbg_name + '_1p'][0].width)
self.chibis = []
def update(self):
self.donbg_move.update(get_current_ms())
if self.donbg_move.is_finished:
self.donbg_move = Animation.create_move(2500, start_position=0, total_distance=-self.textures[self.donbg_name + '_1p'][0].width)
for chibi in self.chibis:
chibi.update()
if chibi.move.is_finished:
self.chibis.remove(chibi)
def draw(self):
ray.draw_texture(self.textures[self.bg_normal_name][0], 0, 360, ray.WHITE)
ray.draw_texture(self.textures[self.bg_normal_name][1], 0, 360, ray.fade(ray.WHITE, 0.25))
# for chibi in self.chibis:
# chibi.draw(self.textures[self.chibi_name])
'''
class Background: class Background:
def __init__(self, screen_width: int, screen_height: int): def __init__(self, screen_width: int, screen_height: int):

View File

@@ -1,8 +1,8 @@
import hashlib import hashlib
import math import math
import os
from collections import deque from collections import deque
from dataclasses import dataclass, field, fields from dataclasses import dataclass, field, fields
import os
from pathlib import Path from pathlib import Path
from libs.utils import get_pixels_per_frame, strip_comments from libs.utils import get_pixels_per_frame, strip_comments

View File

@@ -1,5 +1,5 @@
import moviepy
import pyray as ray import pyray as ray
from moviepy import VideoFileClip
from libs.audio import audio from libs.audio import audio
from libs.utils import get_current_ms from libs.utils import get_current_ms
@@ -12,7 +12,7 @@ class VideoPlayer:
""" """
self.is_finished_list = [False, False] self.is_finished_list = [False, False]
self.video_path = path self.video_path = path
self.video = moviepy.VideoFileClip(path) self.video = VideoFileClip(path)
audio_path = path[:-4] + '.ogg' audio_path = path[:-4] + '.ogg'
self.audio = audio.load_music_stream(audio_path) self.audio = audio.load_music_stream(audio_path)

View File

@@ -2,6 +2,5 @@ numpy==2.2.5
pydub==0.25.1 pydub==0.25.1
raylib==5.5.0.2 raylib==5.5.0.2
raylib_dynamic==5.5.0.2 raylib_dynamic==5.5.0.2
scipy==1.15.2
sounddevice==0.5.1 sounddevice==0.5.1
moviepy==2.1.2 moviepy==2.1.2