Skip to content

volume #57

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

Closed
wants to merge 6 commits into from
Closed

volume #57

wants to merge 6 commits into from

Conversation

hexthat
Copy link
Contributor

@hexthat hexthat commented May 9, 2019

No description provided.

@hexthat
Copy link
Contributor Author

hexthat commented May 9, 2019

from adafruit_circuitplayground.express import cpx

newvol = -(2**12)

cpx.play_tone(220, 2, newvol)

tone example with volume

@hexthat hexthat marked this pull request as ready for review May 9, 2019 19:46
@hexthat hexthat changed the title volume and melody volume May 11, 2019
@kevinjwalters
Copy link

Would be useful to document the volume variable including the appropriate range of values and the default in the docstring? What happens if you go too loud, does it throw an exception?

Are there any precedents for volume variables in the codebase? Are there any solid plans for doing this elsewhere, e.g. there might already be some future ideas on extending the new audioio.Mixer ?

BTW, there's mention of 0.0 to 1.0 in adafruit/circuitpython#1306

@hexthat
Copy link
Contributor Author

hexthat commented May 15, 2019

yes something can be done like that around lines 566 to 569, but im not sure how to do that.... think i could use something like this for louder but not sure about less quite

int(255* max( 0, min( 1, (1-value) )) )

looks like most that other stuff is for .wav files

@kevinjwalters
Copy link

How does this handle going "too loud", i.e. exceeding the permited range on values? I note CircuitPython 4.x has changed behaviour on values that are out of range for array.array:

bytearray, array.array, and int.to_bytes() now check for values that are too large to fit. This matches CPython behavior. Thanks to godlygeek.

@kevinjwalters
Copy link

An example of errors from exceeding the 16 bit limits:

I'd imagine bad things are likely to happen to values to, even the DSP-esque saturate approach isn't nice here.

shift = 2 ** 15
for i in range(length):
yield int(tone_volume * math.sin(2*math.pi*(i / length)) + shift)

def _generate_sample(self, length=100):
def _generate_sample(self, length=100, volume=None):
Copy link
Contributor

Choose a reason for hiding this comment

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

As written, won't this cause the first volume used to apply to all samples until a restart?

@kattni
Copy link
Contributor

kattni commented Jan 8, 2020

@hexthat There is new discussion on this PR. As well, the library has been entirely restructured since you submitted this, and therefore inclusion of your change will require a significant change to this PR. If this is something you're still interested in seeing included, it may make more sense to submit a new PR to the newly structured library, unless you're comfortable with advanced git and are able to rebase locally. Let me know if you have a preference, and I will leave this PR open or close it accordingly. Thanks!

@kattni
Copy link
Contributor

kattni commented Jan 22, 2020

I'm going to close this PR. If you still wish to add this feature, please consider submitting a new PR in this case, as the library was entirely restructured since it was submitted. These changes would now be added to circuit_playground_base.py and will require testing on both Circuit Playground Express and Bluefruit.

@kattni kattni closed this Jan 22, 2020
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.

4 participants