diff options
author | Joerg Mueller <nexyon@gmail.com> | 2009-08-10 01:16:39 +0400 |
---|---|---|
committer | Joerg Mueller <nexyon@gmail.com> | 2009-08-10 01:16:39 +0400 |
commit | 6c5c58e05799f2b593cd81fcff57e6ef72ad57fb (patch) | |
tree | 8add929ef94d03fc69aecce6ef2baf283505782f /source | |
parent | c1ca2ab5dceb8d5355215a3c7a80b171f394e487 (diff) |
2.5: Sound branch merge!
See mailing list for additional information.
Diffstat (limited to 'source')
60 files changed, 1292 insertions, 1161 deletions
diff --git a/source/blender/blenkernel/BKE_packedFile.h b/source/blender/blenkernel/BKE_packedFile.h index efd930d375a..b6513bede99 100644 --- a/source/blender/blenkernel/BKE_packedFile.h +++ b/source/blender/blenkernel/BKE_packedFile.h @@ -34,7 +34,6 @@ #define RET_OK 0 #define RET_ERROR 1 -struct bSample; struct bSound; struct Image; struct Main; @@ -51,7 +50,7 @@ void packAll(struct Main *bmain, struct ReportList *reports); /* unpack */ char *unpackFile(struct ReportList *reports, char *abs_name, char *local_name, struct PackedFile *pf, int how); int unpackVFont(struct ReportList *reports, struct VFont *vfont, int how); -int unpackSample(struct ReportList *reports, struct bSample *sample, int how); +int unpackSound(struct ReportList *reports, struct bSound *sound, int how); int unpackImage(struct ReportList *reports, struct Image *ima, int how); void unpackAll(struct Main *bmain, struct ReportList *reports, int how); diff --git a/source/blender/blenkernel/BKE_sequence.h b/source/blender/blenkernel/BKE_sequence.h index 7162fa7b9dd..35cff5c9422 100644 --- a/source/blender/blenkernel/BKE_sequence.h +++ b/source/blender/blenkernel/BKE_sequence.h @@ -37,6 +37,7 @@ struct Strip; struct StripElem; struct ImBuf; struct Scene; +struct bContext; #define MAXSEQ 32 @@ -44,7 +45,6 @@ struct Scene; #define BUILD_SEQAR_COUNT_CURRENT 1 #define BUILD_SEQAR_COUNT_CHILDREN 2 - /* sequence iterator */ typedef struct SeqIterator { @@ -137,9 +137,9 @@ struct SeqEffectHandle { /* sequence.c */ // extern -void seq_free_sequence(struct Editing *ed, struct Sequence *seq); +void seq_free_sequence(struct Scene *scene, struct Sequence *seq); void seq_free_strip(struct Strip *strip); -void seq_free_editing(struct Editing *ed); +void seq_free_editing(struct Scene *scene); struct Editing *seq_give_editing(struct Scene *scene, int alloc); char *give_seqname(struct Sequence *seq); struct ImBuf *give_ibuf_seq(struct Scene *scene, int rectx, int recty, int cfra, int chanshown, int render_size); @@ -183,3 +183,4 @@ int seq_test_overlap(struct ListBase * seqbasep, struct Sequence *test); int shuffle_seq(struct ListBase * seqbasep, struct Sequence *test); void free_imbuf_seq(struct ListBase * seqbasep, int check_mem_usage); +void seq_update_sound(struct Sequence *seq); diff --git a/source/blender/blenkernel/BKE_sound.h b/source/blender/blenkernel/BKE_sound.h index f3bed467c3a..ef66b29f112 100644 --- a/source/blender/blenkernel/BKE_sound.h +++ b/source/blender/blenkernel/BKE_sound.h @@ -1,7 +1,7 @@ /** * sound.h (mar-2001 nzc) - * - * $Id$ + * + * $Id$ * * ***** BEGIN GPL LICENSE BLOCK ***** * @@ -33,20 +33,47 @@ struct PackedFile; struct bSound; -struct bSample; +struct bContext; struct ListBase; +struct Main; + +void sound_init(); -/* bad bad global... */ -extern struct ListBase *samples; +void sound_reinit(struct bContext *C); -void sound_free_all_samples(void); +void sound_exit(); -/* void *sound_get_listener(void); implemented in src!also declared there now */ +struct bSound* sound_new_file(struct Main *main, char* filename); -void sound_set_packedfile(struct bSample* sample, struct PackedFile* pf); -struct PackedFile* sound_find_packedfile(struct bSound* sound); -void sound_free_sample(struct bSample* sample); -void sound_free_sound(struct bSound* sound); +// XXX unused currently +#if 0 +struct bSound* sound_new_buffer(struct bContext *C, struct bSound *source); +struct bSound* sound_new_limiter(struct bContext *C, struct bSound *source, float start, float end); #endif +void sound_delete(struct bContext *C, struct bSound* sound); + +void sound_cache(struct bSound* sound, int ignore); + +void sound_load(struct bSound* sound); + +void sound_free(struct bSound* sound); + +void sound_unlink(struct bContext *C, struct bSound* sound); + +struct SoundHandle* sound_new_handle(struct Scene *scene, struct bSound* sound, int startframe, int endframe, int frameskip); + +void sound_delete_handle(struct Scene *scene, struct SoundHandle *handle); + +void sound_update_playing(struct bContext *C); + +void sound_scrub(struct bContext *C); + +#ifdef AUD_CAPI +AUD_Device* sound_mixdown(struct Scene *scene, AUD_Specs specs, int start, int end); +#endif + +void sound_stop_all(struct bContext *C); + +#endif diff --git a/source/blender/blenkernel/BKE_writeavi.h b/source/blender/blenkernel/BKE_writeavi.h index cae1f25d0d8..4ef63b069c2 100644 --- a/source/blender/blenkernel/BKE_writeavi.h +++ b/source/blender/blenkernel/BKE_writeavi.h @@ -37,13 +37,14 @@ extern "C" { /* generic blender movie support, could move to own module */ struct RenderData; -void start_avi(struct RenderData *rd, int rectx, int recty); +struct Scene; +void start_avi(struct Scene *scene, struct RenderData *rd, int rectx, int recty); void end_avi(void); void append_avi(struct RenderData *rd, int frame, int *pixels, int rectx, int recty); void makeavistring (struct RenderData *rd, char *string); typedef struct bMovieHandle { - void (*start_movie)(struct RenderData *rd, int rectx, int recty); + void (*start_movie)(struct Scene *scene, struct RenderData *rd, int rectx, int recty); void (*append_movie)(struct RenderData *rd, int frame, int *pixels, int rectx, int recty); void (*end_movie)(void); int (*get_next_frame)(struct RenderData *rd); /* optional */ diff --git a/source/blender/blenkernel/BKE_writeffmpeg.h b/source/blender/blenkernel/BKE_writeffmpeg.h index be136bd9d6d..07e0e01ef7e 100644 --- a/source/blender/blenkernel/BKE_writeffmpeg.h +++ b/source/blender/blenkernel/BKE_writeffmpeg.h @@ -57,8 +57,9 @@ extern "C" { struct IDProperty; struct RenderData; +struct Scene; -extern void start_ffmpeg(struct RenderData *rd, int rectx, int recty); +extern void start_ffmpeg(struct Scene *scene, struct RenderData *rd, int rectx, int recty); extern void end_ffmpeg(void); extern void append_ffmpeg(struct RenderData *rd, int frame, int *pixels, int rectx, int recty); diff --git a/source/blender/blenkernel/BKE_writeframeserver.h b/source/blender/blenkernel/BKE_writeframeserver.h index e870cbb865d..6a38abe977f 100644 --- a/source/blender/blenkernel/BKE_writeframeserver.h +++ b/source/blender/blenkernel/BKE_writeframeserver.h @@ -33,8 +33,9 @@ extern "C" { #endif struct RenderData; +struct Scene; -extern void start_frameserver(struct RenderData *rd, int rectx, int recty); +extern void start_frameserver(struct Scene *scene, struct RenderData *rd, int rectx, int recty); extern void end_frameserver(void); extern void append_frameserver(struct RenderData *rd, int frame, int *pixels, int rectx, int recty); extern int frameserver_loop(struct RenderData *rd); diff --git a/source/blender/blenkernel/CMakeLists.txt b/source/blender/blenkernel/CMakeLists.txt index a2a7457545d..db9bbfcc5e7 100644 --- a/source/blender/blenkernel/CMakeLists.txt +++ b/source/blender/blenkernel/CMakeLists.txt @@ -34,6 +34,7 @@ SET(INC ../../../extern/bullet2/src ../nodes ../../../extern/glew/include ../gpu ../makesrna ../../../intern/smoke/extern ../../../intern/bsp/extern + ../../../intern/audaspace ${ZLIB_INC} ) diff --git a/source/blender/blenkernel/SConscript b/source/blender/blenkernel/SConscript index 5b1c7b163ba..ce0ee5cf3c8 100644 --- a/source/blender/blenkernel/SConscript +++ b/source/blender/blenkernel/SConscript @@ -11,6 +11,7 @@ incs += ' #/extern/bullet2/src' incs += ' #/intern/opennl/extern #/intern/bsp/extern' incs += ' ../gpu #/extern/glew/include' incs += ' #/intern/smoke/extern' +incs += ' #/intern/audaspace' incs += ' ' + env['BF_OPENGL_INC'] incs += ' ' + env['BF_ZLIB_INC'] diff --git a/source/blender/blenkernel/intern/blender.c b/source/blender/blenkernel/intern/blender.c index 2728aa30e6e..2e4e5596450 100644 --- a/source/blender/blenkernel/intern/blender.c +++ b/source/blender/blenkernel/intern/blender.c @@ -176,8 +176,6 @@ void pushpop_test() void free_blender(void) { /* samples are in a global list..., also sets G.main->sound->sample NULL */ - sound_free_all_samples(); - free_main(G.main); G.main= NULL; @@ -330,9 +328,6 @@ static void setup_app_data(bContext *C, BlendFileData *bfd, char *filename) MEM_freeN(bfd->user); } - /* samples is a global list... */ - sound_free_all_samples(); - /* case G_FILE_NO_UI or no screens in file */ if(mode) { /* leave entire context further unaltered? */ diff --git a/source/blender/blenkernel/intern/library.c b/source/blender/blenkernel/intern/library.c index ff065fd4bf6..3c8bf9200f8 100644 --- a/source/blender/blenkernel/intern/library.c +++ b/source/blender/blenkernel/intern/library.c @@ -567,7 +567,7 @@ void free_libblock(ListBase *lb, void *idv) //XXX free_script((Script *)id); break; case ID_SO: - sound_free_sound((bSound *)id); + sound_free((bSound*)id); break; case ID_GR: free_group((Group *)id); diff --git a/source/blender/blenkernel/intern/packedFile.c b/source/blender/blenkernel/intern/packedFile.c index 590189fbd5d..8c77ed92aa1 100644 --- a/source/blender/blenkernel/intern/packedFile.c +++ b/source/blender/blenkernel/intern/packedFile.c @@ -123,7 +123,7 @@ int countPackedFiles(Main *bmain) { Image *ima; VFont *vf; - bSample *sample; + bSound *sound; int count = 0; // let's check if there are packed files... @@ -135,10 +135,9 @@ int countPackedFiles(Main *bmain) if(vf->packedfile) count++; - if(samples) - for(sample=samples->first; sample; sample=sample->id.next) - if(sample->packedfile) - count++; + for(sound=bmain->sound.first; sound; sound=sound->id.next) + if(sound->packedfile) + count++; return count; } @@ -208,8 +207,8 @@ void packAll(Main *bmain, ReportList *reports) { Image *ima; VFont *vf; - bSample *sample; - + bSound *sound; + for(ima=bmain->image.first; ima; ima=ima->id.next) if(ima->packedfile == NULL) ima->packedfile = newPackedFile(reports, ima->name); @@ -218,10 +217,9 @@ void packAll(Main *bmain, ReportList *reports) if(vf->packedfile == NULL) vf->packedfile = newPackedFile(reports, vf->name); - if(samples) - for(sample=samples->first; sample; sample=sample->id.next) - if(sample->packedfile == NULL) - sound_set_packedfile(sample, newPackedFile(reports, sample->name)); + for(sound=bmain->sound.first; sound; sound=sound->id.next) + if(sound->packedfile == NULL) + sound->packedfile = newPackedFile(reports, sound->name); } @@ -456,28 +454,26 @@ int unpackVFont(ReportList *reports, VFont *vfont, int how) return (ret_value); } -int unpackSample(ReportList *reports, bSample *sample, int how) +int unpackSound(ReportList *reports, bSound *sound, int how) { char localname[FILE_MAXDIR + FILE_MAX], fi[FILE_MAX]; char *newname; int ret_value = RET_ERROR; - PackedFile *pf; - - if (sample != NULL) { - strcpy(localname, sample->name); + + if (sound != NULL) { + strcpy(localname, sound->name); BLI_splitdirstring(localname, fi); - sprintf(localname, "//samples/%s", fi); - - newname = unpackFile(reports, sample->name, localname, sample->packedfile, how); + sprintf(localname, "//sounds/%s", fi); + + newname = unpackFile(reports, sound->name, localname, sound->packedfile, how); if (newname != NULL) { - strcpy(sample->name, newname); + strcpy(sound->name, newname); MEM_freeN(newname); - pf = sample->packedfile; - // because samples and sounds can point to the - // same packedfile we have to check them all - sound_set_packedfile(sample, NULL); - freePackedFile(pf); + freePackedFile(sound->packedfile); + sound->packedfile = 0; + + sound_load(sound); ret_value = RET_OK; } @@ -515,7 +511,7 @@ void unpackAll(Main *bmain, ReportList *reports, int how) { Image *ima; VFont *vf; - bSample *sample; + bSound *sound; for(ima=bmain->image.first; ima; ima=ima->id.next) if(ima->packedfile) @@ -525,9 +521,8 @@ void unpackAll(Main *bmain, ReportList *reports, int how) if(vf->packedfile) unpackVFont(reports, vf, how); - if(samples) - for(sample=samples->first; sample; sample=sample->id.next) - if(sample->packedfile) - unpackSample(reports, sample, how); + for(sound=bmain->sound.first; sound; sound=sound->id.next) + if(sound->packedfile) + unpackSound(reports, sound, how); } diff --git a/source/blender/blenkernel/intern/sca.c b/source/blender/blenkernel/intern/sca.c index 74d2347ec39..9a66603fef0 100644 --- a/source/blender/blenkernel/intern/sca.c +++ b/source/blender/blenkernel/intern/sca.c @@ -35,6 +35,8 @@ #include <stdio.h> #include <string.h> +#include <float.h> + #include "MEM_guardedalloc.h" #include "DNA_text_types.h" @@ -410,6 +412,7 @@ void init_actuator(bActuator *act) { /* also use when actuator changes type */ bObjectActuator *oa; + bSoundActuator *sa; if(act->data) MEM_freeN(act->data); act->data= 0; @@ -422,7 +425,14 @@ void init_actuator(bActuator *act) break; #endif case ACT_SOUND: - act->data= MEM_callocN(sizeof(bSoundActuator), "soundact"); + sa = act->data= MEM_callocN(sizeof(bSoundActuator), "soundact"); + sa->volume = 1.0f; + sa->sound3D.rolloff_factor = 1.0f; + sa->sound3D.reference_distance = 1.0f; + sa->sound3D.max_gain = 1.0f; + sa->sound3D.cone_inner_angle = 360.0f; + sa->sound3D.cone_outer_angle = 360.0f; + sa->sound3D.max_distance = FLT_MAX; break; case ACT_CD: act->data= MEM_callocN(sizeof(bCDActuator), "cdact"); diff --git a/source/blender/blenkernel/intern/scene.c b/source/blender/blenkernel/intern/scene.c index a44118d186b..0a93874f24e 100644 --- a/source/blender/blenkernel/intern/scene.c +++ b/source/blender/blenkernel/intern/scene.c @@ -140,7 +140,7 @@ void free_scene(Scene *sce) /* do not free objects! */ BLI_freelistN(&sce->base); - seq_free_editing(sce->ed); + seq_free_editing(sce); BKE_free_animdata((ID *)sce); BKE_keyingsets_free(&sce->keyingsets); diff --git a/source/blender/blenkernel/intern/sequence.c b/source/blender/blenkernel/intern/sequence.c index 3b675a87e59..159a60ad3af 100644 --- a/source/blender/blenkernel/intern/sequence.c +++ b/source/blender/blenkernel/intern/sequence.c @@ -52,6 +52,10 @@ #include "BLI_threads.h" #include <pthread.h> +#include "BKE_context.h" +#include "BKE_sound.h" +#include "AUD_C-API.h" + #ifdef WIN32 #define snprintf _snprintf #endif @@ -178,12 +182,16 @@ void seq_free_strip(Strip *strip) MEM_freeN(strip); } -void seq_free_sequence(Editing *ed, Sequence *seq) +void seq_free_sequence(Scene *scene, Sequence *seq) { + Editing *ed = scene->ed; + if(seq->strip) seq_free_strip(seq->strip); if(seq->anim) IMB_free_anim(seq->anim); - //XXX if(seq->hdaudio) sound_close_hdaudio(seq->hdaudio); + + if(seq->sound_handle) + sound_delete_handle(scene, seq->sound_handle); if (seq->type & SEQ_EFFECT) { struct SeqEffectHandle sh = get_sequence_effect(seq); @@ -208,8 +216,9 @@ Editing *seq_give_editing(Scene *scene, int alloc) return scene->ed; } -void seq_free_editing(Editing *ed) +void seq_free_editing(Scene *scene) { + Editing *ed = scene->ed; MetaStack *ms; Sequence *seq; @@ -217,7 +226,7 @@ void seq_free_editing(Editing *ed) return; SEQ_BEGIN(ed, seq) { - seq_free_sequence(ed, seq); + seq_free_sequence(scene, seq); } SEQ_END @@ -444,6 +453,8 @@ void calc_sequence_disp(Sequence *seq) else if(seq->enddisp-seq->startdisp > 250) { seq->handsize= (float)((seq->enddisp-seq->startdisp)/25); } + + seq_update_sound(seq); } void calc_sequence(Sequence *seq) @@ -515,8 +526,8 @@ void reload_sequence_new_file(Scene *scene, Sequence * seq) char str[FILE_MAXDIR+FILE_MAXFILE]; if (!(seq->type == SEQ_MOVIE || seq->type == SEQ_IMAGE || - seq->type == SEQ_HD_SOUND || seq->type == SEQ_RAM_SOUND || - seq->type == SEQ_SCENE || seq->type == SEQ_META)) { + seq->type == SEQ_SOUND || + seq->type == SEQ_SCENE || seq->type == SEQ_META)) { return; } @@ -558,23 +569,8 @@ void reload_sequence_new_file(Scene *scene, Sequence * seq) seq->len = 0; } seq->strip->len = seq->len; - } else if (seq->type == SEQ_HD_SOUND) { -// XXX if(seq->hdaudio) sound_close_hdaudio(seq->hdaudio); -// seq->hdaudio = sound_open_hdaudio(str); - - if (!seq->hdaudio) { - return; - } - -// XXX seq->len = sound_hdaudio_get_duration(seq->hdaudio, FPS) - seq->anim_startofs - seq->anim_endofs; - if (seq->len < 0) { - seq->len = 0; - } - seq->strip->len = seq->len; - } else if (seq->type == SEQ_RAM_SOUND) { - seq->len = (int) ( ((float)(seq->sound->streamlen-1)/ - ((float)scene->audio.mixrate*4.0 )) - * FPS); + } else if (seq->type == SEQ_SOUND) { + seq->len = AUD_getInfo(seq->sound->snd_sound).length * FPS; seq->len -= seq->anim_startofs; seq->len -= seq->anim_endofs; if (seq->len < 0) { @@ -693,8 +689,7 @@ char *give_seqname_by_type(int type) case SEQ_IMAGE: return "Image"; case SEQ_SCENE: return "Scene"; case SEQ_MOVIE: return "Movie"; - case SEQ_RAM_SOUND: return "Audio (RAM)"; - case SEQ_HD_SOUND: return "Audio (HD)"; + case SEQ_SOUND: return "Audio"; case SEQ_CROSS: return "Cross"; case SEQ_GAMCROSS: return "Gamma Cross"; case SEQ_ADD: return "Add"; @@ -1071,10 +1066,9 @@ int evaluate_seq_frame(Scene *scene, int cfra) static int video_seq_is_rendered(Sequence * seq) { - return (seq - && !(seq->flag & SEQ_MUTE) - && seq->type != SEQ_RAM_SOUND - && seq->type != SEQ_HD_SOUND); + return (seq + && !(seq->flag & SEQ_MUTE) + && seq->type != SEQ_SOUND); } static int get_shown_sequences( ListBase * seqbasep, int cfra, int chanshown, Sequence ** seq_arr_out) @@ -3309,7 +3303,7 @@ void seq_tx_handle_xlimits(Sequence *seq, int leftflag, int rightflag) } /* sounds cannot be extended past their endpoints */ - if (seq->type == SEQ_RAM_SOUND || seq->type == SEQ_HD_SOUND) { + if (seq->type == SEQ_SOUND) { seq->startstill= 0; seq->endstill= 0; } @@ -3406,3 +3400,15 @@ int shuffle_seq(ListBase * seqbasep, Sequence *test) return 1; } } + +void seq_update_sound(struct Sequence *seq) +{ + if(seq->type == SEQ_SOUND) + { + seq->sound_handle->startframe = seq->startdisp; + seq->sound_handle->endframe = seq->enddisp; + seq->sound_handle->frameskip = seq->startofs + seq->anim_startofs; + seq->sound_handle->mute = seq->flag & SEQ_MUTE ? 1 : 0; + seq->sound_handle->changed = -1; + } +} diff --git a/source/blender/blenkernel/intern/sound.c b/source/blender/blenkernel/intern/sound.c index 2c5b49246fb..347837d1dd0 100644 --- a/source/blender/blenkernel/intern/sound.c +++ b/source/blender/blenkernel/intern/sound.c @@ -1,6 +1,6 @@ /** * sound.c (mar-2001 nzc) - * + * * $Id$ */ @@ -14,125 +14,468 @@ #include "DNA_scene_types.h" #include "DNA_sound_types.h" #include "DNA_packedFile_types.h" +#include "DNA_screen_types.h" +#include "DNA_userdef_types.h" + +#include "AUD_C-API.h" #include "BKE_utildefines.h" #include "BKE_global.h" #include "BKE_main.h" #include "BKE_sound.h" +#include "BKE_context.h" +#include "BKE_library.h" #include "BKE_packedFile.h" #ifdef HAVE_CONFIG_H #include <config.h> #endif -ListBase _samples = {0,0}, *samples = &_samples; +void sound_init() +{ + AUD_Specs specs; + specs.channels = AUD_CHANNELS_STEREO; + specs.format = AUD_FORMAT_S16; + specs.rate = AUD_RATE_44100; + + if(!AUD_init(AUD_SDL_DEVICE, specs, AUD_DEFAULT_BUFFER_SIZE)) + if(!AUD_init(AUD_OPENAL_DEVICE, specs, AUD_DEFAULT_BUFFER_SIZE*4)) + AUD_init(AUD_NULL_DEVICE, specs, AUD_DEFAULT_BUFFER_SIZE); +} -void sound_free_sound(bSound *sound) +void sound_reinit(struct bContext *C) { - /* when sounds have been loaded, but not played, the packedfile was not copied - to sample block and not freed otherwise */ - if(sound->sample==NULL) { - if (sound->newpackedfile) { - freePackedFile(sound->newpackedfile); - sound->newpackedfile = NULL; - } + AUD_Specs specs; + int device, buffersize; + + device = U.audiodevice; + buffersize = U.mixbufsize; + specs.channels = U.audiochannels; + specs.format = U.audioformat; + specs.rate = U.audiorate; + + if(buffersize < 128) + buffersize = AUD_DEFAULT_BUFFER_SIZE; + + if(specs.rate < AUD_RATE_8000) + specs.rate = AUD_RATE_44100; + + if(specs.format <= AUD_FORMAT_INVALID) + specs.format = AUD_FORMAT_S16; + + if(specs.channels <= AUD_CHANNELS_INVALID) + specs.channels = AUD_CHANNELS_STEREO; + + if(!AUD_init(device, specs, buffersize)) + AUD_init(AUD_NULL_DEVICE, specs, buffersize); +} + +void sound_exit() +{ + AUD_exit(); +} + +struct bSound* sound_new_file(struct Main *main, char* filename) +{ + bSound* sound = NULL; + + char str[FILE_MAX]; + int len; + + strcpy(str, filename); + BLI_convertstringcode(str, G.sce); + + len = strlen(filename); + while(len > 0 && filename[len-1] != '/' && filename[len-1] != '\\') + len--; + + sound = alloc_libblock(&main->sound, ID_SO, filename+len); + strcpy(sound->name, filename); + sound->type = SOUND_TYPE_FILE; + + sound_load(sound); + + if(!sound->snd_sound) + { + free_libblock(&main->sound, sound); + sound = NULL; + } + + return sound; +} + +// XXX unused currently +#if 0 +struct bSound* sound_new_buffer(struct bContext *C, struct bSound *source) +{ + bSound* sound = NULL; + + char name[25]; + strcpy(name, "buf_"); + strcpy(name + 4, source->id.name); + + sound = alloc_libblock(&CTX_data_main(C)->sound, ID_SO, name); + + sound->child_sound = source; + sound->type = SOUND_TYPE_BUFFER; + + sound_load(sound); + + if(!sound->snd_sound) + { + free_libblock(&CTX_data_main(C)->sound, sound); + sound = NULL; + } + + return sound; +} + +struct bSound* sound_new_limiter(struct bContext *C, struct bSound *source, float start, float end) +{ + bSound* sound = NULL; + + char name[25]; + strcpy(name, "lim_"); + strcpy(name + 4, source->id.name); + + sound = alloc_libblock(&CTX_data_main(C)->sound, ID_SO, name); + + sound->child_sound = source; + sound->start = start; + sound->end = end; + sound->type = SOUND_TYPE_LIMITER; + + sound_load(sound); + + if(!sound->snd_sound) + { + free_libblock(&CTX_data_main(C)->sound, sound); + sound = NULL; + } + + return sound; +} +#endif + +void sound_delete(struct bContext *C, struct bSound* sound) +{ + if(sound) + { + sound_free(sound); + + sound_unlink(C, sound); + + free_libblock(&CTX_data_main(C)->sound, sound); } - if (sound->stream) free(sound->stream); } -void sound_free_sample(bSample *sample) +void sound_cache(struct bSound* sound, int ignore) +{ + if(sound->cache && !ignore) + AUD_unload(sound->cache); + + sound->cache = AUD_bufferSound(sound->snd_sound); +} + +void sound_load(struct bSound* sound) { - if (sample) { - if (sample->data != &sample->fakedata[0] && sample->data != NULL) { - MEM_freeN(sample->data); - sample->data = &sample->fakedata[0]; + if(sound) + { + if(sound->snd_sound) + { + AUD_unload(sound->snd_sound); + sound->snd_sound = NULL; } - - if (sample->packedfile) { - freePackedFile(sample->packedfile); //FIXME: crashes sometimes - sample->packedfile = NULL; + + switch(sound->type) + { + case SOUND_TYPE_FILE: + { + char fullpath[FILE_MAX]; + char *path; + + /* load sound */ + PackedFile* pf = sound->packedfile; + + /* dont modify soundact->sound->name, only change a copy */ + BLI_strncpy(fullpath, sound->name, sizeof(fullpath)); + + if(sound->id.lib) + path = sound->id.lib->filename; + else + path = G.sce; + + BLI_convertstringcode(fullpath, path); + + /* but we need a packed file then */ + if (pf) + sound->snd_sound = AUD_loadBuffer((unsigned char*) pf->data, pf->size); + /* or else load it from disk */ + else + sound->snd_sound = AUD_load(fullpath); + break; } - - if (sample->alindex != SAMPLE_INVALID) { -// AUD_free_sample(sample->snd_sample); - sample->alindex = SAMPLE_INVALID; + case SOUND_TYPE_BUFFER: + if(sound->child_sound && sound->child_sound->snd_sound) + sound->snd_sound = AUD_bufferSound(sound->child_sound->snd_sound); + break; + case SOUND_TYPE_LIMITER: + if(sound->child_sound && sound->child_sound->snd_sound) + sound->snd_sound = AUD_limitSound(sound->child_sound, sound->start, sound->end); + break; } - sample->type = SAMPLE_INVALID; + if(sound->cache) + { + + } } } -/* this is called after file reading or undos */ -void sound_free_all_samples(void) +void sound_free(struct bSound* sound) { - bSample *sample; - bSound *sound; - - /* ensure no sample pointers exist, and check packedfile */ - for(sound= G.main->sound.first; sound; sound= sound->id.next) { - if(sound->sample && sound->sample->packedfile==sound->newpackedfile) - sound->newpackedfile= NULL; - sound->sample= NULL; + if (sound->packedfile) + { + freePackedFile(sound->packedfile); + sound->packedfile = NULL; } - - /* now free samples */ - for(sample= samples->first; sample; sample= sample->id.next) - sound_free_sample(sample); - BLI_freelistN(samples); - -} - -void sound_set_packedfile(bSample *sample, PackedFile *pf) -{ - bSound *sound; - - if (sample) { - sample->packedfile = pf; - sound = G.main->sound.first; - while (sound) { - if (sound->sample == sample) { - sound->newpackedfile = pf; - if (pf == NULL) { - strcpy(sound->name, sample->name); + + if(sound->snd_sound) + { + AUD_unload(sound->snd_sound); + sound->snd_sound = NULL; + } +} + +void sound_unlink(struct bContext *C, struct bSound* sound) +{ + bSound *snd; + Scene *scene; + SoundHandle *handle; + + for(snd = CTX_data_main(C)->sound.first; snd; snd = snd->id.next) + { + if(snd->child_sound == sound) + { + snd->child_sound = NULL; + if(snd->snd_sound) + { + AUD_unload(sound->snd_sound); + snd->snd_sound = NULL; + } + + sound_unlink(C, snd); + } + } + + for(scene = CTX_data_main(C)->scene.first; scene; scene = scene->id.next) + { + for(handle = scene->sound_handles.first; handle; handle = handle->next) + { + if(handle->source == sound) + { + handle->source = NULL; + if(handle->handle) + AUD_stop(handle->handle); + } + } + } +} + +struct SoundHandle* sound_new_handle(struct Scene *scene, struct bSound* sound, int startframe, int endframe, int frameskip) +{ + ListBase* handles = &scene->sound_handles; + + SoundHandle* handle = MEM_callocN(sizeof(SoundHandle), "sound_handle"); + handle->source = sound; + handle->startframe = startframe; + handle->endframe = endframe; + handle->frameskip = frameskip; + handle->state = AUD_STATUS_INVALID; + handle->volume = 1.0f; + + BLI_addtail(handles, handle); + + return handle; +} + +void sound_delete_handle(struct Scene *scene, struct SoundHandle *handle) +{ + if(handle == NULL) + return; + + if(handle->handle) + AUD_stop(handle->handle); + + BLI_freelinkN(&scene->sound_handles, handle); +} + +void sound_stop_all(struct bContext *C) +{ + SoundHandle *handle; + + for(handle = CTX_data_scene(C)->sound_handles.first; handle; handle = handle->next) + { + if(handle->state == AUD_STATUS_PLAYING) + { + AUD_pause(handle->handle); + handle->state = AUD_STATUS_PAUSED; + } + } +} + +#define SOUND_PLAYBACK_LAMBDA 1.0 + +void sound_update_playing(struct bContext *C) +{ + SoundHandle *handle; + Scene* scene = CTX_data_scene(C); + int cfra = CFRA; + float fps = FPS; + int action; + + AUD_lock(); + + for(handle = scene->sound_handles.first; handle; handle = handle->next) + { + if(cfra < handle->startframe || cfra >= handle->endframe || handle->mute) + { + if(handle->state == AUD_STATUS_PLAYING) + { + AUD_pause(handle->handle); + handle->state = AUD_STATUS_PAUSED; + } + } + else + { + action = 0; + + if(handle->changed != handle->source->changed) + { + handle->changed = handle->source->changed; + action = 3; + if(handle->state != AUD_STATUS_INVALID) + { + AUD_stop(handle->handle); + handle->state = AUD_STATUS_INVALID; + } + } + else + { + if(handle->state != AUD_STATUS_PLAYING) + action = 3; + else + { + handle->state = AUD_getStatus(handle->handle); + if(handle->state != AUD_STATUS_PLAYING) + action = 3; + else + { + float diff = AUD_getPosition(handle->handle) - (cfra - handle->startframe) / fps; +// AUD_XXX float diff = AUD_getPosition(handle->handle) * fps - cfra + handle->startframe + if(diff < 0.0) + diff = -diff; + if(diff > SOUND_PLAYBACK_LAMBDA) +// AUD_XXX if(diff > 5.0f) + { + action = 2; + } + } + } + } + + if(action & 1) + { + if(handle->state == AUD_STATUS_INVALID) + { + if(handle->source && handle->source->snd_sound) + { + AUD_Sound* limiter = AUD_limitSound(handle->source->cache ? handle->source->cache : handle->source->snd_sound, handle->frameskip / fps, (handle->frameskip + handle->endframe - handle->startframe)/fps); + handle->handle = AUD_play(limiter, 1); + AUD_unload(limiter); + if(handle->handle) + handle->state = AUD_STATUS_PLAYING; + if(cfra == handle->startframe) + action &= ~2; + } } + else + if(AUD_resume(handle->handle)) + handle->state = AUD_STATUS_PLAYING; + else + handle->state = AUD_STATUS_INVALID; } - sound = sound->id.next; + + if(action & 2) + AUD_seek(handle->handle, (cfra - handle->startframe) / fps); } } + + AUD_unlock(); } -PackedFile* sound_find_packedfile(bSound *sound) -{ - bSound *search; - PackedFile *pf = NULL; - char soundname[FILE_MAXDIR + FILE_MAXFILE], searchname[FILE_MAXDIR + FILE_MAXFILE]; - - // convert sound->name to abolute filename - strcpy(soundname, sound->name); - BLI_convertstringcode(soundname, G.sce); - - search = G.main->sound.first; - while (search) { - if (search->sample && search->sample->packedfile) { - strcpy(searchname, search->sample->name); - BLI_convertstringcode(searchname, G.sce); - - if (BLI_streq(searchname, soundname)) { - pf = search->sample->packedfile; - break; +void sound_scrub(struct bContext *C) +{ + SoundHandle *handle; + Scene* scene = CTX_data_scene(C); + int cfra = CFRA; + float fps = FPS; + + if(scene->audio.flag & AUDIO_SCRUB && !CTX_wm_screen(C)->animtimer) + { + AUD_lock(); + + for(handle = scene->sound_handles.first; handle; handle = handle->next) + { + if(cfra >= handle->startframe && cfra < handle->endframe && !handle->mute) + { + if(handle->source && handle->source->snd_sound) + { + int frameskip = handle->frameskip + cfra - handle->startframe; + AUD_Sound* limiter = AUD_limitSound(handle->source->cache ? handle->source->cache : handle->source->snd_sound, frameskip / fps, (frameskip + 1)/fps); + AUD_play(limiter, 0); + AUD_unload(limiter); + } } - } - - if (search->newpackedfile) { - strcpy(searchname, search->name); - BLI_convertstringcode(searchname, G.sce); - if (BLI_streq(searchname, soundname)) { - pf = search->newpackedfile; - break; + } + + AUD_unlock(); + } +} + +AUD_Device* sound_mixdown(struct Scene *scene, AUD_Specs specs, int start, int end) +{ + AUD_Device* mixdown = AUD_openReadDevice(specs); + SoundHandle *handle; + float fps = FPS; + AUD_Sound *limiter, *delayer; + int frameskip, s, e; + + end++; + + for(handle = scene->sound_handles.first; handle; handle = handle->next) + { + if(start < handle->endframe && end > handle->startframe && !handle->mute && handle->source && handle->source->snd_sound) + { + frameskip = handle->frameskip; + s = handle->startframe - start; + e = handle->frameskip + AUD_MIN(handle->endframe, end) - handle->startframe; + + if(s < 0) + { + frameskip -= s; + s = 0; } + + limiter = AUD_limitSound(handle->source->snd_sound, frameskip / fps, e / fps); + delayer = AUD_delaySound(limiter, s / fps); + + AUD_playDevice(mixdown, delayer); + + AUD_unload(delayer); + AUD_unload(limiter); } - search = search->id.next; } - - return (pf); + + return mixdown; } diff --git a/source/blender/blenkernel/intern/writeavi.c b/source/blender/blenkernel/intern/writeavi.c index cfbe3f629d6..7c58a4f9499 100644 --- a/source/blender/blenkernel/intern/writeavi.c +++ b/source/blender/blenkernel/intern/writeavi.c @@ -127,7 +127,7 @@ void makeavistring (RenderData *rd, char *string) } } -void start_avi(RenderData *rd, int rectx, int recty) +void start_avi(struct Scene *scene, RenderData *rd, int rectx, int recty) { int x, y; char name[256]; diff --git a/source/blender/blenkernel/intern/writeffmpeg.c b/source/blender/blenkernel/intern/writeffmpeg.c index 5e3c8024524..e7164dc4794 100644 --- a/source/blender/blenkernel/intern/writeffmpeg.c +++ b/source/blender/blenkernel/intern/writeffmpeg.c @@ -65,6 +65,10 @@ #include "DNA_scene_types.h" +#include "AUD_C-API.h" +#include "BKE_sound.h" +#include "BKE_main.h" + #ifdef HAVE_CONFIG_H #include <config.h> #endif @@ -96,6 +100,8 @@ static int audio_input_frame_size = 0; static uint8_t* audio_output_buffer = 0; static int audio_outbuf_size = 0; +static AUD_Device* audio_mixdown_device = 0; + #define FFMPEG_AUTOSPLIT_SIZE 2000000000 /* Delete a picture buffer */ @@ -127,9 +133,8 @@ static int write_audio_frame(void) c = get_codec_from_stream(audio_stream); - //XXX audiostream_fill(audio_input_buffer, - // audio_input_frame_size - // * sizeof(short) * c->channels); + if(audio_mixdown_device) + AUD_readDevice(audio_mixdown_device, audio_input_buffer, audio_input_frame_size); av_init_packet(&pkt); @@ -827,11 +832,21 @@ static void makeffmpegstring(RenderData* rd, char* string) { } -void start_ffmpeg(RenderData *rd, int rectx, int recty) +void start_ffmpeg(struct Scene *scene, RenderData *rd, int rectx, int recty) { ffmpeg_autosplit_count = 0; start_ffmpeg_impl(rd, rectx, recty); + + if(ffmpeg_multiplex_audio && audio_stream) + { + AVCodecContext* c = get_codec_from_stream(audio_stream); + AUD_Specs specs; + specs.channels = c->channels; + specs.format = AUD_FORMAT_S16; + specs.rate = rd->audio.mixrate; + audio_mixdown_device = sound_mixdown(scene, specs, rd->sfra, rd->efra); + } } void end_ffmpeg(void); @@ -884,6 +899,12 @@ void end_ffmpeg(void) if (audio_stream && video_stream) { write_audio_frames(); } + + if(audio_mixdown_device) + { + AUD_closeReadDevice(audio_mixdown_device); + audio_mixdown_device = 0; + } if (outfile) { av_write_trailer(outfile); diff --git a/source/blender/blenkernel/intern/writeframeserver.c b/source/blender/blenkernel/intern/writeframeserver.c index 2d3a2e6b883..0780cd0dc48 100644 --- a/source/blender/blenkernel/intern/writeframeserver.c +++ b/source/blender/blenkernel/intern/writeframeserver.c @@ -101,7 +101,7 @@ static int closesocket(int fd) } #endif -void start_frameserver(RenderData *rd, int rectx, int recty) +void start_frameserver(struct Scene *scene, RenderData *rd, int rectx, int recty) { struct sockaddr_in addr; int arg = 1; diff --git a/source/blender/blenlib/intern/bpath.c b/source/blender/blenlib/intern/bpath.c index 85a95fa6e66..6c89afe7173 100644 --- a/source/blender/blenlib/intern/bpath.c +++ b/source/blender/blenlib/intern/bpath.c @@ -51,7 +51,7 @@ /* for sequence */ //XXX #include "BSE_sequence.h" //XXX define below from BSE_sequence.h - otherwise potentially odd behaviour -#define SEQ_HAS_PATH(seq) (seq->type==SEQ_MOVIE || seq->type==SEQ_HD_SOUND || seq->type==SEQ_RAM_SOUND || seq->type==SEQ_IMAGE) +#define SEQ_HAS_PATH(seq) (seq->type==SEQ_MOVIE || seq->type==SEQ_IMAGE) /* path/file handeling stuff */ #ifndef WIN32 diff --git a/source/blender/blenloader/intern/readfile.c b/source/blender/blenloader/intern/readfile.c index d87cd052454..7f414f8c0f6 100644 --- a/source/blender/blenloader/intern/readfile.c +++ b/source/blender/blenloader/intern/readfile.c @@ -149,6 +149,8 @@ #include "BKE_utildefines.h" // SWITCH_INT DATA ENDB DNA1 O_BINARY GLOB USER TEST REND #include "BKE_idprop.h" +#include "BKE_sound.h" + //XXX #include "BIF_butspace.h" // badlevel, for do_versions, patching event codes //XXX #include "BIF_filelist.h" // badlevel too, where to move this? - elubie //XXX #include "BIF_previewrender.h" // bedlelvel, for struct RenderInfo @@ -4052,14 +4054,16 @@ static void lib_link_scene(FileData *fd, Main *main) if(seq->ipo) seq->ipo= newlibadr_us(fd, sce->id.lib, seq->ipo); if(seq->scene) seq->scene= newlibadr(fd, sce->id.lib, seq->scene); if(seq->sound) { - seq->sound= newlibadr(fd, sce->id.lib, seq->sound); + if(seq->type == SEQ_HD_SOUND) + seq->type = SEQ_SOUND; + else + seq->sound= newlibadr(fd, sce->id.lib, seq->sound); if (seq->sound) { seq->sound->id.us++; - seq->sound->flags |= SOUND_FLAGS_SEQUENCE; + seq->sound_handle= sound_new_handle(sce, seq->sound, seq->startdisp, seq->enddisp, seq->startofs); } } seq->anim= 0; - seq->hdaudio = 0; } SEQ_END @@ -4103,7 +4107,9 @@ static void direct_link_scene(FileData *fd, Scene *sce) sce->theDag = NULL; sce->dagisvalid = 0; sce->obedit= NULL; - + + memset(&sce->sound_handles, 0, sizeof(sce->sound_handles)); + /* set users to one by default, not in lib-link, this will increase it for compo nodes */ sce->id.us= 1; @@ -5041,6 +5047,8 @@ static void lib_link_sound(FileData *fd, Main *main) sound->id.flag -= LIB_NEEDLINK; sound->ipo= newlibadr_us(fd, sound->id.lib, sound->ipo); // XXX depreceated - old animation system sound->stream = 0; + + sound_load(sound); } sound= sound->id.next; } @@ -9186,7 +9194,67 @@ static void do_versions(FileData *fd, Library *lib, Main *main) Object *ob; PTCacheID *pid; ListBase pidlist; - + + bSound *sound; + Sequence *seq; + bActuator *act; + + for(sound = main->sound.first; sound; sound = sound->id.next) + { + if(sound->newpackedfile) + { + sound->packedfile = sound->newpackedfile; + sound->newpackedfile = NULL; + } + } + + for(ob = main->object.first; ob; ob= ob->id.next) { + for(act= ob->actuators.first; act; act= act->next) { + if (act->type == ACT_SOUND) { + bSoundActuator *sAct = (bSoundActuator*) act->data; + if(sAct->sound) + { + sound = newlibadr(fd, lib, sAct->sound); + sAct->flag = sound->flags | SOUND_FLAGS_3D ? ACT_SND_3D_SOUND : 0; + sAct->pitch = sound->pitch; + sAct->volume = sound->volume; + sAct->sound3D.reference_distance = sound->distance; + sAct->sound3D.max_gain = sound->max_gain; + sAct->sound3D.min_gain = sound->min_gain; + sAct->sound3D.rolloff_factor = sound->attenuation; + } + else + { + sAct->sound3D.reference_distance = 1.0f; + sAct->volume = 1.0f; + sAct->sound3D.max_gain = 1.0f; + sAct->sound3D.rolloff_factor = 1.0f; + } + sAct->sound3D.cone_inner_angle = 360.0f; + sAct->sound3D.cone_outer_angle = 360.0f; + sAct->sound3D.max_distance = FLT_MAX; + } + } + } + + for(scene = main->scene.first; scene; scene = scene->id.next) + { + if(scene->ed && scene->ed->seqbasep) + { + for(seq = scene->ed->seqbasep->first; seq; seq = seq->next) + { + if(seq->type == SEQ_HD_SOUND) + { + char str[FILE_MAX]; + BLI_join_dirfile(str, seq->strip->dir, seq->strip->stripdata->name); + BLI_convertstringcode(str, G.sce); + BLI_convertstringframe(str, scene->r.cfra); + seq->sound = sound_new_file(main, str); + } + } + } + } + for(screen= main->screen.first; screen; screen= screen->id.next) { do_versions_windowmanager_2_50(screen); do_versions_gpencil_2_50(main, screen); @@ -9504,7 +9572,17 @@ static BHead *read_userdef(BlendFileData *bfd, FileData *fd, BHead *bhead) // XXX bfd->user->uifonts.first= bfd->user->uifonts.last= NULL; bfd->user->uistyles.first= bfd->user->uistyles.last= NULL; - + + // AUD_XXX + if(bfd->user->audiochannels == 0) + bfd->user->audiochannels = 2; + if(bfd->user->audiodevice == 0) + bfd->user->audiodevice = 1; + if(bfd->user->audioformat == 0) + bfd->user->audioformat = 0x12; + if(bfd->user->audiorate == 0) + bfd->user->audiorate = 44100; + bhead = blo_nextbhead(fd, bhead); /* read all attached data */ diff --git a/source/blender/blenloader/intern/writefile.c b/source/blender/blenloader/intern/writefile.c index 05ea60b50df..868dafdb98a 100644 --- a/source/blender/blenloader/intern/writefile.c +++ b/source/blender/blenloader/intern/writefile.c @@ -2137,45 +2137,21 @@ static void write_texts(WriteData *wd, ListBase *idbase) static void write_sounds(WriteData *wd, ListBase *idbase) { bSound *sound; - bSample *sample; PackedFile * pf; - // set all samples to unsaved status - - sample = samples->first; // samples is a global defined in sound.c - while (sample) { - sample->flags |= SAMPLE_NEEDS_SAVE; - sample = sample->id.next; - } - sound= idbase->first; while(sound) { if(sound->id.us>0 || wd->current) { - // do we need to save the packedfile as well ? - sample = sound->sample; - if (sample) { - if (sample->flags & SAMPLE_NEEDS_SAVE) { - sound->newpackedfile = sample->packedfile; - sample->flags &= ~SAMPLE_NEEDS_SAVE; - } else { - sound->newpackedfile = NULL; - } - } - /* write LibData */ writestruct(wd, ID_SO, "bSound", 1, sound); if (sound->id.properties) IDP_WriteProperty(sound->id.properties, wd); - if (sound->newpackedfile) { - pf = sound->newpackedfile; + if (sound->packedfile) { + pf = sound->packedfile; writestruct(wd, DATA, "PackedFile", 1, pf); writedata(wd, DATA, pf->size, pf->data); } - - if (sample) { - sound->newpackedfile = sample->packedfile; - } } sound= sound->id.next; } diff --git a/source/blender/editors/CMakeLists.txt b/source/blender/editors/CMakeLists.txt index 28cfcb3ff6e..fdee568c350 100644 --- a/source/blender/editors/CMakeLists.txt +++ b/source/blender/editors/CMakeLists.txt @@ -36,6 +36,7 @@ SET(INC ../windowmanager ../../kernel/gen_system ../../../intern/SoundSystem ../readstreamglue ../quicktime ../../../intern/elbeem/extern ../../../intern/ghost ../../../intern/opennl/extern ../../../extern/glew/include ../../../intern/smoke/extern + ../../../intern/audaspace ../nodes ../gpu ../blenfont diff --git a/source/blender/editors/animation/anim_ops.c b/source/blender/editors/animation/anim_ops.c index 9c039693b72..ffa44e60d00 100644 --- a/source/blender/editors/animation/anim_ops.c +++ b/source/blender/editors/animation/anim_ops.c @@ -56,6 +56,8 @@ #include "ED_markers.h" #include "ED_screen.h" +#include "BKE_sound.h" + /* ********************** frame change operator ***************************/ /* Set any flags that are necessary to indicate modal time-changing operation */ @@ -91,6 +93,8 @@ static void change_frame_apply(bContext *C, wmOperator *op) if (cfra < MINAFRAME) cfra= MINAFRAME; CFRA= cfra; + sound_scrub(C); + WM_event_add_notifier(C, NC_SCENE|ND_FRAME, scene); } @@ -121,6 +125,7 @@ static int change_frame_exec(bContext *C, wmOperator *op) change_frame_apply(C, op); change_frame_exit(C, op); + return OPERATOR_FINISHED; } diff --git a/source/blender/editors/screen/screen_ops.c b/source/blender/editors/screen/screen_ops.c index f04e4c5b347..f882a25c363 100644 --- a/source/blender/editors/screen/screen_ops.c +++ b/source/blender/editors/screen/screen_ops.c @@ -56,6 +56,7 @@ #include "BKE_report.h" #include "BKE_screen.h" #include "BKE_utildefines.h" +#include "BKE_sound.h" #include "WM_api.h" #include "WM_types.h" @@ -2277,7 +2278,9 @@ static int screen_animation_step(bContext *C, wmOperator *op, wmEvent *event) /* since we follow drawflags, we can't send notifier but tag regions ourselves */ ED_update_for_newframe(C, 1); - + + sound_update_playing(C); + for(sa= screen->areabase.first; sa; sa= sa->next) { ARegion *ar; for(ar= sa->regionbase.first; ar; ar= ar->next) { @@ -2322,6 +2325,7 @@ static int screen_animation_play(bContext *C, wmOperator *op, wmEvent *event) if(screen->animtimer) { ED_screen_animation_timer(C, 0, 0); + sound_stop_all(C); } else { ScrArea *sa= CTX_wm_area(C); diff --git a/source/blender/editors/screen/screendump.c b/source/blender/editors/screen/screendump.c index 2ae2712d02d..5ae1bdf84aa 100644 --- a/source/blender/editors/screen/screendump.c +++ b/source/blender/editors/screen/screendump.c @@ -228,7 +228,7 @@ static void screenshot_startjob(void *sjv, short *stop, short *do_update) rd.frs_sec_base= 1.0f; if(BKE_imtype_is_movie(rd.imtype)) - mh->start_movie(&rd, sj->dumpsx, sj->dumpsy); + mh->start_movie(sj->scene, &rd, sj->dumpsx, sj->dumpsy); else mh= NULL; diff --git a/source/blender/editors/space_file/filelist.c b/source/blender/editors/space_file/filelist.c index 7ebc8c4338f..538c1e4fce7 100644 --- a/source/blender/editors/space_file/filelist.c +++ b/source/blender/editors/space_file/filelist.c @@ -840,7 +840,16 @@ void filelist_setfiletypes(struct FileList* filelist, short has_quicktime) || BLI_testextensie(file->relname, ".mv")) { file->flags |= MOVIEFILE; } - else if(BLI_testextensie(file->relname, ".wav")) { + else if(BLI_testextensie(file->relname, ".wav") + || BLI_testextensie(file->relname, ".ogg") + || BLI_testextensie(file->relname, ".oga") + || BLI_testextensie(file->relname, ".mp3") + || BLI_testextensie(file->relname, ".mp2") + || BLI_testextensie(file->relname, ".ac3") + || BLI_testextensie(file->relname, ".aac") + || BLI_testextensie(file->relname, ".flac") + || BLI_testextensie(file->relname, ".wma") + || BLI_testextensie(file->relname, ".eac3")) { file->flags |= SOUNDFILE; } } else { // no quicktime @@ -875,7 +884,16 @@ void filelist_setfiletypes(struct FileList* filelist, short has_quicktime) || BLI_testextensie(file->relname, ".mv")) { file->flags |= MOVIEFILE; } - else if(BLI_testextensie(file->relname, ".wav")) { + else if(BLI_testextensie(file->relname, ".wav") + || BLI_testextensie(file->relname, ".ogg") + || BLI_testextensie(file->relname, ".oga") + || BLI_testextensie(file->relname, ".mp3") + || BLI_testextensie(file->relname, ".mp2") + || BLI_testextensie(file->relname, ".ac3") + || BLI_testextensie(file->relname, ".aac") + || BLI_testextensie(file->relname, ".flac") + || BLI_testextensie(file->relname, ".wma") + || BLI_testextensie(file->relname, ".eac3")) { file->flags |= SOUNDFILE; } } diff --git a/source/blender/editors/space_logic/logic_window.c b/source/blender/editors/space_logic/logic_window.c index 274f5f47e43..96f491c9a8a 100644 --- a/source/blender/editors/space_logic/logic_window.c +++ b/source/blender/editors/space_logic/logic_window.c @@ -1984,11 +1984,14 @@ static short draw_actuatorbuttons(Object *ob, bActuator *act, uiBlock *block, sh } case ACT_SOUND: { - ysize = 70; - sa = act->data; sa->sndnr = 0; + if(sa->flag & ACT_SND_3D_SOUND) + ysize = 114; + else + ysize = 92; + wval = (width-20)/2; glRects(xco, yco-ysize, xco+width, yco); uiEmboss((float)xco, (float)yco-ysize, (float)xco+width, (float)yco, 1); @@ -2003,8 +2006,14 @@ static short draw_actuatorbuttons(Object *ob, bActuator *act, uiBlock *block, sh char dummy_str[] = "Sound mode %t|Play Stop %x0|Play End %x1|Loop Stop %x2|Loop End %x3|Loop Ping Pong Stop %x5|Loop Ping Pong %x4"; uiDefBut(block, TEX, B_IDNAME, "SO:",xco+30,yco-22,width-40,19, sa->sound->id.name+2, 0.0, 21.0, 0, 0, ""); uiDefButS(block, MENU, 1, dummy_str,xco+10,yco-44,width-20, 19, &sa->type, 0.0, 0.0, 0, 0, ""); - uiDefButF(block, NUM, 0, "Volume:", xco+10,yco-66,wval, 19, &sa->sound->volume, 0.0, 1.0, 0, 0, "Sets the volume of this sound"); - uiDefButF(block, NUM, 0, "Pitch:",xco+wval+10,yco-66,wval, 19, &sa->sound->pitch,-12.0, 12.0, 0, 0, "Sets the pitch of this sound"); + uiDefButF(block, NUM, 0, "Volume:", xco+10,yco-66,wval, 19, &sa->volume, 0.0, 1.0, 0, 0, "Sets the volume of this sound"); + uiDefButF(block, NUM, 0, "Pitch:",xco+wval+10,yco-66,wval, 19, &sa->pitch,-12.0, 12.0, 0, 0, "Sets the pitch of this sound"); + uiDefButS(block, TOG | BIT, 0, "3D Sound", xco+10, yco-88, width-20, 19, &sa->flag, 0.0, 1.0, 0.0, 0.0, "Plays the sound positioned in 3D space."); + if(sa->flag & ACT_SND_3D_SOUND) + { + uiDefButF(block, NUM, 0, "Rolloff: ", xco+10, yco-110, wval, 19, &sa->sound3D.rolloff_factor, 0.0, 5.0, 0.0, 0.0, "The rolloff factor defines the influence factor on volume depending on distance."); + uiDefButF(block, NUM, 0, "Reference distance: ", xco+wval+10, yco-110, wval, 19, &sa->sound3D.reference_distance, 0.0, 1000.0, 0.0, 0.0, "The reference distance is the distance where the sound has a gain of 1.0."); + } } MEM_freeN(str); } diff --git a/source/blender/editors/space_outliner/outliner.c b/source/blender/editors/space_outliner/outliner.c index 84dea679767..51cc8507ff8 100644 --- a/source/blender/editors/space_outliner/outliner.c +++ b/source/blender/editors/space_outliner/outliner.c @@ -4178,13 +4178,13 @@ static void tselem_draw_icon(float x, float y, TreeStoreElem *tselem, TreeElemen case TSE_POSEGRP_BASE: UI_icon_draw(x, y, ICON_VERTEXSEL); break; case TSE_SEQUENCE: - if((te->idcode==SEQ_MOVIE) || (te->idcode==SEQ_MOVIE_AND_HD_SOUND)) + if(te->idcode==SEQ_MOVIE) UI_icon_draw(x, y, ICON_SEQUENCE); else if(te->idcode==SEQ_META) UI_icon_draw(x, y, ICON_DOT); else if(te->idcode==SEQ_SCENE) UI_icon_draw(x, y, ICON_SCENE); - else if((te->idcode==SEQ_RAM_SOUND) || (te->idcode==SEQ_HD_SOUND)) + else if(te->idcode==SEQ_SOUND) UI_icon_draw(x, y, ICON_SOUND); else if(te->idcode==SEQ_IMAGE) UI_icon_draw(x, y, ICON_IMAGE_COL); diff --git a/source/blender/editors/space_sequencer/SConscript b/source/blender/editors/space_sequencer/SConscript index ab51068a529..9e7ea185c25 100644 --- a/source/blender/editors/space_sequencer/SConscript +++ b/source/blender/editors/space_sequencer/SConscript @@ -6,5 +6,6 @@ sources = env.Glob('*.c') incs = '../include ../../blenlib ../../blenkernel ../../blenfont ../../makesdna ../../imbuf' incs += ' ../../windowmanager #/intern/guardedalloc #/extern/glew/include' incs += ' ../../makesrna' +incs += ' #/intern/audaspace' env.BlenderLib ( 'bf_editors_space_sequencer', sources, Split(incs), [], libtype=['core'], priority=[100] ) diff --git a/source/blender/editors/space_sequencer/sequencer_add.c b/source/blender/editors/space_sequencer/sequencer_add.c index 99a13c8d9e0..5d58ea431a9 100644 --- a/source/blender/editors/space_sequencer/sequencer_add.c +++ b/source/blender/editors/space_sequencer/sequencer_add.c @@ -89,6 +89,9 @@ #include "UI_resources.h" #include "UI_view2d.h" +#include "BKE_sound.h" +#include "AUD_C-API.h" + /* own include */ #include "sequencer_intern.h" @@ -224,24 +227,80 @@ void SEQUENCER_OT_scene_strip_add(struct wmOperatorType *ot) RNA_def_string(ot->srna, "scene", "", MAX_ID_NAME-2, "Scene Name", "Scene name to add as a strip"); } +static Sequence* sequencer_add_sound_strip(bContext *C, wmOperator *op, int start_frame, int channel, char* filename) +{ + Scene *scene= CTX_data_scene(C); + Editing *ed= seq_give_editing(scene, TRUE); + + bSound *sound; + + Sequence *seq; /* generic strip vars */ + Strip *strip; + StripElem *se; + + AUD_SoundInfo info; + + sound = sound_new_file(CTX_data_main(C), filename); + + if (sound==NULL || sound->snd_sound == NULL) { + if(op) + BKE_report(op->reports, RPT_ERROR, "Unsupported audio format"); + return NULL; + } + + info = AUD_getInfo(sound->snd_sound); + + if (info.specs.format == AUD_FORMAT_INVALID) { + sound_delete(C, sound); + if(op) + BKE_report(op->reports, RPT_ERROR, "Unsupported audio format"); + return NULL; + } + + seq = alloc_sequence(ed->seqbasep, start_frame, channel); + + seq->type= SEQ_SOUND; + seq->sound= sound; + + /* basic defaults */ + seq->strip= strip= MEM_callocN(sizeof(Strip), "strip"); + strip->len = seq->len = (int) (info.length * FPS); + strip->us= 1; + + strip->stripdata= se= MEM_callocN(seq->len*sizeof(StripElem), "stripelem"); + + BLI_split_dirfile_basic(filename, strip->dir, se->name); + + seq->sound_handle = sound_new_handle(scene, sound, start_frame, start_frame + strip->len, 0); + + calc_sequence_disp(seq); + sort_seq(scene); + + /* last active name */ + strncpy(ed->act_sounddir, strip->dir, FILE_MAXDIR-1); + + return seq; +} + /* add movie operator */ static int sequencer_add_movie_strip_exec(bContext *C, wmOperator *op) { Scene *scene= CTX_data_scene(C); Editing *ed= seq_give_editing(scene, TRUE); - + struct anim *an; char filename[FILE_MAX]; - Sequence *seq; /* generic strip vars */ + Sequence *seq, *soundseq; /* generic strip vars */ Strip *strip; StripElem *se; - - int start_frame, channel; /* operator props */ - + + int start_frame, channel, sound; /* operator props */ + start_frame= RNA_int_get(op->ptr, "start_frame"); channel= RNA_int_get(op->ptr, "channel"); - + sound = RNA_boolean_get(op->ptr, "sound"); + RNA_string_get(op->ptr, "filename", filename); an = openanim(filename, IB_rect); @@ -271,10 +330,19 @@ static int sequencer_add_movie_strip_exec(bContext *C, wmOperator *op) calc_sequence_disp(seq); sort_seq(scene); + if(sound) + { + soundseq = sequencer_add_sound_strip(C, NULL, start_frame, channel+1, filename); + if(soundseq != NULL) + RNA_string_get(op->ptr, "name", soundseq->name); + } + if (RNA_boolean_get(op->ptr, "replace_sel")) { deselect_all_seq(scene); set_last_seq(scene, seq); seq->flag |= SELECT; + if(soundseq) + soundseq->flag |= SELECT; } ED_area_tag_redraw(CTX_wm_area(C)); @@ -310,24 +378,15 @@ void SEQUENCER_OT_movie_strip_add(struct wmOperatorType *ot) WM_operator_properties_filesel(ot, FOLDERFILE|MOVIEFILE); sequencer_generic_props__internal(ot, SEQPROP_STARTFRAME); - RNA_def_boolean(ot->srna, "sound", TRUE, "Sound", "Load hd sound with the movie"); // XXX need to impliment this + RNA_def_boolean(ot->srna, "sound", TRUE, "Sound", "Load sound with the movie"); } - /* add sound operator */ static int sequencer_add_sound_strip_exec(bContext *C, wmOperator *op) { - Scene *scene= CTX_data_scene(C); - Editing *ed= seq_give_editing(scene, TRUE); - - bSound *sound; - char filename[FILE_MAX]; - + Scene *scene= CTX_data_scene(C); Sequence *seq; /* generic strip vars */ - Strip *strip; - StripElem *se; - int start_frame, channel; /* operator props */ start_frame= RNA_int_get(op->ptr, "start_frame"); @@ -335,47 +394,16 @@ static int sequencer_add_sound_strip_exec(bContext *C, wmOperator *op) RNA_string_get(op->ptr, "filename", filename); - /* XXX if(sfile->flag & FILE_STRINGCODE) { - BLI_makestringcode(G.sce, str); - }*/ - -// XXX sound= sound_new_sound(filename); - sound= NULL; - - if (sound==NULL || sound->sample->type == SAMPLE_INVALID) { - BKE_report(op->reports, RPT_ERROR, "Unsupported audio format"); - return OPERATOR_CANCELLED; - } + seq = sequencer_add_sound_strip(C, op, start_frame, channel, filename); - if (sound==NULL || sound->sample->bits != 16) { - BKE_report(op->reports, RPT_ERROR, "Only 16 bit audio is supported"); + if(seq == NULL) return OPERATOR_CANCELLED; - } - - sound->flags |= SOUND_FLAGS_SEQUENCE; -// XXX audio_makestream(sound); - - seq = alloc_sequence(ed->seqbasep, start_frame, channel); - - seq->type= SEQ_RAM_SOUND; - seq->sound= sound; - - /* basic defaults */ - seq->strip= strip= MEM_callocN(sizeof(Strip), "strip"); - strip->len = seq->len = (int) ( ((float)(sound->streamlen-1) / ( (float)scene->r.audio.mixrate*4.0 ))* FPS); - strip->us= 1; - - strip->stripdata= se= MEM_callocN(seq->len*sizeof(StripElem), "stripelem"); - - BLI_split_dirfile_basic(filename, strip->dir, se->name); RNA_string_get(op->ptr, "name", seq->name); - - calc_sequence_disp(seq); - sort_seq(scene); - - /* last active name */ - strncpy(ed->act_sounddir, strip->dir, FILE_MAXDIR-1); + + if (RNA_boolean_get(op->ptr, "cache")) { + sound_cache(seq->sound, 0); + } if (RNA_boolean_get(op->ptr, "replace_sel")) { deselect_all_seq(scene); @@ -416,7 +444,7 @@ void SEQUENCER_OT_sound_strip_add(struct wmOperatorType *ot) WM_operator_properties_filesel(ot, FOLDERFILE|SOUNDFILE); sequencer_generic_props__internal(ot, SEQPROP_STARTFRAME); - RNA_def_boolean(ot->srna, "cache", FALSE, "Cache", "Load the sound as streaming audio"); // XXX need to impliment this + RNA_def_boolean(ot->srna, "cache", FALSE, "Cache", "Cache the sound in memory."); } /* add image operator */ @@ -585,7 +613,7 @@ static int sequencer_add_effect_strip_exec(bContext *C, wmOperator *op) if(seq->plugin==NULL) { BLI_remlink(ed->seqbasep, seq); - seq_free_sequence(ed, seq); + seq_free_sequence(scene, seq); BKE_reportf(op->reports, RPT_ERROR, "Sequencer plugin \"%s\" could not load.", filename); return OPERATOR_CANCELLED; } diff --git a/source/blender/editors/space_sequencer/sequencer_draw.c b/source/blender/editors/space_sequencer/sequencer_draw.c index 3b90039335e..3d0d908d3f6 100644 --- a/source/blender/editors/space_sequencer/sequencer_draw.c +++ b/source/blender/editors/space_sequencer/sequencer_draw.c @@ -173,8 +173,7 @@ static void get_seq_color3ubv(Scene *curscene, Sequence *seq, char *col) case SEQ_PLUGIN: UI_GetThemeColor3ubv(TH_SEQ_PLUGIN, col); break; - case SEQ_HD_SOUND: - case SEQ_RAM_SOUND: + case SEQ_SOUND: UI_GetThemeColor3ubv(TH_SEQ_AUDIO, col); blendcol[0] = blendcol[1] = blendcol[2] = 128; if(seq->flag & SEQ_MUTE) UI_GetColorPtrBlendShade3ubv(col, blendcol, col, 0.5, 20); @@ -546,11 +545,8 @@ static void draw_seq_text(View2D *v2d, Sequence *seq, float x1, float x2, float else sprintf(str, "%d | %s", seq->len, give_seqname(seq)); } - else if (seq->type == SEQ_RAM_SOUND) { - sprintf(str, "%d | %s", seq->len, seq->strip->stripdata->name); - } - else if (seq->type == SEQ_HD_SOUND) { - sprintf(str, "%d | %s", seq->len, seq->strip->stripdata->name); + else if (seq->type == SEQ_SOUND) { + sprintf(str, "%d | %s", seq->len, seq->sound->name); } else if (seq->type == SEQ_MOVIE) { sprintf(str, "%d | %s%s", seq->len, seq->strip->dir, seq->strip->stripdata->name); @@ -664,8 +660,9 @@ static void draw_seq_strip(Scene *scene, ARegion *ar, SpaceSeq *sseq, Sequence * draw_shadedstrip(seq, background_col, x1, y1, x2, y2); /* draw additional info and controls */ - if (seq->type == SEQ_RAM_SOUND) - drawseqwave(scene, v2d, seq, x1, y1, x2, y2, ar->winx); +// XXX +/* if (seq->type == SEQ_SOUND) + drawseqwave(scene, v2d, seq, x1, y1, x2, y2, ar->winx);*/ if (!is_single_image) draw_seq_extensions(scene, sseq, seq); diff --git a/source/blender/editors/space_sequencer/sequencer_edit.c b/source/blender/editors/space_sequencer/sequencer_edit.c index 036c0769c1e..1555784f470 100644 --- a/source/blender/editors/space_sequencer/sequencer_edit.c +++ b/source/blender/editors/space_sequencer/sequencer_edit.c @@ -65,6 +65,7 @@ #include "BKE_scene.h" #include "BKE_utildefines.h" #include "BKE_report.h" +#include "BKE_sound.h" #include "WM_api.h" #include "WM_types.h" @@ -166,7 +167,7 @@ Sequence *get_foreground_frame_seq(Scene *scene, int frame) if(seq->flag & SEQ_MUTE || seq->startdisp > frame || seq->enddisp <= frame) continue; /* only use elements you can see - not */ - if (ELEM6(seq->type, SEQ_IMAGE, SEQ_META, SEQ_SCENE, SEQ_MOVIE, SEQ_MOVIE_AND_HD_SOUND, SEQ_COLOR)) { + if (ELEM5(seq->type, SEQ_IMAGE, SEQ_META, SEQ_SCENE, SEQ_MOVIE, SEQ_COLOR)) { if (seq->machine > best_machine) { best_seq = seq; best_machine = seq->machine; @@ -563,7 +564,7 @@ static void reload_sound_strip(Scene *scene, char *name) calc_sequence(seqact); seq->strip= 0; - seq_free_sequence(ed, seq); + seq_free_sequence(scene, seq); BLI_remlink(ed->seqbasep, seq); seq= ed->seqbasep->first; @@ -603,7 +604,7 @@ static void reload_image_strip(Scene *scene, char *name) calc_sequence(seqact); seq->strip= 0; - seq_free_sequence(ed, seq); + seq_free_sequence(scene, seq); BLI_remlink(ed->seqbasep, seq); update_changed_seq_and_deps(scene, seqact, 1, 1); @@ -722,7 +723,7 @@ int seq_effect_find_selected(Scene *scene, Sequence *activeseq, int type, Sequen for(seq=ed->seqbasep->first; seq; seq=seq->next) { if(seq->flag & SELECT) { - if (seq->type == SEQ_RAM_SOUND || seq->type == SEQ_HD_SOUND) { + if (seq->type == SEQ_SOUND) { *error_str= "Can't apply effects to audio sequence strips"; return 0; } @@ -849,7 +850,6 @@ static Sequence *del_seq_find_replace_recurs(Scene *scene, Sequence *seq) static void recurs_del_seq_flag(Scene *scene, ListBase *lb, short flag, short deleteall) { - Editing *ed= seq_give_editing(scene, FALSE); Sequence *seq, *seqn; Sequence *last_seq = get_last_seq(scene); @@ -857,20 +857,20 @@ static void recurs_del_seq_flag(Scene *scene, ListBase *lb, short flag, short de while(seq) { seqn= seq->next; if((seq->flag & flag) || deleteall) { - if(seq->type==SEQ_RAM_SOUND && seq->sound) + if(seq->type==SEQ_SOUND && seq->sound) seq->sound->id.us--; BLI_remlink(lb, seq); if(seq==last_seq) set_last_seq(scene, NULL); if(seq->type==SEQ_META) recurs_del_seq_flag(scene, &seq->seqbase, flag, 1); if(seq->ipo) seq->ipo->id.us--; - seq_free_sequence(ed, seq); + seq_free_sequence(scene, seq); } seq= seqn; } } -static Sequence *dupli_seq(Sequence *seq) +static Sequence *dupli_seq(struct Scene *scene, Sequence *seq) { Sequence *seqn = MEM_dupallocN(seq); // XXX animato: ID *id; @@ -936,14 +936,13 @@ static Sequence *dupli_seq(Sequence *seq) seqn->strip->stripdata = MEM_dupallocN(seq->strip->stripdata); seqn->anim= 0; - } else if(seq->type == SEQ_RAM_SOUND) { - seqn->strip->stripdata = + } else if(seq->type == SEQ_SOUND) { + seqn->strip->stripdata = MEM_dupallocN(seq->strip->stripdata); + if(seq->sound_handle) + seqn->sound_handle = sound_new_handle(scene, seqn->sound, seq->sound_handle->startframe, seq->sound_handle->endframe, seq->sound_handle->frameskip); + seqn->sound->id.us++; - } else if(seq->type == SEQ_HD_SOUND) { - seqn->strip->stripdata = - MEM_dupallocN(seq->strip->stripdata); - seqn->hdaudio = 0; } else if(seq->type == SEQ_IMAGE) { seqn->strip->stripdata = MEM_dupallocN(seq->strip->stripdata); @@ -970,13 +969,13 @@ static Sequence *dupli_seq(Sequence *seq) return seqn; } -static Sequence * deep_dupli_seq(Sequence * seq) +static Sequence * deep_dupli_seq(struct Scene *scene, Sequence * seq) { - Sequence * seqn = dupli_seq(seq); + Sequence * seqn = dupli_seq(scene, seq); if (seq->type == SEQ_META) { Sequence * s; for(s= seq->seqbase.first; s; s = s->next) { - Sequence * n = deep_dupli_seq(s); + Sequence * n = deep_dupli_seq(scene, s); if (n) { BLI_addtail(&seqn->seqbase, n); } @@ -995,7 +994,7 @@ static void recurs_dupli_seq(Scene *scene, ListBase *old, ListBase *new) for(seq= old->first; seq; seq= seq->next) { seq->tmp= NULL; if(seq->flag & SELECT) { - seqn = dupli_seq(seq); + seqn = dupli_seq(scene, seq); if (seqn) { /*should never fail */ seq->flag &= SEQ_DESEL; seqn->flag &= ~(SEQ_LEFTSEL+SEQ_RIGHTSEL+SEQ_LOCK); @@ -1061,10 +1060,10 @@ static Sequence *cut_seq_hard(Scene *scene, Sequence * seq, int cutframe) reload_sequence_new_file(scene, seq); calc_sequence(seq); - + if (!skip_dup) { /* Duplicate AFTER the first change */ - seqn = deep_dupli_seq(seq); + seqn = deep_dupli_seq(scene, seq); } if (seqn) { @@ -1150,10 +1149,10 @@ static Sequence *cut_seq_soft(Scene *scene, Sequence * seq, int cutframe) } calc_sequence(seq); - + if (!skip_dup) { /* Duplicate AFTER the first change */ - seqn = deep_dupli_seq(seq); + seqn = deep_dupli_seq(scene, seq); } if (seqn) { @@ -1493,11 +1492,13 @@ static int sequencer_mute_exec(bContext *C, wmOperator *op) if(selected){ /* mute unselected */ if (seq->flag & SELECT) { seq->flag |= SEQ_MUTE; + seq_update_sound(seq); } } else { if ((seq->flag & SELECT)==0) { seq->flag |= SEQ_MUTE; + seq_update_sound(seq); } } } @@ -1544,11 +1545,13 @@ static int sequencer_unmute_exec(bContext *C, wmOperator *op) if(selected){ /* unmute unselected */ if (seq->flag & SELECT) { seq->flag &= ~SEQ_MUTE; + seq_update_sound(seq); } } else { if ((seq->flag & SELECT)==0) { seq->flag &= ~SEQ_MUTE; + seq_update_sound(seq); } } } @@ -2007,7 +2010,7 @@ static int sequencer_separate_images_exec(bContext *C, wmOperator *op) start_ofs += step; } - seq_free_sequence(ed, seq); + seq_free_sequence(scene, seq); seq = seq->next; } else { seq = seq->next; @@ -2130,7 +2133,7 @@ static int sequencer_meta_make_exec(bContext *C, wmOperator *op) while(seq) { if(seq->flag & SELECT) { tot++; - if (seq->type == SEQ_RAM_SOUND) { + if (seq->type == SEQ_SOUND) { BKE_report(op->reports, RPT_ERROR, "Can't make Meta Strip from audio"); return OPERATOR_CANCELLED;; } @@ -2242,7 +2245,7 @@ static int sequencer_meta_separate_exec(bContext *C, wmOperator *op) last_seq->seqbase.last= 0; BLI_remlink(ed->seqbasep, last_seq); - seq_free_sequence(ed, last_seq); + seq_free_sequence(scene, last_seq); /* emtpy meta strip, delete all effects depending on it */ for(seq=ed->seqbasep->first; seq; seq=seq->next) diff --git a/source/blender/editors/space_sequencer/sequencer_select.c b/source/blender/editors/space_sequencer/sequencer_select.c index 335652235c6..dda5837e5f5 100644 --- a/source/blender/editors/space_sequencer/sequencer_select.c +++ b/source/blender/editors/space_sequencer/sequencer_select.c @@ -153,7 +153,7 @@ void select_single_seq(Scene *scene, Sequence *seq, int deselect_all) /* BRING B if(seq->strip) strncpy(ed->act_imagedir, seq->strip->dir, FILE_MAXDIR-1); } - else if((seq->type==SEQ_HD_SOUND) || (seq->type==SEQ_RAM_SOUND)) { + else if(seq->type==SEQ_SOUND) { if(seq->strip) strncpy(ed->act_sounddir, seq->strip->dir, FILE_MAXDIR-1); } @@ -336,7 +336,7 @@ static int sequencer_select_invoke(bContext *C, wmOperator *op, wmEvent *event) strncpy(ed->act_imagedir, seq->strip->dir, FILE_MAXDIR-1); } } else - if (seq->type == SEQ_HD_SOUND || seq->type == SEQ_RAM_SOUND) { + if (seq->type == SEQ_SOUND) { if(seq->strip) { strncpy(ed->act_sounddir, seq->strip->dir, FILE_MAXDIR-1); } diff --git a/source/blender/makesdna/DNA_actuator_types.h b/source/blender/makesdna/DNA_actuator_types.h index c3f668ff622..bbfd9cadf67 100644 --- a/source/blender/makesdna/DNA_actuator_types.h +++ b/source/blender/makesdna/DNA_actuator_types.h @@ -37,6 +37,9 @@ struct Scene; struct Group; struct Text; +// for Sound3D +#include "DNA_sound_types.h" + /* ****************** ACTUATORS ********************* */ /* unused now, moved to editobjectactuator in 2.02. Still needed for dna */ @@ -62,7 +65,9 @@ typedef struct bSoundActuator { short flag, sndnr; int sta, end; short pad1[2]; + float volume, pitch; struct bSound *sound; + struct Sound3D sound3D; short type, makecopy; short copymade, pad2[1]; } bSoundActuator; @@ -432,6 +437,9 @@ typedef struct FreeCamera { #define ACT_RANDOM_FLOAT_NORMAL 8 #define ACT_RANDOM_FLOAT_NEGATIVE_EXPONENTIAL 9 +/* SoundActuator->flag */ +#define ACT_SND_3D_SOUND 1 + /* SoundActuator->type */ #define ACT_SND_PLAY_STOP_SOUND 0 #define ACT_SND_PLAY_END_SOUND 1 diff --git a/source/blender/makesdna/DNA_scene_types.h b/source/blender/makesdna/DNA_scene_types.h index 752f756401c..36cd0c6ffdf 100644 --- a/source/blender/makesdna/DNA_scene_types.h +++ b/source/blender/makesdna/DNA_scene_types.h @@ -662,6 +662,7 @@ typedef struct Scene { ListBase markers; ListBase transform_spaces; + ListBase sound_handles; /* none of the dependancy graph vars is mean to be saved */ struct DagForest *theDag; diff --git a/source/blender/makesdna/DNA_sequence_types.h b/source/blender/makesdna/DNA_sequence_types.h index 422e1b07ed7..6d455d20f59 100644 --- a/source/blender/makesdna/DNA_sequence_types.h +++ b/source/blender/makesdna/DNA_sequence_types.h @@ -160,7 +160,7 @@ typedef struct Sequence { ListBase seqbase; /* list of strips for metastrips */ struct bSound *sound; /* the linked "bSound" object */ - struct hdaudio *hdaudio; /* external hdaudio object */ + struct SoundHandle *sound_handle; float level, pan; /* level in dB (0=full), pan -1..1 */ int scenenr; /* for scene selection */ float strobe; @@ -281,7 +281,7 @@ typedef struct SpeedControlVars { #define SEQ_MOVIE 3 #define SEQ_RAM_SOUND 4 #define SEQ_HD_SOUND 5 -#define SEQ_MOVIE_AND_HD_SOUND 6 /* helper for add_sequence */ +#define SEQ_SOUND 4 #define SEQ_EFFECT 8 #define SEQ_CROSS 8 diff --git a/source/blender/makesdna/DNA_sound_types.h b/source/blender/makesdna/DNA_sound_types.h index 5dedd20e1e4..841aae099cc 100644 --- a/source/blender/makesdna/DNA_sound_types.h +++ b/source/blender/makesdna/DNA_sound_types.h @@ -64,18 +64,43 @@ typedef struct bSample { short us; } bSample; - +// runtime only - no saving +typedef struct SoundHandle { + struct SoundHandle *next, *prev; + struct bSound *source; + void *handle; + int state; + int startframe; + int endframe; + int frameskip; + int mute; + int changed; + float volume; + float pad; +} SoundHandle; + +typedef struct Sound3D +{ + float min_gain; + float max_gain; + float reference_distance; + float max_distance; + float rolloff_factor; + float cone_inner_angle; + float cone_outer_angle; + float cone_outer_gain; +} Sound3D; typedef struct bSound { ID id; char name[160]; - struct bSample *sample; - void *stream; + struct bSample *sample; // AUD_XXX deprecated + void *stream; // AUD_XXX deprecated struct PackedFile *packedfile; - struct PackedFile *newpackedfile; - void *snd_sound; - struct Ipo *ipo; - float volume, panning; + struct PackedFile *newpackedfile; // AUD_XXX deprecated + void *snd_sound; // AUD_XXX used for AUD_Sound now + struct Ipo *ipo; // AUD_XXX deprecated + float volume, panning; // AUD_XXX deprecated /** * Sets the rollofffactor. The rollofffactor is a per-Source parameter * the application can use to increase or decrease the range of a source @@ -84,27 +109,43 @@ typedef struct bSound { * value of 0, which indicates that the application does not wish any * distance attenuation on the respective Source. */ - float attenuation; - float pitch; + float attenuation; // AUD_XXX deprecated + float pitch; // AUD_XXX deprecated /** * min_gain indicates the minimal gain which is always guaranteed for this sound */ - float min_gain; + float min_gain; // AUD_XXX deprecated /** * max_gain indicates the maximal gain which is always guaranteed for this sound */ - float max_gain; + float max_gain; // AUD_XXX deprecated /** * Sets the referencedistance at which the listener will experience gain. */ - float distance; - int flags; - int streamlen; - char channels; - char highprio; - char pad[10]; + float distance; // AUD_XXX deprecated + int flags; // AUD_XXX deprecated + int streamlen; // AUD_XXX deprecated + char channels; // AUD_XXX deprecated + char highprio; // AUD_XXX deprecated + char pad[10]; // AUD_XXX deprecated + + // AUD_XXX NEW + int type; + int changed; + struct bSound *child_sound; + void *cache; + + // SOUND_TYPE_LIMITER + float start, end; } bSound; +typedef enum eSound_Type { + SOUND_TYPE_INVALID = -1, + SOUND_TYPE_FILE = 0, + SOUND_TYPE_BUFFER, + SOUND_TYPE_LIMITER +} eSound_Type; + typedef struct bSoundListener { ID id; /** diff --git a/source/blender/makesdna/DNA_userdef_types.h b/source/blender/makesdna/DNA_userdef_types.h index f61b4b2904d..4a317dfb369 100644 --- a/source/blender/makesdna/DNA_userdef_types.h +++ b/source/blender/makesdna/DNA_userdef_types.h @@ -293,6 +293,11 @@ typedef struct UserDef { short userpref, viewzoom; int mixbufsize; + int audiodevice; + int audiorate; + int audioformat; + int audiochannels; + int scrollback; /* console scrollback limit */ int dpi; /* range 48-128? */ short encoding; diff --git a/source/blender/makesrna/intern/rna_sequence.c b/source/blender/makesrna/intern/rna_sequence.c index 8ca023dc57c..fec91c64e4d 100644 --- a/source/blender/makesrna/intern/rna_sequence.c +++ b/source/blender/makesrna/intern/rna_sequence.c @@ -192,10 +192,8 @@ static StructRNA* rna_Sequence_refine(struct PointerRNA *ptr) case SEQ_SCENE: return &RNA_SceneSequence; case SEQ_MOVIE: - case SEQ_MOVIE_AND_HD_SOUND: return &RNA_MovieSequence; - case SEQ_RAM_SOUND: - case SEQ_HD_SOUND: + case SEQ_SOUND: return &RNA_SoundSequence; case SEQ_CROSS: case SEQ_ADD: @@ -362,9 +360,7 @@ static void rna_def_sequence(BlenderRNA *brna) {SEQ_META, "META", 0, "Meta", ""}, {SEQ_SCENE, "SCENE", 0, "Scene", ""}, {SEQ_MOVIE, "MOVIE", 0, "Movie", ""}, - {SEQ_RAM_SOUND, "RAM_SOUND", 0, "Ram Sound", ""}, - {SEQ_HD_SOUND, "HD_SOUND", 0, "HD Sound", ""}, - {SEQ_MOVIE_AND_HD_SOUND, "MOVIE_AND_HD_SOUND", 0, "Movie and HD Sound", ""}, + {SEQ_SOUND, "_SOUND", 0, "Sound", ""}, {SEQ_EFFECT, "REPLACE", 0, "Replace", ""}, {SEQ_CROSS, "CROSS", 0, "Cross", ""}, {SEQ_ADD, "ADD", 0, "Add", ""}, @@ -616,21 +612,6 @@ static void rna_def_filter_video(StructRNA *srna) RNA_def_property_update(prop, NC_SCENE|ND_SEQUENCER, NULL); } -static void rna_def_filter_sound(StructRNA *srna) -{ - PropertyRNA *prop; - - prop= RNA_def_property(srna, "sound_gain", PROP_FLOAT, PROP_NONE); - RNA_def_property_float_sdna(prop, NULL, "level"); - RNA_def_property_range(prop, -96.0f, 6.0f); - RNA_def_property_ui_text(prop, "Sound Gain", "Sound level in dB (0 = full volume)."); - - prop= RNA_def_property(srna, "sound_pan", PROP_FLOAT, PROP_NONE); - RNA_def_property_float_sdna(prop, NULL, "pan"); - RNA_def_property_range(prop, -1.0f, 1.0f); - RNA_def_property_ui_text(prop, "Sound Pan", "Stereo sound balance."); -} - static void rna_def_proxy(StructRNA *srna) { PropertyRNA *prop; @@ -772,7 +753,6 @@ static void rna_def_sound(BlenderRNA *brna) RNA_def_property_string_sdna(prop, NULL, "strip->dir"); RNA_def_property_ui_text(prop, "Directory", ""); - rna_def_filter_sound(srna); rna_def_input(srna); } diff --git a/source/blender/makesrna/intern/rna_sound.c b/source/blender/makesrna/intern/rna_sound.c index 363a5595b43..9ca2a74bedd 100644 --- a/source/blender/makesrna/intern/rna_sound.c +++ b/source/blender/makesrna/intern/rna_sound.c @@ -149,71 +149,6 @@ static void rna_def_sound(BlenderRNA *brna) prop= RNA_def_property(srna, "packed_file", PROP_POINTER, PROP_NONE); RNA_def_property_pointer_sdna(prop, NULL, "packedfile"); RNA_def_property_ui_text(prop, "Packed File", ""); - - /* game engine settings */ - prop= RNA_def_property(srna, "volume", PROP_FLOAT, PROP_UNSIGNED); - RNA_def_property_float_sdna(prop, NULL, "volume"); - RNA_def_property_ui_range(prop, 0.0, 1.0, 10, 4); - RNA_def_property_ui_text(prop, "Volume", "Game engine only: volume for this sound."); - - prop= RNA_def_property(srna, "pitch", PROP_FLOAT, PROP_NONE); - RNA_def_property_float_sdna(prop, NULL, "pitch"); - RNA_def_property_ui_range(prop, -12.0, 12.0, 10, 4); - RNA_def_property_ui_text(prop, "Pitch", "Game engine only: set the pitch of this sound."); - - prop= RNA_def_property(srna, "loop", PROP_BOOLEAN, PROP_NONE); - RNA_def_property_boolean_sdna(prop, NULL, "flags", SOUND_FLAGS_LOOP); - RNA_def_property_ui_text(prop, "Sound Loop", "Game engine only: toggle between looping on/off."); - - prop= RNA_def_property(srna, "ping_pong", PROP_BOOLEAN, PROP_NONE); - RNA_def_property_boolean_sdna(prop, NULL, "flags", SOUND_FLAGS_BIDIRECTIONAL_LOOP); - RNA_def_property_ui_text(prop, "Ping Pong", "Game engine only: Toggle between A->B and A->B->A looping."); - - prop= RNA_def_property(srna, "sound_3d", PROP_BOOLEAN, PROP_NONE); - RNA_def_property_boolean_sdna(prop, NULL, "flags", SOUND_FLAGS_3D); - RNA_def_property_ui_text(prop, "3D Sound", "Game engine only: turns 3D sound on."); - - prop= RNA_def_property(srna, "attenuation", PROP_FLOAT, PROP_NONE); - RNA_def_property_float_sdna(prop, NULL, "attenuation"); - RNA_def_property_range(prop, 0.0, 5.0); - RNA_def_property_ui_text(prop, "Attenuation", "Game engine only: sets the surround scaling factor for 3D sound."); - - /* gain */ - prop= RNA_def_property(srna, "min_gain", PROP_FLOAT, PROP_NONE); - RNA_def_property_float_sdna(prop, NULL, "min_gain"); - RNA_def_property_range(prop, 0.0, 1.0); - RNA_def_property_ui_text(prop, "Min Gain", "Minimal gain which is always guaranteed for this sound."); - - prop= RNA_def_property(srna, "max_gain", PROP_FLOAT, PROP_NONE); - RNA_def_property_float_sdna(prop, NULL, "max_gain"); - RNA_def_property_range(prop, 0.0, 1.0); - RNA_def_property_ui_text(prop, "Max Gain", "Maximal gain which is always guaranteed for this sound."); - - prop= RNA_def_property(srna, "reference_distance", PROP_FLOAT, PROP_NONE); - RNA_def_property_float_sdna(prop, NULL, "distance"); - RNA_def_property_ui_text(prop, "Reference Distance", "Reference distance at which the listener will experience gain."); - RNA_def_property_ui_range(prop, 0.0, 1000.0, 10, 4); /* NOT used anywhere */ - - /* unused - prop= RNA_def_property(srna, "panning", PROP_FLOAT, PROP_NONE); - RNA_def_property_float_sdna(prop, NULL, "panning"); - RNA_def_property_ui_range(prop, -1.0, 1.0, 10, 4); - RNA_def_property_ui_text(prop, "Panning", "Pan the sound from left to right"); */ - - /* unused - prop= RNA_def_property(srna, "fixed_volume", PROP_BOOLEAN, PROP_NONE); - RNA_def_property_boolean_sdna(prop, NULL, "flags", SOUND_FLAGS_FIXED_VOLUME); - RNA_def_property_ui_text(prop, "Fixed Volume", "Constraint sound to fixed volume."); */ - - /* unused - prop= RNA_def_property(srna, "fixed_panning", PROP_BOOLEAN, PROP_NONE); - RNA_def_property_boolean_sdna(prop, NULL, "flags", SOUND_FLAGS_FIXED_PANNING); - RNA_def_property_ui_text(prop, "Fixed Panning", "Constraint sound to fixed panning."); */ - - /* unused - prop= RNA_def_property(srna, "priority", PROP_BOOLEAN, PROP_NONE); - RNA_def_property_boolean_sdna(prop, NULL, "flags", SOUND_FLAGS_PRIORITY); - RNA_def_property_ui_text(prop, "Priority", "Make sound higher priority."); */ } void RNA_def_sound(BlenderRNA *brna) diff --git a/source/blender/makesrna/intern/rna_userdef.c b/source/blender/makesrna/intern/rna_userdef.c index f1fd11a0094..8dcca446507 100644 --- a/source/blender/makesrna/intern/rna_userdef.c +++ b/source/blender/makesrna/intern/rna_userdef.c @@ -37,6 +37,8 @@ #include "BKE_utildefines.h" +#include "BKE_sound.h" + #ifdef RNA_RUNTIME static void rna_userdef_lmb_select_set(struct PointerRNA *ptr,int value) @@ -116,6 +118,11 @@ static PointerRNA rna_UserDef_system_get(PointerRNA *ptr) return rna_pointer_inherit_refine(ptr, &RNA_UserPreferencesSystem, ptr->data); } +static void rna_UserDef_audio_update(bContext *C, PointerRNA *ptr) +{ + sound_reinit(C); +} + #else static void rna_def_userdef_theme_ui_font_style(BlenderRNA *brna) @@ -1977,6 +1984,46 @@ static void rna_def_userdef_system(BlenderRNA *brna) {512, "AUDIO_SAMPLES_512", 0, "512", "Set audio mixing buffer size to 512 samples"}, {1024, "AUDIO_SAMPLES_1024", 0, "1024", "Set audio mixing buffer size to 1024 samples"}, {2048, "AUDIO_SAMPLES_2048", 0, "2048", "Set audio mixing buffer size to 2048 samples"}, + {4096, "AUDIO_SAMPLES_4096", 0, "4096", "Set audio mixing buffer size to 4096 samples"}, + {8192, "AUDIO_SAMPLES_8192", 0, "8192", "Set audio mixing buffer size to 8192 samples"}, + {16384, "AUDIO_SAMPLES_16384", 0, "16384", "Set audio mixing buffer size to 16384 samples"}, + {32768, "AUDIO_SAMPLES_32768", 0, "32768", "Set audio mixing buffer size to 32768 samples"}, + {0, NULL, 0, NULL, NULL}}; + + static EnumPropertyItem audio_device_items[] = { + {0, "AUDIO_DEVICE_NULL", 0, "No Audio", "Null device - there will be no audio output."}, + {1, "AUDIO_DEVICE_SDL", 0, "SDL", "SDL device - simple direct media layer, recommended for sequencer usage."}, + {2, "AUDIO_DEVICE_OPENAL", 0, "OpenAL", "OpenAL device - supports 3D audio, recommended for game engine usage."}, + {0, NULL, 0, NULL, NULL}}; + + static EnumPropertyItem audio_rate_items[] = { +// {8000, "AUDIO_RATE_8000", 0, "8 kHz", "Set audio sampling rate to 8000 samples per second."}, +// {11025, "AUDIO_RATE_11025", 0, "11.025 kHz", "Set audio sampling rate to 11025 samples per second."}, +// {16000, "AUDIO_RATE_16000", 0, "16 kHz", "Set audio sampling rate to 16000 samples per second."}, +// {22050, "AUDIO_RATE_22050", 0, "22.05 kHz", "Set audio sampling rate to 22050 samples per second."}, +// {32000, "AUDIO_RATE_32000", 0, "32 kHz", "Set audio sampling rate to 32000 samples per second."}, + {44100, "AUDIO_RATE_44100", 0, "44.1 kHz", "Set audio sampling rate to 44100 samples per second."}, + {48000, "AUDIO_RATE_48000", 0, "48 kHz", "Set audio sampling rate to 48000 samples per second."}, +// {88200, "AUDIO_RATE_88200", 0, "88.2 kHz", "Set audio sampling rate to 88200 samples per second."}, + {96000, "AUDIO_RATE_96000", 0, "96 kHz", "Set audio sampling rate to 96000 samples per second."}, + {192000, "AUDIO_RATE_192000", 0, "192 kHz", "Set audio sampling rate to 192000 samples per second."}, + {0, NULL, 0, NULL, NULL}}; + + static EnumPropertyItem audio_format_items[] = { + {0x01, "AUDIO_FORMAT_U8", 0, "8-bit Unsigned", "Set audio sample format to 8 bit unsigned integer."}, + {0x12, "AUDIO_FORMAT_S16", 0, "16-bit Signed", "Set audio sample format to 16 bit signed integer."}, + {0x13, "AUDIO_FORMAT_S24", 0, "24-bit Signed", "Set audio sample format to 24 bit signed integer."}, + {0x14, "AUDIO_FORMAT_S32", 0, "32-bit Signed", "Set audio sample format to 32 bit signed integer."}, + {0x24, "AUDIO_FORMAT_FLOAT", 0, "32-bit Float", "Set audio sample format to 32 bit float."}, + {0x28, "AUDIO_FORMAT_DOUBLE", 0, "64-bit Float", "Set audio sample format to 64 bit float."}, + {0, NULL, 0, NULL, NULL}}; + + static EnumPropertyItem audio_channel_items[] = { + {1, "AUDIO_CHANNELS_MONO", 0, "Mono", "Set audio channels to mono."}, + {2, "AUDIO_CHANNELS_STEREO", 0, "Stereo", "Set audio channels to stereo."}, + {4, "AUDIO_CHANNELS_SURROUND4", 0, "4 Channels", "Set audio channels to 4 channels."}, + {6, "AUDIO_CHANNELS_SURROUND51", 0, "5.1 Surround", "Set audio channels to 5.1 surround sound."}, + {8, "AUDIO_CHANNELS_SURROUND71", 0, "7.1 Surround", "Set audio channels to 7.1 surround sound."}, {0, NULL, 0, NULL, NULL}}; static EnumPropertyItem draw_method_items[] = { @@ -2078,6 +2125,31 @@ static void rna_def_userdef_system(BlenderRNA *brna) RNA_def_property_enum_sdna(prop, NULL, "mixbufsize"); RNA_def_property_enum_items(prop, audio_mixing_samples_items); RNA_def_property_ui_text(prop, "Audio Mixing Buffer", "Sets the number of samples used by the audio mixing buffer."); + RNA_def_property_update(prop, 0, "rna_UserDef_audio_update"); + + prop= RNA_def_property(srna, "audio_device", PROP_ENUM, PROP_NONE); + RNA_def_property_enum_sdna(prop, NULL, "audiodevice"); + RNA_def_property_enum_items(prop, audio_device_items); + RNA_def_property_ui_text(prop, "Audio Device", "Sets the audio output device."); + RNA_def_property_update(prop, 0, "rna_UserDef_audio_update"); + + prop= RNA_def_property(srna, "audio_sample_rate", PROP_ENUM, PROP_NONE); + RNA_def_property_enum_sdna(prop, NULL, "audiorate"); + RNA_def_property_enum_items(prop, audio_rate_items); + RNA_def_property_ui_text(prop, "Audio Sample Rate", "Sets the audio sample rate."); + RNA_def_property_update(prop, 0, "rna_UserDef_audio_update"); + + prop= RNA_def_property(srna, "audio_sample_format", PROP_ENUM, PROP_NONE); + RNA_def_property_enum_sdna(prop, NULL, "audioformat"); + RNA_def_property_enum_items(prop, audio_format_items); + RNA_def_property_ui_text(prop, "Audio Sample Format", "Sets the audio sample format."); + RNA_def_property_update(prop, 0, "rna_UserDef_audio_update"); + + prop= RNA_def_property(srna, "audio_channels", PROP_ENUM, PROP_NONE); + RNA_def_property_enum_sdna(prop, NULL, "audiochannels"); + RNA_def_property_enum_items(prop, audio_channel_items); + RNA_def_property_ui_text(prop, "Audio Channels", "Sets the audio channel count."); + RNA_def_property_update(prop, 0, "rna_UserDef_audio_update"); #if 0 prop= RNA_def_property(srna, "verse_master", PROP_STRING, PROP_NONE); diff --git a/source/blender/render/intern/source/pipeline.c b/source/blender/render/intern/source/pipeline.c index 14df6b8ec9f..4744288f3a9 100644 --- a/source/blender/render/intern/source/pipeline.c +++ b/source/blender/render/intern/source/pipeline.c @@ -2692,7 +2692,7 @@ void RE_BlenderAnim(Render *re, Scene *scene, int sfra, int efra, int tfra) re->result_ok= 0; if(BKE_imtype_is_movie(scene->r.imtype)) - mh->start_movie(&re->r, re->rectx, re->recty); + mh->start_movie(scene, &re->r, re->rectx, re->recty); if (mh->get_next_frame) { while (!(G.afbreek == 1)) { diff --git a/source/blender/windowmanager/intern/wm_init_exit.c b/source/blender/windowmanager/intern/wm_init_exit.c index 7179efb186d..e4e585a33b6 100644 --- a/source/blender/windowmanager/intern/wm_init_exit.c +++ b/source/blender/windowmanager/intern/wm_init_exit.c @@ -90,7 +90,7 @@ #include "GPU_extensions.h" #include "GPU_draw.h" - +#include "BKE_sound.h" /* XXX */ static void sound_init_listener(void) @@ -156,6 +156,8 @@ void WM_init(bContext *C) read_Blog(); BLI_strncpy(G.lib, G.sce, FILE_MAX); + + sound_init(); } /* free strings of open recent files */ @@ -184,7 +186,9 @@ extern void free_posebuf(); void WM_exit(bContext *C) { wmWindow *win; - + + sound_exit(); + /* first wrap up running stuff, we assume only the active WM is running */ /* modal handlers are on window level freed, others too? */ /* note; same code copied in wm_files.c */ diff --git a/source/creator/CMakeLists.txt b/source/creator/CMakeLists.txt index 064681b37ea..2fd289f70d5 100644 --- a/source/creator/CMakeLists.txt +++ b/source/creator/CMakeLists.txt @@ -174,6 +174,7 @@ IF(WIN32) COMMAND copy /Y \"${WIN_LIBDIR}\\python\\lib\\python26.dll\" \"${TARGETDIR}\\\" COMMAND copy /Y \"${WIN_LIBDIR}\\python\\lib\\python26_d.dll\" \"${TARGETDIR}\\\" COMMAND copy /Y \"${WIN_LIBDIR}\\pthreads\\lib\\pthreadVC2.dll\" \"${TARGETDIR}\\\" + COMMAND copy /Y \"${WIN_LIBDIR}\\samplerate\\lib\\libsamplerate-0.dll\" \"${TARGETDIR}\\\" ) IF(WITH_INTERNATIONAL) @@ -284,6 +285,7 @@ IF(UNIX) bf_dna bf_blenfont bf_soundsystem + bf_audaspace ) FOREACH(SORTLIB ${BLENDER_SORTED_LIBS}) diff --git a/source/gameengine/BlenderRoutines/BL_KetsjiEmbedStart.cpp b/source/gameengine/BlenderRoutines/BL_KetsjiEmbedStart.cpp index 086c259c4bb..1c79d97ae55 100644 --- a/source/gameengine/BlenderRoutines/BL_KetsjiEmbedStart.cpp +++ b/source/gameengine/BlenderRoutines/BL_KetsjiEmbedStart.cpp @@ -186,19 +186,8 @@ extern "C" void StartKetsjiShell(struct bContext *C, struct ARegion *ar, int alw // create a networkdevice NG_NetworkDeviceInterface* networkdevice = new NG_LoopBackNetworkDeviceInterface(); - - // - SYS_SystemHandle hSystem = SYS_GetSystem(); - bool noaudio = SYS_GetCommandLineInt(hSystem,"noaudio",0); - if (noaudio)/*(noaudio) intrr: disable game engine audio (openal) */ - SND_DeviceManager::SetDeviceType(snd_e_dummydevice); - - // get an audiodevice - SND_DeviceManager::Subscribe(); - SND_IAudioDevice* audiodevice = SND_DeviceManager::Instance(); - audiodevice->UseCD(); - + // // create a ketsji/blendersystem (only needed for timing and stuff) KX_BlenderSystem* kxsystem = new KX_BlenderSystem(); @@ -213,7 +202,6 @@ extern "C" void StartKetsjiShell(struct bContext *C, struct ARegion *ar, int alw ketsjiengine->SetRenderTools(rendertools); ketsjiengine->SetRasterizer(rasterizer); ketsjiengine->SetNetworkDevice(networkdevice); - ketsjiengine->SetAudioDevice(audiodevice); ketsjiengine->SetUseFixedTime(usefixed); ketsjiengine->SetTimingDisplay(frameRate, profile, properties); @@ -374,7 +362,6 @@ extern "C" void StartKetsjiShell(struct bContext *C, struct ARegion *ar, int alw KX_Scene* startscene = new KX_Scene(keyboarddevice, mousedevice, networkdevice, - audiodevice, startscenename, blscene); @@ -519,8 +506,6 @@ extern "C" void StartKetsjiShell(struct bContext *C, struct ARegion *ar, int alw canvas->SetMouseState(RAS_ICanvas::MOUSE_NORMAL); // clean up some stuff - audiodevice->StopCD(); - if (ketsjiengine) { delete ketsjiengine; @@ -637,11 +622,6 @@ extern "C" void StartKetsjiShellSimulation(struct wmWindow *win, NG_NetworkDeviceInterface* networkdevice = new NG_LoopBackNetworkDeviceInterface(); - // get an audiodevice - SND_DeviceManager::Subscribe(); - SND_IAudioDevice* audiodevice = SND_DeviceManager::Instance(); - audiodevice->UseCD(); - // create a ketsji/blendersystem (only needed for timing and stuff) KX_BlenderSystem* kxsystem = new KX_BlenderSystem(); @@ -692,7 +672,6 @@ extern "C" void StartKetsjiShellSimulation(struct wmWindow *win, KX_Scene* startscene = new KX_Scene(keyboarddevice, mousedevice, networkdevice, - audiodevice, startscenename, blscene); @@ -756,7 +735,6 @@ extern "C" void StartKetsjiShellSimulation(struct wmWindow *win, canvas->SetMouseState(RAS_ICanvas::MOUSE_NORMAL); // clean up some stuff - audiodevice->StopCD(); if (ketsjiengine) { delete ketsjiengine; diff --git a/source/gameengine/Converter/BL_BlenderDataConversion.cpp b/source/gameengine/Converter/BL_BlenderDataConversion.cpp index e148861ca5a..2c7df80a3fc 100644 --- a/source/gameengine/Converter/BL_BlenderDataConversion.cpp +++ b/source/gameengine/Converter/BL_BlenderDataConversion.cpp @@ -101,9 +101,6 @@ #include "KX_KetsjiEngine.h" #include "KX_BlenderSceneConverter.h" -#include"SND_Scene.h" -#include "SND_SoundListener.h" - /* This little block needed for linking to Blender... */ #ifdef WIN32 #include "BLI_winstuff.h" @@ -2616,23 +2613,7 @@ void BL_ConvertBlenderObjects(struct Main* maggie, } } - sumolist->Release(); - - // convert global sound stuff - - /* XXX, glob is the very very wrong place for this - * to be, re-enable once the listener has been moved into - * the scene. */ -#if 1 - SND_Scene* soundscene = kxscene->GetSoundScene(); - SND_SoundListener* listener = soundscene->GetListener(); - if (listener && G.listener) - { - listener->SetDopplerFactor(G.listener->dopplerfactor); - listener->SetDopplerVelocity(G.listener->dopplervelocity); - listener->SetGain(G.listener->gain); - } -#endif + sumolist->Release(); // convert world KX_WorldInfo* worldinfo = new BlenderWorldInfo(blenderscene->world); diff --git a/source/gameengine/Converter/CMakeLists.txt b/source/gameengine/Converter/CMakeLists.txt index 031c2234ea8..f4aa50cd837 100644 --- a/source/gameengine/Converter/CMakeLists.txt +++ b/source/gameengine/Converter/CMakeLists.txt @@ -32,6 +32,7 @@ SET(INC ../../../intern/string ../../../intern/guardedalloc ../../../source/gameengine/Rasterizer/RAS_OpenGLRasterizer + ../../../intern/audaspace ../../../intern/SoundSystem ../../../intern/SoundSystem/include ../../../intern/SoundSystem/openal diff --git a/source/gameengine/Converter/KX_ConvertActuators.cpp b/source/gameengine/Converter/KX_ConvertActuators.cpp index c18e4fce8a5..1afadac5c0a 100644 --- a/source/gameengine/Converter/KX_ConvertActuators.cpp +++ b/source/gameengine/Converter/KX_ConvertActuators.cpp @@ -38,7 +38,7 @@ #include "KX_BlenderSceneConverter.h" #include "KX_ConvertActuators.h" -#include "SND_Scene.h" +#include "AUD_C-API.h" // Actuators //SCA logiclibrary native logicbricks #include "SCA_PropertyActuator.h" @@ -347,8 +347,7 @@ void BL_ConvertActuators(char* maggiename, { bSoundActuator* soundact = (bSoundActuator*) bact->data; /* get type, and possibly a start and end frame */ - short startFrame = soundact->sta, stopFrame = soundact->end; - KX_SoundActuator::KX_SOUNDACT_TYPE + KX_SoundActuator::KX_SOUNDACT_TYPE soundActuatorType = KX_SoundActuator::KX_SOUNDACT_NODEF; switch(soundact->type) { @@ -378,114 +377,38 @@ void BL_ConvertActuators(char* maggiename, if (soundActuatorType != KX_SoundActuator::KX_SOUNDACT_NODEF) { - SND_Scene* soundscene = scene->GetSoundScene(); - STR_String samplename = ""; - bool sampleisloaded = false; - - if (soundact->sound) { - /* Need to convert the samplename into absolute path - * before checking if its loaded */ - char fullpath[FILE_MAX]; - - /* dont modify soundact->sound->name, only change a copy */ - BLI_strncpy(fullpath, soundact->sound->name, sizeof(fullpath)); - BLI_convertstringcode(fullpath, maggiename); - samplename = fullpath; - - /* let's see if the sample was already loaded */ - if (soundscene->IsSampleLoaded(samplename)) - { - sampleisloaded = true; - } - else { - /* if not, make it so */ - PackedFile* pf = soundact->sound->newpackedfile; - - /* but we need a packed file then */ - if (pf) - { - if (soundscene->LoadSample(samplename, pf->data, pf->size) > -1) - sampleisloaded = true; - } - /* or else load it from disk */ - else - { - if (soundscene->LoadSample(samplename, NULL, 0) > -1) { - sampleisloaded = true; - } - else { - std::cout << "WARNING: Sound actuator \"" << bact->name << - "\" from object \"" << blenderobject->id.name+2 << - "\" failed to load sample." << std::endl; - } - } - } - } else { + bSound* sound = soundact->sound; + bool is3d = soundact->flag & ACT_SND_3D_SOUND ? true : false; + AUD_Sound* snd_sound = NULL; + KX_3DSoundSettings settings; + settings.cone_inner_angle = soundact->sound3D.cone_inner_angle; + settings.cone_outer_angle = soundact->sound3D.cone_outer_angle; + settings.cone_outer_gain = soundact->sound3D.cone_outer_gain; + settings.max_distance = soundact->sound3D.max_distance; + settings.max_gain = soundact->sound3D.max_gain; + settings.min_gain = soundact->sound3D.min_gain; + settings.reference_distance = soundact->sound3D.reference_distance; + settings.rolloff_factor = soundact->sound3D.rolloff_factor; + + if(!sound) + { std::cout << "WARNING: Sound actuator \"" << bact->name << "\" from object \"" << blenderobject->id.name+2 << "\" has no sound datablock." << std::endl; } - - /* Note, allowing actuators for sounds that are not there was added since 2.47 - * This is because python may expect the actuator and raise an exception if it dosnt find it - * better just to add a dummy sound actuator. */ - SND_SoundObject* sndobj = NULL; - if (sampleisloaded) - { - /* setup the SND_SoundObject */ - sndobj = new SND_SoundObject(); - sndobj->SetSampleName(samplename.Ptr()); - sndobj->SetObjectName(bact->name); - if (soundact->sound) { - sndobj->SetRollOffFactor(soundact->sound->attenuation); - sndobj->SetGain(soundact->sound->volume); - sndobj->SetPitch(exp((soundact->sound->pitch / 12.0) * log(2.0))); - // sndobj->SetLoopStart(soundact->sound->loopstart); - // sndobj->SetLoopStart(soundact->sound->loopend); - if (soundact->sound->flags & SOUND_FLAGS_LOOP) - { - if (soundact->sound->flags & SOUND_FLAGS_BIDIRECTIONAL_LOOP) - sndobj->SetLoopMode(SND_LOOP_BIDIRECTIONAL); - else - sndobj->SetLoopMode(SND_LOOP_NORMAL); - } - else { - sndobj->SetLoopMode(SND_LOOP_OFF); - } - - if (soundact->sound->flags & SOUND_FLAGS_PRIORITY) - sndobj->SetHighPriority(true); - else - sndobj->SetHighPriority(false); - - if (soundact->sound->flags & SOUND_FLAGS_3D) - sndobj->Set3D(true); - else - sndobj->Set3D(false); - } - else { - /* dummy values for a NULL sound - * see editsound.c - defaults are unlikely to change soon */ - sndobj->SetRollOffFactor(1.0); - sndobj->SetGain(1.0); - sndobj->SetPitch(1.0); - sndobj->SetLoopMode(SND_LOOP_OFF); - sndobj->SetHighPriority(false); - sndobj->Set3D(false); - } - } - KX_SoundActuator* tmpsoundact = - new KX_SoundActuator(gameobj, - sndobj, - scene->GetSoundScene(), // needed for replication! - soundActuatorType, - startFrame, - stopFrame); - + else + snd_sound = sound->cache ? sound->cache : sound->snd_sound; + KX_SoundActuator* tmpsoundact = + new KX_SoundActuator(gameobj, + snd_sound, + soundact->volume, + exp((soundact->pitch / 12.0) * log(2.0)), + is3d, + settings, + soundActuatorType); + tmpsoundact->SetName(bact->name); baseact = tmpsoundact; - if (sndobj) - soundscene->AddObject(sndobj); } break; } @@ -525,27 +448,6 @@ void BL_ConvertActuators(char* maggiename, /* This is an error!!! */ cdActuatorType = KX_CDActuator::KX_CDACT_NODEF; } - - if (cdActuatorType != KX_CDActuator::KX_CDACT_NODEF) - { - SND_CDObject* pCD = SND_CDObject::Instance(); - - if (pCD) - { - pCD->SetGain(cdact->volume); - - KX_CDActuator* tmpcdact = - new KX_CDActuator(gameobj, - scene->GetSoundScene(), // needed for replication! - cdActuatorType, - cdact->track, - startFrame, - stopFrame); - - tmpcdact->SetName(bact->name); - baseact = tmpcdact; - } - } break; } case ACT_PROPERTY: diff --git a/source/gameengine/Converter/SConscript b/source/gameengine/Converter/SConscript index 05ea01c902a..1c03179ea07 100644 --- a/source/gameengine/Converter/SConscript +++ b/source/gameengine/Converter/SConscript @@ -6,6 +6,7 @@ defs = [] incs = '. #source/kernel/gen_system #intern/string #intern/guardedalloc' incs += ' #source/gameengine/Rasterizer/RAS_OpenGLRasterizer' +incs += ' #intern/audaspace' incs += ' #intern/SoundSystem #intern/SoundSystem/include #intern/SoundSystem/openal' incs += ' #intern/SoundSystem/dummy #intern/SoundSystem/intern #source/gameengine/Converter' incs += ' #source/gameengine/BlenderRoutines #source/blender/imbuf' diff --git a/source/gameengine/Ketsji/CMakeLists.txt b/source/gameengine/Ketsji/CMakeLists.txt index f703841c40b..d368e9f4efd 100644 --- a/source/gameengine/Ketsji/CMakeLists.txt +++ b/source/gameengine/Ketsji/CMakeLists.txt @@ -55,6 +55,7 @@ SET(INC ../../../source/gameengine/Physics/Sumo ../../../source/gameengine/Physics/Sumo/Fuzzics/include ../../../source/gameengine/Network/LoopBackNetwork + ../../../intern/audaspace ../../../intern/SoundSystem ../../../source/blender/misc ../../../source/blender/blenloader diff --git a/source/gameengine/Ketsji/KX_CDActuator.cpp b/source/gameengine/Ketsji/KX_CDActuator.cpp index bfca81f45d9..0861a54d848 100644 --- a/source/gameengine/Ketsji/KX_CDActuator.cpp +++ b/source/gameengine/Ketsji/KX_CDActuator.cpp @@ -31,9 +31,7 @@ */ #include "KX_CDActuator.h" -#include "SND_CDObject.h" #include "KX_GameObject.h" -#include "SND_Scene.h" // needed for replication #include <iostream> #ifdef HAVE_CONFIG_H @@ -44,21 +42,18 @@ /* Native functions */ /* ------------------------------------------------------------------------- */ KX_CDActuator::KX_CDActuator(SCA_IObject* gameobject, - SND_Scene* soundscene, KX_CDACT_TYPE type, int track, short start, short end) : SCA_IActuator(gameobject) { - m_soundscene = soundscene; m_type = type; m_track = track; m_lastEvent = true; m_isplaying = false; m_startFrame = start; m_endFrame = end; - m_gain = SND_CDObject::Instance()->GetGain(); } @@ -82,60 +77,13 @@ bool KX_CDActuator::Update() { bool result = false; bool bNegativeEvent = IsNegativeEvent(); - + RemoveAllEvents(); - + if (!bNegativeEvent) { switch (m_type) { - case KX_CDACT_PLAY_ALL: - { - SND_CDObject::Instance()->SetPlaymode(SND_CD_ALL); - SND_CDObject::Instance()->SetTrack(1); - SND_CDObject::Instance()->SetPlaystate(SND_MUST_PLAY); - //result = true; - break; - } - case KX_CDACT_PLAY_TRACK: - { - SND_CDObject::Instance()->SetPlaymode(SND_CD_TRACK); - SND_CDObject::Instance()->SetTrack(m_track); - SND_CDObject::Instance()->SetPlaystate(SND_MUST_PLAY); - //result = true; - break; - } - case KX_CDACT_LOOP_TRACK: - { - SND_CDObject::Instance()->SetPlaymode(SND_CD_ALL); - SND_CDObject::Instance()->SetTrack(m_track); - SND_CDObject::Instance()->SetPlaystate(SND_MUST_PLAY); - //result = true; - break; - } - case KX_CDACT_STOP: - { - SND_CDObject::Instance()->SetPlaystate(SND_MUST_STOP); - break; - } - case KX_CDACT_PAUSE: - { - SND_CDObject::Instance()->SetPlaystate(SND_MUST_PAUSE); - //result = true; - break; - } - case KX_CDACT_RESUME: - { - SND_CDObject::Instance()->SetPlaystate(SND_MUST_RESUME); - //result = true; - break; - } - case KX_CDACT_VOLUME: - { - SND_CDObject::Instance()->SetGain(m_gain); - //result = true; - break; - } default: // implement me !! break; @@ -196,7 +144,6 @@ PyMethodDef KX_CDActuator::Methods[] = { }; PyAttributeDef KX_CDActuator::Attributes[] = { - KX_PYATTRIBUTE_FLOAT_RW_CHECK("volume", 0.0, 1.0, KX_CDActuator, m_gain,pyattr_setGain), KX_PYATTRIBUTE_INT_RW("track", 1, 99, false, KX_CDActuator, m_track), { NULL } //Sentinel }; @@ -204,7 +151,6 @@ PyAttributeDef KX_CDActuator::Attributes[] = { int KX_CDActuator::pyattr_setGain(void *self, const struct KX_PYATTRIBUTE_DEF *attrdef) { KX_CDActuator* act = static_cast<KX_CDActuator*>(self); - SND_CDObject::Instance()->SetGain(act->m_gain); return PY_SET_ATTR_SUCCESS; } @@ -212,34 +158,30 @@ KX_PYMETHODDEF_DOC_NOARGS(KX_CDActuator, startCD, "startCD()\n" "\tStarts the CD playing.\n") { - SND_CDObject::Instance()->SetPlaystate(SND_MUST_PLAY); Py_RETURN_NONE; -} +} KX_PYMETHODDEF_DOC_NOARGS(KX_CDActuator, pauseCD, "pauseCD()\n" "\tPauses the CD playing.\n") { - SND_CDObject::Instance()->SetPlaystate(SND_MUST_PAUSE); Py_RETURN_NONE; -} +} KX_PYMETHODDEF_DOC_NOARGS(KX_CDActuator, resumeCD, "resumeCD()\n" "\tResumes the CD playing.\n") { - SND_CDObject::Instance()->SetPlaystate(SND_MUST_RESUME); Py_RETURN_NONE; -} +} KX_PYMETHODDEF_DOC_NOARGS(KX_CDActuator, stopCD, "stopCD()\n" "\tStops the CD playing.\n") { - SND_CDObject::Instance()->SetPlaystate(SND_MUST_STOP); Py_RETURN_NONE; } @@ -250,9 +192,6 @@ KX_PYMETHODDEF_DOC_O(KX_CDActuator, playTrack, { if (PyLong_Check(value)) { int track = PyLong_AsSsize_t(value); - SND_CDObject::Instance()->SetPlaymode(SND_CD_TRACK); - SND_CDObject::Instance()->SetTrack(track); - SND_CDObject::Instance()->SetPlaystate(SND_MUST_PLAY); } Py_RETURN_NONE; } @@ -263,11 +202,8 @@ KX_PYMETHODDEF_DOC_NOARGS(KX_CDActuator, playAll, "playAll()\n" "\tPlays the CD from the beginning.\n") { - SND_CDObject::Instance()->SetPlaymode(SND_CD_ALL); - SND_CDObject::Instance()->SetTrack(1); - SND_CDObject::Instance()->SetPlaystate(SND_MUST_PLAY); Py_RETURN_NONE; -} +} // Deprecated -----> PyObject* KX_CDActuator::PySetGain(PyObject* args) @@ -276,20 +212,18 @@ PyObject* KX_CDActuator::PySetGain(PyObject* args) ShowDeprecationWarning("setGain()", "the volume property"); if (!PyArg_ParseTuple(args, "f:setGain", &gain)) return NULL; - - SND_CDObject::Instance()->SetGain(gain); - + Py_RETURN_NONE; -} +} PyObject* KX_CDActuator::PyGetGain(PyObject* args) { - float gain = SND_CDObject::Instance()->GetGain(); + float gain = 1.0; ShowDeprecationWarning("getGain()", "the volume property"); PyObject* result = PyFloat_FromDouble(gain); - + return result; } // <----- diff --git a/source/gameengine/Ketsji/KX_CDActuator.h b/source/gameengine/Ketsji/KX_CDActuator.h index b01ad73777e..bce29adb6e8 100644 --- a/source/gameengine/Ketsji/KX_CDActuator.h +++ b/source/gameengine/Ketsji/KX_CDActuator.h @@ -33,7 +33,6 @@ #define __KX_CDACTUATOR #include "SCA_IActuator.h" -#include "SND_CDObject.h" class KX_CDActuator : public SCA_IActuator { @@ -41,9 +40,7 @@ class KX_CDActuator : public SCA_IActuator bool m_lastEvent; bool m_isplaying; /* just some handles to the audio-data... */ - class SND_Scene* m_soundscene; int m_track; - float m_gain; short m_startFrame; short m_endFrame; @@ -64,7 +61,6 @@ public: KX_CDACT_TYPE m_type; KX_CDActuator(SCA_IObject* gameobject, - SND_Scene* soundscene, KX_CDACT_TYPE type, int track, short start, diff --git a/source/gameengine/Ketsji/KX_KetsjiEngine.cpp b/source/gameengine/Ketsji/KX_KetsjiEngine.cpp index da72fe2fa50..13643e3a1ac 100644 --- a/source/gameengine/Ketsji/KX_KetsjiEngine.cpp +++ b/source/gameengine/Ketsji/KX_KetsjiEngine.cpp @@ -61,8 +61,7 @@ #include "KX_PyConstraintBinding.h" #include "PHY_IPhysicsEnvironment.h" -#include "SND_Scene.h" -#include "SND_IAudioDevice.h" +#include "AUD_C-API.h" #include "NG_NetworkScene.h" #include "NG_NetworkDeviceInterface.h" @@ -113,7 +112,6 @@ KX_KetsjiEngine::KX_KetsjiEngine(KX_ISystem* system) m_rendertools(NULL), m_sceneconverter(NULL), m_networkdevice(NULL), - m_audiodevice(NULL), m_pythondictionary(NULL), m_keyboarddevice(NULL), m_mousedevice(NULL), @@ -211,15 +209,6 @@ void KX_KetsjiEngine::SetNetworkDevice(NG_NetworkDeviceInterface* networkdevice) } - -void KX_KetsjiEngine::SetAudioDevice(SND_IAudioDevice* audiodevice) -{ - MT_assert(audiodevice); - m_audiodevice = audiodevice; -} - - - void KX_KetsjiEngine::SetCanvas(RAS_ICanvas* canvas) { MT_assert(canvas); @@ -690,10 +679,7 @@ else if (m_networkdevice) m_networkdevice->NextFrame(); - - if (m_audiodevice) - m_audiodevice->NextFrame(); - + // scene management ProcessScheduledScenes(); @@ -970,13 +956,40 @@ void KX_KetsjiEngine::DoSound(KX_Scene* scene) MT_Vector3 listenervelocity = cam->GetLinearVelocity(); MT_Matrix3x3 listenerorientation = cam->NodeGetWorldOrientation(); - SND_Scene* soundscene = scene->GetSoundScene(); - soundscene->SetListenerTransform( - listenerposition, - listenervelocity, - listenerorientation); + { + AUD_3DData data; + float f; + + listenerorientation.getValue3x3(data.orientation); + listenerposition.getValue(data.position); + listenervelocity.getValue(data.velocity); + + f = data.position[1]; + data.position[1] = data.position[2]; + data.position[2] = -f; + + f = data.velocity[1]; + data.velocity[1] = data.velocity[2]; + data.velocity[2] = -f; + + f = data.orientation[1]; + data.orientation[1] = data.orientation[2]; + data.orientation[2] = -f; - soundscene->Proceed(); + f = data.orientation[3]; + data.orientation[3] = -data.orientation[6]; + data.orientation[6] = f; + + f = data.orientation[4]; + data.orientation[4] = -data.orientation[8]; + data.orientation[8] = -f; + + f = data.orientation[5]; + data.orientation[5] = data.orientation[7]; + data.orientation[7] = f; + + AUD_updateListener(&data); + } } @@ -1595,7 +1608,6 @@ KX_Scene* KX_KetsjiEngine::CreateScene(const STR_String& scenename) KX_Scene* tmpscene = new KX_Scene(m_keyboarddevice, m_mousedevice, m_networkdevice, - m_audiodevice, scenename, scene); diff --git a/source/gameengine/Ketsji/KX_KetsjiEngine.h b/source/gameengine/Ketsji/KX_KetsjiEngine.h index abba23ca376..a36b3f163fd 100644 --- a/source/gameengine/Ketsji/KX_KetsjiEngine.h +++ b/source/gameengine/Ketsji/KX_KetsjiEngine.h @@ -70,7 +70,6 @@ private: class RAS_IRenderTools* m_rendertools; class KX_ISceneConverter* m_sceneconverter; class NG_NetworkDeviceInterface* m_networkdevice; - class SND_IAudioDevice* m_audiodevice; PyObject* m_pythondictionary; class SCA_IInputDevice* m_keyboarddevice; class SCA_IInputDevice* m_mousedevice; @@ -200,7 +199,6 @@ public: void SetKeyboardDevice(SCA_IInputDevice* keyboarddevice); void SetMouseDevice(SCA_IInputDevice* mousedevice); void SetNetworkDevice(NG_NetworkDeviceInterface* networkdevice); - void SetAudioDevice(SND_IAudioDevice* audiodevice); void SetCanvas(RAS_ICanvas* canvas); void SetRenderTools(RAS_IRenderTools* rendertools); void SetRasterizer(RAS_IRasterizer* rasterizer); diff --git a/source/gameengine/Ketsji/KX_Scene.cpp b/source/gameengine/Ketsji/KX_Scene.cpp index 12df262df56..c45e4294d13 100644 --- a/source/gameengine/Ketsji/KX_Scene.cpp +++ b/source/gameengine/Ketsji/KX_Scene.cpp @@ -34,7 +34,6 @@ #include "KX_Scene.h" #include "MT_assert.h" -#include "SND_Scene.h" #include "KX_KetsjiEngine.h" #include "KX_BlenderMaterial.h" #include "RAS_IPolygonMaterial.h" @@ -135,7 +134,6 @@ extern bool gUseVisibilityTemp; KX_Scene::KX_Scene(class SCA_IInputDevice* keyboarddevice, class SCA_IInputDevice* mousedevice, class NG_NetworkDeviceInterface *ndi, - class SND_IAudioDevice* adi, const STR_String& sceneName, Scene *scene): PyObjectPlus(), @@ -144,7 +142,6 @@ KX_Scene::KX_Scene(class SCA_IInputDevice* keyboarddevice, m_sceneConverter(NULL), m_physicsEnvironment(0), m_sceneName(sceneName), - m_adi(adi), m_networkDeviceInterface(ndi), m_active_camera(NULL), m_ueberExecutionPriority(0), @@ -200,7 +197,6 @@ KX_Scene::KX_Scene(class SCA_IInputDevice* keyboarddevice, m_logicmgr->RegisterEventManager(joymgr); } - m_soundScene = new SND_Scene(adi); MT_assert (m_networkDeviceInterface != NULL); m_networkScene = new NG_NetworkScene(m_networkDeviceInterface); @@ -250,9 +246,6 @@ KX_Scene::~KX_Scene() if (m_physicsEnvironment) delete m_physicsEnvironment; - if (m_soundScene) - delete m_soundScene; - if (m_networkScene) delete m_networkScene; @@ -364,12 +357,6 @@ class KX_WorldInfo* KX_Scene::GetWorldInfo() } - -SND_Scene* KX_Scene::GetSoundScene() -{ - return m_soundScene; -} - const STR_String& KX_Scene::GetName() { return m_sceneName; diff --git a/source/gameengine/Ketsji/KX_Scene.h b/source/gameengine/Ketsji/KX_Scene.h index a2e328fb5d5..f48e9520f53 100644 --- a/source/gameengine/Ketsji/KX_Scene.h +++ b/source/gameengine/Ketsji/KX_Scene.h @@ -63,8 +63,6 @@ class SCA_TimeEventManager; class SCA_MouseManager; class SCA_ISystem; class SCA_IInputDevice; -class SND_Scene; -class SND_IAudioDevice; class NG_NetworkDeviceInterface; class NG_NetworkScene; class SG_IObject; @@ -160,14 +158,7 @@ protected: * @section Different scenes, linked to ketsji scene */ - /** - * Sound scenes - */ - SND_Scene* m_soundScene; - SND_IAudioDevice* m_adi; - - /** * Network scene. */ NG_NetworkDeviceInterface* m_networkDeviceInterface; @@ -283,7 +274,6 @@ public: KX_Scene(class SCA_IInputDevice* keyboarddevice, class SCA_IInputDevice* mousedevice, class NG_NetworkDeviceInterface* ndi, - class SND_IAudioDevice* adi, const STR_String& scenename, struct Scene* scene); @@ -480,7 +470,6 @@ public: void CalculateVisibleMeshes(RAS_IRasterizer* rasty, KX_Camera *cam, int layer=0); void UpdateMeshTransformations(); KX_Camera* GetpCamera(); - SND_Scene* GetSoundScene(); NG_NetworkDeviceInterface* GetNetworkDeviceInterface(); NG_NetworkScene* GetNetworkScene(); diff --git a/source/gameengine/Ketsji/KX_SoundActuator.cpp b/source/gameengine/Ketsji/KX_SoundActuator.cpp index 39381182944..db1788629ed 100644 --- a/source/gameengine/Ketsji/KX_SoundActuator.cpp +++ b/source/gameengine/Ketsji/KX_SoundActuator.cpp @@ -46,37 +46,94 @@ /* Native functions */ /* ------------------------------------------------------------------------- */ KX_SoundActuator::KX_SoundActuator(SCA_IObject* gameobj, - SND_SoundObject* sndobj, - SND_Scene* sndscene, - KX_SOUNDACT_TYPE type, - short start, - short end) + AUD_Sound* sound, + float volume, + float pitch, + bool is3d, + KX_3DSoundSettings settings, + KX_SOUNDACT_TYPE type)//, : SCA_IActuator(gameobj) { - m_soundObject = sndobj; - m_soundScene = sndscene; + m_sound = sound; + m_volume = volume; + m_pitch = pitch; + m_is3d = is3d; + m_3d = settings; + m_handle = NULL; m_type = type; - m_lastEvent = true; m_isplaying = false; - m_startFrame = start; - m_endFrame = end; - m_pino = false; - - } KX_SoundActuator::~KX_SoundActuator() { - if (m_soundObject) - { - m_soundScene->RemoveActiveObject(m_soundObject); - m_soundScene->DeleteObject(m_soundObject); - } + if(m_handle) + AUD_stop(m_handle); } +void KX_SoundActuator::play() +{ + if(m_handle) + AUD_stop(m_handle); + + if(!m_sound) + return; + + // this is the sound that will be played and not deleted afterwards + AUD_Sound* sound = m_sound; + // this sounds are for temporary stacked sounds, will be deleted if not NULL + AUD_Sound* sound2 = NULL; + AUD_Sound* sound3 = NULL; + switch (m_type) + { + case KX_SOUNDACT_LOOPBIDIRECTIONAL: + case KX_SOUNDACT_LOOPBIDIRECTIONAL_STOP: + // create a ping pong sound on sound2 stacked on the orignal sound + sound2 = AUD_pingpongSound(sound); + // create a loop sound on sound3 stacked on the pingpong sound and let that one play (save it to sound) + sound = sound3 = AUD_loopSound(sound2); + break; + case KX_SOUNDACT_LOOPEND: + case KX_SOUNDACT_LOOPSTOP: + // create a loop sound on sound2 stacked on the pingpong sound and let that one play (save it to sound) + sound = sound2 = AUD_loopSound(sound); + break; + case KX_SOUNDACT_PLAYSTOP: + case KX_SOUNDACT_PLAYEND: + default: + break; + } + + if(m_is3d) + { + // sound shall be played 3D + m_handle = AUD_play3D(sound, 0); + + AUD_set3DSourceSetting(m_handle, AUD_3DSS_MAX_GAIN, m_3d.max_gain); + AUD_set3DSourceSetting(m_handle, AUD_3DSS_MIN_GAIN, m_3d.min_gain); + AUD_set3DSourceSetting(m_handle, AUD_3DSS_REFERENCE_DISTANCE, m_3d.reference_distance); + AUD_set3DSourceSetting(m_handle, AUD_3DSS_MAX_DISTANCE, m_3d.max_distance); + AUD_set3DSourceSetting(m_handle, AUD_3DSS_ROLLOFF_FACTOR, m_3d.rolloff_factor); + AUD_set3DSourceSetting(m_handle, AUD_3DSS_CONE_INNER_ANGLE, m_3d.cone_inner_angle); + AUD_set3DSourceSetting(m_handle, AUD_3DSS_CONE_OUTER_ANGLE, m_3d.cone_outer_angle); + AUD_set3DSourceSetting(m_handle, AUD_3DSS_CONE_OUTER_GAIN, m_3d.cone_outer_gain); + } + else + m_handle = AUD_play(sound, 0); + + AUD_setSoundPitch(m_handle, m_pitch); + AUD_setSoundVolume(m_handle, m_volume); + m_isplaying = true; + + // now we unload the pingpong and loop sounds, as we don't need them anymore + // the started sound will continue playing like it was created, don't worry! + if(sound3) + AUD_unload(sound3); + if(sound2) + AUD_unload(sound2); +} CValue* KX_SoundActuator::GetReplica() { @@ -88,13 +145,8 @@ CValue* KX_SoundActuator::GetReplica() void KX_SoundActuator::ProcessReplica() { SCA_IActuator::ProcessReplica(); - if (m_soundObject) - { - SND_SoundObject* soundobj = new SND_SoundObject(*m_soundObject); - setSoundObject(soundobj); - m_soundScene->AddObject(soundobj); - } -} + m_handle = 0; +} bool KX_SoundActuator::Update(double curtime, bool frame) { @@ -108,22 +160,16 @@ bool KX_SoundActuator::Update(double curtime, bool frame) RemoveAllEvents(); - if (!m_soundObject) + if(!m_sound) return false; // actual audio device playing state - bool isplaying = (m_soundObject->GetPlaystate() != SND_STOPPED && m_soundObject->GetPlaystate() != SND_INITIAL) ? true : false; - - if (m_pino) - { - bNegativeEvent = true; - m_pino = false; - } + bool isplaying = AUD_getStatus(m_handle) == AUD_STATUS_PLAYING; if (bNegativeEvent) - { + { // here must be a check if it is still playing - if (m_isplaying && isplaying) + if (m_isplaying && isplaying) { switch (m_type) { @@ -131,19 +177,20 @@ bool KX_SoundActuator::Update(double curtime, bool frame) case KX_SOUNDACT_LOOPSTOP: case KX_SOUNDACT_LOOPBIDIRECTIONAL_STOP: { - m_soundScene->RemoveActiveObject(m_soundObject); + // stop immediately + AUD_stop(m_handle); break; } case KX_SOUNDACT_PLAYEND: { - m_soundObject->SetPlaystate(SND_MUST_STOP_WHEN_FINISHED); + // do nothing, sound will stop anyway when it's finished break; } case KX_SOUNDACT_LOOPEND: case KX_SOUNDACT_LOOPBIDIRECTIONAL: { - m_soundObject->SetLoopMode(SND_LOOP_OFF); - m_soundObject->SetPlaystate(SND_MUST_STOP_WHEN_FINISHED); + // stop the looping so that the sound stops when it finished + AUD_stopLoop(m_handle); break; } default: @@ -166,50 +213,49 @@ bool KX_SoundActuator::Update(double curtime, bool frame) // the negative pulse is done continuesly #endif if (!m_isplaying) - { - switch (m_type) - { - case KX_SOUNDACT_LOOPBIDIRECTIONAL: - case KX_SOUNDACT_LOOPBIDIRECTIONAL_STOP: - { - m_soundObject->SetLoopMode(SND_LOOP_BIDIRECTIONAL); - m_soundScene->AddActiveObject(m_soundObject, curtime); - m_isplaying = true; - result = true; - break; - } - case KX_SOUNDACT_LOOPEND: - case KX_SOUNDACT_LOOPSTOP: - { - m_soundObject->SetLoopMode(SND_LOOP_NORMAL); - m_soundScene->AddActiveObject(m_soundObject, curtime); - m_isplaying = true; - result = true; - break; - } - case KX_SOUNDACT_PLAYSTOP: - case KX_SOUNDACT_PLAYEND: - { - m_soundObject->SetLoopMode(SND_LOOP_OFF); - m_soundScene->AddActiveObject(m_soundObject, curtime); - m_isplaying = true; - result = true; - break; - } - default: - // implement me !! - break; - } - } + play(); } // verify that the sound is still playing - isplaying = (m_soundObject->GetPlaystate() != SND_STOPPED && m_soundObject->GetPlaystate() != SND_INITIAL) ? true : false; + isplaying = AUD_getStatus(m_handle) == AUD_STATUS_PLAYING ? true : false; if (isplaying) { - m_soundObject->SetPosition(((KX_GameObject*)this->GetParent())->NodeGetWorldPosition()); - m_soundObject->SetVelocity(((KX_GameObject*)this->GetParent())->GetLinearVelocity()); - m_soundObject->SetOrientation(((KX_GameObject*)this->GetParent())->NodeGetWorldOrientation()); + if(m_is3d) + { + AUD_3DData data; + float f; + ((KX_GameObject*)this->GetParent())->NodeGetWorldPosition().getValue(data.position); + ((KX_GameObject*)this->GetParent())->GetLinearVelocity().getValue(data.velocity); + ((KX_GameObject*)this->GetParent())->NodeGetWorldOrientation().getValue3x3(data.orientation); + + /* + * The 3D data from blender has to be transformed for OpenAL: + * - In blender z is up and y is forwards + * - In OpenAL y is up and z is backwards + * We have to do that for all 5 vectors. + */ + f = data.position[1]; + data.position[1] = data.position[2]; + data.position[2] = -f; + + f = data.velocity[1]; + data.velocity[1] = data.velocity[2]; + data.velocity[2] = -f; + + f = data.orientation[1]; + data.orientation[1] = data.orientation[2]; + data.orientation[2] = -f; + + f = data.orientation[4]; + data.orientation[4] = data.orientation[5]; + data.orientation[5] = -f; + + f = data.orientation[7]; + data.orientation[7] = data.orientation[8]; + data.orientation[8] = -f; + + AUD_update3DSource(m_handle, &data); + } result = true; } else @@ -217,23 +263,11 @@ bool KX_SoundActuator::Update(double curtime, bool frame) m_isplaying = false; result = false; } - /* - if (result && (m_soundObject->IsLifeSpanOver(curtime)) && ((m_type == KX_SOUNDACT_PLAYEND) || (m_type == KX_SOUNDACT_PLAYSTOP))) - { - m_pino = true; - } - */ return result; } -void KX_SoundActuator::setSoundObject(class SND_SoundObject* soundobject) -{ - m_soundObject = soundobject; -} - - /* ------------------------------------------------------------------------- */ /* Python functions */ @@ -272,19 +306,12 @@ PyTypeObject KX_SoundActuator::Type = { PyMethodDef KX_SoundActuator::Methods[] = { // Deprecated -----> - {"setFilename", (PyCFunction) KX_SoundActuator::sPySetFilename, METH_VARARGS,NULL}, - {"getFilename", (PyCFunction) KX_SoundActuator::sPyGetFilename, METH_NOARGS,NULL}, {"setGain",(PyCFunction) KX_SoundActuator::sPySetGain,METH_VARARGS,NULL}, {"getGain",(PyCFunction) KX_SoundActuator::sPyGetGain,METH_NOARGS,NULL}, {"setPitch",(PyCFunction) KX_SoundActuator::sPySetPitch,METH_VARARGS,NULL}, {"getPitch",(PyCFunction) KX_SoundActuator::sPyGetPitch,METH_NOARGS,NULL}, {"setRollOffFactor",(PyCFunction) KX_SoundActuator::sPySetRollOffFactor,METH_VARARGS,NULL}, {"getRollOffFactor",(PyCFunction) KX_SoundActuator::sPyGetRollOffFactor,METH_NOARGS,NULL}, - {"setLooping",(PyCFunction) KX_SoundActuator::sPySetLooping,METH_VARARGS,NULL}, - {"getLooping",(PyCFunction) KX_SoundActuator::sPyGetLooping,METH_NOARGS,NULL}, - {"setPosition",(PyCFunction) KX_SoundActuator::sPySetPosition,METH_VARARGS,NULL}, - {"setVelocity",(PyCFunction) KX_SoundActuator::sPySetVelocity,METH_VARARGS,NULL}, - {"setOrientation",(PyCFunction) KX_SoundActuator::sPySetOrientation,METH_VARARGS,NULL}, {"setType",(PyCFunction) KX_SoundActuator::sPySetType,METH_VARARGS,NULL}, {"getType",(PyCFunction) KX_SoundActuator::sPyGetType,METH_NOARGS,NULL}, // <----- @@ -296,171 +323,91 @@ PyMethodDef KX_SoundActuator::Methods[] = { }; PyAttributeDef KX_SoundActuator::Attributes[] = { - KX_PYATTRIBUTE_RW_FUNCTION("fileName", KX_SoundActuator, pyattr_get_filename, pyattr_set_filename), KX_PYATTRIBUTE_RW_FUNCTION("volume", KX_SoundActuator, pyattr_get_gain, pyattr_set_gain), KX_PYATTRIBUTE_RW_FUNCTION("pitch", KX_SoundActuator, pyattr_get_pitch, pyattr_set_pitch), KX_PYATTRIBUTE_RW_FUNCTION("rollOffFactor", KX_SoundActuator, pyattr_get_rollOffFactor, pyattr_set_rollOffFactor), - KX_PYATTRIBUTE_RW_FUNCTION("looping", KX_SoundActuator, pyattr_get_looping, pyattr_set_looping), - KX_PYATTRIBUTE_RW_FUNCTION("position", KX_SoundActuator, pyattr_get_position, pyattr_set_position), - KX_PYATTRIBUTE_RW_FUNCTION("velocity", KX_SoundActuator, pyattr_get_velocity, pyattr_set_velocity), - KX_PYATTRIBUTE_RW_FUNCTION("orientation", KX_SoundActuator, pyattr_get_orientation, pyattr_set_orientation), KX_PYATTRIBUTE_ENUM_RW("mode",KX_SoundActuator::KX_SOUNDACT_NODEF+1,KX_SoundActuator::KX_SOUNDACT_MAX-1,false,KX_SoundActuator,m_type), { NULL } //Sentinel }; /* Methods ----------------------------------------------------------------- */ -KX_PYMETHODDEF_DOC_NOARGS(KX_SoundActuator, startSound, +KX_PYMETHODDEF_DOC_NOARGS(KX_SoundActuator, startSound, "startSound()\n" "\tStarts the sound.\n") { - if (m_soundObject) - // This has no effect if the actuator is not active. - // To start the sound you must activate the actuator. - // This function is to restart the sound. - m_soundObject->StartSound(); + switch(AUD_getStatus(m_handle)) + { + case AUD_STATUS_PLAYING: + break; + case AUD_STATUS_PAUSED: + AUD_resume(m_handle); + break; + default: + play(); + } Py_RETURN_NONE; -} +} KX_PYMETHODDEF_DOC_NOARGS(KX_SoundActuator, pauseSound, "pauseSound()\n" "\tPauses the sound.\n") { - if (m_soundObject) - // unfortunately, openal does not implement pause correctly, it is equivalent to a stop - m_soundObject->PauseSound(); + AUD_pause(m_handle); Py_RETURN_NONE; -} +} KX_PYMETHODDEF_DOC_NOARGS(KX_SoundActuator, stopSound, "stopSound()\n" "\tStops the sound.\n") { - if (m_soundObject) - m_soundObject->StopSound(); + AUD_stop(m_handle); Py_RETURN_NONE; } /* Atribute setting and getting -------------------------------------------- */ -PyObject* KX_SoundActuator::pyattr_get_filename(void *self, const struct KX_PYATTRIBUTE_DEF *attrdef) -{ - KX_SoundActuator * actuator = static_cast<KX_SoundActuator *> (self); - if (!actuator->m_soundObject) - { - return PyUnicode_FromString(""); - } - STR_String objectname = actuator->m_soundObject->GetObjectName(); - char* name = objectname.Ptr(); - - if (!name) { - PyErr_SetString(PyExc_RuntimeError, "value = actuator.fileName: KX_SoundActuator, unable to get sound fileName"); - return NULL; - } else - return PyUnicode_FromString(name); -} - PyObject* KX_SoundActuator::pyattr_get_gain(void *self, const struct KX_PYATTRIBUTE_DEF *attrdef) { KX_SoundActuator * actuator = static_cast<KX_SoundActuator *> (self); - float gain = (actuator->m_soundObject) ? actuator->m_soundObject->GetGain() : 1.0f; + float gain = actuator->m_volume; PyObject* result = PyFloat_FromDouble(gain); - + return result; } PyObject* KX_SoundActuator::pyattr_get_pitch(void *self, const struct KX_PYATTRIBUTE_DEF *attrdef) { KX_SoundActuator * actuator = static_cast<KX_SoundActuator *> (self); - float pitch = (actuator->m_soundObject) ? actuator->m_soundObject->GetPitch() : 1.0; + float pitch = actuator->m_pitch; + PyObject* result = PyFloat_FromDouble(pitch); - + return result; } PyObject* KX_SoundActuator::pyattr_get_rollOffFactor(void *self, const struct KX_PYATTRIBUTE_DEF *attrdef) { KX_SoundActuator * actuator = static_cast<KX_SoundActuator *> (self); - float rollofffactor = (actuator->m_soundObject) ? actuator->m_soundObject->GetRollOffFactor() : 1.0; + float rollofffactor = actuator->m_3d.rolloff_factor; PyObject* result = PyFloat_FromDouble(rollofffactor); - - return result; -} - -PyObject* KX_SoundActuator::pyattr_get_looping(void *self, const struct KX_PYATTRIBUTE_DEF *attrdef) -{ - KX_SoundActuator * actuator = static_cast<KX_SoundActuator *> (self); - int looping = (actuator->m_soundObject) ? actuator->m_soundObject->GetLoopMode() : (int)SND_LOOP_OFF; - PyObject* result = PyLong_FromSsize_t(looping); - - return result; -} - -PyObject* KX_SoundActuator::pyattr_get_position(void * self, const struct KX_PYATTRIBUTE_DEF *attrdef) -{ - KX_SoundActuator * actuator = static_cast<KX_SoundActuator *> (self); - MT_Vector3 pos(0.0, 0.0, 0.0); - if (actuator->m_soundObject) - pos = actuator->m_soundObject->GetPosition(); - - PyObject * result = PyObjectFrom(pos); return result; } -PyObject* KX_SoundActuator::pyattr_get_velocity(void *self, const struct KX_PYATTRIBUTE_DEF *attrdef) -{ - KX_SoundActuator * actuator = static_cast<KX_SoundActuator *> (self); - MT_Vector3 vel; - - if (actuator->m_soundObject) - vel = actuator->m_soundObject->GetVelocity(); - - PyObject * result = PyObjectFrom(vel); - return result; -} - -PyObject* KX_SoundActuator::pyattr_get_orientation(void *self, const struct KX_PYATTRIBUTE_DEF *attrdef) -{ - KX_SoundActuator * actuator = static_cast<KX_SoundActuator *> (self); - MT_Matrix3x3 ori; - - if (actuator->m_soundObject) - ori = actuator->m_soundObject->GetOrientation(); - - PyObject * result = PyObjectFrom(ori); - return result; -} - -int KX_SoundActuator::pyattr_set_filename(void *self, const struct KX_PYATTRIBUTE_DEF *attrdef, PyObject *value) -{ - char *soundName = NULL; - KX_SoundActuator * actuator = static_cast<KX_SoundActuator*> (self); - // void *soundPointer = NULL; /*unused*/ - - if (!PyArg_Parse(value, "s", &soundName)) - return PY_SET_ATTR_FAIL; - - if (actuator->m_soundObject) { - actuator->m_soundObject->SetObjectName(soundName); - } - - return PY_SET_ATTR_SUCCESS; -} - - int KX_SoundActuator::pyattr_set_gain(void *self, const struct KX_PYATTRIBUTE_DEF *attrdef, PyObject *value) { float gain = 1.0; KX_SoundActuator * actuator = static_cast<KX_SoundActuator *> (self); if (!PyArg_Parse(value, "f", &gain)) return PY_SET_ATTR_FAIL; - - if (actuator->m_soundObject) - actuator->m_soundObject->SetGain(gain); - + + actuator->m_volume = gain; + if(actuator->m_handle) + AUD_setSoundVolume(actuator->m_handle, gain); + return PY_SET_ATTR_SUCCESS; -} +} int KX_SoundActuator::pyattr_set_pitch(void *self, const struct KX_PYATTRIBUTE_DEF *attrdef, PyObject *value) { @@ -468,12 +415,13 @@ int KX_SoundActuator::pyattr_set_pitch(void *self, const struct KX_PYATTRIBUTE_D KX_SoundActuator * actuator = static_cast<KX_SoundActuator *> (self); if (!PyArg_Parse(value, "f", &pitch)) return PY_SET_ATTR_FAIL; - - if (actuator->m_soundObject) - actuator->m_soundObject->SetPitch(pitch); - + + actuator->m_pitch = pitch; + if(actuator->m_handle) + AUD_setSoundPitch(actuator->m_handle, pitch); + return PY_SET_ATTR_SUCCESS; -} +} int KX_SoundActuator::pyattr_set_rollOffFactor(void *self, const struct KX_PYATTRIBUTE_DEF *attrdef, PyObject *value) { @@ -481,127 +429,36 @@ int KX_SoundActuator::pyattr_set_rollOffFactor(void *self, const struct KX_PYATT float rollofffactor = 1.0; if (!PyArg_Parse(value, "f", &rollofffactor)) return PY_SET_ATTR_FAIL; - - if (actuator->m_soundObject) - actuator->m_soundObject->SetRollOffFactor(rollofffactor); - - return PY_SET_ATTR_SUCCESS; -} - -int KX_SoundActuator::pyattr_set_looping(void *self, const struct KX_PYATTRIBUTE_DEF *attrdef, PyObject *value) -{ - KX_SoundActuator * actuator = static_cast<KX_SoundActuator *> (self); - int looping = 1; - if (!PyArg_Parse(value, "i", &looping)) - return PY_SET_ATTR_FAIL; - - if (actuator->m_soundObject) - actuator->m_soundObject->SetLoopMode(looping); - - return PY_SET_ATTR_SUCCESS; -} - -int KX_SoundActuator::pyattr_set_position(void *self, const struct KX_PYATTRIBUTE_DEF *attrdef, PyObject *value) -{ - float pos[3]; - - KX_SoundActuator * actuator = static_cast<KX_SoundActuator *> (self); - - if (!PyArg_ParseTuple(value, "fff", &pos[0], &pos[1], &pos[2])) - return PY_SET_ATTR_FAIL; - - if (actuator->m_soundObject) - actuator->m_soundObject->SetPosition(MT_Vector3(pos)); - - return PY_SET_ATTR_SUCCESS; -} - -int KX_SoundActuator::pyattr_set_velocity(void *self, const struct KX_PYATTRIBUTE_DEF *attrdef, PyObject *value) -{ - float vel[3]; - KX_SoundActuator * actuator = static_cast<KX_SoundActuator *> (self); - - - if (!PyArg_ParseTuple(value, "fff", &vel[0], &vel[1], &vel[2])) - return PY_SET_ATTR_FAIL; - - if (actuator->m_soundObject) - actuator->m_soundObject->SetVelocity(MT_Vector3(vel)); - - return PY_SET_ATTR_SUCCESS; - -} - -int KX_SoundActuator::pyattr_set_orientation(void *self, const struct KX_PYATTRIBUTE_DEF *attrdef, PyObject *value) -{ - MT_Matrix3x3 rot; - KX_SoundActuator * actuator = static_cast<KX_SoundActuator *> (self); + actuator->m_3d.rolloff_factor = rollofffactor; + if(actuator->m_handle) + AUD_set3DSourceSetting(actuator->m_handle, AUD_3DSS_ROLLOFF_FACTOR, rollofffactor); - /* if value is not a sequence PyOrientationTo makes an error */ - if (!PyOrientationTo(value, rot, "actuator.orientation = value: KX_SoundActuator")) - return PY_SET_ATTR_FAIL; - - /* Since not having m_soundObject didn't do anything in the old version, - * it probably should be kept that way */ - if (!actuator->m_soundObject) - return PY_SET_ATTR_SUCCESS; - - actuator->m_soundObject->SetOrientation(rot); return PY_SET_ATTR_SUCCESS; } -// Deprecated -----> -PyObject* KX_SoundActuator::PySetFilename(PyObject* args) -{ - char *soundName = NULL; - ShowDeprecationWarning("setFilename()", "the fileName property"); - // void *soundPointer = NULL; /*unused*/ - - if (!PyArg_ParseTuple(args, "s", &soundName)) - return NULL; - - Py_RETURN_NONE; -} - -PyObject* KX_SoundActuator::PyGetFilename() -{ - ShowDeprecationWarning("getFilename()", "the fileName property"); - if (!m_soundObject) - { - return PyUnicode_FromString(""); - } - STR_String objectname = m_soundObject->GetObjectName(); - char* name = objectname.Ptr(); - - if (!name) { - PyErr_SetString(PyExc_RuntimeError, "Unable to get sound fileName"); - return NULL; - } else - return PyUnicode_FromString(name); -} - PyObject* KX_SoundActuator::PySetGain(PyObject* args) { ShowDeprecationWarning("setGain()", "the volume property"); float gain = 1.0; if (!PyArg_ParseTuple(args, "f:setGain", &gain)) return NULL; - - if (m_soundObject) - m_soundObject->SetGain(gain); - + + m_volume = gain; + if(m_handle) + AUD_setSoundVolume(m_handle, gain); + Py_RETURN_NONE; -} +} PyObject* KX_SoundActuator::PyGetGain() { ShowDeprecationWarning("getGain()", "the volume property"); - float gain = (m_soundObject) ? m_soundObject->GetGain() : 1.0f; + float gain = m_volume; PyObject* result = PyFloat_FromDouble(gain); - + return result; } @@ -613,21 +470,22 @@ PyObject* KX_SoundActuator::PySetPitch(PyObject* args) float pitch = 1.0; if (!PyArg_ParseTuple(args, "f:setPitch", &pitch)) return NULL; - - if (m_soundObject) - m_soundObject->SetPitch(pitch); - + + m_pitch = pitch; + if(m_handle) + AUD_setSoundPitch(m_handle, pitch); + Py_RETURN_NONE; -} +} PyObject* KX_SoundActuator::PyGetPitch() { ShowDeprecationWarning("getPitch()", "the pitch property"); - float pitch = (m_soundObject) ? m_soundObject->GetPitch() : 1.0; + float pitch = m_pitch; PyObject* result = PyFloat_FromDouble(pitch); - + return result; } @@ -639,113 +497,27 @@ PyObject* KX_SoundActuator::PySetRollOffFactor(PyObject* args) float rollofffactor = 1.0; if (!PyArg_ParseTuple(args, "f:setRollOffFactor", &rollofffactor)) return NULL; - - if (m_soundObject) - m_soundObject->SetRollOffFactor(rollofffactor); + + m_3d.rolloff_factor = rollofffactor; + if(m_handle) + AUD_set3DSourceSetting(m_handle, AUD_3DSS_ROLLOFF_FACTOR, rollofffactor); Py_RETURN_NONE; -} +} PyObject* KX_SoundActuator::PyGetRollOffFactor() { ShowDeprecationWarning("getRollOffFactor()", "the rollOffFactor property"); - float rollofffactor = (m_soundObject) ? m_soundObject->GetRollOffFactor() : 1.0; + float rollofffactor = m_3d.rolloff_factor; PyObject* result = PyFloat_FromDouble(rollofffactor); - - return result; -} - - - -PyObject* KX_SoundActuator::PySetLooping(PyObject* args) -{ - ShowDeprecationWarning("setLooping()", "the looping property"); - bool looping = 1; - if (!PyArg_ParseTuple(args, "i:setLooping", &looping)) - return NULL; - - if (m_soundObject) - m_soundObject->SetLoopMode(looping); - - Py_RETURN_NONE; -} - - -PyObject* KX_SoundActuator::PyGetLooping() -{ - ShowDeprecationWarning("getLooping()", "the looping property"); - int looping = (m_soundObject) ? m_soundObject->GetLoopMode() : (int)SND_LOOP_OFF; - PyObject* result = PyLong_FromSsize_t(looping); - return result; } -PyObject* KX_SoundActuator::PySetPosition(PyObject* args) -{ - MT_Point3 pos; - ShowDeprecationWarning("setPosition()", "the position property"); - pos[0] = 0.0; - pos[1] = 0.0; - pos[2] = 0.0; - - if (!PyArg_ParseTuple(args, "fff:setPosition", &pos[0], &pos[1], &pos[2])) - return NULL; - - if (m_soundObject) - m_soundObject->SetPosition(pos); - - Py_RETURN_NONE; -} - - - -PyObject* KX_SoundActuator::PySetVelocity(PyObject* args) -{ - MT_Vector3 vel; - ShowDeprecationWarning("setVelocity()", "the velocity property"); - vel[0] = 0.0; - vel[1] = 0.0; - vel[2] = 0.0; - - if (!PyArg_ParseTuple(args, "fff:setVelocity", &vel[0], &vel[1], &vel[2])) - return NULL; - - if (m_soundObject) - m_soundObject->SetVelocity(vel); - - Py_RETURN_NONE; -} - - - -PyObject* KX_SoundActuator::PySetOrientation(PyObject* args) -{ - MT_Matrix3x3 ori; - ShowDeprecationWarning("setOrientation()", "the orientation property"); - ori[0][0] = 1.0; - ori[0][1] = 0.0; - ori[0][2] = 0.0; - ori[1][0] = 0.0; - ori[1][1] = 1.0; - ori[1][2] = 0.0; - ori[2][0] = 0.0; - ori[2][1] = 0.0; - ori[2][2] = 1.0; - - if (!PyArg_ParseTuple(args, "fffffffff:setOrientation", &ori[0][0], &ori[0][1], &ori[0][2], &ori[1][0], &ori[1][1], &ori[1][2], &ori[2][0], &ori[2][1], &ori[2][2])) - return NULL; - - if (m_soundObject) - m_soundObject->SetOrientation(ori); - - Py_RETURN_NONE; -} - PyObject* KX_SoundActuator::PySetType(PyObject* args) { int typeArg; diff --git a/source/gameengine/Ketsji/KX_SoundActuator.h b/source/gameengine/Ketsji/KX_SoundActuator.h index adafee0a30b..ddf8330072e 100644 --- a/source/gameengine/Ketsji/KX_SoundActuator.h +++ b/source/gameengine/Ketsji/KX_SoundActuator.h @@ -34,17 +34,41 @@ #include "SCA_IActuator.h" +#include "AUD_C-API.h" +#include "BKE_sound.h" + +typedef struct KX_3DSoundSettings +{ + float min_gain; + float max_gain; + float reference_distance; + float max_distance; + float rolloff_factor; + float cone_inner_angle; + float cone_outer_angle; + float cone_outer_gain; +} KX_3DSoundSettings; + class KX_SoundActuator : public SCA_IActuator { Py_Header; - bool m_lastEvent; +// bool m_lastEvent; bool m_isplaying; /* just some handles to the audio-data... */ - class SND_SoundObject* m_soundObject; - class SND_Scene* m_soundScene; - short m_startFrame; - short m_endFrame; - bool m_pino; + AUD_Sound* m_sound; + float m_volume; + float m_pitch; + bool m_is3d; + KX_3DSoundSettings m_3d; + AUD_Handle* m_handle; +// class SND_SoundObject* m_soundObject; +// class SND_Scene* m_soundScene; +// short m_startFrame; +// short m_endFrame; +// bool m_pino; + + void play(); + public: enum KX_SOUNDACT_TYPE @@ -62,15 +86,15 @@ public: KX_SOUNDACT_TYPE m_type; KX_SoundActuator(SCA_IObject* gameobj, - class SND_SoundObject* sndobj, - class SND_Scene* sndscene, - KX_SOUNDACT_TYPE type, - short start, - short end); + AUD_Sound* sound, + float volume, + float pitch, + bool is3d, + KX_3DSoundSettings settings, + KX_SOUNDACT_TYPE type); ~KX_SoundActuator(); - void setSoundObject(class SND_SoundObject* soundobject); virtual bool Update(double curtime, bool frame); CValue* GetReplica(); @@ -84,40 +108,23 @@ public: KX_PYMETHOD_DOC_NOARGS(KX_SoundActuator, pauseSound); KX_PYMETHOD_DOC_NOARGS(KX_SoundActuator, stopSound); - static int pyattr_set_filename(void *self, const struct KX_PYATTRIBUTE_DEF *attrdef, PyObject *value); static int pyattr_set_gain(void *self, const struct KX_PYATTRIBUTE_DEF *attrdef, PyObject *value); static int pyattr_set_pitch(void *self, const struct KX_PYATTRIBUTE_DEF *attrdef, PyObject *value); static int pyattr_set_rollOffFactor(void *self, const struct KX_PYATTRIBUTE_DEF *attrdef, PyObject *value); - static int pyattr_set_looping(void *self, const struct KX_PYATTRIBUTE_DEF *attrdef, PyObject *value); - static int pyattr_set_position(void *self, const struct KX_PYATTRIBUTE_DEF *attrdef, PyObject *value); - static int pyattr_set_velocity(void *self, const struct KX_PYATTRIBUTE_DEF *attrdef, PyObject *value); - static int pyattr_set_orientation(void *self, const struct KX_PYATTRIBUTE_DEF *attrdef, PyObject *value); static int pyattr_set_type(void *self, const struct KX_PYATTRIBUTE_DEF *attrdef, PyObject *value); - static PyObject* pyattr_get_filename(void *self, const struct KX_PYATTRIBUTE_DEF *attrdef); static PyObject* pyattr_get_gain(void *self, const struct KX_PYATTRIBUTE_DEF *attrdef); static PyObject* pyattr_get_pitch(void *self, const struct KX_PYATTRIBUTE_DEF *attrdef); - static PyObject* pyattr_get_looping(void *self, const struct KX_PYATTRIBUTE_DEF *attrdef); static PyObject* pyattr_get_rollOffFactor(void *self, const struct KX_PYATTRIBUTE_DEF *attrdef); - static PyObject* pyattr_get_position(void *self, const struct KX_PYATTRIBUTE_DEF *attrdef); - static PyObject* pyattr_get_velocity(void *self, const struct KX_PYATTRIBUTE_DEF *attrdef); - static PyObject* pyattr_get_orientation(void *self, const struct KX_PYATTRIBUTE_DEF *attrdef); static PyObject* pyattr_get_type(void *self, const struct KX_PYATTRIBUTE_DEF *attrdef); // Deprecated -----> - KX_PYMETHOD_VARARGS(KX_SoundActuator,SetFilename); - KX_PYMETHOD_NOARGS(KX_SoundActuator,GetFilename); KX_PYMETHOD_VARARGS(KX_SoundActuator,SetGain); KX_PYMETHOD_NOARGS(KX_SoundActuator,GetGain); KX_PYMETHOD_VARARGS(KX_SoundActuator,SetPitch); KX_PYMETHOD_NOARGS(KX_SoundActuator,GetPitch); KX_PYMETHOD_VARARGS(KX_SoundActuator,SetRollOffFactor); KX_PYMETHOD_NOARGS(KX_SoundActuator,GetRollOffFactor); - KX_PYMETHOD_VARARGS(KX_SoundActuator,SetLooping); - KX_PYMETHOD_NOARGS(KX_SoundActuator,GetLooping); - KX_PYMETHOD_VARARGS(KX_SoundActuator,SetPosition); - KX_PYMETHOD_VARARGS(KX_SoundActuator,SetVelocity); - KX_PYMETHOD_VARARGS(KX_SoundActuator,SetOrientation); KX_PYMETHOD_VARARGS(KX_SoundActuator,SetType); KX_PYMETHOD_NOARGS(KX_SoundActuator,GetType); // <----- diff --git a/source/gameengine/Ketsji/SConscript b/source/gameengine/Ketsji/SConscript index 1edffe0e587..373f1ca2606 100644 --- a/source/gameengine/Ketsji/SConscript +++ b/source/gameengine/Ketsji/SConscript @@ -11,6 +11,7 @@ incs = '. #source/blender/python/generic' # Only for Mathutils! and bpy_internal incs += ' #source/kernel/gen_system #intern/string #intern/guardedalloc' incs += ' #source/gameengine/Rasterizer/RAS_OpenGLRasterizer' incs += ' #intern/SoundSystem #intern/SoundSystem/include #intern/SoundSystem/openal' +incs += ' #intern/audaspace' incs += ' #intern/SoundSystem/dummy #intern/SoundSystem/intern #source/gameengine/Converter' incs += ' #source/gameengine/BlenderRoutines #source/blender/imbuf #intern/moto/include' incs += ' #source/gameengine/Ketsji #source/gameengine/Ketsji/KXNetwork #source/blender/blenlib' diff --git a/source/nan_definitions.mk b/source/nan_definitions.mk index 96405116363..d6701c6fa44 100644 --- a/source/nan_definitions.mk +++ b/source/nan_definitions.mk @@ -90,6 +90,7 @@ ifndef CONFIG_GUESS export NAN_BSP ?= $(LCGDIR)/bsp export NAN_BOOLOP ?= $(LCGDIR)/boolop export NAN_SOUNDSYSTEM ?= $(LCGDIR)/SoundSystem + export NAN_AUDASPACE ?= $(LCGDIR)/audaspace export NAN_STRING ?= $(LCGDIR)/string export NAN_MEMUTIL ?= $(LCGDIR)/memutil export NAN_CONTAINER ?= $(LCGDIR)/container |