Skip to content

Commit 76701c1

Browse files
committed
[refactor] 주석 추가, 수정
1 parent 2b622d6 commit 76701c1

File tree

6 files changed

+61
-58
lines changed

6 files changed

+61
-58
lines changed

audio_visualizer/src/main/java/com/miller198/audio_visualizer/configs/Configs.kt

+13-27
Original file line numberDiff line numberDiff line change
@@ -13,24 +13,22 @@ import com.miller198.audio_visualizer.defaultPreProcessFftData
1313
*/
1414
sealed interface VisualizerConfig {
1515

16-
// Whether to use waveform (time domain) capture
16+
/** Whether to use waveform (time domain) capture */
1717
val useWaveCapture: Boolean
1818

19-
// Whether to use FFT (frequency domain) capture
19+
/** Whether to use FFT (frequency domain) capture */
2020
val useFftCapture: Boolean
2121

22-
// Buffer size for audio capture (e.g., 512, 1024)
22+
/** Buffer size for audio capture (e.g., 512, 1024) */
2323
val captureSize: Int
2424

25-
// Optional FFT data processing function
25+
/** Optional FFT data processing function */
2626
val processFftData: ((Visualizer, ByteArray, Int) -> List<Float>)?
2727

28-
// Optional waveform data processing function
28+
/** Optional waveform data processing function */
2929
val processWaveData: ((Visualizer, ByteArray, Int) -> List<Float>)?
3030

31-
/**
32-
* Fully custom configuration defined by the user.
33-
*/
31+
/** Fully custom configuration defined by the user. */
3432
data class Custom(
3533
override val useWaveCapture: Boolean,
3634
override val useFftCapture: Boolean,
@@ -39,9 +37,7 @@ sealed interface VisualizerConfig {
3937
override val processWaveData: ((Visualizer, ByteArray, Int) -> List<Float>)?
4038
) : VisualizerConfig
4139

42-
/**
43-
* FFT-based visualizer configuration.
44-
*/
40+
/** FFT-based visualizer configuration. */
4541
data class FftCaptureConfig(
4642
val minFrequency: Int, // Minimum frequency to analyze (Hz)
4743
val maxFrequency: Int, // Maximum frequency to analyze (Hz)
@@ -61,14 +57,12 @@ sealed interface VisualizerConfig {
6157
}
6258
}
6359

64-
/**
65-
* Default FFT configuration.
66-
*/
60+
/** Default FFT configuration. */
6761
companion object {
6862
const val DEFAULT_MIN_FREQ = 40
6963
const val DEFAULT_MAX_FREQ = 4000
7064
const val DEFAULT_CAPTURE_SIZE = 1024
71-
65+
7266
val Default = FftCaptureConfig(
7367
minFrequency = DEFAULT_MIN_FREQ,
7468
maxFrequency = DEFAULT_MAX_FREQ,
@@ -92,9 +86,7 @@ sealed interface VisualizerConfig {
9286
override val useFftCapture: Boolean = false
9387
override val processFftData: ((Visualizer, ByteArray, Int) -> List<Float>)? = null
9488

95-
/**
96-
* Default waveform configuration.
97-
*/
89+
/** Default waveform configuration. */
9890
data object Default : WaveCaptureConfig(
9991
captureSize = 1024,
10092
processWaveData = { _, byteArray, _ ->
@@ -113,28 +105,22 @@ sealed interface GradientConfig {
113105
val duration: Int // Animation duration in milliseconds
114106
val color: Color // Base color of the gradient
115107

116-
/**
117-
* Default gradient config (enabled).
118-
*/
108+
/** Default gradient config (enabled). */
119109
data object Default : GradientConfig {
120110
override val useGradient: Boolean = true
121111
override val duration: Int = 2500
122112
override val color: Color = White
123113
}
124114

125-
/**
126-
* Enabled gradient config with custom options.
127-
*/
115+
/** Enabled gradient config with custom options. */
128116
data class Enabled(
129117
override val duration: Int,
130118
override val color: Color,
131119
) : GradientConfig {
132120
override val useGradient: Boolean = true
133121
}
134122

135-
/**
136-
* Disabled gradient config (no animation, transparent color).
137-
*/
123+
/** Disabled gradient config (no animation, transparent color) */
138124
data object Disabled : GradientConfig {
139125
override val useGradient: Boolean = false
140126
override val duration: Int = 0

audio_visualizer/src/main/java/com/miller198/audio_visualizer/soundeffect/DrawSoundBar.kt

+5-5
Original file line numberDiff line numberDiff line change
@@ -33,19 +33,19 @@ internal fun DrawSoundBar(
3333
color: Color,
3434
modifier: Modifier = Modifier,
3535
) {
36-
// The radius from the center to the start of the bars
36+
/** The radius from the center to the start of the bars */
3737
var adjustedRadius by remember { mutableFloatStateOf(0f) }
3838

39-
// The maximum possible bar height based on canvas size
39+
/** The maximum possible bar height based on canvas size */
4040
var maxEffectHeight by remember { mutableFloatStateOf(0f) }
4141

42-
// Animated gradient radius for dynamic glow effects
42+
/** Animated gradient radius for dynamic glow effects */
4343
val animatedGradientRadius = animatedGradientRadius(LinearEasing)
4444

45-
// Angle between each bar in the 360° circle
45+
/** Angle between each bar in the 360° circle */
4646
val angleStep = 360f / audioData.size
4747

48-
// Main canvas for drawing the sound bars
48+
/** Main canvas for drawing the sound bars */
4949
Canvas(
5050
modifier = modifier
5151
.fillMaxSize()

audio_visualizer/src/main/java/com/miller198/audio_visualizer/soundeffect/DrawSoundWaveFill.kt

+7-7
Original file line numberDiff line numberDiff line change
@@ -37,25 +37,25 @@ internal fun DrawSoundWaveFill(
3737
color: Color,
3838
modifier: Modifier = Modifier,
3939
) {
40-
// The radius from the center to the start of the bars
40+
/** The radius from the center to the start of the bars */
4141
var adjustedRadius by remember { mutableFloatStateOf(0f) }
4242

43-
// The maximum possible bar height based on canvas size
43+
/** The maximum possible bar height based on canvas size */
4444
var maxEffectHeight by remember { mutableFloatStateOf(0f) }
4545

46-
// Path used to define the circular center hole (to clip out)
46+
/** Path used to define the circular center hole (to clip out) */
4747
var holePath by remember { mutableStateOf(Path()) }
4848

49-
// Angle between each bar in the 360° circle
49+
/** Angle between each bar in the 360° circle */
5050
val angleStep = 360f / audioData.size
5151

52-
// The path that represents the full waveform
52+
/** The path that represents the full waveform */
5353
val path = Path()
5454

55-
// Animated gradient radius for visual effect
55+
/** Animated gradient radius for visual effect */
5656
val animatedGradientRadius = animatedGradientRadius(LinearOutSlowInEasing)
5757

58-
// Main canvas for drawing the sound wave
58+
/** Main canvas for drawing the sound wave */
5959
Canvas(
6060
modifier = modifier
6161
.fillMaxSize()

audio_visualizer/src/main/java/com/miller198/audio_visualizer/soundeffect/DrawSoundWaveStroke.kt

+5-5
Original file line numberDiff line numberDiff line change
@@ -29,19 +29,19 @@ internal fun DrawSoundWaveStroke(
2929
color: Color,
3030
modifier: Modifier = Modifier,
3131
) {
32-
// The radius from the center to the start of the bars
32+
/** The radius from the center to the start of the bars */
3333
var adjustedRadius by remember { mutableFloatStateOf(0f) }
3434

35-
// The maximum possible bar height based on canvas size
35+
/** The maximum possible bar height based on canvas size */
3636
var maxEffectHeight by remember { mutableFloatStateOf(0f) }
3737

38-
// Angle between each bar in the 360° circle
38+
/** Angle between each bar in the 360° circle */
3939
val angleStep = 360f / audioData.size
4040

41-
// The path that represents the full waveform
41+
/** The path that represents the full waveform */
4242
val path = Path()
4343

44-
// Main canvas for drawing the sound bars
44+
/** Main canvas for drawing the sound bars */
4545
Canvas(
4646
modifier = modifier
4747
.fillMaxSize()

audio_visualizer/src/main/java/com/miller198/audio_visualizer/soundeffect/SoundEffects.kt

+4-12
Original file line numberDiff line numberDiff line change
@@ -17,28 +17,20 @@ enum class SoundEffects(
1717
modifier: Modifier,
1818
) -> Unit
1919
) {
20-
/**
21-
* No effect. This does not render any audio visualization.
22-
*/
20+
/** No effect. This does not render any audio visualization. */
2321
NONE({ _, _, _ -> }),
2422

25-
/**
26-
* A vertical bar graph representation of the audio data.
27-
*/
23+
/** A vertical bar graph representation of the audio data. */
2824
BAR({ audioData, color, modifier ->
2925
DrawSoundBar(audioData, color, modifier)
3026
}),
3127

32-
/**
33-
* A waveform rendered using stroke (outline only).
34-
*/
28+
/** A waveform rendered using stroke (outline only). */
3529
WAVE_STROKE({ audioData, color, modifier ->
3630
DrawSoundWaveStroke(audioData, color, modifier)
3731
}),
3832

39-
/**
40-
* A waveform rendered as a filled shape.
41-
*/
33+
/** A waveform rendered as a filled shape. */
4234
WAVE_FILL({ audioData, color, modifier ->
4335
DrawSoundWaveFill(audioData, color, modifier)
4436
})

audio_visualizer/src/main/java/com/miller198/audio_visualizer/ui/CircleVisualizer.kt

+27-2
Original file line numberDiff line numberDiff line change
@@ -21,44 +21,67 @@ import com.miller198.audio_visualizer.soundeffect.DrawSoundEffectConfigs
2121
import com.miller198.audio_visualizer.soundeffect.SoundEffects
2222
import kotlinx.coroutines.launch
2323

24+
/**
25+
* Composable that visualizes audio data as a circular sound effect (e.g., wave or bar),
26+
* using a provided audio session ID.
27+
*
28+
* @param audioSessionId The audio session ID from the audio output source (e.g., MediaPlayer).
29+
* @param soundEffects Object that defines how to draw the sound effect. use [SoundEffects] (waveform, bars, etc.).
30+
* @param visualizerConfig Configuration for how the visualizer captures and processes audio data [VisualizerConfig].
31+
* @param modifier Modifier to apply to the visualizer's layout.
32+
* @param color The primary color to use for drawing the sound visualization.
33+
* @param clippingRadiusConfig Configuration for the inner clipping radius of the circle visualization. Default is [ClippingRadiusConfig.FullClip].
34+
* @param gradientConfig Configuration for gradient animation within the visualizer (optional). Default is [GradientConfig.Default] which uses gradient animation.
35+
*/
2436
@Composable
2537
fun CircleVisualizer(
2638
audioSessionId: Int,
2739
soundEffects: SoundEffects,
2840
visualizerConfig: VisualizerConfig,
2941
modifier: Modifier = Modifier,
3042
color: Color = White,
31-
innerRadiusConfig: ClippingRadiusConfig = ClippingRadiusConfig.FullClip,
43+
clippingRadiusConfig: ClippingRadiusConfig = ClippingRadiusConfig.FullClip,
3244
gradientConfig: GradientConfig = GradientConfig.Default,
3345
) {
46+
/** Holds the current list of magnitude values */
3447
val magnitudes = remember { mutableStateOf<List<Float>>(emptyList()) }
48+
49+
/** Animated version of the magnitudes for smooth transitions in visualization */
3550
val animateMagnitudes = remember { mutableStateOf<List<Animatable<Float, AnimationVector1D>>>(emptyList()) }
51+
3652
val visualizer = remember { BaseVisualizer() }
3753

54+
// Set global visual configuration (used in other rendering composable functions)
3855
DrawSoundEffectConfigs.gradientConfig = gradientConfig
39-
DrawSoundEffectConfigs.innerRadiusConfig = innerRadiusConfig
56+
DrawSoundEffectConfigs.innerRadiusConfig = clippingRadiusConfig
4057

58+
// Start the visualizer when the composable is composed with the given audio session ID
4159
LaunchedEffect(audioSessionId) {
4260
visualizer.start(
4361
audioSessionId = audioSessionId,
4462
captureSize = visualizerConfig.captureSize,
4563
useWaveCapture = visualizerConfig.useWaveCapture,
4664
useFftCapture = visualizerConfig.useFftCapture,
4765
visualizerCallbacks = VisualizerCallbacks(
66+
// Callback for waveform audio data (optional processing)
4867
onWaveCaptured = { visualizer, bytes, samplingRate ->
4968
magnitudes.value = visualizerConfig.processWaveData?.invoke(visualizer, bytes, samplingRate) ?: emptyList()
5069
},
70+
// Callback for FFT audio data (optional processing)
5171
onFftCaptured = { visualizer, bytes, samplingRate ->
5272
magnitudes.value = visualizerConfig.processFftData?.invoke(visualizer, bytes, samplingRate) ?: emptyList()
5373
},
5474
)
5575
)
5676
}
5777

78+
// Animate changes in magnitude values for smoother rendering transitions
5879
LaunchedEffect(magnitudes.value) {
5980
if (animateMagnitudes.value.isEmpty()) {
81+
// Initialize the animatable list if not already done
6082
animateMagnitudes.value = magnitudes.value.map { Animatable(it) }
6183
} else {
84+
// Animate each value to its new magnitude
6285
magnitudes.value.forEachIndexed { i, magnitude ->
6386
launch {
6487
animateMagnitudes.value[i].animateTo(
@@ -73,12 +96,14 @@ fun CircleVisualizer(
7396
}
7497
}
7598

99+
// Release the visualizer when composable leaves the composition
76100
DisposableEffect(audioSessionId) {
77101
onDispose {
78102
visualizer.stop()
79103
}
80104
}
81105

106+
// Draw the sound effect using the provided drawEffect lambda
82107
soundEffects.drawEffect.invoke(
83108
animateMagnitudes.value.map { it.value },
84109
color,

0 commit comments

Comments
 (0)