Skip to content

Commit 382e556

Browse files
committed
Add missing feedback from #350
I had forgotten to force-push, oops :(
1 parent 1a6ca71 commit 382e556

File tree

2 files changed

+22
-9
lines changed

2 files changed

+22
-9
lines changed

src/Audio_Registers.md

+10-5
Original file line numberDiff line numberDiff line change
@@ -163,7 +163,7 @@ Bit 3 - Envelope direction (0=Decrease, 1=Increase)
163163
Bit 2-0 - Sweep pace (0=No Sweep)
164164
```
165165

166-
Setting bits 3-7 of this register all to 0 turns the DAC off (and thus, the channel as well).
166+
Setting bits 3-7 of this register all to 0 turns the DAC off (and thus, the channel as well), which [may cause an audio pop](<#Mixer>).
167167

168168
The envelope ticks at 64 Hz, and the channel's envelope will be increased / decreased (depending on bit 3) every <var>Sweep pace</var> of those ticks.
169169

@@ -217,14 +217,16 @@ Like other channels, turning the DAC off immediately turns the channel off as we
217217
Bit 7 - Sound Channel 3 DAC (0=Off, 1=On)
218218
```
219219

220-
The channel is often turned off just before writing to [wave RAM](<#FF30–FF3F — Wave pattern RAM>) to avoid issues with accessing it; see there for more info.
220+
The DAC is often turned off just before writing to [wave RAM](<#FF30–FF3F — Wave pattern RAM>) to avoid issues with accessing it; see further below for more info.
221+
222+
Turning the DAC off [may cause an audio pop](<#Mixer>).
221223

222224
### FF1B — NR31: Channel 3 length timer \[write-only\]
223225

224226
This register controls the channel's [length timer](<#Length timer>).
225227

226228
```
227-
Bit 5-0 - length timer
229+
Bit 7-0 - length timer
228230
```
229231

230232
The higher the [length timer](<#Length timer>), the shorter the time before the channel is cut.
@@ -314,13 +316,16 @@ So, from the CPU's point of view, wave RAM reads out the same byte, regardless o
314316

315317
## Sound Channel 4 — Noise
316318

317-
This channel is used to output white noise, which is done by randomly switching the amplitude between two levels fairly fast.
319+
This channel is used to output white noise[^not_white], which is done by randomly switching the amplitude between two levels fairly fast.
318320

319321
The frequency can be adjusted in order to make the noise appear "harder" (lower frequency) or "softer" (higher frequency).
320322

321323
The random function that switches the output level can also be manipulated.
322324
Certain settings can cause the wave to be more regular, sounding closer to a pulse than noise.
323325

326+
[^not_white]:
327+
By default, the noise will sound close to white; but it can be manipulated to sound differently.
328+
324329
### FF20 — NR41: Channel 4 length timer \[write-only\]
325330

326331
This register controls the channel's [length timer](<#Length timer>).
@@ -341,7 +346,7 @@ Bit 3 - Envelope direction (0=Decrease, 1=Increase)
341346
Bit 2-0 - Sweep pace (0=No Sweep)
342347
```
343348

344-
Setting bits 3-7 of this register all to 0 turns the DAC off (and thus, the channel as well).
349+
Setting bits 3-7 of this register all to 0 turns the DAC off (and thus, the channel as well), which [may cause an audio pop](<#Mixer>).
345350

346351
The envelope ticks at 64 Hz, and the channel's envelope will be increased / decreased (depending on bit 3) every <var>Sweep pace</var> of those ticks.
347352

src/Audio_details.md

+12-4
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ tl;dr:
5050
Each of the four "conceptual" channels is composed of a "generation" circuit (designated "channel" in the above diagram), and a [DAC](https://en.wikipedia.org/wiki/Digital-to-analog_converter).
5151
The digital value produced by the generator, which ranges between $0 and $F (0 and 15), is linearly translated by the DAC into an analog[^digital_analog] value between -1 and 1 (the unit is arbitrary).
5252

53-
The four analog channel outputs are then fed into the mixer[^vin], which selectively adds them (depending on [`NR51`](<#FF25 — NR51: Sound panning>)) into two analog outputs (Left and Right).
53+
The four analog channel outputs are then fed into the mixer[^vin], which selectively adds them (depending on [`NR51`]) into two analog outputs (Left and Right).
5454
Thus, the analog range of those outputs is 4× that of each channel, -4 to 4.
5555

5656
Then, both of these two get their respective volume scaled, once from [`NR50`](<#FF24 — NR50: Master volume & VIN panning>), and once from the volume knob (if the console has one).
@@ -103,11 +103,17 @@ Indicated values are under normal operation; the frequencies will obviously diff
103103
A high-pass filter (HPF) removes constant biases over time.
104104
The HPFs therefore remove the DC offset created by inactive channels with an enabled DAC, and off-center waveforms.
105105

106-
Enabling or disabling a DAC ([see below](#DACs)), adding or removing it using NR51, or changing the volume in NR50, will cause an audio "pop".
106+
::: tip Avoiding audio pops
107+
108+
Enabling or disabling a DAC ([see below](#DACs)), adding or removing it using NR51, or changing the volume in NR50, will cause an audio pop.
107109
(All of these actions cause a change in DC offset, which is smoothed out by the HPFs over time, but still creates a pop.)
108110

111+
To avoid this, a sound driver should avoid turning the DACs off; this can be done by writing $08 to `NRx2` (silences the channel but keeps the DAC on) then $80 to `NRx4` to retrigger the channel and reload `NRx2`.
112+
113+
:::
114+
109115
The HPF is more aggressive on GBA than on GBC, which itself is more aggressive than on DMG.
110-
(The more "aggressive" a HPF, the faster it pulls the signal towards "analog 0"; this reduces the pops, but tends to also distort waveforms.)
116+
(The more "aggressive" a HPF, the faster it pulls the signal towards "analog 0"; this tends to also distort waveforms.)
111117

112118
### DACs
113119

@@ -183,10 +189,12 @@ This does not happen under regular operation, but can be achieved by switching f
183189
## Game Boy Advance audio
184190

185191
The APU was reworked pretty heavily for the GBA, which introduces some slightly different behavior:
186-
- Instead of mixing being done analogically, it's instead done digitally; then, sound is converted to an analog signal and an offset is added (see `SOUNDBIAS` in [GBATEK](http://problemkaputt.de/gbatek.htm#gbasoundcontrolregisters) for more details).
192+
- Instead of mixing being done by analog circuitry, it's instead done digitally; then, sound is converted to an analog signal and an offset is added (see `SOUNDBIAS` in [GBATEK](http://problemkaputt.de/gbatek.htm#gbasoundcontrolregisters) for more details).
187193
- This also means that the GBA APU has no DACs.
188194
Instead, they are emulated digitally such that a disabled "DAC" behaves like an enabled DAC receiving 0 as its input.
189195
- Additionally, CH3's DAC has its output inverted.
190196
In particular, this causes the channel to emit a loud spike when disabled; therefore, it's a good idea to "disconnect" the channel using NR51 before accessing wave RAM.
191197

192198
None of the additional features (more wave RAM, digital FIFOs, etc.) are available to CGB programs.
199+
200+
[`NR51`]: <#FF25 — NR51: Sound panning>

0 commit comments

Comments
 (0)