99import random
1010from decimal import *
1111import math
12+ import threading
1213import sys
1314import time
1415import os
15- import numpy as np
1616#import svg
1717import datetime
1818import pickle
1919import json
2020import csv
2121import asyncio
22- import pydub
23- import audioop
24- from pydub import AudioSegment
2522import io
2623from io import BytesIO
27- import librosa
28- import soundfile as sf
29- from pydub .playback import play
24+ import numpy as np
3025import sounddevice as sd
26+ import librosa
3127#pynanosvg
32-
33- GameFPS = 60
34-
28+ GameFPS = 24
3529def resource_path (relative_path ):
3630 """ Get absolute path to resource, works for dev and for PyInstaller """
3731 try :
@@ -528,6 +522,7 @@ def resetupgrades():
528522delta_time = 0.000001
529523game_time = - 0.000001
530524GameFPS = 1 / delta_time
525+ musicplays = 0
531526bulkbuy = 1
532527CamPos = [0 , 0 ]
533528CamPos2 = [0 , 0 ]
@@ -545,20 +540,20 @@ def constrain(val, min_val, max_val):
545540musicfilepath = ""
546541musicintrofilepath = ""
547542pymusictype = ""
548-
549543def pitch_shift (sound , semitones ):
550544 new_sample_rate = int (sound .frame_rate * (2.0 ** (semitones / 12.0 )))
551545 shifted = sound ._spawn (sound .raw_data , overrides = {'frame_rate' : new_sample_rate })
552546 return shifted .set_frame_rate (sound .frame_rate )
553547
554548def PlayMusic (musNum ):
555549 pygame .mixer .music .stop ()
556- global pygamemixermusic , musicfilepath , musicintrofilepath
550+ global pygamemixermusic , musicfilepath , musicintrofilepath , sr1 , sr2 , y1 , y2
557551 pygamemixermusic = 1
558552 if musNum == 1 :
559553 pygamemixermusic = 0.25
560554 pymusictype = "wav"
561555 musicfilepath = "./assets/audio/Debug Menu Unused Paper Mario The Thousand Year Door.wav"
556+ #musicfilepath = "./assets/audio/Debug Menu Unused Paper Mario The Thousand Year Door.mp3"
562557 musicintrofilepath = "./assets/audio/nosound.wav"
563558 elif musNum == 2 :
564559 pygamemixermusic = 1
@@ -569,6 +564,7 @@ def PlayMusic(musNum):
569564 pygamemixermusic = 0.7
570565 pymusictype = "wav"
571566 musicfilepath = "./assets/audio/Kevin MacLeod - Hep Cats.wav"
567+ #musicfilepath = "./assets/audio/Kevin MacLeod - Hep Cats.mp3"
572568 musicintrofilepath = "./assets/audio/nosound.wav"
573569 elif musNum == 4 :
574570 pygamemixermusic = 1
@@ -579,26 +575,45 @@ def PlayMusic(musNum):
579575 pygamemixermusic = .9
580576 pymusictype = "wav"
581577 musicfilepath = "./assets/audio/(radzlan - Miami Hotline Vol.3 (feat. Demonicity)) 673473_-Miami-Hotline--Vol3.wav"
578+ #musicfilepath = "./assets/audio/(radzlan - Miami Hotline Vol.3 (feat. Demonicity)) 673473_-Miami-Hotline--Vol3.mp3"
582579 musicintrofilepath = "./assets/audio/nosound.wav"
583580 elif musNum == 6 :
584581 pygamemixermusic = .9
585582 pymusictype = "wav"
586- musicfilepath = "./assets/audio/INOSSI - Got you-loop 44100 .wav"
587- musicintrofilepath = "./assets/audio/INOSSI - Got you-start 44100 .wav"
583+ musicfilepath = "./assets/audio/INOSSI - Got you-loop.wav"
584+ musicintrofilepath = "./assets/audio/INOSSI - Got you-start.wav"
588585 # Load audio file
586+ y1 , sr1 = librosa .load (musicintrofilepath , sr = None )
587+ y2 , sr2 = librosa .load (musicfilepath , sr = None )
589588 pygame .mixer .music .load (musicintrofilepath )
590- music1 = AudioSegment .from_file (musicintrofilepath )
591- music2 = AudioSegment .from_file (musicfilepath )
589+ pygame .mixer .music .set_volume (pygamemixermusic )
590+ #pygame.mixer.music.play()
591+
592+ speed_factor = [1.2 ]
593+ stop_flag = [False ]
594+ def play_audio ():
595+ index = 0
596+ while not stop_flag [0 ]:
597+ # Resample audio to new rate
598+ new_sr = int (sr1 * speed_factor [0 ])
599+ # Resample only a portion of the original audio to avoid long wait
600+ chunk_len = sr1 // 2 # Half-second chunks
601+ chunk = y1 [index :index + chunk_len ]
602+ if len (chunk ) == 0 :
603+ break
604+
605+ resampled = librosa .resample (chunk , orig_sr = sr1 , target_sr = new_sr )
606+
607+ # Play resampled audio at the new sample rate
608+ sd .play (resampled , new_sr )
609+ sd .wait ()
610+
611+ # Advance index based on original audio (not resampled)
612+ index += chunk_len
592613
593- #shifted_sound1 = pitch_shift(music1, 3) # 4 semitones up
594- #shifted_sound2 = pitch_shift(music2, 3) # 4 semitones up
595- #play(shifted_sound1)
596- pygame .mixer .music .load (musicintrofilepath )
597- pygame .mixer .music .set_volume (Decimal (pygamemixermusic ))
598- pygame .mixer .music .set_volume (min (1.0 , pygame .mixer .music .get_volume () * 1.1 ))
599- pygame .mixer .music .play ()
600614PlayMusic (random .randint (1 ,6 ))
601- pygame .mixer .music .set_volume (Decimal (pygamemixermusic ) * (Settings [1 ]["value" ] / 100 ))
615+ play_audio ()
616+ pygame .mixer .music .set_volume (pygamemixermusic * float (Settings [1 ]["value" ] / 100 ))
602617click_sound = pygame .mixer .Sound (resource_path ("./assets/audio/Click mouse - Fugitive Simulator - The-Nick-of-Time.wav" ))
603618hover_sound = pygame .mixer .Sound (resource_path ("./assets/audio/251389__deadsillyrabbit__button_hover-wav.wav" ))
604619upgrade_sound = pygame .mixer .Sound (resource_path ("./assets/audio/Upgrade SOund 0001.wav" ))
@@ -907,11 +922,12 @@ def draw_text(text, font, color, x, y, align, alpha):
907922 draw_text (f"Total Clicks Per Click: { abbreviate ((click_value * click_value_multi + cps_to_cpc * auto_click_value * auto_click_rate )* gemboost , "s" , 3 , 100000 , False )} " , font , WHITE , 10 * WindowScale2 + CamPos [0 ]* WindowXscale , 280 * WindowScale2 + CamPos [1 ]* WindowYscale , "left" , 255 )
908923
909924 def prestige ():
910- global score , gems
925+ global score , gems , musicplays
911926 score = 0
912927 resetupgrades ()
913928 PlayMusic (random .randint (1 ,6 ))
914- pygame .mixer .music .set_volume (Decimal (pygamemixermusic ) * (Settings [1 ]["value" ] / 100 ))
929+ musicplays = 0
930+ pygame .mixer .music .set_volume (pygamemixermusic * float (Settings [1 ]["value" ] / 100 ))
915931 gems += gemstoget
916932
917933 # Draw upgrade buttons
@@ -978,7 +994,7 @@ def distance_to(ax, ay, bx, by):
978994 screen .blit (realarrowupimg1 , (1100 * WindowXscale + CamPos [0 ]* WindowXscale , (34 * WindowYscale ) + mos_y / 40 + CamPos [1 ]* WindowYscale ))
979995
980996 if not isinstance (Settings [1 ]["value" ], str ):
981- pygame .mixer .music .set_volume (Decimal ( pygamemixermusic ) * ( Decimal ( Settings [1 ]["value" ]) / 100 ))
997+ pygame .mixer .music .set_volume (pygamemixermusic * float ( Settings [1 ]["value" ] / 100 ))
982998 if not isinstance (Settings [0 ]["value" ], str ):
983999 upgrade_sound .set_volume (Decimal (Settings [0 ]["value" ]/ 100 ))
9841000 hover_sound .set_volume (Decimal (Settings [0 ]["value" ]/ 100 ))
@@ -998,9 +1014,7 @@ def distance_to(ax, ay, bx, by):
9981014 pygame .display .flip ()
9991015 #clock.tick(24)
10001016 keys = pygame .key .get_pressed ()
1001- if not pygame .mixer .music .get_busy ():
1002- pygame .mixer .music .load (musicfilepath )
1003- pygame .mixer .music .play (- 1 )
1017+ musicplays += 1
10041018 if keys [pygame .K_a ]:
10051019 CamPos = [1280 , 0 ]
10061020 if keys [pygame .K_s ]:
@@ -1020,4 +1034,4 @@ def distance_to(ax, ay, bx, by):
10201034 if keys [pygame .K_c ]:
10211035 CamPos = [- 1280 , - 720 ]
10221036# Quit Pygame
1023- pygame .quit ()
1037+ pygame .quit ()
0 commit comments