From 60267b5aa7f7350895ebbdbeed6d06d48bdbad71 Mon Sep 17 00:00:00 2001 From: Anthony Wang Date: Sun, 12 Mar 2023 00:18:58 -0500 Subject: 32-bit audio because why not --- README.md | 2 +- example.ogg | Bin 422704 -> 433074 bytes music.py | 6 +++--- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index f2aba34..7a50d67 100644 --- a/README.md +++ b/README.md @@ -4,4 +4,4 @@ Lambeat is a new way to make music using functional programming. It's heavily in ## Get started First, install [Sox](https://sox.sourceforge.net/) and clone this repo. Write some music in `music.scm`. Enjoy your music with `guile --fresh-auto-compile lambeat.scm | play -r 8000 -t s16 -`! -For the Python version, use `pypy3 music.py | play -r 44100 -t s16 -` to listen and `pypy3 music.py | sox -r 44100 -t s16 - example.ogg` to save to a file. +For the Python version, use `pypy3 music.py | play -r 44100 -t s32 -` to listen and `pypy3 music.py | sox -r 44100 -t s32 - example.ogg` to save to a file. diff --git a/example.ogg b/example.ogg index b89a0d8..fcf9198 100644 Binary files a/example.ogg and b/example.ogg differ diff --git a/music.py b/music.py index 85c7918..4d9c7cc 100644 --- a/music.py +++ b/music.py @@ -314,7 +314,7 @@ def at(t): """ Returns the total intensity of music sampled at time t """ - i = bisect.bisect(music, (t, 10**9)) + i = bisect.bisect(music, (t, 2**31)) # This is actually pretty efficient ngl # Because people usually don't have that many overlapping notes ret = 0 @@ -322,9 +322,9 @@ def at(t): m = music[j] # if m[0] + m[1] > t: ret += m[4] * tone(freq(m[2], m[3]), t - m[0]) - return int(2**12 * ret) + return int(2**28 * ret) # Print out music encoded in s16 to standard output for i in range(0 * bitrate, 84 * bitrate): - sys.stdout.buffer.write(struct.pack("h", at(i / bitrate))) + sys.stdout.buffer.write(struct.pack("i", at(i / bitrate))) -- cgit v1.2.3-70-g09d2