Repository navigation
feat: Android hardware equalizer via AudioEffect #83
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
base: main
Are you sure you want to change the base?
Changes from all commits
529f1b6
8427565
79e87be
951442f
d37636b
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -9,6 +9,13 @@ import { | |
| View, | ||
| } from "react-native"; | ||
| import { Ionicons } from "@expo/vector-icons"; | ||
| import Slider from "@react-native-community/slider"; | ||
| import { | ||
| getEqualizerInfo, | ||
| setEqualizerBandLevel, | ||
| setEqualizerEnabled, | ||
| type EqualizerInfo, | ||
| } from "../../modules/audioEqualizer"; | ||
| import { | ||
| APP_THEME_OPTIONS, | ||
| SEEK_STEP_OPTIONS, | ||
|
|
@@ -377,6 +384,62 @@ function ThemeChoiceCard({ | |
| ); | ||
| } | ||
|
|
||
| /** | ||
| * Band sliders, shown only when the setting is on and the device actually has | ||
| * an equalizer. Levels live in the system effect; nothing is persisted. | ||
| */ | ||
| function EqualizerBands({ colors }: { colors: ReturnType<typeof useTheme>["colors"] }) { | ||
| const { t } = useAppLanguage(); | ||
| const [info, setInfo] = useState<EqualizerInfo | null>(null); | ||
| const [levels, setLevels] = useState<number[]>([]); | ||
|
|
||
| useEffect(() => { | ||
| let alive = true; | ||
| getEqualizerInfo().then((next) => { | ||
| if (!alive) return; | ||
| setInfo(next); | ||
| setLevels(next.levels); | ||
| }); | ||
| return () => { | ||
| alive = false; | ||
| }; | ||
| }, []); | ||
|
|
||
| if (!info?.supported) { | ||
| return <MutedText style={styles.settingDescription}>{t("settings.equalizerUnsupported")}</MutedText>; | ||
| } | ||
|
|
||
| return ( | ||
| <View style={styles.choiceWrap}> | ||
| {info.centerFreqHz.map((hz, index) => ( | ||
| <View key={hz} style={styles.equalizerBand}> | ||
| <MutedText style={styles.settingDescription}> | ||
| {hz >= 1000 ? `${hz / 1000}k` : hz} | ||
| </MutedText> | ||
| <View | ||
| accessible | ||
| accessibilityRole="adjustable" | ||
| accessibilityLabel={`${hz} Hz`} | ||
| > | ||
| <Slider | ||
| value={levels[index] ?? 0} | ||
| minimumValue={info.minMillibel} | ||
| maximumValue={Math.max(info.maxMillibel, info.minMillibel)} | ||
| minimumTrackTintColor={colors.accent} | ||
| maximumTrackTintColor={colors.borderSubtle} | ||
| thumbTintColor={colors.accent} | ||
| onValueChange={(value) => { | ||
| setLevels((prev) => prev.map((v, i) => (i === index ? value : v))); | ||
| void setEqualizerBandLevel(index, value); | ||
|
Comment on lines
+432
to
+433
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🟠 High · Persist EQ profiles The issue asks to persist EQ settings per output device, but band changes are only held in component state and sent to the native effect. Persist band levels and maintain separate speaker/headset profiles. Prompt for AI agentsIn `components/screens/SettingsScreen.tsx` at lines 432-433:
**Persist EQ profiles**
The issue asks to persist EQ settings per output device, but band changes are only held in component state and sent to the native effect. Persist band levels and maintain separate speaker/headset profiles.From #28: Persist user EQ per device, with speaker and headset profiles. |
||
| }} | ||
| /> | ||
| </View> | ||
| </View> | ||
| ))} | ||
| </View> | ||
| ); | ||
|
Comment on lines
+413
to
+440
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🟠 High · Requested EQ controls are missing When the EQ screen is opened, the UI exposes band sliders and a toggle but no preset controls with corresponding band settings, draggable band curve, or reset alongside the toggle, so users cannot use the requested EQ controls. Add the requested preset controls and band settings, draggable band curve, and reset control alongside the toggle. Prompt for AI agentsIn `components/screens/SettingsScreen.tsx` at lines 413-440:
**Requested EQ controls are missing**
When the EQ screen is opened, the UI exposes band sliders and a toggle but no preset controls with corresponding band settings, draggable band curve, or reset alongside the toggle, so users cannot use the requested EQ controls.
Add the requested preset controls and band settings, draggable band curve, and reset control alongside the toggle.From #28: Provide presets such as Bass boost, Vocal, Rock, and Acoustic.From #28: Provide an EQ screen with a draggable band curve, preset chips, reset, and a Settings → Playback toggle. |
||
| } | ||
|
|
||
| export default function SettingsScreen({ | ||
| navigation, | ||
| }: { | ||
|
|
@@ -1315,6 +1378,31 @@ export default function SettingsScreen({ | |
| /> | ||
| } | ||
| /> | ||
| <SettingRow | ||
| label={t("settings.equalizer")} | ||
| description={t("settings.equalizerDescription")} | ||
| colors={colors} | ||
| controlPlacement="inline" | ||
| control={ | ||
| <SettingsSwitch | ||
| accessibilityLabel={t("settings.equalizer")} | ||
| accessibilityHint={t("settings.equalizerDescription")} | ||
| value={settings.equalizerEnabled} | ||
| onValueChange={(value) => { | ||
| updateSettings({ equalizerEnabled: value }); | ||
| void setEqualizerEnabled(value); | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🟠 High · Restore EQ on restart The enabled preference is saved, but the native effect is only enabled in response to a toggle change and band levels are not restored on app startup. Reapply the saved EQ state and levels after restart. Prompt for AI agentsIn `components/screens/SettingsScreen.tsx` at line 1393:
**Restore EQ on restart**
The enabled preference is saved, but the native effect is only enabled in response to a toggle change and band levels are not restored on app startup. Reapply the saved EQ state and levels after restart.From #28: Have the EQ survive track changes and app restart. |
||
| }} | ||
|
Comment on lines
+1391
to
+1394
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🎯 Functional Correctness | 🟠 Major | ⚡ Quick win Apply the persisted Only this toggle handler calls 🤖 Prompt for AI Agents |
||
| /> | ||
| } | ||
| /> | ||
| {settings.equalizerEnabled ? ( | ||
| <SettingRow | ||
| label={t("settings.equalizer")} | ||
| description={t("settings.equalizerDescription")} | ||
| colors={colors} | ||
| control={<EqualizerBands colors={colors} />} | ||
| /> | ||
| ) : null} | ||
| </Section> | ||
| ) : null} | ||
|
|
||
|
|
@@ -1692,6 +1780,10 @@ const styles = StyleSheet.create({ | |
| flexWrap: "wrap", | ||
| gap: 8, | ||
| }, | ||
| equalizerBand: { | ||
| minWidth: 72, | ||
| flexGrow: 1, | ||
| }, | ||
| chip: { | ||
| minHeight: 44, | ||
| minWidth: 44, | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,91 @@ | ||
| /******************************************************************** | ||
| * audioEqualizer.ts - JS side of StreamifyEqualizerModule (issue #28) | ||
| * | ||
| * Android-only hardware equalizer on AudioEffect.EFFECT_TYPE_EQUALIZER, | ||
| * attached to the global output mix (session 0) because neither | ||
| * kotlin-audio nor track-player exposes a sessionId to JS. | ||
| * | ||
| * Web/iOS get a clean "unsupported" surface so call sites never need | ||
| * platform checks. Nothing here can throw into a playback path. | ||
| *******************************************************************/ | ||
| import { NativeModules, Platform } from "react-native"; | ||
|
|
||
| export interface EqualizerInfo { | ||
| supported: boolean; | ||
| numberOfBands: number; | ||
| minMillibel: number; | ||
| maxMillibel: number; | ||
| levels: number[]; | ||
| centerFreqHz: number[]; | ||
| } | ||
|
|
||
| type EqualizerNative = { | ||
| getInfo(): Promise<EqualizerInfo>; | ||
| setBandLevel(band: number, millibel: number): Promise<number>; | ||
| setEnabled(enabled: boolean): Promise<boolean>; | ||
| }; | ||
|
|
||
| const native = (NativeModules as any).StreamifyEqualizerModule as | ||
| | EqualizerNative | ||
| | undefined; | ||
|
|
||
| /** Surfaced when the Android binary was built without the config plugin. */ | ||
| export const EQUALIZER_LINK_ERROR = | ||
| "StreamifyEqualizerModule is not linked. Run `npx expo prebuild --clean` and rebuild the Android app."; | ||
|
|
||
| const UNSUPPORTED: EqualizerInfo = { | ||
| supported: false, | ||
| numberOfBands: 0, | ||
| minMillibel: 0, | ||
| maxMillibel: 0, | ||
| levels: [], | ||
| centerFreqHz: [], | ||
| }; | ||
|
|
||
| export const isEqualizerSupported = Platform.OS === "android" && Boolean(native); | ||
|
|
||
| let linkErrorLogged = false; | ||
|
|
||
| export async function getEqualizerInfo(): Promise<EqualizerInfo> { | ||
| if (Platform.OS !== "android") { | ||
| return UNSUPPORTED; | ||
| } | ||
| if (!native) { | ||
| if (!linkErrorLogged) { | ||
| linkErrorLogged = true; | ||
| console.warn(EQUALIZER_LINK_ERROR); | ||
| } | ||
| return UNSUPPORTED; | ||
| } | ||
| try { | ||
| return await native.getInfo(); | ||
| } catch { | ||
| return UNSUPPORTED; | ||
| } | ||
| } | ||
|
|
||
| /** Resolves the millibel actually applied (native clamps), or null if absent. */ | ||
| export async function setEqualizerBandLevel( | ||
| band: number, | ||
| millibel: number, | ||
| ): Promise<number | null> { | ||
| if (!native || Platform.OS !== "android") { | ||
| return null; | ||
| } | ||
| try { | ||
| return await native.setBandLevel(band, millibel); | ||
| } catch { | ||
| return null; | ||
| } | ||
| } | ||
|
|
||
| export async function setEqualizerEnabled(enabled: boolean): Promise<boolean> { | ||
| if (!native || Platform.OS !== "android") { | ||
| return false; | ||
| } | ||
| try { | ||
| return await native.setEnabled(enabled); | ||
| } catch { | ||
| return false; | ||
| } | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
issue (bug_risk): When
equalizerEnabledis restored astrueafter an app restart,getEqualizerInfo()constructs the effect but this mount effect never callssetEqualizerEnabled(true). The persisted setting displays the sliders while the newly created Android effect remains disabled, so the equalizer is not actually enabled after relaunch.Triggers: When the user enables the equalizer, closes the app, and later opens it with the persisted setting still true.
Suggested fix: After obtaining supported info, explicitly apply the current enabled setting, or centralize the setting-to-native synchronization in an effect that runs after settings hydration.