Blender V2.61 - r43446
|
00001 /* 00002 * ***** BEGIN GPL LICENSE BLOCK ***** 00003 * 00004 * This program is free software; you can redistribute it and/or 00005 * modify it under the terms of the GNU General Public License 00006 * as published by the Free Software Foundation; either version 2 00007 * of the License, or (at your option) any later version. 00008 * 00009 * This program is distributed in the hope that it will be useful, 00010 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00011 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00012 * GNU General Public License for more details. 00013 * 00014 * You should have received a copy of the GNU General Public License 00015 * along with this program; if not, write to the Free Software Foundation, 00016 * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. 00017 * 00018 * The Original Code is Copyright (C) 2001-2002 by NaN Holding BV. 00019 * All rights reserved. 00020 * 00021 * The Original Code is: all of this file. 00022 * 00023 * Contributor(s): none yet. 00024 * 00025 * ***** END GPL LICENSE BLOCK ***** 00026 */ 00027 00032 #include <string.h> 00033 #include <stdlib.h> 00034 00035 #include "MEM_guardedalloc.h" 00036 00037 #include "BLI_blenlib.h" 00038 #include "BLI_math.h" 00039 00040 #include "DNA_anim_types.h" 00041 #include "DNA_object_types.h" 00042 #include "DNA_scene_types.h" 00043 #include "DNA_sequence_types.h" 00044 #include "DNA_packedFile_types.h" 00045 #include "DNA_screen_types.h" 00046 #include "DNA_sound_types.h" 00047 #include "DNA_speaker_types.h" 00048 00049 #ifdef WITH_AUDASPACE 00050 # include "AUD_C-API.h" 00051 #endif 00052 00053 #include "BKE_utildefines.h" 00054 #include "BKE_global.h" 00055 #include "BKE_main.h" 00056 #include "BKE_sound.h" 00057 #include "BKE_context.h" 00058 #include "BKE_library.h" 00059 #include "BKE_packedFile.h" 00060 #include "BKE_animsys.h" 00061 #include "BKE_sequencer.h" 00062 #include "BKE_scene.h" 00063 00064 // evil quiet NaN definition 00065 static const int NAN_INT = 0x7FC00000; 00066 #define NAN_FLT *((float*)(&NAN_INT)) 00067 00068 #ifdef WITH_AUDASPACE 00069 // evil global ;-) 00070 static int sound_cfra; 00071 #endif 00072 00073 struct bSound* sound_new_file(struct Main *bmain, const char *filename) 00074 { 00075 bSound* sound = NULL; 00076 00077 char str[FILE_MAX]; 00078 char *path; 00079 00080 size_t len; 00081 00082 BLI_strncpy(str, filename, sizeof(str)); 00083 00084 path = /*bmain ? bmain->name :*/ G.main->name; 00085 00086 BLI_path_abs(str, path); 00087 00088 len = strlen(filename); 00089 while(len > 0 && filename[len-1] != '/' && filename[len-1] != '\\') 00090 len--; 00091 00092 sound = alloc_libblock(&bmain->sound, ID_SO, filename+len); 00093 BLI_strncpy(sound->name, filename, FILE_MAX); 00094 // XXX unused currently sound->type = SOUND_TYPE_FILE; 00095 00096 sound_load(bmain, sound); 00097 00098 if(!sound->playback_handle) 00099 { 00100 free_libblock(&bmain->sound, sound); 00101 sound = NULL; 00102 } 00103 00104 return sound; 00105 } 00106 00107 void sound_free(struct bSound* sound) 00108 { 00109 if (sound->packedfile) 00110 { 00111 freePackedFile(sound->packedfile); 00112 sound->packedfile = NULL; 00113 } 00114 00115 #ifdef WITH_AUDASPACE 00116 if(sound->handle) 00117 { 00118 AUD_unload(sound->handle); 00119 sound->handle = NULL; 00120 sound->playback_handle = NULL; 00121 } 00122 00123 if(sound->cache) 00124 { 00125 AUD_unload(sound->cache); 00126 sound->cache = NULL; 00127 } 00128 00129 sound_free_waveform(sound); 00130 #endif // WITH_AUDASPACE 00131 } 00132 00133 #ifdef WITH_AUDASPACE 00134 00135 static int force_device = -1; 00136 00137 #ifdef WITH_JACK 00138 static void sound_sync_callback(void* data, int mode, float time) 00139 { 00140 struct Main* bmain = (struct Main*)data; 00141 struct Scene* scene; 00142 00143 scene = bmain->scene.first; 00144 while(scene) 00145 { 00146 if(scene->audio.flag & AUDIO_SYNC) 00147 { 00148 if(mode) 00149 sound_play_scene(scene); 00150 else 00151 sound_stop_scene(scene); 00152 if(scene->sound_scene_handle) 00153 AUD_seek(scene->sound_scene_handle, time); 00154 } 00155 scene = scene->id.next; 00156 } 00157 } 00158 #endif 00159 00160 int sound_define_from_str(const char *str) 00161 { 00162 if (BLI_strcaseeq(str, "NULL")) 00163 return AUD_NULL_DEVICE; 00164 if (BLI_strcaseeq(str, "SDL")) 00165 return AUD_SDL_DEVICE; 00166 if (BLI_strcaseeq(str, "OPENAL")) 00167 return AUD_OPENAL_DEVICE; 00168 if (BLI_strcaseeq(str, "JACK")) 00169 return AUD_JACK_DEVICE; 00170 00171 return -1; 00172 } 00173 00174 void sound_force_device(int device) 00175 { 00176 force_device = device; 00177 } 00178 00179 void sound_init_once(void) 00180 { 00181 AUD_initOnce(); 00182 } 00183 00184 void sound_init(struct Main *bmain) 00185 { 00186 AUD_DeviceSpecs specs; 00187 int device, buffersize; 00188 00189 device = U.audiodevice; 00190 buffersize = U.mixbufsize; 00191 specs.channels = U.audiochannels; 00192 specs.format = U.audioformat; 00193 specs.rate = U.audiorate; 00194 00195 if(force_device >= 0) 00196 device = force_device; 00197 00198 if(buffersize < 128) 00199 buffersize = AUD_DEFAULT_BUFFER_SIZE; 00200 00201 if(specs.rate < AUD_RATE_8000) 00202 specs.rate = AUD_RATE_44100; 00203 00204 if(specs.format <= AUD_FORMAT_INVALID) 00205 specs.format = AUD_FORMAT_S16; 00206 00207 if(specs.channels <= AUD_CHANNELS_INVALID) 00208 specs.channels = AUD_CHANNELS_STEREO; 00209 00210 if(!AUD_init(device, specs, buffersize)) 00211 AUD_init(AUD_NULL_DEVICE, specs, buffersize); 00212 00213 sound_init_main(bmain); 00214 } 00215 00216 void sound_init_main(struct Main *bmain) 00217 { 00218 #ifdef WITH_JACK 00219 AUD_setSyncCallback(sound_sync_callback, bmain); 00220 #else 00221 (void)bmain; /* unused */ 00222 #endif 00223 } 00224 00225 void sound_exit(void) 00226 { 00227 AUD_exit(); 00228 } 00229 00230 // XXX unused currently 00231 #if 0 00232 struct bSound* sound_new_buffer(struct Main *bmain, struct bSound *source) 00233 { 00234 bSound* sound = NULL; 00235 00236 char name[MAX_ID_NAME+5]; 00237 strcpy(name, "buf_"); 00238 strcpy(name + 4, source->id.name); 00239 00240 sound = alloc_libblock(&bmain->sound, ID_SO, name); 00241 00242 sound->child_sound = source; 00243 sound->type = SOUND_TYPE_BUFFER; 00244 00245 sound_load(bmain, sound); 00246 00247 if(!sound->playback_handle) 00248 { 00249 free_libblock(&bmain->sound, sound); 00250 sound = NULL; 00251 } 00252 00253 return sound; 00254 } 00255 00256 struct bSound* sound_new_limiter(struct Main *bmain, struct bSound *source, float start, float end) 00257 { 00258 bSound* sound = NULL; 00259 00260 char name[MAX_ID_NAME+5]; 00261 strcpy(name, "lim_"); 00262 strcpy(name + 4, source->id.name); 00263 00264 sound = alloc_libblock(&bmain->sound, ID_SO, name); 00265 00266 sound->child_sound = source; 00267 sound->start = start; 00268 sound->end = end; 00269 sound->type = SOUND_TYPE_LIMITER; 00270 00271 sound_load(bmain, sound); 00272 00273 if(!sound->playback_handle) 00274 { 00275 free_libblock(&bmain->sound, sound); 00276 sound = NULL; 00277 } 00278 00279 return sound; 00280 } 00281 #endif 00282 00283 void sound_delete(struct Main *bmain, struct bSound* sound) 00284 { 00285 if(sound) 00286 { 00287 sound_free(sound); 00288 00289 free_libblock(&bmain->sound, sound); 00290 } 00291 } 00292 00293 void sound_cache(struct bSound* sound) 00294 { 00295 sound->flags |= SOUND_FLAGS_CACHING; 00296 if(sound->cache) 00297 AUD_unload(sound->cache); 00298 00299 sound->cache = AUD_bufferSound(sound->handle); 00300 if(sound->cache) 00301 sound->playback_handle = sound->cache; 00302 else 00303 sound->playback_handle = sound->handle; 00304 } 00305 00306 void sound_cache_notifying(struct Main* main, struct bSound* sound) 00307 { 00308 sound_cache(sound); 00309 sound_update_sequencer(main, sound); 00310 } 00311 00312 void sound_delete_cache(struct bSound* sound) 00313 { 00314 sound->flags &= ~SOUND_FLAGS_CACHING; 00315 if(sound->cache) 00316 { 00317 AUD_unload(sound->cache); 00318 sound->cache = NULL; 00319 sound->playback_handle = sound->handle; 00320 } 00321 } 00322 00323 void sound_load(struct Main *bmain, struct bSound* sound) 00324 { 00325 if(sound) 00326 { 00327 if(sound->cache) 00328 { 00329 AUD_unload(sound->cache); 00330 sound->cache = NULL; 00331 } 00332 00333 if(sound->handle) 00334 { 00335 AUD_unload(sound->handle); 00336 sound->handle = NULL; 00337 sound->playback_handle = NULL; 00338 } 00339 00340 sound_free_waveform(sound); 00341 00342 // XXX unused currently 00343 #if 0 00344 switch(sound->type) 00345 { 00346 case SOUND_TYPE_FILE: 00347 #endif 00348 { 00349 char fullpath[FILE_MAX]; 00350 00351 /* load sound */ 00352 PackedFile* pf = sound->packedfile; 00353 00354 /* dont modify soundact->sound->name, only change a copy */ 00355 BLI_strncpy(fullpath, sound->name, sizeof(fullpath)); 00356 BLI_path_abs(fullpath, ID_BLEND_PATH(bmain, &sound->id)); 00357 00358 /* but we need a packed file then */ 00359 if (pf) 00360 sound->handle = AUD_loadBuffer((unsigned char*) pf->data, pf->size); 00361 /* or else load it from disk */ 00362 else 00363 sound->handle = AUD_load(fullpath); 00364 } 00365 // XXX unused currently 00366 #if 0 00367 break; 00368 } 00369 case SOUND_TYPE_BUFFER: 00370 if(sound->child_sound && sound->child_sound->handle) 00371 sound->handle = AUD_bufferSound(sound->child_sound->handle); 00372 break; 00373 case SOUND_TYPE_LIMITER: 00374 if(sound->child_sound && sound->child_sound->handle) 00375 sound->handle = AUD_limitSound(sound->child_sound, sound->start, sound->end); 00376 break; 00377 } 00378 #endif 00379 if(sound->flags & SOUND_FLAGS_MONO) 00380 { 00381 void* handle = AUD_monoSound(sound->handle); 00382 AUD_unload(sound->handle); 00383 sound->handle = handle; 00384 } 00385 00386 if(sound->flags & SOUND_FLAGS_CACHING) 00387 { 00388 sound->cache = AUD_bufferSound(sound->handle); 00389 } 00390 00391 if(sound->cache) 00392 sound->playback_handle = sound->cache; 00393 else 00394 sound->playback_handle = sound->handle; 00395 00396 sound_update_sequencer(bmain, sound); 00397 } 00398 } 00399 00400 AUD_Device* sound_mixdown(struct Scene *scene, AUD_DeviceSpecs specs, int start, float volume) 00401 { 00402 return AUD_openMixdownDevice(specs, scene->sound_scene, volume, start / FPS); 00403 } 00404 00405 void sound_create_scene(struct Scene *scene) 00406 { 00407 scene->sound_scene = AUD_createSequencer(FPS, scene->audio.flag & AUDIO_MUTE); 00408 AUD_updateSequencerData(scene->sound_scene, scene->audio.speed_of_sound, 00409 scene->audio.doppler_factor, scene->audio.distance_model); 00410 scene->sound_scene_handle = NULL; 00411 scene->sound_scrub_handle = NULL; 00412 scene->speaker_handles = NULL; 00413 } 00414 00415 void sound_destroy_scene(struct Scene *scene) 00416 { 00417 if(scene->sound_scene_handle) 00418 AUD_stop(scene->sound_scene_handle); 00419 if(scene->sound_scrub_handle) 00420 AUD_stop(scene->sound_scrub_handle); 00421 if(scene->sound_scene) 00422 AUD_destroySequencer(scene->sound_scene); 00423 if(scene->speaker_handles) 00424 AUD_destroySet(scene->speaker_handles); 00425 } 00426 00427 void sound_mute_scene(struct Scene *scene, int muted) 00428 { 00429 if(scene->sound_scene) 00430 AUD_setSequencerMuted(scene->sound_scene, muted); 00431 } 00432 00433 void sound_update_fps(struct Scene *scene) 00434 { 00435 if(scene->sound_scene) 00436 AUD_setSequencerFPS(scene->sound_scene, FPS); 00437 } 00438 00439 void sound_update_scene_listener(struct Scene *scene) 00440 { 00441 AUD_updateSequencerData(scene->sound_scene, scene->audio.speed_of_sound, 00442 scene->audio.doppler_factor, scene->audio.distance_model); 00443 } 00444 00445 void* sound_scene_add_scene_sound(struct Scene *scene, struct Sequence* sequence, int startframe, int endframe, int frameskip) 00446 { 00447 if(scene != sequence->scene) 00448 return AUD_addSequence(scene->sound_scene, sequence->scene->sound_scene, startframe / FPS, endframe / FPS, frameskip / FPS); 00449 return NULL; 00450 } 00451 00452 void* sound_scene_add_scene_sound_defaults(struct Scene *scene, struct Sequence* sequence) 00453 { 00454 return sound_scene_add_scene_sound(scene, sequence, 00455 sequence->startdisp, sequence->enddisp, 00456 sequence->startofs + sequence->anim_startofs); 00457 } 00458 00459 void* sound_add_scene_sound(struct Scene *scene, struct Sequence* sequence, int startframe, int endframe, int frameskip) 00460 { 00461 void* handle = AUD_addSequence(scene->sound_scene, sequence->sound->playback_handle, startframe / FPS, endframe / FPS, frameskip / FPS); 00462 AUD_muteSequence(handle, (sequence->flag & SEQ_MUTE) != 0); 00463 AUD_setSequenceAnimData(handle, AUD_AP_VOLUME, CFRA, &sequence->volume, 0); 00464 AUD_setSequenceAnimData(handle, AUD_AP_PITCH, CFRA, &sequence->pitch, 0); 00465 AUD_setSequenceAnimData(handle, AUD_AP_PANNING, CFRA, &sequence->pan, 0); 00466 return handle; 00467 } 00468 00469 void* sound_add_scene_sound_defaults(struct Scene *scene, struct Sequence* sequence) 00470 { 00471 return sound_add_scene_sound(scene, sequence, 00472 sequence->startdisp, sequence->enddisp, 00473 sequence->startofs + sequence->anim_startofs); 00474 } 00475 00476 void sound_remove_scene_sound(struct Scene *scene, void* handle) 00477 { 00478 AUD_removeSequence(scene->sound_scene, handle); 00479 } 00480 00481 void sound_mute_scene_sound(void* handle, char mute) 00482 { 00483 AUD_muteSequence(handle, mute); 00484 } 00485 00486 void sound_move_scene_sound(struct Scene *scene, void* handle, int startframe, int endframe, int frameskip) 00487 { 00488 AUD_moveSequence(handle, startframe / FPS, endframe / FPS, frameskip / FPS); 00489 } 00490 00491 void sound_move_scene_sound_defaults(struct Scene *scene, struct Sequence* sequence) 00492 { 00493 if (sequence->scene_sound) { 00494 sound_move_scene_sound(scene, sequence->scene_sound, 00495 sequence->startdisp, sequence->enddisp, 00496 sequence->startofs + sequence->anim_startofs); 00497 } 00498 } 00499 00500 void sound_update_scene_sound(void* handle, struct bSound* sound) 00501 { 00502 AUD_updateSequenceSound(handle, sound->playback_handle); 00503 } 00504 00505 void sound_set_cfra(int cfra) 00506 { 00507 sound_cfra = cfra; 00508 } 00509 00510 void sound_set_scene_volume(struct Scene *scene, float volume) 00511 { 00512 AUD_setSequencerAnimData(scene->sound_scene, AUD_AP_VOLUME, CFRA, &volume, (scene->audio.flag & AUDIO_VOLUME_ANIMATED) != 0); 00513 } 00514 00515 void sound_set_scene_sound_volume(void* handle, float volume, char animated) 00516 { 00517 AUD_setSequenceAnimData(handle, AUD_AP_VOLUME, sound_cfra, &volume, animated); 00518 } 00519 00520 void sound_set_scene_sound_pitch(void* handle, float pitch, char animated) 00521 { 00522 AUD_setSequenceAnimData(handle, AUD_AP_PITCH, sound_cfra, &pitch, animated); 00523 } 00524 00525 void sound_set_scene_sound_pan(void* handle, float pan, char animated) 00526 { 00527 AUD_setSequenceAnimData(handle, AUD_AP_PANNING, sound_cfra, &pan, animated); 00528 } 00529 00530 void sound_update_sequencer(struct Main* main, struct bSound* sound) 00531 { 00532 struct Scene* scene; 00533 00534 for(scene = main->scene.first; scene; scene = scene->id.next) 00535 seq_update_sound(scene, sound); 00536 } 00537 00538 static void sound_start_play_scene(struct Scene *scene) 00539 { 00540 if(scene->sound_scene_handle) 00541 AUD_stop(scene->sound_scene_handle); 00542 00543 AUD_setSequencerDeviceSpecs(scene->sound_scene); 00544 00545 if((scene->sound_scene_handle = AUD_play(scene->sound_scene, 1))) 00546 AUD_setLoop(scene->sound_scene_handle, -1); 00547 } 00548 00549 void sound_play_scene(struct Scene *scene) 00550 { 00551 AUD_Status status; 00552 AUD_lock(); 00553 00554 status = scene->sound_scene_handle ? AUD_getStatus(scene->sound_scene_handle) : AUD_STATUS_INVALID; 00555 00556 if(status == AUD_STATUS_INVALID) 00557 sound_start_play_scene(scene); 00558 00559 if(!scene->sound_scene_handle) 00560 { 00561 AUD_unlock(); 00562 return; 00563 } 00564 00565 if(status != AUD_STATUS_PLAYING) 00566 { 00567 AUD_seek(scene->sound_scene_handle, CFRA / FPS); 00568 AUD_resume(scene->sound_scene_handle); 00569 } 00570 00571 if(scene->audio.flag & AUDIO_SYNC) 00572 AUD_startPlayback(); 00573 00574 AUD_unlock(); 00575 } 00576 00577 void sound_stop_scene(struct Scene *scene) 00578 { 00579 if(scene->sound_scene_handle) 00580 { 00581 AUD_pause(scene->sound_scene_handle); 00582 00583 if(scene->audio.flag & AUDIO_SYNC) 00584 AUD_stopPlayback(); 00585 } 00586 } 00587 00588 void sound_seek_scene(struct Main *bmain, struct Scene *scene) 00589 { 00590 AUD_Status status; 00591 bScreen *screen; 00592 int animation_playing; 00593 00594 AUD_lock(); 00595 00596 status = scene->sound_scene_handle ? AUD_getStatus(scene->sound_scene_handle) : AUD_STATUS_INVALID; 00597 00598 if(status == AUD_STATUS_INVALID) 00599 { 00600 sound_start_play_scene(scene); 00601 00602 if(!scene->sound_scene_handle) 00603 { 00604 AUD_unlock(); 00605 return; 00606 } 00607 00608 AUD_pause(scene->sound_scene_handle); 00609 } 00610 00611 animation_playing = 0; 00612 for(screen=bmain->screen.first; screen; screen=screen->id.next) 00613 if(screen->animtimer) 00614 animation_playing = 1; 00615 00616 if(scene->audio.flag & AUDIO_SCRUB && !animation_playing) 00617 { 00618 if(scene->audio.flag & AUDIO_SYNC) 00619 { 00620 AUD_seek(scene->sound_scene_handle, CFRA / FPS); 00621 AUD_seekSequencer(scene->sound_scene_handle, CFRA / FPS); 00622 } 00623 else 00624 AUD_seek(scene->sound_scene_handle, CFRA / FPS); 00625 AUD_resume(scene->sound_scene_handle); 00626 if(scene->sound_scrub_handle && AUD_getStatus(scene->sound_scrub_handle) != AUD_STATUS_INVALID) 00627 AUD_seek(scene->sound_scrub_handle, 0); 00628 else 00629 { 00630 if(scene->sound_scrub_handle) 00631 AUD_stop(scene->sound_scrub_handle); 00632 scene->sound_scrub_handle = AUD_pauseAfter(scene->sound_scene_handle, 1 / FPS); 00633 } 00634 } 00635 else 00636 { 00637 if(scene->audio.flag & AUDIO_SYNC) 00638 AUD_seekSequencer(scene->sound_scene_handle, CFRA / FPS); 00639 else 00640 { 00641 if(status == AUD_STATUS_PLAYING) 00642 AUD_seek(scene->sound_scene_handle, CFRA / FPS); 00643 } 00644 } 00645 00646 AUD_unlock(); 00647 } 00648 00649 float sound_sync_scene(struct Scene *scene) 00650 { 00651 if(scene->sound_scene_handle) 00652 { 00653 if(scene->audio.flag & AUDIO_SYNC) 00654 return AUD_getSequencerPosition(scene->sound_scene_handle); 00655 else 00656 return AUD_getPosition(scene->sound_scene_handle); 00657 } 00658 return NAN_FLT; 00659 } 00660 00661 int sound_scene_playing(struct Scene *scene) 00662 { 00663 if(scene->audio.flag & AUDIO_SYNC) 00664 return AUD_doesPlayback(); 00665 else 00666 return -1; 00667 } 00668 00669 void sound_free_waveform(struct bSound* sound) 00670 { 00671 if(sound->waveform) 00672 { 00673 MEM_freeN(((SoundWaveform*)sound->waveform)->data); 00674 MEM_freeN(sound->waveform); 00675 } 00676 00677 sound->waveform = NULL; 00678 } 00679 00680 void sound_read_waveform(struct bSound* sound) 00681 { 00682 AUD_SoundInfo info; 00683 00684 info = AUD_getInfo(sound->playback_handle); 00685 00686 if(info.length > 0) 00687 { 00688 SoundWaveform* waveform = MEM_mallocN(sizeof(SoundWaveform), "SoundWaveform"); 00689 int length = info.length * SOUND_WAVE_SAMPLES_PER_SECOND; 00690 00691 waveform->data = MEM_mallocN(length * sizeof(float) * 3, "SoundWaveform.samples"); 00692 waveform->length = AUD_readSound(sound->playback_handle, waveform->data, length, SOUND_WAVE_SAMPLES_PER_SECOND); 00693 00694 sound_free_waveform(sound); 00695 sound->waveform = waveform; 00696 } 00697 } 00698 00699 void sound_update_scene(struct Scene* scene) 00700 { 00701 Object* ob; 00702 Base* base; 00703 NlaTrack* track; 00704 NlaStrip* strip; 00705 Speaker* speaker; 00706 Scene* sce_it; 00707 00708 void* new_set = AUD_createSet(); 00709 void* handle; 00710 float quat[4]; 00711 00712 for(SETLOOPER(scene, sce_it, base)) 00713 { 00714 ob = base->object; 00715 if(ob->type == OB_SPEAKER) 00716 { 00717 if(ob->adt) 00718 { 00719 for(track = ob->adt->nla_tracks.first; track; track = track->next) 00720 { 00721 for(strip = track->strips.first; strip; strip = strip->next) 00722 { 00723 if(strip->type == NLASTRIP_TYPE_SOUND) 00724 { 00725 speaker = (Speaker*)ob->data; 00726 00727 if(AUD_removeSet(scene->speaker_handles, strip->speaker_handle)) 00728 { 00729 if(speaker->sound) 00730 AUD_moveSequence(strip->speaker_handle, strip->start / FPS, -1, 0); 00731 else 00732 { 00733 AUD_removeSequence(scene->sound_scene, strip->speaker_handle); 00734 strip->speaker_handle = NULL; 00735 } 00736 } 00737 else 00738 { 00739 if(speaker->sound) 00740 { 00741 strip->speaker_handle = AUD_addSequence(scene->sound_scene, speaker->sound->playback_handle, strip->start / FPS, -1, 0); 00742 AUD_setRelativeSequence(strip->speaker_handle, 0); 00743 } 00744 } 00745 00746 if(strip->speaker_handle) 00747 { 00748 AUD_addSet(new_set, strip->speaker_handle); 00749 AUD_updateSequenceData(strip->speaker_handle, speaker->volume_max, 00750 speaker->volume_min, speaker->distance_max, 00751 speaker->distance_reference, speaker->attenuation, 00752 speaker->cone_angle_outer, speaker->cone_angle_inner, 00753 speaker->cone_volume_outer); 00754 00755 mat4_to_quat(quat, ob->obmat); 00756 AUD_setSequenceAnimData(strip->speaker_handle, AUD_AP_LOCATION, CFRA, ob->obmat[3], 1); 00757 AUD_setSequenceAnimData(strip->speaker_handle, AUD_AP_ORIENTATION, CFRA, quat, 1); 00758 AUD_setSequenceAnimData(strip->speaker_handle, AUD_AP_VOLUME, CFRA, &speaker->volume, 1); 00759 AUD_setSequenceAnimData(strip->speaker_handle, AUD_AP_PITCH, CFRA, &speaker->pitch, 1); 00760 AUD_updateSequenceSound(strip->speaker_handle, speaker->sound->playback_handle); 00761 AUD_muteSequence(strip->speaker_handle, ((strip->flag & NLASTRIP_FLAG_MUTED) != 0) || ((speaker->flag & SPK_MUTED) != 0)); 00762 } 00763 } 00764 } 00765 } 00766 } 00767 } 00768 } 00769 00770 while((handle = AUD_getSet(scene->speaker_handles))) 00771 { 00772 AUD_removeSequence(scene->sound_scene, handle); 00773 } 00774 00775 if(scene->camera) 00776 { 00777 mat4_to_quat(quat, scene->camera->obmat); 00778 AUD_setSequencerAnimData(scene->sound_scene, AUD_AP_LOCATION, CFRA, scene->camera->obmat[3], 1); 00779 AUD_setSequencerAnimData(scene->sound_scene, AUD_AP_ORIENTATION, CFRA, quat, 1); 00780 } 00781 00782 AUD_destroySet(scene->speaker_handles); 00783 scene->speaker_handles = new_set; 00784 } 00785 00786 void* sound_get_factory(void* sound) 00787 { 00788 return ((struct bSound*) sound)->playback_handle; 00789 } 00790 00791 #else // WITH_AUDASPACE 00792 00793 #include "BLI_utildefines.h" 00794 00795 int sound_define_from_str(const char *UNUSED(str)) { return -1;} 00796 void sound_force_device(int UNUSED(device)) {} 00797 void sound_init_once(void) {} 00798 void sound_init(struct Main *UNUSED(bmain)) {} 00799 void sound_exit(void) {} 00800 void sound_cache(struct bSound* UNUSED(sound)) { } 00801 void sound_delete_cache(struct bSound* UNUSED(sound)) {} 00802 void sound_load(struct Main *UNUSED(bmain), struct bSound* UNUSED(sound)) {} 00803 void sound_create_scene(struct Scene *UNUSED(scene)) {} 00804 void sound_destroy_scene(struct Scene *UNUSED(scene)) {} 00805 void sound_mute_scene(struct Scene *UNUSED(scene), int UNUSED(muted)) {} 00806 void* sound_scene_add_scene_sound(struct Scene *UNUSED(scene), struct Sequence* UNUSED(sequence), int UNUSED(startframe), int UNUSED(endframe), int UNUSED(frameskip)) { return NULL; } 00807 void* sound_scene_add_scene_sound_defaults(struct Scene *UNUSED(scene), struct Sequence* UNUSED(sequence)) { return NULL; } 00808 void* sound_add_scene_sound(struct Scene *UNUSED(scene), struct Sequence* UNUSED(sequence), int UNUSED(startframe), int UNUSED(endframe), int UNUSED(frameskip)) { return NULL; } 00809 void* sound_add_scene_sound_defaults(struct Scene *UNUSED(scene), struct Sequence* UNUSED(sequence)) { return NULL; } 00810 void sound_remove_scene_sound(struct Scene *UNUSED(scene), void* UNUSED(handle)) {} 00811 void sound_mute_scene_sound(void* UNUSED(handle), char UNUSED(mute)) {} 00812 void sound_move_scene_sound(struct Scene *UNUSED(scene), void* UNUSED(handle), int UNUSED(startframe), int UNUSED(endframe), int UNUSED(frameskip)) {} 00813 void sound_move_scene_sound_defaults(struct Scene *UNUSED(scene), struct Sequence *UNUSED(sequence)) {} 00814 void sound_play_scene(struct Scene *UNUSED(scene)) {} 00815 void sound_stop_scene(struct Scene *UNUSED(scene)) {} 00816 void sound_seek_scene(struct Main *UNUSED(bmain), struct Scene *UNUSED(scene)) {} 00817 float sound_sync_scene(struct Scene *UNUSED(scene)) { return NAN_FLT; } 00818 int sound_scene_playing(struct Scene *UNUSED(scene)) { return -1; } 00819 int sound_read_sound_buffer(struct bSound* UNUSED(sound), float* UNUSED(buffer), int UNUSED(length), float UNUSED(start), float UNUSED(end)) { return 0; } 00820 void sound_read_waveform(struct bSound* sound) { (void)sound; } 00821 void sound_init_main(struct Main *bmain) { (void)bmain; } 00822 void sound_set_cfra(int cfra) { (void)cfra; } 00823 void sound_update_sequencer(struct Main* main, struct bSound* sound) { (void)main; (void)sound; } 00824 void sound_update_scene(struct Scene* scene) { (void)scene; } 00825 void sound_update_scene_sound(void* handle, struct bSound* sound) { (void)handle; (void)sound; } 00826 void sound_update_scene_listener(struct Scene *scene) { (void)scene; } 00827 void sound_update_fps(struct Scene *scene) { (void)scene; } 00828 void sound_set_scene_sound_volume(void* handle, float volume, char animated) { (void)handle; (void)volume; (void)animated; } 00829 void sound_set_scene_sound_pan(void* handle, float pan, char animated) { (void)handle; (void)pan; (void)animated; } 00830 void sound_set_scene_volume(struct Scene *scene, float volume) { (void)scene; (void)volume; } 00831 void sound_set_scene_sound_pitch(void* handle, float pitch, char animated) { (void)handle; (void)pitch; (void)animated; } 00832 00833 #endif // WITH_AUDASPACE