mirror of
https://github.com/KrisKennaway/ii-sound.git
synced 2024-06-25 22:29:29 +00:00
- we simulate the speaker at full 1-cycle resolution, and evaluate all possible opcodes that can be scheduled for the given position in the TCP stream - this lets us tick the speaker at any cycle interval >=9 (except 10 cycles)
28 lines
567 B
Python
28 lines
567 B
Python
import sys
|
|
import librosa
|
|
import numpy
|
|
import soundfile as sf
|
|
|
|
|
|
def preprocess(
|
|
filename: str, target_sample_rate: int,
|
|
normalize: float = 0.5) -> numpy.ndarray:
|
|
data, _ = librosa.load(filename, sr=target_sample_rate, mono=True)
|
|
|
|
max_value = numpy.percentile(data, 90)
|
|
data /= max_value
|
|
data *= normalize
|
|
|
|
return data
|
|
|
|
|
|
def main(argv):
|
|
serve_file = argv[1]
|
|
out = argv[2]
|
|
sample_rate = int(1024. * 1000)
|
|
|
|
sf.write(out, preprocess(serve_file, sample_rate), sample_rate)
|
|
|
|
|
|
if __name__ == "__main__":
|
|
main(sys.argv) |