App 2.43.4: the Halloween pumpkin's light follows the music
The bass from Android's audio analyser drives the glow and brightens the carving on the beat, only while the style is on screen. Yellow and green and the embers keep their meaning; without a signal, as with the radio, the light stays as it was. Levels only. Tried on the emulator. Not tried on the car. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01LhzAVaUyqcw5PkGjz4mWW6
This commit is contained in:
@@ -0,0 +1,71 @@
|
||||
package com.evsuite.abrp;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
public class MusicPulseTest {
|
||||
|
||||
private static final float STEP = 0.04f;
|
||||
|
||||
@Test
|
||||
public void noReadingAndSilenceLightNothing() {
|
||||
MusicPulse p = new MusicPulse();
|
||||
assertEquals(0f, p.update(null, STEP), 0f);
|
||||
assertEquals(0f, p.update(Float.NaN, STEP), 0f);
|
||||
assertEquals(0f, p.update(0f, STEP), 0f);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void aBeatLightsAndFadesSlowerThanItRises() {
|
||||
MusicPulse p = new MusicPulse();
|
||||
for (int i = 0; i < 50; i++) p.update(0.05f, STEP);
|
||||
float beat = p.update(0.5f, STEP);
|
||||
assertTrue("a beat lights it, got " + beat, beat > 0.8f);
|
||||
float after = p.update(0.05f, STEP);
|
||||
assertTrue("it fades, got " + after, after < beat);
|
||||
assertTrue("slowly, got " + after, after > beat * 0.7f);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void aSteadyHumSettlesAtNothing() {
|
||||
MusicPulse p = new MusicPulse();
|
||||
float last = 1f;
|
||||
for (int i = 0; i < 400; i++) last = p.update(0.3f, STEP);
|
||||
assertEquals(0f, last, 0f);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void quietAndLoudSongsPulseAlike() {
|
||||
assertEquals(beatOf(0.5f), beatOf(0.05f), 0.02f);
|
||||
}
|
||||
|
||||
private static float beatOf(float scale) {
|
||||
MusicPulse p = new MusicPulse();
|
||||
float top = 0f;
|
||||
for (int i = 0; i < 500; i++) {
|
||||
top = Math.max(top * 0.99f, p.update(i % 12 == 0 ? scale : scale * 0.2f, STEP));
|
||||
}
|
||||
return top;
|
||||
}
|
||||
|
||||
@Test
|
||||
public void whenTheMusicStopsItGoesOut() {
|
||||
MusicPulse p = new MusicPulse();
|
||||
for (int i = 0; i < 100; i++) p.update(i % 12 == 0 ? 0.5f : 0.1f, STEP);
|
||||
float last = 1f;
|
||||
for (int i = 0; i < 100; i++) last = p.update(null, STEP);
|
||||
assertEquals(0f, last, 0f);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void itStaysBetweenZeroAndOne() {
|
||||
MusicPulse p = new MusicPulse();
|
||||
for (int i = 0; i < 2000; i++) {
|
||||
Float bass = i % 11 == 0 ? null : Float.valueOf(i % 7 == 0 ? 1f : 0.1f);
|
||||
float v = p.update(bass, i % 5 == 0 ? 2f : STEP);
|
||||
assertTrue(v >= 0f && v <= 1f);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user