Skip to content

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

Merged
merged 8 commits into from
Mar 7, 2023

Conversation

zeyus
Copy link
Owner

@zeyus zeyus commented Mar 5, 2023

…xtendable MF generators etc.

WIP, I'll try and complete it tomorrow as I didn't have much time to spend on it today.

i += 1
yield mftone
# no pause if last
if i < seq_len:
Copy link
Owner Author

@zeyus zeyus Mar 5, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should be <=

Copy link
Owner Author

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]:
Copy link
Owner Author

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

Copy link
Owner Author

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)
Copy link
Owner Author

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.
"""

Copy link
Owner Author

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

Copy link
Owner Author

@zeyus zeyus Mar 5, 2023

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()

"""PyAudioBackendNonBlocking class for the PyAudio backend."""

def _get_stream(self, callback: t.Callable) -> pyaudio.Stream:
"""Get the PyAudio stream."""
Copy link
Owner Author

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.

@zeyus
Copy link
Owner Author

zeyus commented Mar 6, 2023

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

@zeyus zeyus removed the blocked label Mar 7, 2023
@zeyus
Copy link
Owner Author

zeyus commented Mar 7, 2023

I'm calling this done :)

@zeyus zeyus merged commit 7744c7b into main Mar 7, 2023
@zeyus zeyus deleted the feature/modernize-bluebox branch March 7, 2023 12:04
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant