@@ -9,9 +9,10 @@ This document provides an in-depth explanation of the Bayan Flow architecture, d
993 . [ Data Flow] ( #data-flow )
10104 . [ Algorithm Implementation] ( #algorithm-implementation )
11115 . [ Animation System] ( #animation-system )
12- 6 . [ State Management] ( #state-management )
13- 7 . [ Testing Strategy] ( #testing-strategy )
14- 8 . [ Performance Optimizations] ( #performance-optimizations )
12+ 6 . [ Audio System] ( #audio-system )
13+ 7 . [ State Management] ( #state-management )
14+ 8 . [ Testing Strategy] ( #testing-strategy )
15+ 9 . [ Performance Optimizations] ( #performance-optimizations )
1516
1617## System Architecture
1718
@@ -220,6 +221,60 @@ for (let step of steps) {
220221}
221222```
222223
224+ ## Audio System
225+
226+ ### SoundManager Architecture
227+
228+ The audio system uses ** Tone.js** for Web Audio API abstraction and provides contextual sound feedback for algorithm operations.
229+
230+ ** Core Design:**
231+ ``` javascript
232+ class SoundManager {
233+ constructor () {
234+ this .isEnabled = false ;
235+ this .softSynth = new Tone.Synth ({... }); // UI sounds
236+ this .pluckSynth = new Tone.PluckSynth ({... }); // Compare sounds
237+ this .metallicSynth = new Tone.MetalSynth ({... }); // Swap sounds
238+ this .polySynth = new Tone.PolySynth ({... }); // Chord sounds
239+ }
240+ }
241+ ```
242+
243+ ### Sound Mapping Strategy
244+
245+ ** Sorting Operations:**
246+ - ** Compare** : Pluck synth with frequency mapped to element value (150-350Hz)
247+ - ** Swap** : Metallic synth for distinct swap feedback
248+ - ** Pivot** : Soft synth with lower frequency range (100-200Hz)
249+ - ** Sorted** : Major chord (C-E-G) for completion celebration
250+
251+ ** Pathfinding Operations:**
252+ - ** Node Visit** : Soft synth at 220Hz (A3 note)
253+ - ** Path Found** : Extended chord (C3-E3-G3-C4) for success
254+ - ** UI Interactions** : Brief G4 note for clicks
255+
256+ ### Integration Pattern
257+
258+ ** Hook Integration:**
259+ ``` javascript
260+ const executeStep = useCallback ((step ) => {
261+ // Update visual state
262+ setArray (step .array );
263+ setStates (step .states );
264+
265+ // Trigger contextual audio
266+ if (step .states .includes (ELEMENT_STATES .SWAPPING )) {
267+ soundManager .playSwap (step .array [swapIndex]);
268+ }
269+ }, []);
270+ ```
271+
272+ ** Benefits:**
273+ - ** Non-blocking** : Audio failures don't affect visualization
274+ - ** User-controlled** : Easy enable/disable toggle
275+ - ** Performance** : Early returns when disabled
276+ - ** Contextual** : Sounds match visual operations
277+
223278## State Management
224279
225280### Custom Hook: useSortingVisualization
0 commit comments