ofSoundPlayer
![]()
http://www.openframeworks.cc/documentation#ofSoundPlayer-about
//testApp.h ファイル--------------
ofSoundPlayer mySnd;
//testApp.cpp ファイル------------
// void testApp::setup()
{mySnd.loadSound("データフォルダの中のサウンドファイル名");
}
wavfiles.zip // 解凍して フォルダ data の中に配置してください。
こちらユニバーサルバイナリのライブラリです。SndObjlib.zip フォルダをこのように配置してください。
pre release v0.05 x-code FAT
├─ apps
├─ blablib
│ ├ SndObjLib
│ ├
├─ libs
└─ otherhttp://music.nuim.ie//musictec/SndObj/main.html
http://music.nuim.ie//musictec/man/SndObj/examples.html
テンプレート: blab_sndobj_template フォルダをこのように配置してください。
pre release v0.05 x-code FAT
├─ apps
│ ├ blabExample
│ ├ blab_sndobj_template
├─ blablib
├─ libs
└─ otherPPCを使っている人は、
メニュー Project -> Edit Projecdt Settings -> Architecture ->
の欄を ppc のみにしてください(i386を消す)
基本的な流れは、以下のスタイルです。
スレッドスタイル:常にバックグラウンドでサウンドプロセスが進行する。
testApp.h でクラスのメンバーとして、必要なsoundObjectのメンバーを定義する。
void testApp::exit() { } を定義し、 上記で定義したsoundObjectのメンバーをdelete する処理を書いておく。
プリセットの table (波形)を定義する
上記で作った波形からオシレータを定義する
出力ポートを設定。
オシレータを出力ポートにセットする。
サウンドスレッドに、オシレータ、出力ポートを追加。
スレッドスタート。
オシレータのメンバーを動的に操作するなど…。
----------------------------------------------------------------------------------
testApp.h でクラスのメンバーとして、必要なsoundObjectのメンバーを定義する。
SndRTIO *output; // SndRTIO サウンドリアルタイム入出力ポートとして、outputを定義。音を出す場合はマスト。
SndThread sndthread; // サウンド生成のためのスレッド。スレッドタイプの場合はマスト。
/////////////// ここからはプロジェクトの内容による。
HarmTable *table1; // プリセット波形
Oscili *osil; //オシレータ、発振
void testApp::exit() { } を定義し、 上記で定義したsoundObjectのメンバーをdelete する処理を書いておく。
delete output;
delete osil;
delete table1;
プリセットの table (波形)を定義する ( void testApp::setup() 中 )
Class HarmTable を使う
table1 = new Harmtable(1024, 1, SINE); // バッファ長さ、倍音の数、波形タイプ
Harmonic function table. Generates four preset types of waveforms: sine, saw, square and
buzz (pulse), with any number of harmonics.上記で作った波形からオシレータを定義する ( void testApp::setup() 中 )
Class Oscili を使う
osil = new Oscili( table1, 440.f, 10000.f ); // プリセット波形、周波数、アンプ最大値
Public Methodsとして以下のものが設定、操作できるようになっている。
void SetFreq(float fr, SndObj* inputfreq = 0)
void SetAmp(float amp, SndObj* inputamp = 0 )
void SetFreq(SndObj* inputfreq = 0)
void SetAmp(SndObj* inputamp = 0 )
void SetPhase(float phase)
void SetTable(Table* table)出力ポートを設定。
output = new SndRTIO( 2, SND_OUTPUT ); // ステレオ、出力デバイス
オシレータを出力ポートにセットする。
output->SetOutput( 1, oscil ); // チャンネル1 左に上記オシレータをセット
サウンドスレッドに、オシレータ、出力ポートを追加。
sndthread.AddObj(oscil);
sndthread.AddObj(output, SNDIO_OUT);
スレッドスタート。
sndthread.ProcOn();
オシレータのメンバーを動的に操作するなど…。
osil->SetAmp(mouseX*100.);
外部設定ファイルを記述できます。
testApp.cpp の中だけで使用するケースが多いので、 testApp.cpp の上方でScriptEngine.hxx をインクルードしてください。
#include "testApp.h"
#include "ScriptEngine.hxx"
myscript.py を data フォルダに配置してください。
void testApp::setup() のなかで
scriptEngine::Start(); // スクリプトエンジンスタート
scriptEngine::Load(ofToDataPath("myscript.py")); // data`フォルダ内の myscript.py を読み込むたとえばInsect クラス vector 配列の大きさを myscript.py で決める。
myscript.py 内:
insectArrayLength = 100
testApp.cpp 内 void testApp::setup() のなか 配列を初期化するあたり
int arrayLength = scriptEngine::GetIntValue("insectArrayLength",0); // スクリプト内の変数、デフォルト値(変数の記述が見つからなかった場合)
for(int i=0;i<arrayLength;i++)//insectArray.size();i++)
{
//Insect insect;
Insect insect(ofRandom(0,1000),ofRandom(0,500));
insect.img->loadImage("release-development.png");
insect.font->loadFont("verdana.ttf",9);
//insect.font=&font;
insect.sndp=&sndp;
insect.sndp2=&sndp2;
insectArray.push_back(insect);
}たとえば背景色を myscript.py で決める。
myscript.py 内:
BackGroundColor = [ 10., 0.5, 1.0, 1.0 ]testApp.h 内 背景色を定義するメンバーを定義しておく
float bgR,bgG,bgB,bgA;
testApp.cpp 内 void testApp::setup() のなか
scriptEngine::FloatList farray;
scriptEngine::GetFloatArray("BackGroundColor",farray);bgR=farray[0];
bgG=farray[1];
bgB=farray[2];
bgA=farray[3];testApp.cpp 内 void testApp::draw() のなか
glClearColor(bgR,bgG,bgB,bgA);
たとえばアプリ実行中にスクリプトを書き換えて、再ロードする場合:
testApp.cpp 内 void testApp::mouseReleased() のなかで、再度ロード関数をコールして、数値を設定しなおす。scriptEngine::Load(ofToDataPath("myscript.py"));
scriptEngine::FloatList farray;
scriptEngine::GetFloatArray("BackGroundColor",farray);bgR=farray[0];
bgG=farray[1];
bgB=farray[2];
bgA=farray[3];