본문으로 건너뛰기
cccskills
무료GitHub에 공개

matlab-write-audio-plugin

Guide authoring of Audio Toolbox plugins (audioPlugin, audioPluginSource) that pass validateAudioPlugin and generate deployable VST/AU code. Use when creating audio effect or generator plugins, writing classdef files inheriting from audioPlugin, or troubleshooting validateAudioPlugin failures.

한국어 요약은 준비 중입니다. 원문 설명을 표시하고 있습니다.

설치 방법 보기

포함된 파일(7)

  • SKILL.md10.1 KB
  • manifest.yaml524 B
  • references/advanced-patterns.md6.8 KB
  • references/available-functions.md9.0 KB
  • references/deep-learning.md8.0 KB
  • references/grid-layout.md3.9 KB
  • references/parameters.md1.4 KB

SKILL.md(원문)

설치하기 전에 에이전트에게 전달되는 지시 내용을 확인할 수 있습니다.

Writing Audio Plugins in MATLAB

When To Use

  • Creating audio effect or generator plugins (classdef inheriting from audioPlugin or audioPluginSource)
  • Troubleshooting validateAudioPlugin or generateAudioPlugin failures
  • Converting a MATLAB audio algorithm into a deployable VST/AU plugin
  • Integrating deep learning inference into a real-time audio plugin

When NOT To Use

  • General MATLAB class authoring unrelated to audio plugins
  • Audio file I/O, feature extraction, or analysis (no plugin involved)
  • Simulink audio processing blocks
  • Writing Audio Toolbox functions that are not plugins (e.g., audioDatastore, audioFeatureExtractor)

Structure

Every audio plugin is a classdef with %#codegen, public tunable properties, a Constant PluginInterface, and methods process + reset.

classdef MyPlugin < audioPlugin
%#codegen

    properties
        Gain = 0.5
        Cutoff = 1000
    end

    properties (Access = private)
        pSR = 44100
        pB = [1 0 0]
        pA = [1 0 0]
        pState = zeros(2, 2)  % (filterOrder, numChannels)
    end

    properties (Constant)
        PluginInterface = audioPluginInterface( ...
            audioPluginParameter('Gain', ...
                DisplayName='Gain', Label='dB', Mapping={'lin', 0, 1}), ...
            audioPluginParameter('Cutoff', ...
                DisplayName='Cutoff', Label='Hz', Mapping={'log', 20, 20000}), ...
            InputChannels=2, OutputChannels=2)
    end

    methods
        function y = process(plugin, x)
            [y, plugin.pState] = filter(plugin.pB, plugin.pA, x, plugin.pState);
            y = y * plugin.Gain;
        end

        function reset(plugin)
            plugin.pSR = getSampleRate(plugin);
            plugin.pState = zeros(2, 2);
            designFilter(plugin);
        end

        function set.Cutoff(plugin, val)
            plugin.Cutoff = val;
            designFilter(plugin); %#ok<MCSUP>
        end
    end

    methods (Access = private)
        function designFilter(plugin)
            wn = plugin.Cutoff / (plugin.pSR / 2);
            wn = max(eps, min(wn, 1 - eps));
            [plugin.pB, plugin.pA] = butter(2, wn);
        end
    end
end

Source plugins inherit audioPluginSource, omit InputChannels, and process takes no audio input — use getSamplesPerFrame(plugin) for output frame size.

System Object hybrids (matlab.System & audioPlugin) require (StrictDefaults), isInputSizeMutableImpl returning true, and stepImpl/resetImpl instead of process/reset. Use only when user requests Simulink compatibility.


Plugin Lifecycle

  1. Constructor — Construct all sub-objects with literal arguments. getSampleRate returns 44100 here; use for initial buffer sizing only.
  2. reset — Called when sample rate or frame size changes. Cache getSampleRate(plugin) in pSR. Recompute all SR-dependent values. Call reset() on every sub-object (after setting their sample rate).
  3. process — Called per audio frame. Return double output sized [N, numOutputChannels]. Never assign to properties registered in audioPluginParameter — for output meters, keep properties public but unregistered.
  4. Set methods — Recompute derived values (coefficients, buffer sizes) when parameters change. Add %#ok<MCSUP> only when the set method actually accesses another property through obj.PropertyName or calls a method that does (e.g., designFilter(plugin) from set.Cutoff). Do not add it preemptively — only suppress warnings that checkcode actually raises on that line.
  5. Save/load (optional, MATLAB-only) — Only needed when the plugin has private state that reset cannot reconstruct from parameters and sample rate (e.g., loaded data, handle sub-objects with internal buffers). Not compiled into generated VSTs/standalones — DAW hosts persist parameters via the plugin interface and call reset on restore. See references/advanced-patterns.md for the pattern.

Codegen Requirements

All code must be codegen-compatible. validateAudioPlugin sweeps 5 sample rates (8000–192000), frame sizes 2.^(1:13)+1 (max 8193), and all parameter extremes.

Always use built-in functions over hand-implementations. Prefer toolbox functions in this order: Audio Toolbox → DSP System Toolbox → Signal Processing Toolbox → base MATLAB. If unsure whether a codegen-compatible built-in exists for an operation, consult references/available-functions.md before implementing manually.

Buffers and State

Pre-allocate all state to maximum needed size. Codegen locks property size from the constructor's last assignment — allocate at the maximum the parameter can reach, then index into the active region at runtime.

Shift with indexed assignment:

buf(1:end-N) = buf(N+1:end);   % shift left by N
buf(end-N+1:end) = newData;     % fill tail

Never concatenate to shift — [buf(N+1:end); zeros(N,ch)] produces a variable-size result that codegen rejects on assignment to a fixed-size property.

Never use : on the column dimension when assigning to a fixed-size property — codegen treats x(i,:) as variable-size. Index columns explicitly: [x(i,1), x(i,2)].

Initialize arrays that will hold complex values with complex(zeros(...)) — not bare zeros(...). Codegen locks the real/complex attribute from the first assignment. If the array starts real, assigning FFT output into it later fails with "left-hand side constrained to be non-complex."

dsp.AsyncBuffer capacity must exceed the largest single write the plugin will receive. validateAudioPlugin delivers frames up to 8193 samples; account for that plus any overlap when sizing the buffer.

When filter() input comes from a sub-object (e.g., crossoverFilter), codegen cannot propagate the column count — the returned state becomes variable-size. Process channels explicitly:

[low(:,1), plugin.pState(:,1)] = filter(b, a, low(:,1), plugin.pState(:,1));
[low(:,2), plugin.pState(:,2)] = filter(b, a, low(:,2), plugin.pState(:,2));

Enum Parameters (Different-Length Values)

Use Style='dropdown' for 3+ values, 'vrocker'/'vtoggle' for exactly 2.

When enum values have different character lengths ('On'/'Off', 'Short'/'VeryLong'), prefer a separate int32 enum class file. The framework can handle char padding internally, but an explicit enum class produces cleaner generated code with typed dispatch instead of string comparisons:

% MyMode.m
classdef MyMode < int32
    enumeration
        Normal     (0)
        Aggressive (1)
        Subtle     (2)
    end
end

Plugin property: Mode = MyMode.Normal with Mapping={'enum','Normal','Aggressive','Subtle'}.

Derived Values from Parameters

When computing normalized frequency or delay indices from parameters, clamp the result:

wn = plugin.Cutoff / (plugin.pSR / 2);
wn = max(eps, min(wn, 1 - eps));   % keep in valid (0,1) range for butter/cheby

Clamp delay-line read indices to [1, bufferLength]. This prevents out-of-bounds at extreme sample rates or parameter settings that validateAudioPlugin will exercise.

Switch Completeness

Every switch that assigns a variable must include otherwise with a safe default — codegen requires all branches to define the same outputs.

Sub-Objects

Construct with literal arguments in the constructor. In reset, propagate sample rate then reset:

function reset(plugin)
    fs = getSampleRate(plugin);
    setSampleRate(plugin.pEcho, fs);
    reset(plugin.pEcho);
    plugin.pCompressor.SampleRate = fs;
    reset(plugin.pCompressor);
end

Call sub-plugins as process(plugin.pSub, x). Call System Objects as plugin.pObj(x). Forward parameter changes in set methods.

External Data and Runtime-Only Calls

  • Load data files: coder.load('data.mat') in the constructor — baked into the binary
  • Guard non-codegen calls: wrap fprintf/disp/plot in if isempty(coder.target)

Validation

validateAudioPlugin -nomex ClassName   % structural + testbench
validateAudioPlugin ClassName          % full MEX codegen
generateAudioPlugin ClassName          % produce VST/AU binary

After validation passes:

  1. Run checkcode on all produced .m files — resolve every warning by renaming or restructuring, not by adding %#ok suppressions (except %#ok<MCSUP> in set methods). Re-run checkcode to confirm zero warnings remain.
  2. Verify functional behavior: instantiate, setSampleRate, reset, process a test signal, confirm output matches intent.

Generation

Default output is VST 2. Use flags to select other formats:

FlagFormatPlatform
-vstVST 2 (default)Windows, macOS
-vst3VST 3Windows, macOS
-auAudio Unit v2macOS only
-auv3Audio Unit v3macOS only
-exeStandalone executableWindows, macOS
-juceprojectJUCE project (source code)All (including Linux)

When the user requests an output format unavailable on the current platform (e.g., AU on Windows, or any compiled binary on Linux), explain the constraint and suggest the closest alternative (-juceproject on Linux, -vst/-vst3 on Windows instead of AU).


References

  • references/available-functions.md — Built-in streaming DSP objects (prefer over manual implementations)
  • references/advanced-patterns.md — AsyncBuffer, modulated delay, save/load, codegen edge cases
  • references/parameters.md — Mapping laws, multi-bus I/O, grid layout constraints
  • references/grid-layout.md — Grid layout syntax, row allocation with DisplayNameLocation
  • references/deep-learning.md — Neural network inference with coder.loadDeepLearningNetwork

Copyright 2026 The MathWorks, Inc.

리뷰

아직 리뷰가 없습니다. 사용해 본 소감을 남겨 주세요.

댓글

로그인 없이 쓸 수 있습니다. 사용 후기, 질문, 작동하지 않은 환경 등을 편하게 남겨 주세요.

아직 댓글이 없습니다. 첫 댓글을 남겨 보세요.

보내면 바로 공개됩니다. 이메일 주소나 전화번호 같은 개인 정보는 쓰지 마세요. URL은 2개까지입니다.

0 / 1,000자

이 양식은 reCAPTCHA로 보호되며 Google 개인정보처리방침 및 서비스 약관이 적용됩니다.

같은 저장소의 스킬

Guide for accessing financial and economic data in MATLAB using the Datafeed Toolbox. Covers Bloomberg (market data via bloomberg/blp/bloombergHypermedia), FRED (Federal Reserve economic data via fredrs), Haver Analytics (economic data via haver/haverdirect/haverview), and LSEG Datastream (historical data via datastreamws). Use when connecting to any of these data providers from MATLAB.

한국어 요약은 준비 중입니다. 원문 설명을 표시하고 있습니다.

matlab/matlab-agentic-toolkit1.2천2026년 10월 14일 업데이트

Read BEFORE writing any code that adds Additive White Gaussian Noise (AWGN) to signals and converts between SNR, Eb/No, Es/No, and per-subcarrier SNR for communications simulations, using awgn(), convertSNR(), berawgn(). The default MATLAB patterns for AWGN (e.g., 'measured' option, manual SNR formulas) produce subtly incorrect results. This skill specifies the correct calling conventions, required function usage, and critical anti-patterns that must be avoided.

한국어 요약은 준비 중입니다. 원문 설명을 표시하고 있습니다.

matlab/matlab-agentic-toolkit1.2천2026년 10월 14일 업데이트

Analyze AMS waveform data using Mixed-Signal Blockset utilities: phase noise measurement, clock jitter, anti-aliased resampling, timing measurements, lock time, INL/DNL, ADC/DAC calibration, HSpice import. Use when analyzing time-domain voltage from PLL/VCO/clock simulations, measuring phase noise from variable-step solver output, computing jitter, or resampling non-uniform data.

한국어 요약은 준비 중입니다. 원문 설명을 표시하고 있습니다.

matlab/matlab-agentic-toolkit1.2천2026년 10월 14일 업데이트

Design and analyze electrically large antenna structures using MATLAB Antenna Toolbox. Covers reflector antennas (parabolic, Cassegrain, Gregorian, offset, corner, cylindrical, spherical, custom STL), reflectarrays and reconfigurable intelligent surfaces (RIS), antennas installed on platforms (vehicles, aircraft, ships, satellites), and radar cross section (RCS) analysis. Includes solver selection (MoM-PO, PO, MoM, FMM), mesh control, and GPU acceleration. Use when the user wants to design a dish/reflector antenna, reflectarray, analyze an antenna on a platform, or compute RCS.

한국어 요약은 준비 중입니다. 원문 설명을 표시하고 있습니다.

matlab/matlab-agentic-toolkit1.2천2026년 10월 14일 업데이트

Analyze data using MATLAB. Use when the task involves tables, timetables, time-series data, numeric arrays, sensor matrices, or gridded data — including but not limited to exploring, row filtering, sorting, cleaning, transforming, aggregating, smoothing, padding, trimming, and answering questions about data. MATLAB provides extensive, easy-to-use built-in functions for these workflows with no additional products required.

한국어 요약은 준비 중입니다. 원문 설명을 표시하고 있습니다.

matlab/matlab-agentic-toolkit1.2천2026년 10월 14일 업데이트

S-parameters, insertion loss, fields, currents, mesh control, and solver selection for RF PCB performance validation. TRIGGER: user asks to compute S-parameters, analyze insertion/return loss, extract fields or currents, compare MoM vs FEM, or control mesh for any RF PCB component. Invoke BEFORE writing sparameters() or solver code — API is non-obvious. SKIP: designing or creating components (use the specific matlab-design-pcb-* skill), material/stackup setup only (use matlab-manage-pcb-material), optimization sweeps (use matlab-optimize-pcb-design), PDN/IR-drop analysis (use matlab-analyze-pcb-pdn).

한국어 요약은 준비 중입니다. 원문 설명을 표시하고 있습니다.

matlab/matlab-agentic-toolkit1.2천2026년 10월 14일 업데이트

matlab의 스킬 모두 보기

이 스킬의 문제 신고