主要内容

Wavetablesynthesizer

Generate periodic signal from single-cycle waveforms

描述

WavetablesynthesizerSystem object™ generates a periodic signal with tunable properties. The periodic signal is defined by a single-cycle waveform cached as theWavetableproperty of yourWavetablesynthesizerobject.

To generate a periodic signal:

  1. 创建Wavetablesynthesizerobject and set its properties.

  2. Call the object with arguments, as if it were a function.

To learn more about how System objects work, seeWhat Are System Objects?

Creation

描述

waveSynth= wavetableSynthesizercreates a wavetable synthesizer System object,waveSynth,具有默认属性值。

waveSynth= wavetableSynthesizer(wavetableValue)sets theWavetableproperty towavetableValue

waveSynth= wavetableSynthesizer(wavetableValue,frequencyValue)sets theFrequencyproperty tofrequencyValue

WaveSynth = WaveTablessynthesizer(___,Name,Value)sets each propertyNameto the specifiedValue。Unspecified properties have default values.

例子:WaveSynth = WaveTablessynthesizer('振幅',2,'DCOffset',2.5)creates a System object,waveSynth, that generates the default sine waveform with an amplitude of 2 and a DC offset of 2.5.

Properties

expand all

Unless otherwise indicated, properties are不可否认,这意味着您在调用对象后不能更改其值。呼叫时锁定对象,然后releasefunction unlocks them.

If a property istunable, you can change its value at any time.

For more information on changing property values, seeSystem Design in MATLAB Using System Objects

Single-cycle waveform, specified as a vector of real values. The algorithm of theWavetablesynthesizerindexes into the single-cycle waveform to synthesize a periodic wave.

Tunable:Yes

Data Types:single|double

Frequency of generated signal in Hz, specified as a real scalar greater than or equal to 0.

Tunable:Yes

Data Types:single|double

生成信号的振幅,指定为大于或等于0的真实标量。

这generated signal is multiplied by the value specified byAmplitudeat the output, beforeDCOffsetis applied.

Tunable:Yes

Data Types:single|double

Normalized phase offset of generated signal, specified as a real scalar with values in the range [0, 1]. The range is a normalized 2π radians interval.

Tunable:No

Data Types:single|double

Value added to each element of the generated signal, specified as a real scalar.

Tunable:Yes

Data Types:single|double

每帧样品数量, specified as a positive integer in the range [1, 192000].

This property determines the vector length that yourWavetablesynthesizerobject outputs.

Tunable:Yes

Data Types:single|double|int8|INT16|INT32|int64|uint8|UINT16|uint32|uint64

Hz中生成信号的采样率,指定为真实的正标量。

Tunable:Yes

生成信号的数据类型,指定为'double'or'single'

Tunable:No

Data Types:char|string

Usage

描述

example

波形= waveSynth()generates a periodic signal,波形。信号的类型由算法和属性指定WavetablesynthesizerSystem object,waveSynth

Output Arguments

expand all

Waveform output from the wavetable synthesizer, returned as a column vector with length specified by theSampleSperframeproperty and data type specified by theOutputDataTypeproperty.

Data Types:single|double

Object Functions

To use an object function, specify the System object as the first input argument. For example, to release system resources of a System object namedobj,使用此语法:

release(obj)

expand all

createAudioPluginClass Create audio plugin class that implements functionality ofSystem object
parametertuner Tune object parameters while streaming
configureMIDI Configure MIDI connections between audio object and MIDI controller
disconnectMIDI Disconnect MIDI controls from audio object
getMIDIConnections 获取音频对象的MIDI连接
clone 创建重复System object
isLocked 确定是否System object正在使用
release Release resources and allow changes toSystem objectproperty values and input characteristics
重启 重置内部状态System object
step RunSystem objectalgorithm

createAudioPluginClassandconfigureMIDI功能映射可调属性WavetablesynthesizerSystem object to user-facing parameters:

Property Range Mapping Unit
Frequency [0.1, 20000] 日志 Hz
Amplitude [0, 10] linear none
DCOffset [–10,10] linear none

例子

collapse all

Define and plot a single-cycle waveform.

values = -1:0.1:1; singleCycleWave = ones(100,1) * values; singleCycleWave = reshape(singleCycleWave,numel(singleCycleWave),1); plot(singleCycleWave) xlabel('Index') ylabel('振幅')

Figure contains an axes object. The axes object contains an object of type line.

创建一个波表synthesizer,waveSynth,使用单周期波形生成楼梯波。指定10 Hz的频率。

WaveSynth = WaveTablessynthesizer(singleCycleWave,10);

Create a time scope to visualize the staircase wave generated bywaveSynth

范围= timescope(。。。'SampleRate',waveSynth.SampleRate,。。。'TimeSpanSource','Property','TimeSpan',0.1,。。。'YLimits',[-1.5,1.5],。。。'TimeSpanOverrunAction','Scroll',。。。“ showgrid',true,。。。'标题','Variable-Frequency Staircase Wave');

Place the wavetable synthesizer in an audio stream loop. Increase the frequency of your staircase wave in 10 Hz increments.

counter = 0;while(counter < 1e4) counter = counter + 1; staircaseWave = waveSynth(); scope(staircaseWave)ifmod(counter,1000)==0 waveSynth.Frequency = waveSynth.Frequency + 10;endend

采样音频文件并将其保存到Wavetable财产的Wavetablesynthesizer系统对象™。利用波表合成器manipulate your audio sample.

Read in an entire audio file. Clip out an interesting sound from the audio and then play it.

[audio,fs] = audioread('MainStreetOne-16-16-mono-12secs.wav'); aSound = audio(2.5e4:5e4); sound(aSound,fs)

创建一个波表synthesizer using your audio clip. The duration of theengineaudio clip isnumel(aSound)/fsseconds. In theWavetablesynthesizer, set theFrequency属性为1/(剪辑持续时间)。现在,生成的信号以与记录的相同速率播放。

持续时间= numel(asound)/fs;WaveSynth = WaveTablessynthesizer('Wavetable',aSound,'SampleRate',fs,。。。'Frequency',1/duration);

Create anaudioDeviceWriterto write to your audio device.

DeviceWriter = AudioDeviceWriter('SampleRate',fs);

在循环中,将Wavetable合成器播放到您的设备上。三秒钟后,开始增加可波动合成器的频率。六秒钟后,开始降低可波动合成器的频率。

timeElapsed = 0;whiletimeElapsed < 9 audioWave = waveSynth(); deviceWriter(audioWave);if(timeElapsed > 3) && (timeElapsed < 6) waveSynth.Frequency = waveSynth.Frequency + 0.001;elseif时间序列> 6波synth。endtimeElapsed = timeElapsed + waveSynth.SamplesPerFrame*(1/fs);end

Modify theWavetable财产的Wavetablesynthesizerobject while stream processing. Visualize the wavetable and play the resulting audio.

创建一个单周波形Wavetablesynthesizer索引。创建一个可挥发的合成对象。

t = 0:0.001:1; exponent = 5; waveTable = [t.^exponent,fliplr(t.^exponent)] - 0.5; waveSynth = wavetableSynthesizer('Wavetable',waveTable);

Create adsp.ArrayPlotobject to plot the wavetable as it is modified over time. Create anaudioDeviceWriterobject to listen to the signal output by your wavetable synthesizer.

arrayplotter = dsp.ArrayPlot('YLimits',[-1,1],'PlotType','Line'); deviceWriter = audioDeviceWriter;

In an audio stream loop, incrementally modify theWavetableproperty of the wavetable synthesizer and plot it. Call the synthesizer to output a waveform and play the waveform to your audio device.

ticwhiletoc < 10 exponent = exponent - 0.01; waveSynth.Wavetable = [t.^abs(exponent),fliplr(t.^abs(exponent))] - 0.5; arrayPlotter(waveSynth.Wavetable') deviceWriter(waveSynth());end

release(deviceWriter)

Create aWavetablesynthesizerto generate a waveform. Create atimescopeto visualize the waveform. Create anaudioDeviceWriterto write audio to your sound card.

FS = 44.1E3;wvsynth = wavetablessynthesizer('SampleRate',fs);范围= timescope(。。。'SampleRate',wvSynth.SampleRate,。。。'TimeSpanSource','Property','TimeSpan',1,。。。'YLimits',[-2,2],。。。'TimeSpanOverrunAction','Scroll',。。。“ showgrid',true); deviceWriter = audioDeviceWriter('SampleRate',wvsynth.samplate);

Callparametertuner在流媒体传输时打开一个UI调整Wavetable合成器的参数。

parametertuner(wvSynth)

图音频参数调谐器:wavetablesynthesizer [wvsynth]包含一个类型的uigridlayout对象。

在音频流循环中:

  1. Call the wavetable synthesizer without arguments to output one frame of data.

  2. 使用时间范围可视化数据。

  3. Write the frame of audio to your audio device for listening.

While streaming, tune parameters of the wavetable synthesizer and listen to the effect.

duration = 15; numIterations = round(wvSynth.SampleRate*duration/wvSynth.SamplesPerFrame);fori = 1:numIterations audioOut = wvSynth(); scope(audioOut) deviceWriter(audioOut); drawnowlimitrate% required to update parameterend

图音频参数调谐器:wavetablesynthesizer [wvsynth]包含一个类型的uigridlayout对象。

As a best practice, release your objects when done.

release(deviceWriter) release(wvSynth) release(scope)

Algorithms

expand all

WavetablesynthesizerSystem object synthesizes periodic signals using a cached single-cycle waveform, specified waveform properties, and phase memory.

Extended Capabilities

Introduced in R2016a