doxygen: blender/blenkernel tagged.
[blender.git] / source / blender / blenkernel / intern / sound.c
index a1a6880569b398476a4fb705abec1b9c43248d03..cfc98b4a67d2755c9f49555092836ee349efc295 100644 (file)
@@ -1,3 +1,6 @@
+/** \file blender/blenkernel/intern/sound.c
+ *  \ingroup bke
+ */
 /**
  * sound.c (mar-2001 nzc)
  *
 /**
  * sound.c (mar-2001 nzc)
  *
 #include "DNA_anim_types.h"
 #include "DNA_scene_types.h"
 #include "DNA_sequence_types.h"
 #include "DNA_anim_types.h"
 #include "DNA_scene_types.h"
 #include "DNA_sequence_types.h"
-#include "DNA_sound_types.h"
 #include "DNA_packedFile_types.h"
 #include "DNA_screen_types.h"
 #include "DNA_packedFile_types.h"
 #include "DNA_screen_types.h"
-#include "DNA_userdef_types.h"
+#include "DNA_sound_types.h"
 
 #include "AUD_C-API.h"
 
 
 #include "AUD_C-API.h"
 
 #include "BKE_fcurve.h"
 #include "BKE_animsys.h"
 
 #include "BKE_fcurve.h"
 #include "BKE_animsys.h"
 
-#include "RNA_access.h"
-
-#ifdef HAVE_CONFIG_H
-#include <config.h>
-#endif
 
 static int force_device = -1;
 
 
 static int force_device = -1;
 
+#ifdef WITH_JACK
 static void sound_sync_callback(void* data, int mode, float time)
 {
 static void sound_sync_callback(void* data, int mode, float time)
 {
-       struct Main* main = (struct Main*)data;
+       struct Main* bmain = (struct Main*)data;
        struct Scene* scene;
 
        struct Scene* scene;
 
-       scene = main->scene.first;
+       scene = bmain->scene.first;
        while(scene)
        {
                if(scene->audio.flag & AUDIO_SYNC)
        while(scene)
        {
                if(scene->audio.flag & AUDIO_SYNC)
@@ -58,8 +56,9 @@ static void sound_sync_callback(void* data, int mode, float time)
                scene = scene->id.next;
        }
 }
                scene = scene->id.next;
        }
 }
+#endif
 
 
-int sound_define_from_str(char *str)
+int sound_define_from_str(const char *str)
 {
        if (BLI_strcaseeq(str, "NULL"))
                return AUD_NULL_DEVICE;
 {
        if (BLI_strcaseeq(str, "NULL"))
                return AUD_NULL_DEVICE;
@@ -78,7 +77,12 @@ void sound_force_device(int device)
        force_device = device;
 }
 
        force_device = device;
 }
 
-void sound_init(struct Main *main)
+void sound_init_once(void)
+{
+       AUD_initOnce();
+}
+
+void sound_init(struct Main *bmain)
 {
        AUD_DeviceSpecs specs;
        int device, buffersize;
 {
        AUD_DeviceSpecs specs;
        int device, buffersize;
@@ -106,37 +110,47 @@ void sound_init(struct Main *main)
 
        if(!AUD_init(device, specs, buffersize))
                AUD_init(AUD_NULL_DEVICE, specs, buffersize);
 
        if(!AUD_init(device, specs, buffersize))
                AUD_init(AUD_NULL_DEVICE, specs, buffersize);
-       AUD_setSyncCallback(sound_sync_callback, main);
+               
+#ifdef WITH_JACK
+       AUD_setSyncCallback(sound_sync_callback, bmain);
+#else
+       (void)bmain; /* unused */
+#endif
 }
 
 }
 
-void sound_exit()
+void sound_exit(void)
 {
        AUD_exit();
 }
 
 {
        AUD_exit();
 }
 
-struct bSound* sound_new_file(struct Main *main, char* filename)
+struct bSound* sound_new_file(struct Main *bmain, const char *filename)
 {
        bSound* sound = NULL;
 
        char str[FILE_MAX];
 {
        bSound* sound = NULL;
 
        char str[FILE_MAX];
+       char *path;
+
        int len;
 
        strcpy(str, filename);
        int len;
 
        strcpy(str, filename);
-       BLI_convertstringcode(str, main->name);
+
+       path = /*bmain ? bmain->name :*/ G.main->name;
+
+       BLI_path_abs(str, path);
 
        len = strlen(filename);
        while(len > 0 && filename[len-1] != '/' && filename[len-1] != '\\')
                len--;
 
 
        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 = alloc_libblock(&bmain->sound, ID_SO, filename+len);
+       BLI_strncpy(sound->name, filename, FILE_MAX);
 // XXX unused currently        sound->type = SOUND_TYPE_FILE;
 
 // XXX unused currently        sound->type = SOUND_TYPE_FILE;
 
-       sound_load(main, sound);
+       sound_load(bmain, sound);
 
        if(!sound->playback_handle)
        {
 
        if(!sound->playback_handle)
        {
-               free_libblock(&main->sound, sound);
+               free_libblock(&bmain->sound, sound);
                sound = NULL;
        }
 
                sound = NULL;
        }
 
@@ -225,7 +239,7 @@ void sound_delete_cache(struct bSound* sound)
        }
 }
 
        }
 }
 
-void sound_load(struct Main *main, struct bSound* sound)
+void sound_load(struct Main *bmain, struct bSound* sound)
 {
        if(sound)
        {
 {
        if(sound)
        {
@@ -253,11 +267,11 @@ void sound_load(struct Main *main, struct bSound* sound)
                        BLI_strncpy(fullpath, sound->name, sizeof(fullpath));
 
                        if(sound->id.lib)
                        BLI_strncpy(fullpath, sound->name, sizeof(fullpath));
 
                        if(sound->id.lib)
-                               path = sound->id.lib->filename;
+                               path = sound->id.lib->filepath;
                        else
                        else
-                               path = main ? main->name : G.sce;
+                               path = bmain->name;
 
 
-                       BLI_convertstringcode(fullpath, path);
+                       BLI_path_abs(fullpath, path);
 
                        /* but we need a packed file then */
                        if (pf)
 
                        /* but we need a packed file then */
                        if (pf)
@@ -265,7 +279,7 @@ void sound_load(struct Main *main, struct bSound* sound)
                        /* or else load it from disk */
                        else
                                sound->handle = AUD_load(fullpath);
                        /* or else load it from disk */
                        else
                                sound->handle = AUD_load(fullpath);
-               } // XXX
+               }
 // XXX unused currently
 #if 0
                        break;
 // XXX unused currently
 #if 0
                        break;
@@ -344,6 +358,13 @@ void sound_destroy_scene(struct Scene *scene)
                AUD_destroySequencer(scene->sound_scene);
 }
 
                AUD_destroySequencer(scene->sound_scene);
 }
 
+void* sound_scene_add_scene_sound(struct Scene *scene, struct Sequence* sequence, int startframe, int endframe, int frameskip)
+{
+       if(scene != sequence->scene)
+               return AUD_addSequencer(scene->sound_scene, &(sequence->scene->sound_scene), startframe / FPS, endframe / FPS, frameskip / FPS, sequence);
+       return NULL;
+}
+
 void* sound_add_scene_sound(struct Scene *scene, struct Sequence* sequence, int startframe, int endframe, int frameskip)
 {
        return AUD_addSequencer(scene->sound_scene, &(sequence->sound->playback_handle), startframe / FPS, endframe / FPS, frameskip / FPS, sequence);
 void* sound_add_scene_sound(struct Scene *scene, struct Sequence* sequence, int startframe, int endframe, int frameskip)
 {
        return AUD_addSequencer(scene->sound_scene, &(sequence->sound->playback_handle), startframe / FPS, endframe / FPS, frameskip / FPS, sequence);
@@ -364,12 +385,10 @@ void sound_move_scene_sound(struct Scene *scene, void* handle, int startframe, i
        AUD_moveSequencer(scene->sound_scene, handle, startframe / FPS, endframe / FPS, frameskip / FPS);
 }
 
        AUD_moveSequencer(scene->sound_scene, handle, startframe / FPS, endframe / FPS, frameskip / FPS);
 }
 
-void sound_start_play_scene(struct Scene *scene)
+static void sound_start_play_scene(struct Scene *scene)
 {
 {
-       AUD_Sound* sound;
-       sound = AUD_loopSound(scene->sound_scene);
-       scene->sound_scene_handle = AUD_play(sound, 1);
-       AUD_unload(sound);
+       scene->sound_scene_handle = AUD_play(scene->sound_scene, 1);
+       AUD_setLoop(scene->sound_scene_handle, -1);
 }
 
 void sound_play_scene(struct Scene *scene)
 }
 
 void sound_play_scene(struct Scene *scene)
@@ -382,8 +401,6 @@ void sound_play_scene(struct Scene *scene)
        if(status == AUD_STATUS_INVALID)
                sound_start_play_scene(scene);
 
        if(status == AUD_STATUS_INVALID)
                sound_start_play_scene(scene);
 
-       AUD_setLoop(scene->sound_scene_handle, -1, -1);
-
        if(status != AUD_STATUS_PLAYING)
        {
                AUD_seek(scene->sound_scene_handle, CFRA / FPS);
        if(status != AUD_STATUS_PLAYING)
        {
                AUD_seek(scene->sound_scene_handle, CFRA / FPS);
@@ -421,12 +438,18 @@ void sound_seek_scene(struct bContext *C)
 
        if(scene->audio.flag & AUDIO_SCRUB && !CTX_wm_screen(C)->animtimer)
        {
 
        if(scene->audio.flag & AUDIO_SCRUB && !CTX_wm_screen(C)->animtimer)
        {
-               AUD_setLoop(scene->sound_scene_handle, -1, 1 / FPS);
                if(scene->audio.flag & AUDIO_SYNC)
                if(scene->audio.flag & AUDIO_SYNC)
+               {
+                       AUD_seek(scene->sound_scene_handle, CFRA / FPS);
                        AUD_seekSequencer(scene->sound_scene_handle, CFRA / FPS);
                        AUD_seekSequencer(scene->sound_scene_handle, CFRA / FPS);
+               }
                else
                        AUD_seek(scene->sound_scene_handle, CFRA / FPS);
                AUD_resume(scene->sound_scene_handle);
                else
                        AUD_seek(scene->sound_scene_handle, CFRA / FPS);
                AUD_resume(scene->sound_scene_handle);
+               if(AUD_getStatus(scene->sound_scrub_handle) != AUD_STATUS_INVALID)
+                       AUD_seek(scene->sound_scrub_handle, 0);
+               else
+                       scene->sound_scrub_handle = AUD_pauseAfter(scene->sound_scene_handle, 1 / FPS);
        }
        else
        {
        }
        else
        {
@@ -458,7 +481,18 @@ int sound_scene_playing(struct Scene *scene)
                return -1;
 }
 
                return -1;
 }
 
-int sound_read_sound_buffer(struct bSound* sound, float* buffer, int length)
+int sound_read_sound_buffer(struct bSound* sound, float* buffer, int length, float start, float end)
+{
+       AUD_Sound* limiter = AUD_limitSound(sound->cache, start, end);
+       return AUD_readSound(limiter, buffer, length);
+       AUD_unload(limiter);
+}
+
+int sound_get_channels(struct bSound* sound)
 {
 {
-       return AUD_readSound(sound->cache, buffer, length);
+       AUD_SoundInfo info;
+
+       info = AUD_getInfo(sound->playback_handle);
+
+       return info.specs.channels;
 }
 }