wiki:misc/misc/processing/bvh_and_sound

Version 2 (modified by noboru.yamamoto, 10 years ago) (diff)

--

モーションキャプチャデータとサウンドの同期再生

ARの表示にモーションキャプチャデータを使えればと言う話が出ました。 で、http://www.perfume-global.com/ で公開されているBVHデータを使えるか どうか試してみます。 まずは、公開されているキャプチャデータ(BVH)とサウンドを同期してProcessingで再生する ことを試してみます。

データとサンプルコード

http://www.perfume-global.com/ からモーションキャプチャデータ(bvh)とサウンド(wav)データを 入手します。また、Processingのサンプルコードもダウンロードします。サンプルコードには、 processingからBVHファイルを読み込むためのライブラリが含まれています。BVHは標準ではProcessingで 読める様にはなっていないので、このライブラリは必須です。

同期再生のためのスケッチ

サウンドとキャプチャデータを同期再生させるために、ダウンロードしたサンプルのスケッチを以下の様に書き換えます。

import ddf.minim.*;

BvhParser? parserA = new BvhParser?(); PBvh bvh1, bvh2, bvh3;

AudioPlayer? player; Minim minim;

public void setup() {

size(1280, 720, P3D); background(0); noStroke(); frameRate(40);

bvh1 = new PBvh(loadStrings("kashiyuka.bvh")); bvh2 = new PBvh(loadStrings("nocchi.bvh")); bvh3 = new PBvh(loadStrings("aachan.bvh"));

minim = new Minim(this); player = minim.loadFile("Perfume_globalsite_sound.wav");

player.play(); player.loop();

}

public void draw() {

int currentTime = player.position();

background(color(255,255,128));

camera

float _cos = cos(currentTime / 5000.f);

float _sin = sin(currentTime / 5000.f);

camera(width/4.f + width/4.f * _cos +200, height/2.0f-100, 550 + 150 * _sin, width/2.0f, height/2.0f, -400, 0, 1, 0);

ground

fill(color(0)); stroke(127); line(width/2.0f, height/2.0f, -30, width/2.0f, height/2.0f, 30); stroke(127); line(width/2.0f-30, height/2.0f, 0, width/2.0f + 30, height/2.0f, 0); stroke(255); pushMatrix(); translate(width/2, height/2-10, 0); rotateX(PI); sphereDetail(10); lights(); directionalLight(100, 100, 100, -1, -1, 0);

model

bvh1.update(currentTime); bvh2.update(currentTime); bvh3.update(currentTime);

bvh1.draw(); bvh2.draw(); bvh3.draw(); popMatrix();

}

これで、アニメーションとサウンドが同期して再生されます。肝は、int currentTime = player.position(); で再生音の時間的なポジションを入手して、 アニメーション画像の変更をこの時間でもって指定する bvh1.update(currentTime);ところです。

processing version 3(beta) 対応

上記のProcessingはProcessingの現行バージョン(2)で動作することを確認しています。 次期バージョンのProcessing 3ではサウンド関係のライブラリが入れ替わっており、Minimライブラリは標準ライブラリから外れています。 代って sound ツールが導入されているようです。色々と試してみて、一応Processing 3でも同期再生ができましたので、参考までにスケッチを載せておきます。

import processing.sound.*;

SoundFile? player;

BvhParser? parserA = new BvhParser?(); PBvh bvh1, bvh2, bvh3;

public void setup() {

size( 1280, 720, P3D ); background( 0 ); noStroke(); frameRate( 40 );not 30 but 40

bvh1 = new PBvh( loadStrings( "bvhfiles/aachan.bvh" ) ); bvh2 = new PBvh( loadStrings( "bvhfiles/kashiyuka.bvh" ) ); bvh3 = new PBvh( loadStrings( "bvhfiles/nocchi.bvh" ) );

minim = new Minim(this); player = minim.loadFile("Perfume_globalsite_sound.wav"); player =new SoundFile?(this,"Perfume_globalsite_sound.wav"); player.play();

player.loop();

}

public void draw() {

background( 0 );

camera float _cos = cos(millis() / 5000.f); float _sin = sin(millis() / 5000.f); camera(width/4.f + width/4.f * _cos +200, height/2.0f-100, 550 + 150 * _sin,width/2.0f, height/2.0f, -400, 0, 1, 0);

ground fill( color( 255 )); stroke(127); line(width/2.0f, height/2.0f, -30, width/2.0f, height/2.0f, 30); stroke(127); line(width/2.0f-30, height/2.0f, 0, width/2.0f + 30, height/2.0f, 0); stroke(255); pushMatrix(); translate( width/2, height/2-10, 0); scale(-1, -1, -1);

model bvh1.update( millis() ); bvh2.update( millis() ); bvh3.update( millis() ); bvh1.draw(); bvh2.draw(); bvh3.draw(); popMatrix();

}

void stop() {

player.stop(); minim.stop();

super.stop();

}

Attachments (3)

Download all attachments as: .zip