Creation Needs Tools

Friday, May 25, 2007

Lemur




The Lemur is a top of the range control surface for audio and media applications,
that breaks from the prior art on several grounds. Its major innovation consists in its
brilliant modular graphic interface concept and its exclusive multitouch sensor
technology. The continiously growing palette of configurable graphic objects
enables you to design made-to-measure interfaces by using the free available
JazzEditor
. This endows the Lemur with the unique and protocol independant
capacity to adapt its behavior according to the application you are controlling:
sequencers, modular synthesizers, virtual instruments, VJ software, 3D animation
tools and light control.
Working with Logic(tm), Protools(tm), Ableton Live(tm), Nuendo(tm), Cubase(tm), Sonar(tm) or Digital Performer(tm)
is maximized to interact with programs and installations based on Modul8, Jitter, Flash, Isadora, Director or Processing.
http://www.jazzmutant.com/videos/lemurlight.mov
www.jazzmutant.com

Beat detection



have broken the FFT into zones and are dealing with them instead of individual
frequencies. Probably should have been doing that from the start, but oh well,
live and learn.

Each zone is assigned a threshold. This threshold is based on the average of the
FFT frequencies with its zone. The if the average is greater than the threshold, a
beat will trigger. I then assign the threshold a value slightly greater than the peak
average that triggered the beat in the first place. After a short duration, the threshold
slowly lowers until another beat is triggered.

Tuesday, May 22, 2007

sound Wave


package {
//导入类
//Sprite是一个只有一帧的MovieClip,相对于MovieClip少了帧和场景...
import flash.display.Sprite;
//混合模式类
import flash.display.BlendMode;
//事件类
import flash.events.*;
//声音类
import flash.media.Sound;
//混音器类
import flash.media.SoundMixer;
//声道类
import flash.media.SoundChannel;
//URLRequest类
import flash.net.URLRequest;
//ByteArray类
import flash.utils.ByteArray;
//位图类
import flash.display.Bitmap;
import flash.display.BitmapData;
//滤镜类
import flash.filters.BlurFilter;
import flash.filters.ColorMatrixFilter;
//滤镜品质类
import flash.filters.BitmapFilterQuality;
//矩形类
import flash.geom.Rectangle;
//Point类(点)
import flash.geom.Point;
//定义类
public class SwfdongSound extends Sprite {
//声明用来包含line和bg的Sprite
private var Main:Sprite=new Sprite;
//声明用来画线的Sprite
private var line:Sprite=new Sprite;
//声明用来放位图数据的BitmapData
private var bmpData:BitmapData=new BitmapData(350,200,true,0xFF0);
//声明用来显示效果的Bitmap
private var bmp:Bitmap=new Bitmap(bmpData);
//声明MP3路径
private var url: It.mp3";
//声明一个Sound对象
private var DongSound:Sound=new Sound;
//声明一个SoundChannel对象
private var sChannel:SoundChannel;
//声明一个ByteArray对象
private var bArray:ByteArray=new ByteArray;
//声明一个数组对象
private var Ary:Array;
//声明两个数字对象
private var n:Number=0;
private var c:Number=0;
//声明一个ColorMatrix滤镜
private var colorM:ColorMatrixFilter=new ColorMatrixFilter([0.95,0,0,0,0,0,0.95,0,0,0,0,0,0.95,0,0,0,0,0,0.55,0,]);

//声明一个BlurFilter滤镜
private var blur:BlurFilter=new BlurFilter(3,3,BitmapFilterQuality.LOW);
//声明一个矩形
private var r:Rectangle=new Rectangle(0,0,350,200);
//声明一个点
private var p:Point=new Point(0,0);
//类构造函数
public function SwfdongSound() {

//Main的混合模式为"添加"
Main.blendMode=BlendMode.ADD;
//在舞台上显示各个部分
Main.addChild(bmp);
Main.addChild(line);
addChild(Main);
//将字符串转化为URLRequest
var req:URLRequest=new URLRequest(url);
//加载歌曲
DongSound.load(req);
//播放
DongSound.play();
//添加一个EnterFrame的侦听器,同以前的this.onEnterFrame=showBar();
this.addEventListener(Event.ENTER_FRAME,showBar);
}
private function showBar(event:Event) {
n=0;
//这里是为了每2次才执行一次滤镜而做的if,如果需要让原来的波形图消失的更慢就把2改成更大的数字
if (c % 2 == 0) {
//将Main的内容绘制到bmpData
bmpData.draw(Main);
//应用滤镜
bmpData.applyFilter(bmpData,r,p,colorM);
bmpData.applyFilter(bmpData,r,p,blur);
}
c++;
//清除绘图
line.graphics.clear();
//设置线条样式,颜色湖蓝,宽度1,透明度100
line.graphics.lineStyle(1,0x0099FF,100);
//将当前声音输出为ByteArray,注意哦,这次用的是false,上次是true
SoundMixer.computeSpectrum(bArray,false,0);
for (var i=0; i < n="bArray.readFloat();" n="n">

Sunday, May 20, 2007

flash.diaplay.beginGradientFill

*例子引用了来自Afeila Studio的部分源代码
*/
createEmptyMovieClip("mcBoardHS", depth++);
with (mcBoardHS) {
_x = 5;
_y = 25;
//下面四行是设定添色的参数
var colors = [0xFF0000, 0xFFFF00, 0x00FF00, 0x00FFFF, 0x0000FF, 0xFF00FF, 0xFF0000];
var alphas = [100, 100, 100, 100, 100, 100, 100];
var ratios = [0x00, 0x2A, 0x55, 0x7F, 0xAA, 0xD4, 0xFF];
var matrix = {matrixType:"box", x:0, y:0, w:96, h:96, r:0};
beginGradientFill("linear", colors, alphas, ratios, matrix);
//画一个宽高都是96的长方形
drawRect(mcBoardHS, 96, 96);
endFill();

//下面画了一个灰度,和色彩交叠呈现了调色板的样子
colors = [0x808080, 0x808080];
alphas = [0, 100];
ratios = [0x00, 0xFF];
matrix = {matrixType:"box", x:0, y:0, w:96, h:96, r:0.5*Math.PI};
beginGradientFill("linear", colors, alphas, ratios, matrix);
drawRect(mcBoardHS, 96, 96);
endFill();
}
//在这个例子中我们只是借下面的函数画一个长方形
function drawRect(mc, w, h, oX, oY, lW, c0, c1) {
//画一个宽w高h亮色c0,暗色c1的带阴影的框
}
然后看图吧:flash自带的调色器说明了那些参数的意义

绿色的为例,RGB码是0x00ff00;然后是alpha(透明度);我一直不理解的是那个ratios ,现在折线指明了,这个参数等效于调色器里边的那些相应颜色的控制点。
var matrix = {matrixType:"box", x:0, y:0, w:96, h:96, r:0};
这句的属性,可以参考设计面板的那个添色工具。
改用eclipse

Thursday, May 17, 2007

AS3 SoundMixer.computeSpectrum

.media.Sound是AS3.0处理声音的类,支持mp3。
使用f9a可以使嵌入的声音被支持的格式范围变大,但是和编程无关。
使用这个类可以让flash播放出声音:嵌入的声音
import *;
class EmbedSoundExample extends Sprite{
[Embed (source="Cubana.mp3")]
var EmbedSound:Class;
public function EmbedSoundExample(){
var sd:Sound = new EmbedSound();
sd।play();
}
}

簡単使用外部声音,记得注册监听器,方法参考Sound.load,
和任何一个产生Event.COMPLETE事件的EventDispatcher一样处理,不再详述。
总之,现在可以听见声音了。留心:
play(p1,p2,st:SoundTransform);第三个参数。
SoundTransform 是声音的变换,就是调节左右声道音量大小的
SoundMixer(混响器)是一个静态类。用来提供对所以声音的全局的支持。
这个类的其中一个可以赋值的属性是SoundTransform类型的。这样,
SoundMixer就能操作这个SoundTransform了。虽然没有什么用,但是通过
这样的赋值就可以把Sound实例和这个静态类关联起来,从而使用SoundMixer.computeSpectrum
方法来计算正在播放的声音当前的频率信息。

SoundMixer.computeSpectrum(输出数组:ByteArray, 输出模式:Boolean(布朗值) = false, 伸长因数:int[整数] = 0)

第一个参数
:
这个ByteArray的结构,是512个浮点数,前256个是左声道的波谱数据,后256个是右声道的波谱数据,而经过多次trace...我发现如果用for(var i=0;i<256,i+=2[这里可以换成任何2的倍数])来读取波谱数据的话,会自动读取ByteArray[ i ]的数据,这一点大大方便了可视化声音效果的制作...

第二个参数
:

如果把输出模式(第二个参数)设置为true的话,适合做条形图或者是环形图,设置成false,就是用来做波形图

第三个参数:
"伸长因数",如果设置成0,数据会以44.1 KHz取样;设置成1,以22.05 KHz取样,设置成2,以11.025KHz取样(所以0是最优的取样质量)
参数是采样率,基数是1/2。参数值默认是0,这表示1/2的0次方,原声采样;1表示1/2的1次方,
采样率是原来的1/2。当然不会希望只采样一次,所以要决定间隔多少时间采样一次,

package {
//导入类
//Sprite是一个只有一帧的MovieClip,相对于MovieClip少了帧和场景...
import flash.display.Sprite;
//事件类
import flash.events.*;
//声音类
import flash.media.Sound;
//混音器类
import flash.media.SoundMixer;
//声音通道类(暂时这么翻吧)
import flash.media.SoundChannel;
//URLRequest类
import flash.net.URLRequest;
//二进制数组类
import flash.utils.ByteArray;
//定义类
public class SwfdongSound extends Sprite {
//声明MP3路径
private var url:String = "MySound.mp3";
//声明一个Sound对象
private var DongSound:Sound = new Sound();
//声明一个SoundChannel对象
private var sChannel:SoundChannel;
//声明一个ByteArray对象
private var bArray:ByteArray = new ByteArray();
//声明一个数组对象
private var Ary:Array;
//声明一个数字对象
private var n:Number = 0;
//初始化函数
public function SwfdongSound() {
var req:URLRequest = new URLRequest(url);
DongSound.load(req);
//播放
DongSound.play();
//添加一个EnterFrame的侦听器,同以前的this.onEnterFrame=showBar();
this.addEventListener(Event.ENTER_FRAME,showBar);
}
private function showBar(event:Event){
n = 0;
//清除绘图
this.graphics.clear();
//将当前声音输出为ByteArray
SoundMixer.computeSpectrum(bArray,true,0);
for(var i=0; i < 256; i=i+16){
//在ByteArray中读取一个32位的单精度浮点数(这个是livedoc上写的,实际就是把数据流读取成浮点数)
n = bArray.readFloat();
//这个实际作用是把n扩大一下
var num:Number = n*360;
//设置线条样式,颜色湖蓝,宽度10,透明度100
this.graphics.lineStyle(10,0x99FF00,100,false,"noSacle","none");
//移动到x坐标50+i,y坐标200的位置
this.graphics.moveTo(50+i,200);
//向上画图
this.graphics.lineTo(50+i,200-num/5);
}

}
}
}

这里有两个要点:
1.新的EnterFrame的用法,大家应该可以看到了吧:
this.addEventListener(Event.ENTER_FRAME,yourfunction);

2.波谱数据的读法:
先输出一个ByteArray,然后转成浮点数,再用For来生成跳动的条条(如果你希望条的数量多一些,就把i每次加的数量减少就可以了)...当然,你可以发挥想象力,做出线性,变颜色的(如外国闪客的"圆环套圆环")...




var timer:Timer = new Timer(interval_here);
//多长时间一次自己决定吧。
timer.addEventListener("timer",snap);
//唉,snap是快照唉,
timer.start();
这样就能每隔 interval_here 毫秒计算一次了。不要使用setInterval,
不要使用Event.ENTER_FRAME,
开始写代码:
package {
import flash.display.*;
import flash.events.Event;
import flash.media.Sound;
import flash.media.SoundTransform;
import flash.media.SoundMixer;
import flash।net।URLRequest;
import flash.utils.ByteArray;
import flash.utils.Timer;
//在Flash8発表用的代码 /
public class SoundSoundSound extends Sprite{
//默认采用计算波形 /
public var fft:Boolean = false;
//constructor兼main
//嵌入声音 //
[Embed(source="Cubana.mp3")]
private var EmbedSound:
Class; public function SoundSoundSound(){
//请stage不要缩放
scaleMode = StageScaleMode।NO_SCALE;
//为了防止上传文件太大,我还是使用外部声音咯,其实我也没打算上传文件--b
//创建一个声音对象,并加在外部声音资源
var sd:Sound = new Sound();
सद.addEventListener(Event।COMPLETE,onComplete);
sd.load(new URLRequest("Cubana.mp3"));
//嵌入声音这样使用咯
var sd:Sound = new Sound();
एस.play(0,0,SoundMixer।soundTransform = new SoundTransform());
*/ //用timer的好处是可以方便的停掉它,但是这里没有体现
var timer:Timer = new Timer(10);
//设置10毫秒
timer.addEventListener("timer",onEnterFrame); timer.start(); }
//如果使用外部声音,要使用监听器
private function onComplete(e:Event):void{ Sound(e.target).play(0,0,SoundMixer.soundTransform = new SoundTransform()); }
//param e timer事件 /
private function onEnterFrame(e:Event):void{
//准备一个ByteArray实例
var b:ByteArray = new ByteArray();
//计算频率,并填充到上面创建的ByteArray实例
SoundMixer.computeSpectrum(b,fft,4); clear(); draw(b); }
//初始化屏幕
private function clear():void{ graphics.clear(); graphics.lineStyle(1); graphics.moveTo(10,200); }
//每隔一段时间根据数据绘制,可以重写这个函数,但是完全没有必要~~ * 这是一个默认实现
//绘制用的数据ByteArray //
protected function draw(b:ByteArray):void{ var i:int=0; b.position = 0;
//防止万一,这句是不必要的,我认为 //画,因为太长了,有2048那么长,所以我只画了1/4,剩下的不要了
while(b.bytesAvailable>b.length*0.75){ graphics.lineTo(++i+10,-0.1*(b.readByte())+200); } } }}

Blog Archive