-
Notifications
You must be signed in to change notification settings - Fork 7
Started making a modularized version with easily swapable backends, e… #4
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
…xtendable MF generators etc.
i += 1 | ||
yield mftone | ||
# no pause if last | ||
if i < seq_len: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should be <=
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No, it shouldn't, but tests will check this logic to make sure the correct number of frames are generated
bluebox/wave.py
Outdated
freq: float, | ||
length: float, | ||
amplitude: float = 1.0, | ||
phase: float = 0.0) -> t.MutableSequence[float]: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Instead of returning the entire tone, make this a generator too, then it can be compatible with streams or backends that require bytes
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
E.g. without any effort you can wrap it and return an int, byte or whatever version of each point...it should be pretty efficient (at least memory wise)
bluebox/wave.py
Outdated
# silence / pauses | ||
if freq == 0.0 or amplitude == 0.0: | ||
for i in range(math.ceil(length * self._sample_rate)): | ||
wave.append(0.0) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If this is a generator, (in fact even if it's not) this would be better as calculating the sum of both points (each * amplitude/2, assuming an equal mix)
|
||
This file can be used to interactively generate tone sequences. | ||
""" | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Interface should be compatible with previous version but maybe require an -i/--interactive
flag, otherwise e.g. read stdin/pipe/file for the sequence
Can make both space and P pause.
Allow setting device on cli, as well as SR, number of channels etc
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also, make backends / MF registry? so if someone subclasses the base classes they can also select it via the cli?
Default classes backends should also be listed in cli alongside registered ones, maybe description can come from an abstract "description" method
E.g.
#my_cli.py
from bluebox import cli, freq
from my_mf import MyMF
if __name__ == "__main__":
freq.register_mf(MyMF)
cli.bluebox()
bluebox/backends/backend_pyaudio.py
Outdated
"""PyAudioBackendNonBlocking class for the PyAudio backend.""" | ||
|
||
def _get_stream(self, callback: t.Callable) -> pyaudio.Stream: | ||
"""Get the PyAudio stream.""" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
add arg docs, also keep params descriptive (channels not ch) (also be consistent)...the privates can still be _sr, _ch etc.
This is almost there, just need to implement the difference source options (file, pipe, stdin) and then its feature complete. I think adding a pause at the start of the audio stream (at least for pyaudio on windows 11) because the first tone doesn't play, even though it gets generated when using the dummy backend in tests. Need to test making a longer tone and see when the playback starts in frames |
I'm calling this done :) |
…xtendable MF generators etc.
WIP, I'll try and complete it tomorrow as I didn't have much time to spend on it today.