Input Files and Supported Decoding
When converting audio files between stereo and mono or editing left-right balance, the first step is loading and decoding the target file into the system.
This system performs these initial operations utilizing FileReader and the Web Audio API, which are standard APIs provided by modern browsers.
The file selection interface provides both a dashed drag-and-drop zone and a standard file dialog opened by clicking, accommodating different user interaction workflows.
Once an audio file is selected, FileReader immediately reads the file binary into memory as an ArrayBuffer. At this stage, reading is confined entirely to the browser on the user's local device without delegating processing to an external server.
The binary data acquired as an ArrayBuffer is passed to the decodeAudioData method of an AudioContext (or webkitAudioContext depending on the environment) and decoded into uncompressed PCM audio data.
Audio formats supported during decoding (such as MP3, WAV, M4A, or OGG) depend on browser implementations. If an uploaded file is corrupted or formatted in an unsupported codec, decoding fails and triggers an exception.
An alert dialog stating "Failed to decode audio file. Please check whether the file is corrupted." is displayed, halting further processing.
Once decoding completes successfully, the total duration is calculated from the extracted AudioBuffer and displayed alongside the original file name.
Wait for decoding to complete and verify the displayed duration before proceeding with editing or playback. The tool's audio processing pipeline originates from this in-memory buffer data, serving as the foundation for all subsequent channel routing and effect processing.
Five Channel Processing Modes
Audio data expanded into an AudioBuffer passes through a routing network combining ChannelSplitterNode and ChannelMergerNode from the Web Audio API to perform conversions and channel extractions between stereo and mono.
The tool provides five independent routing modes to achieve specific acoustic goals, selectable via button controls.
The first mode, "Normal Stereo (None)", preserves the channel structure of the input audio. It bypasses the stream directly to downstream panning and gain controls without altering the left and right channel information of the decoded source.
The second mode, "Mono Mix (L+R Mix)", sums the left and right channels to center them. Internally, the signal is separated into L and R via ChannelSplitterNode, and a GainNode is applied to each branch.
If the input file is two-channel stereo, gains for L and R are each set to 0.5 before summation to prevent clipping saturation. If the input file is originally single-channel mono, L gain is set to 1 and R gain to 0.
The summed signal is then duplicated into both the L and R inputs of the ChannelMergerNode.
The third mode, "Swap L/R Channels", cross-connects the splitter's L output to the merger's R input and the splitter's R output to the merger's L input.
This creates an audio stream with the left and right stereo field completely inverted.
The fourth mode, "Extract L Channel Only", captures solely the separated L output and duplicates it into both the L and R inputs of the merger. Data from the R channel is discarded.
The fifth mode, "Extract R Channel Only", captures solely the R output and duplicates it to both merger channels. As an exception to note, if the input file is single-channel mono, no R channel exists in the source.
Selecting R channel extraction in this state may result in complete silence.
Furthermore, if a routing mode is switched during playback, the system preserves the current playback position, tears down the existing playback node, and immediately recreates nodes with the updated routing configuration to resume playback seamlessly.
Panning, Volume, and Muting
Following channel routing configuration, parameter controls for panning and amplitude (volume) take effect. These adjustments are operated through sliders on the user interface and apply directly to the audio stream in real time even during playback.
Stereo positioning is controlled using the Web Audio API's StereoPannerNode. The "L/R Panning Balance" slider spans from -1.0 to 1.0 in increments of 0.05, where 0.0 represents center positioning.
Moving the slider toward negative values shifts the sound toward the left (L) speaker, while positive values shift it toward the right (R) speaker.
Percentage values such as "L 100%" or "R 50%" update dynamically alongside the slider. Panning applies to the signal after it traverses the five channel routing modes described previously.
For instance, if you select "Extract L Channel Only" and slide the pan fully to "R 100%", the left-channel content from the original file will be played exclusively from the right speaker.
Volume and muting are managed through a GainNode positioned at the final stage. The volume slider ranges from 0.0 to 1.0 in increments of 0.05, defaulting to 0.8.
Adjusting the slider invokes setValueAtTime on the GainNode's gain parameter, reflecting the setting at the current playback time.
Clicking the speaker icon activates muting. When muted, the internal gain is forced to 0 regardless of UI slider position, silencing the output.
Clicking again restores volume immediately to the slider value.
These panning and volume settings serve not only for playback monitoring but also bake directly into the recorded stream during real-time rendering via MediaRecorder.
Previewing and Verifying Settings
After loading a file and setting parameters, a preview playback feature allows you to verify results before final export. Clicking the play button begins playback from the current position.
Clicking it again pauses playback and records the updated position. A reset button with a reload icon returns playback to the beginning of the file and stops playback completely.
Playback progress updates via elapsed time and total duration indicators. Simultaneously, dragging the seek bar shifts the playback position to arbitrary points in the file.
Seeking during playback terminates the current source node, creates a new one at the specified offset, and restarts playback immediately.
A waveform area in the center displays an animation of 48 bars. Updated via requestAnimationFrame on each render frame, the bars highlight according to current playback time to indicate progress visually.
However, vertical oscillations of these bars are generated decoratively using Math.sin calculations and do not reflect real waveform amplitudes or clipping detection measurements from the loaded audio file.
Because bar movement is unaffected by mono/stereo modes or panning, sound quality and clipping must be judged by listening. This preview mechanism allows you to check for unintended phase cancellation, missing channels, or skewed panning before committing to an export.
Real-Time Export Recording
Once parameter tuning and previewing are complete, saving the result initiates a real-time recording (rendering) process. Rather than offline instant rendering, this tool employs real-time recording combining MediaStreamAudioDestinationNode and the MediaRecorder API.
Clicking "Start Recording / Export" halts any active preview, resets playback position to the beginning (0 seconds), and routes the audio stream containing channel mode, panning, and volume adjustments to both speaker output and a MediaStreamAudioDestinationNode.
A MediaRecorder is initialized using the MediaStream from this destination node and starts capturing as playback begins.
During recording, the system activates a recording flag and disables routing mode buttons and the seek bar to prevent mid-recording mode shifts or playback jumps.
Panning, volume, and mute controls remain adjustable and affect the recorded stream directly.
Recording terminates under two conditions: clicking "Stop Recording and Finalize File" manually to truncate the file at that point, or reaching the end of the audio file, which triggers the source node's completion event and automatically halts the MediaRecorder.
Upon stopping, recorded data chunks are combined into a Blob, and a download button labeled "Save Edited Audio" appears.
Two-Channel Mono and Format Limitations
Saving audio edited with this tool entails physical and technical constraints dictated by browser specifications. While exported files append _edited to the original file name, the audio format does not necessarily retain the original file extension (such as MP3 or WAV).
Data captured by MediaRecorder is encoded according to browser-supported MIME types, checking audio/webm;codecs=opus, audio/webm, and audio/mp4 before falling back to browser defaults, with the resulting Blob MIME type mapped to an appropriate file extension such as .webm or .m4a.
The tool does not provide direct encoding to WAV or MP3 upon custom user selection.
The channel configuration of output files also requires careful understanding. Even when recording in "Mono Mix" mode, channel processing duplicates the mixed signal into both left and right paths.
Setting downstream panning away from center alters left-right output balance, so keep panning centered if identical stereo channels are desired.
Consequently, the exported WEBM file is not guaranteed to have metadata strictly flagging it as a single-channel mono file.
Additionally, because mono audio lacks an independent right component, selecting "Swap L/R Channels" routes the left signal to the right.
As noted earlier, selecting "Extract R Channel Only" on a mono file produces silence due to the absence of a source right channel.
For stereo material, if identical components were recorded with inverted phases across channels, summing them in mono mix mode causes phase cancellation that may eliminate certain instruments.
Understanding these limitations allows you to combine this tool effectively with other utilities as needed.