-
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #2 from vkottler/dev/streaming
Dev/streaming
- Loading branch information
Showing
20 changed files
with
423 additions
and
26 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,9 @@ | ||
[MAIN] | ||
ignored-modules=pyaudio | ||
|
||
[DESIGN] | ||
max-args=6 | ||
max-args=7 | ||
max-attributes=8 | ||
|
||
[MESSAGES CONTROL] | ||
disable=too-few-public-methods |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Submodule config
updated
2 files
+100 −0 | python/mklocal/conntextual/__init__.py | |
+4 −0 | python/mklocal/python.py |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
--- | ||
major: 0 | ||
minor: 2 | ||
patch: 0 | ||
patch: 1 | ||
entry: quasimoto |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
portaudio | ||
pyaudio |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
#!/bin/bash | ||
|
||
set -e | ||
|
||
pushd "$CWD" >/dev/null || exit | ||
|
||
# Get PortAudio source. | ||
if [ ! -d portaudio ]; then | ||
git clone https://github.com/PortAudio/portaudio | ||
sudo apt-get install libasound-dev | ||
fi | ||
|
||
# Get PyAudio source. | ||
if [ ! -d pyaudio ]; then | ||
git clone https://people.csail.mit.edu/hubert/git/pyaudio.git | ||
fi | ||
|
||
VENV="venv$PYTHON_VERSION" | ||
PIP="$VENV/bin/pip" | ||
PYTHON="$VENV/bin/python" | ||
|
||
setup_venv() { | ||
$PIP install -e "$REPO" | ||
$PIP install -e pyaudio | ||
} | ||
|
||
if [ ! -d "$VENV" ]; then | ||
"python$PYTHON_VERSION" -m venv "$VENV" | ||
test -f "$PYTHON" | ||
|
||
"$PIP" install -U pip | ||
setup_venv | ||
fi | ||
|
||
on_exit() { | ||
popd >/dev/null || exit | ||
} | ||
|
||
trap on_exit EXIT | ||
|
||
SAMPLE_WAV="$REPO/tests/data/valid/vonbass.wav" | ||
test -f "$SAMPLE_WAV" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
#!/bin/bash | ||
|
||
REPO=$(git rev-parse --show-toplevel) | ||
CWD=$REPO/scripts | ||
source "$CWD/common.sh" | ||
|
||
pushd portaudio >/dev/null || exit | ||
|
||
./configure | ||
make clean | ||
make -j | ||
sudo make install | ||
|
||
popd >/dev/null || exit |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
""" | ||
A module for streaming raw data to pyaudio. | ||
""" | ||
|
||
# built-in | ||
from contextlib import contextmanager | ||
from io import BytesIO | ||
import sys | ||
import time | ||
from typing import Iterator | ||
|
||
# third-party | ||
import pyaudio | ||
|
||
# internal | ||
from quasimoto.sampler import Sampler | ||
from quasimoto.wave import WaveWriter | ||
|
||
|
||
@contextmanager | ||
def get_pyaudio() -> Iterator[pyaudio.PyAudio]: | ||
"""Get a PyAudio instance.""" | ||
|
||
audio = pyaudio.PyAudio() | ||
try: | ||
yield audio | ||
finally: | ||
audio.terminate() | ||
|
||
|
||
def main(argv: list[str]) -> int: | ||
"""The program's main entry.""" | ||
|
||
left = Sampler() | ||
right = left.copy(harmonic=-1) | ||
|
||
def callback(in_data, frame_count, time_info, status) -> bytes: | ||
"""Called when stream needs more data?""" | ||
|
||
# Need to figure out what these are. | ||
del in_data | ||
del time_info | ||
del status | ||
|
||
with BytesIO() as stream: | ||
for _ in range(frame_count): | ||
WaveWriter.to_stream(stream, next(left)) | ||
WaveWriter.to_stream(stream, next(right)) | ||
return (stream.getvalue(), pyaudio.paContinue) | ||
|
||
with get_pyaudio() as audio: | ||
stream = audio.open( | ||
format=audio.get_format_from_width(left.num_bits // 8), | ||
channels=2, | ||
rate=left.sample_rate, | ||
output=True, | ||
stream_callback=callback, | ||
) | ||
|
||
keep_going = True | ||
|
||
while keep_going and stream.is_active(): | ||
try: | ||
time.sleep(0.1) | ||
except KeyboardInterrupt: | ||
stream.close() | ||
keep_going = False | ||
|
||
return 0 | ||
|
||
|
||
if __name__ == "__main__": | ||
sys.exit(main(sys.argv)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
#!/bin/bash | ||
|
||
REPO=$(git rev-parse --show-toplevel) | ||
CWD=$REPO/scripts | ||
source "$CWD/common.sh" | ||
|
||
# Can use this to verify sound output works. | ||
# $PYTHON pyaudio/examples/play_wave.py "$SAMPLE_WAV" | ||
|
||
set -x | ||
$PYTHON stream.py | ||
echo "Exited $?." | ||
set +x |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
--- | ||
app: | ||
- tasks.dev.main | ||
- runtimepy.net.apps.wait_for_stop | ||
|
||
factories: | ||
- {name: tasks.dev.Stereo} | ||
|
||
tasks: | ||
- {name: stereo, factory: stereo, period_s: 0.02} |
Oops, something went wrong.