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

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

View File

@@ -6,63 +6,6 @@ import pyray as ray
from libs.animation import Animation
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:
def __init__(self, screen_width: int, screen_height: int):

View File

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

View File

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