-
-
Notifications
You must be signed in to change notification settings - Fork 234
Android Audio Reactivity #1056
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
Closed
Android Audio Reactivity #1056
Changes from 1 commit
Commits
Show all changes
16 commits
Select commit
Hold shift + click to select a range
14c138d
wip
andybak f8a1a96
Progress
andybak ed51f92
Add audio reactive button to mobile brushes (temp)
andybak 6216689
Android mic capture
andybak ef4eb6b
Add System/Other app as a source on Android
andybak 2788207
Catch hard quit in builds. Missing meta files
andybak 17a1bb7
Don't switch to audio reactive on brush selection
andybak a1f004b
Don't update coefficients unless freq has changed more than an epsilon
andybak c2b8f88
Don't log so much in builds
andybak 4c1994d
Instrumentation / logging
andybak 7540574
More diagnostics
andybak 81632e0
Foreground capture service
andybak 158bf74
Add new service to manifest
andybak 721685c
Ensure we don't fall through to mic input when testing system capture
andybak 29addab
Give up on capturing app audio on android
andybak 145168b
Merge branch 'main' into feature/android-audio-reactivity
andybak File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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,141 @@ | ||
| // Copyright 2020 The Tilt Brush Authors | ||
| // | ||
| // Licensed under the Apache License, Version 2.0 (the "License"); | ||
| // you may not use this file except in compliance with the License. | ||
| // You may obtain a copy of the License at | ||
| // | ||
| // http://www.apache.org/licenses/LICENSE-2.0 | ||
| // | ||
| // Unless required by applicable law or agreed to in writing, software | ||
| // distributed under the License is distributed on an "AS IS" BASIS, | ||
| // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| // See the License for the specific language governing permissions and | ||
| // limitations under the License. | ||
|
|
||
| using System; | ||
| using NUnit.Framework; | ||
|
|
||
| namespace TiltBrush | ||
| { | ||
| internal class TestVisualizerManagedAnalysis | ||
| { | ||
| private const int kFftSize = 512; | ||
| private const int kSampleRate = 48000; | ||
|
|
||
| [Test] | ||
| public void ManagedFftDetectsSineNearExpectedBin() | ||
| { | ||
| const int expectedBin = 8; | ||
| float[] samples = GenerateSine(expectedBin * kSampleRate / kFftSize); | ||
| float[] fft = new float[kFftSize]; | ||
| var analyzer = new VisualizerManagedFft(1, kFftSize); | ||
|
|
||
| analyzer.Add(samples, samples.Length); | ||
| analyzer.GetFftData(fft); | ||
|
|
||
| int peakBin = FindPeakBin(fft, 1, kFftSize / 2); | ||
| Assert.That(peakBin, Is.InRange(expectedBin - 1, expectedBin + 1)); | ||
| Assert.That(fft[peakBin], Is.GreaterThan(fft[expectedBin + 8] * 5.0f)); | ||
| } | ||
|
|
||
| [Test] | ||
| public void ManagedFftKeepsSilenceAtZero() | ||
| { | ||
| float[] samples = new float[kFftSize]; | ||
| float[] fft = new float[kFftSize]; | ||
| var analyzer = new VisualizerManagedFft(1, kFftSize); | ||
|
|
||
| analyzer.Add(samples, samples.Length); | ||
| analyzer.GetFftData(fft); | ||
|
|
||
| for (int i = 0; i < fft.Length; ++i) | ||
| { | ||
| Assert.That(fft[i], Is.EqualTo(0.0f).Within(1e-6f)); | ||
| } | ||
| } | ||
|
|
||
| [Test] | ||
| public void ManagedFftUsesFirstChannelFromInterleavedSamples() | ||
| { | ||
| const int expectedBin = 8; | ||
| float[] mono = GenerateSine(expectedBin * kSampleRate / kFftSize); | ||
| float[] interleaved = new float[kFftSize * 2]; | ||
| for (int i = 0; i < mono.Length; ++i) | ||
| { | ||
| interleaved[i * 2] = mono[i]; | ||
| interleaved[i * 2 + 1] = 0.0f; | ||
| } | ||
| float[] fft = new float[kFftSize]; | ||
| var analyzer = new VisualizerManagedFft(2, kFftSize); | ||
|
|
||
| analyzer.Add(interleaved, interleaved.Length); | ||
| analyzer.GetFftData(fft); | ||
|
|
||
| int peakBin = FindPeakBin(fft, 1, kFftSize / 2); | ||
| Assert.That(peakBin, Is.InRange(expectedBin - 1, expectedBin + 1)); | ||
| } | ||
|
|
||
| [Test] | ||
| public void ManagedLowPassAttenuatesHighFrequencies() | ||
| { | ||
| float[] low = GenerateSine(120); | ||
| float[] high = GenerateSine(4000); | ||
| var lowPass = new VisualizerManagedFilter(VisualizerManagedFilter.FilterType.Low, kSampleRate, 500); | ||
|
|
||
| lowPass.Process(low); | ||
| lowPass = new VisualizerManagedFilter(VisualizerManagedFilter.FilterType.Low, kSampleRate, 500); | ||
| lowPass.Process(high); | ||
|
|
||
| Assert.That(Rms(low), Is.GreaterThan(Rms(high) * 2.0f)); | ||
| } | ||
|
|
||
| [Test] | ||
| public void ManagedHighPassAttenuatesLowFrequencies() | ||
| { | ||
| float[] low = GenerateSine(120); | ||
| float[] high = GenerateSine(4000); | ||
| var highPass = new VisualizerManagedFilter(VisualizerManagedFilter.FilterType.High, kSampleRate, 1000); | ||
|
|
||
| highPass.Process(low); | ||
| highPass = new VisualizerManagedFilter(VisualizerManagedFilter.FilterType.High, kSampleRate, 1000); | ||
| highPass.Process(high); | ||
|
|
||
| Assert.That(Rms(high), Is.GreaterThan(Rms(low) * 2.0f)); | ||
| } | ||
|
|
||
| private static float[] GenerateSine(float frequency) | ||
| { | ||
| float[] samples = new float[kFftSize]; | ||
| for (int i = 0; i < samples.Length; ++i) | ||
| { | ||
| samples[i] = (float)Math.Sin(2.0 * Math.PI * frequency * i / kSampleRate); | ||
| } | ||
| return samples; | ||
| } | ||
|
|
||
| private static int FindPeakBin(float[] fft, int start, int end) | ||
| { | ||
| int peakIndex = start; | ||
| float peak = fft[start]; | ||
| for (int i = start + 1; i < end; ++i) | ||
| { | ||
| if (fft[i] > peak) | ||
| { | ||
| peak = fft[i]; | ||
| peakIndex = i; | ||
| } | ||
| } | ||
| return peakIndex; | ||
| } | ||
|
|
||
| private static float Rms(float[] samples) | ||
| { | ||
| double sumSquares = 0.0; | ||
| for (int i = 0; i < samples.Length; ++i) | ||
| { | ||
| sumSquares += samples[i] * samples[i]; | ||
| } | ||
| return (float)Math.Sqrt(sumSquares / samples.Length); | ||
| } | ||
| } | ||
| } |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.