188 linhas
4.8 KiB
HTML
Arquivo Executável
188 linhas
4.8 KiB
HTML
Arquivo Executável
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
|
|
"http://www.w3.org/TR/html4/loose.dtd">
|
|
<html>
|
|
<head>
|
|
<title>Minim : : Wavetable : : value</title>
|
|
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
|
|
<link href="stylesheet.css" rel="stylesheet" type="text/css">
|
|
</head>
|
|
<body>
|
|
<center>
|
|
<table class="mainTable">
|
|
|
|
<tr>
|
|
<td class="header">
|
|
<span class="indexheader">Minim</span><br/>
|
|
<span class="indexnavigation">
|
|
<a href="index.html">core</a> |
|
|
<a href="index_ugens.html">ugens</a> |
|
|
<a href="index_analysis.html">analysis</a>
|
|
</span>
|
|
</td>
|
|
<td class="border-left"> </td>
|
|
</tr>
|
|
|
|
<tr>
|
|
<td class="classNavigation">
|
|
<p class="mainTextName"><A href="wavetable_class_wavetable.html">Wavetable</A></p>
|
|
<p class="methodName">value</p>
|
|
</td>
|
|
<td class="mainText border-left">
|
|
<p class="memberSectionHeader">Description</p>
|
|
Sample the Wavetable using a value in the range [0,1]. For instance, if
|
|
the Wavetable has 1024 values in its float array, then calling value(0.5)
|
|
will return the 512th value in the array. If the result is that it needs
|
|
say the 456.65th value, this will interpolate between the surrounding
|
|
values.
|
|
|
|
<p class="memberSectionHeader">Signature</p>
|
|
<pre>float value(float at)
|
|
</pre>
|
|
|
|
|
|
<p class="memberSectionHeader">Parameters</p>
|
|
|
|
<span class="parameterName">at</span> — <span class="parameterDescription">float: a value in the range [0, 1]</span><br/>
|
|
|
|
|
|
|
|
<p class="memberSectionHeader">Returns</p>
|
|
<p>float: this Wavetable sampled at the requested interval</p>
|
|
|
|
|
|
<p class="memberSectionHeader">Related</p>
|
|
<A href="wavetable_class_wavetable.html">Wavetable</A><BR>
|
|
|
|
|
|
<p class="memberSectionHeader">Example</p>
|
|
<pre>/**
|
|
* This sketch demonstrates many of the methods available for
|
|
* modifying Wavetables. The controls are as follows:
|
|
* <ul>
|
|
* <li>n: normalize the waveform</li>
|
|
* <li>s: smooth the waveform</li>
|
|
* <li>r: rectify the waveform</li>
|
|
* <li>z: add noise to the waveform</li>
|
|
* <li>q/a: scale the waveform up or down</li>
|
|
* <li>left click and drag: warp the waveform</li>
|
|
* <li>right click: flip the waveform around the y position of the mouse</li>
|
|
* </ul>
|
|
* The waveform shown in red is the Wavetable being used by the Oscil and
|
|
* the moving waveform in white is what the output looks like.
|
|
* <p>
|
|
* For more information about Minim and additional features,
|
|
* visit http://code.compartmental.net/minim/
|
|
*/
|
|
|
|
import ddf.minim.*;
|
|
import ddf.minim.ugens.*;
|
|
|
|
Minim minim;
|
|
AudioOutput out;
|
|
Oscil wave;
|
|
Wavetable table;
|
|
|
|
void setup()
|
|
{
|
|
size(512, 200, P3D);
|
|
|
|
minim = new Minim(this);
|
|
|
|
// use the getLineOut method of the Minim object to get an AudioOutput object
|
|
out = minim.getLineOut();
|
|
|
|
// create a reasonably complex waveform to start, will be slightly different every time
|
|
table = Waves.randomNHarms(16);
|
|
wave = new Oscil( 440, 0.5f, table );
|
|
// patch the Oscil to the output
|
|
wave.patch( out );
|
|
}
|
|
|
|
void draw()
|
|
{
|
|
background(0);
|
|
|
|
stroke(255, 64);
|
|
strokeWeight(1);
|
|
|
|
// draw the waveform of the output
|
|
for(int i = 0; i < out.bufferSize() - 1; i++)
|
|
{
|
|
line( i, 50 - out.left.get(i)*50, i+1, 50 - out.left.get(i+1)*50 );
|
|
line( i, 150 - out.right.get(i)*50, i+1, 150 - out.right.get(i+1)*50 );
|
|
}
|
|
|
|
// draw the waveform we are using in the oscillator
|
|
stroke( 200, 0, 0 );
|
|
strokeWeight(4);
|
|
for( int i = 0; i < width-1; ++i )
|
|
{
|
|
point( i, height/2 - (height*0.49) * table.value( (float)i / width ) );
|
|
}
|
|
}
|
|
|
|
void keyPressed()
|
|
{
|
|
switch( key )
|
|
{
|
|
case 'n':
|
|
// scale the table so that the largest value is -1/1.
|
|
table.normalize();
|
|
break;
|
|
|
|
case 's':
|
|
// smooth out the table, similar to applying a low pass filter
|
|
table.smooth( 64 );
|
|
break;
|
|
|
|
case 'r':
|
|
// change all negative values to positive values
|
|
table.rectify();
|
|
break;
|
|
|
|
case 'z':
|
|
// add some noise
|
|
table.addNoise( 0.1f );
|
|
break;
|
|
|
|
case 'q':
|
|
table.scale( 1.1f );
|
|
break;
|
|
|
|
case 'a':
|
|
table.scale( 0.9f );
|
|
break;
|
|
|
|
default: break;
|
|
}
|
|
}
|
|
|
|
void mousePressed()
|
|
{
|
|
if ( mouseButton == RIGHT )
|
|
{
|
|
float flipPoint = map( mouseY, 0, height, 1, -1 );
|
|
table.flip( flipPoint );
|
|
}
|
|
}
|
|
|
|
void mouseDragged()
|
|
{
|
|
if ( mouseButton == LEFT )
|
|
{
|
|
float warpPoint = constrain( (float)pmouseX / width, 0, 1 );
|
|
float warpTarget = constrain( (float)mouseX / width, 0, 1 );
|
|
table.warp( warpPoint, warpTarget );
|
|
}
|
|
}
|
|
</pre>
|
|
|
|
<p class="memberSectionHeader">Usage</p>
|
|
Web & Application
|
|
</td>
|
|
</tr>
|
|
</table>
|
|
</center>
|
|
</body>
|
|
</html>
|