sound/drivers/opl3/opl3_synth.c
Source file repositories/reference/linux-study-clean/sound/drivers/opl3/opl3_synth.c
File Facts
- System
- Linux kernel
- Corpus path
sound/drivers/opl3/opl3_synth.c- Extension
.c- Size
- 16390 bytes
- Lines
- 607
- Domain
- Driver Families
- Bucket
- sound/drivers
- Inferred role
- Driver Families: exported/initcall integration point
- Status
- integration implementation candidate
Why This File Exists
Repeatable hardware-adapter layer. Deep compatibility for every driver is out of scope; this atlas records patterns, probe lifecycles, bus glue, IRQ/DMA usage, and links back to core abstractions.
- Repeatable hardware-adapter layer. Deep compatibility for every driver is out of scope; this atlas records patterns, probe lifecycles, bus glue, IRQ/DMA usage, and links back to core abstractions.
- Exports symbols or registers init work; inspect boot/module ordering and who consumes the exported contract.
- Touches user memory; correctness depends on fault-safe copying and privilege boundary handling.
- Allocates kernel memory; connect allocation flags and lifetime to context constraints.
- Defines or uses C structs; map object ownership, embedded links, reference counts, and lock ownership.
Dependency Surface
linux/slab.hlinux/export.hlinux/nospec.hsound/opl3.hsound/asound_fm.hopl3_voice.h
Detected Declarations
function snd_opl3_openfunction snd_opl3_ioctlfunction snd_opl3_releasefunction snd_opl3_writefunction headerfunction snd_opl3_clear_patchesfunction snd_opl3_resetfunction snd_opl3_play_notefunction snd_opl3_set_voicefunction snd_opl3_set_paramsfunction snd_opl3_set_modefunction snd_opl3_set_connectionexport snd_opl3_regmapexport snd_opl3_load_patchexport snd_opl3_find_patchexport snd_opl3_reset
Annotated Snippet
if (i < MAX_OPL2_VOICES) {
/* Left register block for voices 0 .. 8 */
reg_side = OPL3_LEFT;
voice_offset = i;
} else {
/* Right register block for voices 9 .. 17 */
reg_side = OPL3_RIGHT;
voice_offset = i - MAX_OPL2_VOICES;
}
opl3_reg = reg_side | (OPL3_REG_KSL_LEVEL + snd_opl3_regmap[voice_offset][0]);
opl3->command(opl3, opl3_reg, OPL3_TOTAL_LEVEL_MASK); /* Operator 1 volume */
opl3_reg = reg_side | (OPL3_REG_KSL_LEVEL + snd_opl3_regmap[voice_offset][1]);
opl3->command(opl3, opl3_reg, OPL3_TOTAL_LEVEL_MASK); /* Operator 2 volume */
opl3_reg = reg_side | (OPL3_REG_KEYON_BLOCK + voice_offset);
opl3->command(opl3, opl3_reg, 0x00); /* Note off */
}
opl3->max_voices = MAX_OPL2_VOICES;
opl3->fm_mode = SNDRV_DM_FM_MODE_OPL2;
opl3->command(opl3, OPL3_LEFT | OPL3_REG_TEST, OPL3_ENABLE_WAVE_SELECT);
opl3->command(opl3, OPL3_LEFT | OPL3_REG_PERCUSSION, 0x00); /* Melodic mode */
opl3->rhythm = 0;
}
EXPORT_SYMBOL(snd_opl3_reset);
static int snd_opl3_play_note(struct snd_opl3 * opl3, struct snd_dm_fm_note * note)
{
unsigned short reg_side;
unsigned char voice_offset;
unsigned short opl3_reg;
unsigned char reg_val;
/* Voices 0 - 8 in OPL2 mode */
/* Voices 0 - 17 in OPL3 mode */
if (note->voice >= ((opl3->fm_mode == SNDRV_DM_FM_MODE_OPL3) ?
MAX_OPL3_VOICES : MAX_OPL2_VOICES))
return -EINVAL;
/* Get register array side and offset of voice */
if (note->voice < MAX_OPL2_VOICES) {
/* Left register block for voices 0 .. 8 */
reg_side = OPL3_LEFT;
voice_offset = note->voice;
} else {
/* Right register block for voices 9 .. 17 */
reg_side = OPL3_RIGHT;
voice_offset = note->voice - MAX_OPL2_VOICES;
}
/* Set lower 8 bits of note frequency */
reg_val = (unsigned char) note->fnum;
opl3_reg = reg_side | (OPL3_REG_FNUM_LOW + voice_offset);
opl3->command(opl3, opl3_reg, reg_val);
reg_val = 0x00;
/* Set output sound flag */
if (note->key_on)
reg_val |= OPL3_KEYON_BIT;
/* Set octave */
reg_val |= (note->octave << 2) & OPL3_BLOCKNUM_MASK;
/* Set higher 2 bits of note frequency */
reg_val |= (unsigned char) (note->fnum >> 8) & OPL3_FNUM_HIGH_MASK;
/* Set OPL3 KEYON_BLOCK register of requested voice */
opl3_reg = reg_side | (OPL3_REG_KEYON_BLOCK + voice_offset);
opl3->command(opl3, opl3_reg, reg_val);
return 0;
}
static int snd_opl3_set_voice(struct snd_opl3 * opl3, struct snd_dm_fm_voice * voice)
{
unsigned short reg_side;
unsigned char op_offset;
unsigned char voice_offset, voice_op;
unsigned short opl3_reg;
unsigned char reg_val;
/* Only operators 1 and 2 */
if (voice->op > 1)
return -EINVAL;
/* Voices 0 - 8 in OPL2 mode */
/* Voices 0 - 17 in OPL3 mode */
if (voice->voice >= ((opl3->fm_mode == SNDRV_DM_FM_MODE_OPL3) ?
Annotation
- Immediate include surface: `linux/slab.h`, `linux/export.h`, `linux/nospec.h`, `sound/opl3.h`, `sound/asound_fm.h`, `opl3_voice.h`.
- Detected declarations: `function snd_opl3_open`, `function snd_opl3_ioctl`, `function snd_opl3_release`, `function snd_opl3_write`, `function header`, `function snd_opl3_clear_patches`, `function snd_opl3_reset`, `function snd_opl3_play_note`, `function snd_opl3_set_voice`, `function snd_opl3_set_params`.
- Atlas domain: Driver Families / sound/drivers.
- Implementation status: integration implementation candidate.
- This snippet crosses the user/kernel memory boundary; validate fault handling and access checks before translating the pattern.
Implementation Notes
- This generated page is the file-by-file coverage layer; curated subsystem chapters should link here when they synthesize a multi-file control flow.
- Core OS pages should be promoted from atlas-only to deep-reviewed when they explain data structures, invariants, locking, lifecycle, and C implementation snippets.
- Driver-family pages are intentionally pattern-oriented unless they are part of the selected PCIe/NVMe representative device path.