sample_player.cpp 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707
  1. /*************************************************************************/
  2. /* sample_player.cpp */
  3. /*************************************************************************/
  4. /* This file is part of: */
  5. /* GODOT ENGINE */
  6. /* http://www.godotengine.org */
  7. /*************************************************************************/
  8. /* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */
  9. /* */
  10. /* Permission is hereby granted, free of charge, to any person obtaining */
  11. /* a copy of this software and associated documentation files (the */
  12. /* "Software"), to deal in the Software without restriction, including */
  13. /* without limitation the rights to use, copy, modify, merge, publish, */
  14. /* distribute, sublicense, and/or sell copies of the Software, and to */
  15. /* permit persons to whom the Software is furnished to do so, subject to */
  16. /* the following conditions: */
  17. /* */
  18. /* The above copyright notice and this permission notice shall be */
  19. /* included in all copies or substantial portions of the Software. */
  20. /* */
  21. /* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
  22. /* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
  23. /* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/
  24. /* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
  25. /* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
  26. /* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
  27. /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
  28. /*************************************************************************/
  29. #include "sample_player.h"
  30. #include "servers/audio_server.h"
  31. bool SamplePlayer::_set(const StringName& p_name, const Variant& p_value) {
  32. String name=p_name;
  33. if (name=="play/play") {
  34. if (library.is_valid()) {
  35. String what=p_value;
  36. if (what=="")
  37. stop_all();
  38. else
  39. play(what);
  40. played_back=what;
  41. }
  42. } else if (name=="config/samples")
  43. set_sample_library(p_value);
  44. else if (name=="config/voices")
  45. set_voice_count(p_value);
  46. else if (name.begins_with("default/")) {
  47. String what=name.right(8);
  48. if (what=="volume_db")
  49. set_default_volume_db(p_value);
  50. else if (what=="pitch_scale")
  51. set_default_pitch_scale(p_value);
  52. else if (what=="pan")
  53. _default.pan=p_value;
  54. else if (what=="depth")
  55. _default.depth=p_value;
  56. else if (what=="height")
  57. _default.height=p_value;
  58. else if (what=="filter/type")
  59. _default.filter_type=FilterType(p_value.operator int());
  60. else if (what=="filter/cutoff")
  61. _default.filter_cutoff=p_value;
  62. else if (what=="filter/resonance")
  63. _default.filter_resonance=p_value;
  64. else if (what=="filter/gain")
  65. _default.filter_gain=p_value;
  66. else if (what=="reverb_room")
  67. _default.reverb_room=ReverbRoomType(p_value.operator int());
  68. else if (what=="reverb_send")
  69. _default.reverb_send=p_value;
  70. else if (what=="chorus_send")
  71. _default.chorus_send=p_value;
  72. else
  73. return false;
  74. } else
  75. return false;
  76. return true;
  77. }
  78. bool SamplePlayer::_get(const StringName& p_name,Variant &r_ret) const {
  79. String name=p_name;
  80. if (name=="play/play") {
  81. r_ret=played_back;
  82. } else if (name=="config/voices") {
  83. r_ret= get_voice_count();
  84. } else if (name=="config/samples") {
  85. r_ret= get_sample_library();
  86. } else if (name.begins_with("default/")) {
  87. String what=name.get_slice("/",1);
  88. if (what=="volume_db")
  89. r_ret= get_default_volume_db();
  90. else if (what=="pitch_scale")
  91. r_ret= get_default_pitch_scale();
  92. else if (what=="pan")
  93. r_ret= _default.pan;
  94. else if (what=="depth")
  95. r_ret= _default.depth;
  96. else if (what=="height")
  97. r_ret= _default.height;
  98. else if (what=="filter/type")
  99. r_ret= _default.filter_type;
  100. else if (what=="filter/cutoff")
  101. r_ret= _default.filter_cutoff;
  102. else if (what=="filter/resonance")
  103. r_ret= _default.filter_resonance;
  104. else if (what=="filter/gain")
  105. r_ret= _default.filter_gain;
  106. else if (what=="reverb_room")
  107. r_ret= _default.reverb_room;
  108. else if (what=="reverb_send")
  109. r_ret= _default.reverb_send;
  110. else if (what=="chorus_send")
  111. r_ret= _default.chorus_send;
  112. else
  113. return false;
  114. } else
  115. return false;
  116. return true;
  117. }
  118. void SamplePlayer::_get_property_list(List<PropertyInfo> *p_list) const {
  119. String en="";
  120. if (library.is_valid()) {
  121. List<StringName> samples;
  122. Ref<SampleLibrary> ncl=library;
  123. ncl->get_sample_list(&samples);
  124. for (List<StringName>::Element *E=samples.front();E;E=E->next()) {
  125. en+=",";
  126. en+=E->get();
  127. }
  128. }
  129. p_list->push_back( PropertyInfo( Variant::STRING, "play/play", PROPERTY_HINT_ENUM, en,PROPERTY_USAGE_EDITOR));
  130. p_list->push_back( PropertyInfo( Variant::INT, "config/voices", PROPERTY_HINT_RANGE, "1,256,1"));
  131. p_list->push_back( PropertyInfo( Variant::OBJECT, "config/samples", PROPERTY_HINT_RESOURCE_TYPE, "SampleLibrary"));
  132. p_list->push_back( PropertyInfo( Variant::REAL, "default/volume_db", PROPERTY_HINT_RANGE, "-80,24,0.01"));
  133. p_list->push_back( PropertyInfo( Variant::REAL, "default/pitch_scale", PROPERTY_HINT_RANGE, "0.01,48,0.01"));
  134. p_list->push_back( PropertyInfo( Variant::REAL, "default/pan", PROPERTY_HINT_RANGE, "-1,1,0.01"));
  135. p_list->push_back( PropertyInfo( Variant::REAL, "default/depth", PROPERTY_HINT_RANGE, "-1,1,0.01"));
  136. p_list->push_back( PropertyInfo( Variant::REAL, "default/height", PROPERTY_HINT_RANGE, "-1,1,0.01"));
  137. p_list->push_back( PropertyInfo( Variant::INT, "default/filter/type", PROPERTY_HINT_ENUM, "Disabled,Lowpass,Bandpass,Highpass,Notch,Peak,BandLimit,LowShelf,HighShelf"));
  138. p_list->push_back( PropertyInfo( Variant::REAL, "default/filter/cutoff", PROPERTY_HINT_RANGE, "20,16384.0,0.01"));
  139. p_list->push_back( PropertyInfo( Variant::REAL, "default/filter/resonance", PROPERTY_HINT_RANGE, "0,4,0.01"));
  140. p_list->push_back( PropertyInfo( Variant::REAL, "default/filter/gain", PROPERTY_HINT_RANGE, "0,2,0.01"));
  141. p_list->push_back( PropertyInfo( Variant::INT, "default/reverb_room", PROPERTY_HINT_ENUM, "Small,Medimum,Large,Hall"));
  142. p_list->push_back( PropertyInfo( Variant::REAL, "default/reverb_send", PROPERTY_HINT_RANGE, "0,1,0.01"));
  143. p_list->push_back( PropertyInfo( Variant::REAL, "default/chorus_send", PROPERTY_HINT_RANGE, "0,1,0.01"));
  144. }
  145. SamplePlayer::Voice::Voice() {
  146. voice=AudioServer::get_singleton()->voice_create();
  147. clear();
  148. }
  149. void SamplePlayer::Voice::clear() {
  150. check=0;
  151. mix_rate=44100;
  152. volume=1;
  153. pan=0;
  154. pan_depth=0;
  155. pan_height=0;
  156. filter_type=FILTER_NONE;
  157. filter_cutoff=0;
  158. filter_resonance=0;
  159. chorus_send=0;
  160. reverb_room=REVERB_HALL;
  161. reverb_send=0;
  162. active=false;
  163. }
  164. SamplePlayer::Voice::~Voice() {
  165. AudioServer::get_singleton()->free(voice);
  166. }
  167. void SamplePlayer::set_voice_count(int p_voice_count) {
  168. ERR_FAIL_COND( p_voice_count <1 || p_voice_count >0xFFFE );
  169. voices.resize(p_voice_count);
  170. }
  171. int SamplePlayer::get_voice_count() const {
  172. return voices.size();
  173. }
  174. SamplePlayer::VoiceID SamplePlayer::play(const String& p_name,bool unique) {
  175. if (library.is_null())
  176. return INVALID_VOICE_ID;
  177. ERR_FAIL_COND_V( !library->has_sample(p_name), INVALID_VOICE_ID );
  178. Ref<Sample> sample = library->get_sample(p_name);
  179. float vol_change = library->sample_get_volume_db(p_name);
  180. float pitch_change = library->sample_get_pitch_scale(p_name);
  181. last_check++;
  182. last_id = (last_id + 1) % voices.size();
  183. Voice&v = voices[last_id];
  184. v.clear();
  185. v.mix_rate=sample->get_mix_rate()*(_default.pitch_scale*pitch_change);
  186. v.sample_mix_rate=sample->get_mix_rate();
  187. v.check=last_check;
  188. v.volume=Math::db2linear(_default.volume_db+vol_change);
  189. v.pan=_default.pan;
  190. v.pan_depth=_default.depth;
  191. v.pan_height=_default.height;
  192. v.filter_type=_default.filter_type;
  193. v.filter_cutoff=_default.filter_cutoff;
  194. v.filter_resonance=_default.filter_resonance;
  195. v.filter_gain=_default.filter_gain;
  196. v.chorus_send=_default.chorus_send;
  197. v.reverb_room=_default.reverb_room;
  198. v.reverb_send=_default.reverb_send;
  199. AudioServer::get_singleton()->voice_play(v.voice,sample->get_rid());
  200. AudioServer::get_singleton()->voice_set_mix_rate(v.voice,v.mix_rate);
  201. AudioServer::get_singleton()->voice_set_volume(v.voice,v.volume);
  202. AudioServer::get_singleton()->voice_set_pan(v.voice,v.pan,v.pan_depth,v.pan_height);
  203. AudioServer::get_singleton()->voice_set_filter(v.voice,(AudioServer::FilterType)v.filter_type,v.filter_cutoff,v.filter_resonance,v.filter_gain);
  204. AudioServer::get_singleton()->voice_set_chorus(v.voice,v.chorus_send);
  205. AudioServer::get_singleton()->voice_set_reverb(v.voice,(AudioServer::ReverbRoomType)v.reverb_room,v.reverb_send);
  206. v.active=true;
  207. if (unique) {
  208. for(int i=0;i<voices.size();i++) {
  209. if (!voices[i].active || uint32_t(i)==last_id)
  210. continue;
  211. AudioServer::get_singleton()->voice_stop(voices[i].voice);
  212. voices[i].clear();
  213. }
  214. }
  215. return last_id | (last_check<<16);
  216. }
  217. void SamplePlayer::stop_all() {
  218. for(int i=0;i<voices.size();i++) {
  219. if (!voices[i].active)
  220. continue;
  221. AudioServer::get_singleton()->voice_stop(voices[i].voice);
  222. voices[i].clear();
  223. }
  224. }
  225. #define _GET_VOICE\
  226. uint32_t voice=p_voice&0xFFFF;\
  227. ERR_FAIL_COND(voice > (uint32_t)voices.size());\
  228. Voice &v=voices[voice];\
  229. if (v.check!=uint32_t(p_voice>>16))\
  230. return;\
  231. ERR_FAIL_COND(!v.active);
  232. void SamplePlayer::stop(VoiceID p_voice) {
  233. _GET_VOICE
  234. AudioServer::get_singleton()->voice_stop(v.voice);
  235. v.active=false;
  236. }
  237. void SamplePlayer::set_mix_rate(VoiceID p_voice, int p_mix_rate) {
  238. _GET_VOICE
  239. v.mix_rate=p_mix_rate;
  240. AudioServer::get_singleton()->voice_set_mix_rate(v.voice,v.mix_rate);
  241. }
  242. void SamplePlayer::set_pitch_scale(VoiceID p_voice, float p_pitch_scale) {
  243. _GET_VOICE
  244. v.mix_rate=v.sample_mix_rate*p_pitch_scale;
  245. AudioServer::get_singleton()->voice_set_mix_rate(v.voice,v.mix_rate);
  246. }
  247. void SamplePlayer::set_volume(VoiceID p_voice, float p_volume) {
  248. _GET_VOICE
  249. v.volume=p_volume;
  250. AudioServer::get_singleton()->voice_set_volume(v.voice,v.volume);
  251. }
  252. void SamplePlayer::set_volume_db(VoiceID p_voice, float p_db) {
  253. //@TODO handle 0 volume as -80db or something
  254. _GET_VOICE
  255. v.volume=Math::db2linear(p_db);
  256. AudioServer::get_singleton()->voice_set_volume(v.voice,v.volume);
  257. }
  258. void SamplePlayer::set_pan(VoiceID p_voice, float p_pan,float p_pan_depth,float p_pan_height) {
  259. _GET_VOICE
  260. v.pan=p_pan;
  261. v.pan_depth=p_pan_depth;
  262. v.pan_height=p_pan_height;
  263. AudioServer::get_singleton()->voice_set_pan(v.voice,v.pan,v.pan_depth,v.pan_height);
  264. }
  265. void SamplePlayer::set_filter(VoiceID p_voice,FilterType p_filter,float p_cutoff,float p_resonance,float p_gain) {
  266. _GET_VOICE
  267. v.filter_type=p_filter;
  268. v.filter_cutoff=p_cutoff;
  269. v.filter_resonance=p_resonance;
  270. v.filter_gain=p_gain;
  271. AudioServer::get_singleton()->voice_set_filter(v.voice,(AudioServer::FilterType)p_filter,p_cutoff,p_resonance);
  272. }
  273. void SamplePlayer::set_chorus(VoiceID p_voice,float p_send) {
  274. _GET_VOICE
  275. v.chorus_send=p_send;
  276. AudioServer::get_singleton()->voice_set_chorus(v.voice,p_send);
  277. }
  278. void SamplePlayer::set_reverb(VoiceID p_voice,ReverbRoomType p_room,float p_send) {
  279. _GET_VOICE
  280. v.reverb_room=p_room;
  281. v.reverb_send=p_send;
  282. AudioServer::get_singleton()->voice_set_reverb(v.voice,(AudioServer::ReverbRoomType)p_room,p_send);
  283. }
  284. #define _GET_VOICE_V(m_ret)\
  285. uint32_t voice=p_voice&0xFFFF;\
  286. ERR_FAIL_COND_V(voice > (uint32_t)voices.size(),m_ret);\
  287. const Voice &v=voices[voice];\
  288. if (v.check!=(p_voice>>16))\
  289. return m_ret;\
  290. ERR_FAIL_COND_V(!v.active,m_ret);
  291. int SamplePlayer::get_mix_rate(VoiceID p_voice) const {
  292. _GET_VOICE_V(0);
  293. return v.mix_rate;
  294. }
  295. float SamplePlayer::get_pitch_scale(VoiceID p_voice) const {
  296. _GET_VOICE_V(0);
  297. return v.sample_mix_rate/(float)v.mix_rate;
  298. }
  299. float SamplePlayer::get_volume(VoiceID p_voice) const {
  300. _GET_VOICE_V(0);
  301. return v.volume;
  302. }
  303. float SamplePlayer::get_volume_db(VoiceID p_voice) const {
  304. _GET_VOICE_V(0);
  305. return Math::linear2db(v.volume);
  306. }
  307. float SamplePlayer::get_pan(VoiceID p_voice) const {
  308. _GET_VOICE_V(0);
  309. return v.pan;
  310. }
  311. float SamplePlayer::get_pan_depth(VoiceID p_voice) const {
  312. _GET_VOICE_V(0);
  313. return v.pan_depth;
  314. }
  315. float SamplePlayer::get_pan_height(VoiceID p_voice) const {
  316. _GET_VOICE_V(0);
  317. return v.pan_height;
  318. }
  319. SamplePlayer::FilterType SamplePlayer::get_filter_type(VoiceID p_voice) const {
  320. _GET_VOICE_V(FILTER_NONE);
  321. return v.filter_type;
  322. }
  323. float SamplePlayer::get_filter_cutoff(VoiceID p_voice) const {
  324. _GET_VOICE_V(0);
  325. return v.filter_cutoff;
  326. }
  327. float SamplePlayer::get_filter_resonance(VoiceID p_voice) const {
  328. _GET_VOICE_V(0);
  329. return v.filter_resonance;
  330. }
  331. float SamplePlayer::get_filter_gain(VoiceID p_voice) const {
  332. _GET_VOICE_V(0);
  333. return v.filter_gain;
  334. }
  335. float SamplePlayer::get_chorus(VoiceID p_voice) const {
  336. _GET_VOICE_V(0);
  337. return v.chorus_send;
  338. }
  339. float SamplePlayer::get_reverb_room(VoiceID p_voice) const {
  340. _GET_VOICE_V(0);
  341. return v.reverb_room;
  342. }
  343. float SamplePlayer::get_reverb(VoiceID p_voice) const {
  344. _GET_VOICE_V(0);
  345. return v.reverb_send;
  346. }
  347. bool SamplePlayer::is_voice_active(VoiceID p_voice) const {
  348. _GET_VOICE_V(false);
  349. return v.active && AudioServer::get_singleton()->voice_is_active(v.voice);
  350. }
  351. bool SamplePlayer::is_active() const {
  352. for(int i=0;i<voices.size();i++) {
  353. if (voices[i].active && AudioServer::get_singleton()->voice_is_active(voices[i].voice))
  354. return true;
  355. }
  356. return false;
  357. }
  358. void SamplePlayer::set_sample_library(const Ref<SampleLibrary>& p_library) {
  359. library=p_library;
  360. }
  361. Ref<SampleLibrary> SamplePlayer::get_sample_library() const {
  362. return library;
  363. }
  364. void SamplePlayer::set_default_pitch_scale(float p_pitch_scale) {
  365. _default.pitch_scale=p_pitch_scale;
  366. }
  367. void SamplePlayer::set_default_volume(float p_volume) {
  368. _default.volume_db=Math::linear2db(p_volume);
  369. }
  370. void SamplePlayer::set_default_volume_db(float p_db) {
  371. _default.volume_db=p_db;
  372. }
  373. void SamplePlayer::set_default_pan(float p_pan,float p_pan_depth,float p_pan_height) {
  374. _default.pan=p_pan;
  375. _default.depth=p_pan_depth;
  376. _default.height=p_pan_height;
  377. }
  378. void SamplePlayer::set_default_filter(FilterType p_filter,float p_cutoff,float p_resonance,float p_gain) {
  379. _default.filter_type=p_filter;
  380. _default.filter_cutoff=p_cutoff;
  381. _default.filter_resonance=p_resonance;
  382. _default.filter_gain=p_gain;
  383. }
  384. void SamplePlayer::set_default_chorus(float p_send) {
  385. _default.chorus_send=p_send;
  386. }
  387. void SamplePlayer::set_default_reverb(ReverbRoomType p_room,float p_send) {
  388. _default.reverb_room=p_room;
  389. _default.reverb_send=p_send;
  390. }
  391. float SamplePlayer::get_default_volume() const {
  392. return Math::db2linear(_default.volume_db);
  393. }
  394. float SamplePlayer::get_default_volume_db() const {
  395. return _default.volume_db;
  396. }
  397. float SamplePlayer::get_default_pitch_scale() const {
  398. return _default.pitch_scale;
  399. }
  400. float SamplePlayer::get_default_pan() const {
  401. return _default.pan;
  402. }
  403. float SamplePlayer::get_default_pan_depth() const {
  404. return _default.depth;
  405. }
  406. float SamplePlayer::get_default_pan_height() const {
  407. return _default.height;
  408. }
  409. SamplePlayer::FilterType SamplePlayer::get_default_filter_type() const {
  410. return _default.filter_type;
  411. }
  412. float SamplePlayer::get_default_filter_cutoff() const {
  413. return _default.filter_cutoff;
  414. }
  415. float SamplePlayer::get_default_filter_resonance() const {
  416. return _default.filter_resonance;
  417. }
  418. float SamplePlayer::get_default_filter_gain() const {
  419. return _default.filter_gain;
  420. }
  421. float SamplePlayer::get_default_chorus() const {
  422. return _default.chorus_send;
  423. }
  424. float SamplePlayer::get_default_reverb_room() const {
  425. return _default.reverb_room;
  426. }
  427. float SamplePlayer::get_default_reverb() const {
  428. return _default.reverb_send;
  429. }
  430. void SamplePlayer::_bind_methods() {
  431. ObjectTypeDB::bind_method(_MD("set_sample_library","library:SampleLibrary"),&SamplePlayer::set_sample_library );
  432. ObjectTypeDB::bind_method(_MD("get_sample_library:SampleLibrary"),&SamplePlayer::get_sample_library );
  433. ObjectTypeDB::bind_method(_MD("set_voice_count","max_voices"),&SamplePlayer::set_voice_count );
  434. ObjectTypeDB::bind_method(_MD("get_voice_count"),&SamplePlayer::get_voice_count );
  435. ObjectTypeDB::bind_method(_MD("play","name","unique"),&SamplePlayer::play, DEFVAL(false) );
  436. ObjectTypeDB::bind_method(_MD("stop","voice"),&SamplePlayer::stop );
  437. ObjectTypeDB::bind_method(_MD("stop_all"),&SamplePlayer::stop_all );
  438. ObjectTypeDB::bind_method(_MD("set_mix_rate","voice","hz"),&SamplePlayer::set_mix_rate );
  439. ObjectTypeDB::bind_method(_MD("set_pitch_scale","voice","ratio"),&SamplePlayer::set_pitch_scale );
  440. ObjectTypeDB::bind_method(_MD("set_volume","voice","nrg"),&SamplePlayer::set_volume );
  441. ObjectTypeDB::bind_method(_MD("set_volume_db","voice","nrg"),&SamplePlayer::set_volume_db );
  442. ObjectTypeDB::bind_method(_MD("set_pan","voice","pan","depth","height"),&SamplePlayer::set_pan,DEFVAL(0),DEFVAL(0) );
  443. ObjectTypeDB::bind_method(_MD("set_filter","voice","type","cutoff_hz","resonance","gain"),&SamplePlayer::set_filter,DEFVAL(0) );
  444. ObjectTypeDB::bind_method(_MD("set_chorus","voice","send"),&SamplePlayer::set_chorus );
  445. ObjectTypeDB::bind_method(_MD("set_reverb","voice","room_type","send"),&SamplePlayer::set_reverb );
  446. ObjectTypeDB::bind_method(_MD("get_mix_rate","voice"),&SamplePlayer::get_mix_rate );
  447. ObjectTypeDB::bind_method(_MD("get_pitch_scale","voice"),&SamplePlayer::get_pitch_scale );
  448. ObjectTypeDB::bind_method(_MD("get_volume","voice"),&SamplePlayer::get_volume );
  449. ObjectTypeDB::bind_method(_MD("get_volume_db","voice"),&SamplePlayer::get_volume_db );
  450. ObjectTypeDB::bind_method(_MD("get_pan","voice"),&SamplePlayer::get_pan );
  451. ObjectTypeDB::bind_method(_MD("get_pan_depth","voice"),&SamplePlayer::get_pan_depth );
  452. ObjectTypeDB::bind_method(_MD("get_pan_height","voice"),&SamplePlayer::get_pan_height );
  453. ObjectTypeDB::bind_method(_MD("get_filter_type","voice"),&SamplePlayer::get_filter_type );
  454. ObjectTypeDB::bind_method(_MD("get_filter_cutoff","voice"),&SamplePlayer::get_filter_cutoff );
  455. ObjectTypeDB::bind_method(_MD("get_filter_resonance","voice"),&SamplePlayer::get_filter_resonance );
  456. ObjectTypeDB::bind_method(_MD("get_filter_gain","voice"),&SamplePlayer::get_filter_gain );
  457. ObjectTypeDB::bind_method(_MD("get_chorus","voice"),&SamplePlayer::get_chorus );
  458. ObjectTypeDB::bind_method(_MD("get_reverb_room","voice"),&SamplePlayer::get_reverb_room );
  459. ObjectTypeDB::bind_method(_MD("get_reverb","voice"),&SamplePlayer::get_reverb );
  460. ObjectTypeDB::bind_method(_MD("set_default_pitch_scale","ratio"),&SamplePlayer::set_default_pitch_scale );
  461. ObjectTypeDB::bind_method(_MD("set_default_volume","nrg"),&SamplePlayer::set_default_volume );
  462. ObjectTypeDB::bind_method(_MD("set_default_volume_db","db"),&SamplePlayer::set_default_volume );
  463. ObjectTypeDB::bind_method(_MD("set_default_pan","pan","depth","height"),&SamplePlayer::set_default_pan,DEFVAL(0),DEFVAL(0) );
  464. ObjectTypeDB::bind_method(_MD("set_default_filter","type","cutoff_hz","resonance","gain"),&SamplePlayer::set_default_filter,DEFVAL(0) );
  465. ObjectTypeDB::bind_method(_MD("set_default_chorus","send"),&SamplePlayer::set_default_chorus );
  466. ObjectTypeDB::bind_method(_MD("set_default_reverb","room_type","send"),&SamplePlayer::set_default_reverb );
  467. ObjectTypeDB::bind_method(_MD("get_default_pitch_scale"),&SamplePlayer::get_default_pitch_scale );
  468. ObjectTypeDB::bind_method(_MD("get_default_volume"),&SamplePlayer::get_default_volume );
  469. ObjectTypeDB::bind_method(_MD("get_default_volume_db"),&SamplePlayer::get_default_volume );
  470. ObjectTypeDB::bind_method(_MD("get_default_pan"),&SamplePlayer::get_default_pan );
  471. ObjectTypeDB::bind_method(_MD("get_default_pan_depth"),&SamplePlayer::get_default_pan_depth );
  472. ObjectTypeDB::bind_method(_MD("get_default_pan_height"),&SamplePlayer::get_default_pan_height );
  473. ObjectTypeDB::bind_method(_MD("get_default_filter_type"),&SamplePlayer::get_default_filter_type );
  474. ObjectTypeDB::bind_method(_MD("get_default_filter_cutoff"),&SamplePlayer::get_default_filter_cutoff );
  475. ObjectTypeDB::bind_method(_MD("get_default_filter_resonance"),&SamplePlayer::get_default_filter_resonance );
  476. ObjectTypeDB::bind_method(_MD("get_default_filter_gain"),&SamplePlayer::get_default_filter_gain );
  477. ObjectTypeDB::bind_method(_MD("get_default_chorus"),&SamplePlayer::get_default_chorus );
  478. ObjectTypeDB::bind_method(_MD("get_default_reverb_room"),&SamplePlayer::get_default_reverb_room );
  479. ObjectTypeDB::bind_method(_MD("get_default_reverb"),&SamplePlayer::get_default_reverb );
  480. ObjectTypeDB::bind_method(_MD("is_active"),&SamplePlayer::is_active );
  481. ObjectTypeDB::bind_method(_MD("is_voice_active","voice"),&SamplePlayer::is_voice_active );
  482. BIND_CONSTANT( FILTER_NONE);
  483. BIND_CONSTANT( FILTER_LOWPASS);
  484. BIND_CONSTANT( FILTER_BANDPASS);
  485. BIND_CONSTANT( FILTER_HIPASS);
  486. BIND_CONSTANT( FILTER_NOTCH);
  487. BIND_CONSTANT( FILTER_PEAK);
  488. BIND_CONSTANT( FILTER_BANDLIMIT); ///< cutoff is LP resonace is HP
  489. BIND_CONSTANT( FILTER_LOW_SHELF);
  490. BIND_CONSTANT( FILTER_HIGH_SHELF);
  491. BIND_CONSTANT( REVERB_SMALL );
  492. BIND_CONSTANT( REVERB_MEDIUM );
  493. BIND_CONSTANT( REVERB_LARGE );
  494. BIND_CONSTANT( REVERB_HALL );
  495. }
  496. SamplePlayer::SamplePlayer() {
  497. voices.resize(1);
  498. _default.pitch_scale=1;
  499. _default.volume_db=0;
  500. _default.pan=0;
  501. _default.depth=0;
  502. _default.height=0;
  503. _default.filter_type=FILTER_NONE;
  504. _default.filter_cutoff=5000;
  505. _default.filter_resonance=1;
  506. _default.filter_gain=1;
  507. _default.chorus_send=0;
  508. _default.reverb_room=REVERB_LARGE;
  509. _default.reverb_send=0;
  510. last_id=0;
  511. last_check=0;
  512. }
  513. SamplePlayer::~SamplePlayer() {
  514. }