Tone: Difference between revisions

From Avisynth wiki
Jump to navigationJump to search
Raffriff42 (talk | contribs)
m note re: default sample_type
Raffriff42 (talk | contribs)
formatting, links, equations
Line 1: Line 1:
{{Template:FuncDef|Tone(float ''length'', float ''frequency'', int ''samplerate'', int ''channels'', string ''type'', float ''level'')}}
This will generate sound at a given {{FuncArg|frequency}} for a given {{FuncArg|length}} of time in seconds.


This will generate sound at a given ''frequency'' for a given ''length'' of time in seconds.


;length
{{Template:FuncDef|Tone( [ float ''length'', float ''frequency'', int ''samplerate'', int ''channels'', string ''type'', float ''level'' ] )}}
:Length of time in seconds. Default = 10.0.
 
;frequency
:{{Par2|length|float|10.0}}
: Tone frequency. Default = 440.
::Length of time in seconds.
;samplerate
 
: Audio sample rate. Default = 48000.
:{{Par2|frequency|float|440}}
;channels
::Tone frequency.
: Number of audio channels. Default = 2.
 
;type
:{{Par2|samplerate|int|48000}}
: "Silence", "Sine", "Noise", "Square", "Triangle" or "Sawtooth". Default = "Sine".
::Audio sample rate.
;level
 
: The amplitude of the waveform. Default = maximum = 1.0.
:{{Par2|channels|int|2}}
::Number of audio channels.
 
:{{Par2|type|string|"Sine"}}
::"Silence", "Sine", "Noise", "Square", "Triangle" or "Sawtooth".  
 
:{{Par2|level|float|1.0}}
::The amplitude of the waveform. Default = 1.0 (or 0[[Wikipedia:Decibel|dB]], the maximum level possible without [[Wikipedia:Clipping_%28audio%29|clipping]]).
::For a particular decibel level, use the equation {{FuncArg|level}} = 10<sup> dB / 20</sup>
::For example, {{FuncArg|level}} = 0.251 gives a -12dB tone.




Line 20: Line 28:




{| border=1 cellspacing=0 cellpadding=5
==== Discussion ====
| [[Image:Tone.jpg]]
<div style="width:600px; margin:0.5em 0.5em 0.5em 1.5em; border:none;">
{| border="0" cellspacing=0 cellpadding=5
|style="text-align:left;"|[[Image:Tone.jpg]]
|-
|-
| Tone(frequency=2, samplerate=48000, channels=2, type="sine", level=0.4)
|style="text-align:left;"|<tt>Tone(frequency=2, samplerate=48000, channels=2, type="sine", level=0.4)</tt>
|}
|}
In the figure above, a sinus is generated (on a gray clip with framerate 24 fps). The period of the waveform (in frames) is the framerate divided by ''frequency'' (or fps/freq, which is 24/2=12 frames in our example). The part of the graph which is light-green represents all samples of the frame under consideration (which is frame 1 here). The number of samples in a particular frame is given by the ''samplerate'' divided by the framerate (which is 48000/24 = 2000 samples in our example). (Note that the bars are made with [[Histogram]] and the graph with the AudioGraph plugin.)
</div>
 
:In the figure above, a sinus is generated (on a gray clip with framerate 24 fps). :The period of the waveform (in frames) is the ''framerate'' divided by ''frequency'' (or fps/freq, which is 24/2=12 frames in our example). The part of the graph which is light-green represents all samples of the frame under consideration (which is frame 1 here). The number of samples in a particular frame is given by the ''samplerate'' divided by the ''framerate'' (which is 48000/24 = 2000 samples in our example).  
More generally, the waveform above is described by
 
g(n,s) = level * sin(2*pi*(frequency*n/framerate + s*frequency/samplerate))
 
with "n" the frame and "s" the sample under consideration (note that s runs from 0 to samplerate/framerate - 1).


In the example above, this reduces to
:More generally, the waveform above is described by
::{{Serif|''g''(''n,s'')}} = {{Serif|''level '''·''' sin''(2 '''·''' ''pi '''·''' ''(''frequency '''·''' n ''/'' framerate + s '''·''' frequency'' / ''samplerate''))}}
:with {{Serif|''n''}} the frame and {{Serif|''s''}} the sample under consideration (note that {{Serif|''s''}} runs from 0 to samplerate/framerate - 1).


g(n,s) = 0.4 * sin(2*pi*(2*n/24 + s*2/48000))
:In the example above, this reduces to
::{{Serif|''g''(''n,s'')}} = {{Serif|0.4 '''·''' ''sin''(2 '''·''' ''pi '''·''' ''(2 '''·''' ''n ''/ 24 ''+ s '''·''' ''2 / 48000))}}
:with {{Serif|''n''}} the frame and {{Serif|''s''}} the sample under consideration (note that {{Serif|''s''}} runs from 0 to 1999).


with "n" the frame and "s" the sample under consideration (note that s runs from 0 to 1999).
:Note that the bars are made with [[Histogram]] and the graph with the [[AudioGraph]] plugin.  


==== Examples ====
:[http://forum.doom9.org/showthread.php?t=172979 ''We Wish You a Merry Christmas''], in harmony (author hanzfrunz)


'''Changes:'''
==== Changes ====
{| border="1"
{| border="1"
|-  
|-  

Revision as of 09:05, 13 January 2016

This will generate sound at a given frequency for a given length of time in seconds.


Tone( [ float length, float frequency, int samplerate, int channels, string type, float level ] )

float  length = 10.0
Length of time in seconds.
float  frequency = 440
Tone frequency.
int  samplerate = 48000
Audio sample rate.
int  channels = 2
Number of audio channels.
string  type = "Sine"
"Silence", "Sine", "Noise", "Square", "Triangle" or "Sawtooth".
float  level = 1.0
The amplitude of the waveform. Default = 1.0 (or 0dB, the maximum level possible without clipping).
For a particular decibel level, use the equation level = 10 dB / 20
For example, level = 0.251 gives a -12dB tone.


The audio sample type is 32-bit float. Use ConvertAudio if this is not what you want.


Discussion

Tone(frequency=2, samplerate=48000, channels=2, type="sine", level=0.4)
In the figure above, a sinus is generated (on a gray clip with framerate 24 fps). :The period of the waveform (in frames) is the framerate divided by frequency (or fps/freq, which is 24/2=12 frames in our example). The part of the graph which is light-green represents all samples of the frame under consideration (which is frame 1 here). The number of samples in a particular frame is given by the samplerate divided by the framerate (which is 48000/24 = 2000 samples in our example).
More generally, the waveform above is described by
g(n,s) = level · sin(2 · pi · (frequency · n / framerate + s · frequency / samplerate))
with n the frame and s the sample under consideration (note that s runs from 0 to samplerate/framerate - 1).
In the example above, this reduces to
g(n,s) = 0.4 · sin(2 · pi · (2 · n / 24 + s · 2 / 48000))
with n the frame and s the sample under consideration (note that s runs from 0 to 1999).
Note that the bars are made with Histogram and the graph with the AudioGraph plugin.

Examples

We Wish You a Merry Christmas, in harmony (author hanzfrunz)

Changes

v2.56 Added Level in v2.56.
v2.54 Initial Release.