Encode audio file into cycle timings and emit tick opcodes. Amazingly,

even the naive opcode implementation works!

The main issue is that when we ACK, the speaker cone is allowed to tick
fully.  Maybe optimizing the ACK codepath to be fast enough will help
with this?
This commit is contained in:
kris 2019-02-27 14:49:21 +00:00
parent 9d4edc6c4a
commit 2b3343f374

34
audio.py Normal file
View File

@ -0,0 +1,34 @@
import numpy as np
import librosa
import soundfile as sf
import opcodes
import video
class Audio:
def encode_audio(self, audio):
for a in audio:
yield opcodes.Tick(a)
yield opcodes.Tick(50-a)
def main():
filename = librosa.util.example_audio_file()
data, samplerate = sf.read(filename, dtype='float32')
data = data.T
a = librosa.resample(data, samplerate, 20000).flatten()
a = librosa.util.normalize(a)
a = (a * 10 + 25).astype(np.int)
s = video.Video(frame_rate=None)
au = Audio()
with open("out.bin", "wb") as out:
out.write(bytes(s.emit_stream(au.encode_audio(a))))
out.write(bytes(s.done()))
if __name__ == "__main__":
main()