Skip to content
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

WIP: Improve Audio #71

Open
wants to merge 3 commits into
base: master
from

Conversation

@dcbriccetti
Copy link
Contributor

dcbriccetti commented Oct 3, 2019

Create a set of improvements for the Express class’s audio features to improve performance and—later—to even volumes across the frequency range.

The existing start_tone method is slow because it generates a waveform prior to playing each tone. I propose to change this.

There is a limit of 350,000 sample points per second. So we can’t use 100 points per sample above 3,500 Hz.

This changed code generates two samples, one for each of two ranges of frequencies.

I added a square wave generator, and it’s much louder and has a much more consistent volume across the entire range (except for the several screaming resonating notes). If you run the program as is now, you’ll hear the square wave.

@tannewt mentioned a new mixer feature coming, but simpler than that (and 4.x compatible) might be to generate multiple square waveforms (just four bytes apiece since they require only 2 values each) at some number of gradations, then add a volume argument to the API. Everything can stay compatible (except that the sound will change).

Also please see my status note in https://docs.google.com/document/d/1suvCpQSY2tuw4wjyZ9G-BFId2iovcZSiA07r3W7gmrs/edit.

…o improve performance and—later—to even volumes across the frequency range. This is a work in progress.
@dcbriccetti dcbriccetti force-pushed the dcbriccetti:express-audio branch from 344f32d to bdb7699 Oct 3, 2019
… across the octaves.
@@ -34,19 +36,25 @@ def _sine_waveform(length, amplitude=1):
yield int(amplitude * max_amplitude * (math.sin(angle) + 1))

This comment has been minimized.

Copy link
@dhalbert

dhalbert Oct 4, 2019

Contributor

You might see if using a regular loop is noticeably faster than using yield. I'm not sure how much difference it would make due to the cost of sin(). Another idea is to have some precomputed sin() values. (Maybe you discussed that in the Monday meeting? I was not following closely.)

This comment has been minimized.

Copy link
@dcbriccetti

dcbriccetti Oct 4, 2019

Author Contributor

Thanks, Dan. I’m thinking Kattni (if it was she) used yield to avoid having two copies of the sample in memory at the same time, since it is loaded into an array. In any case, these sample-generating methods will no longer be the bottleneck.

@dcbriccetti

This comment has been minimized.

Copy link
Contributor Author

dcbriccetti commented Oct 4, 2019

What I record from the speaker is quite different from the pure sine and square waves I produced. Also notice how much louder this middle C is from the square wave.

sine and square recorded from speaker

@dcbriccetti

This comment has been minimized.

Copy link
Contributor Author

dcbriccetti commented Oct 5, 2019

Trying 50 different volume levels now, with the square waveform. The waveform’s amplitude keeps increasing, but the measured volume caps around 50%. Why? https://youtu.be/1hEdERoDkVY

@dhalbert

This comment has been minimized.

Copy link
Contributor

dhalbert commented Oct 5, 2019

I think you are overdriving the on-board audio amplifier or the speaker (or both). You have maxed out the output available from the amplifier, or you are driving the speaker so hard that it is already moving to the limits of its range of motion. It's like you can't close a door any further if it's already closed.

…tations.

A new waveform audiocore.RawSample is generated only when the user requests a different volume or waveform.
@dcbriccetti

This comment has been minimized.

Copy link
Contributor Author

dcbriccetti commented Oct 6, 2019

Thanks, Dan. I’ve lowered the maximum amplitude for the square waveform. Here’s a video of me putting the three waveforms through their paces: https://www.youtube.com/watch?v=j1VUJFcSD30

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
2 participants
You can’t perform that action at this time.