Fix for [#26652] "Audio Muted" in Time Line Editor is not working
authorJoerg Mueller <nexyon@gmail.com>
Sun, 10 Apr 2011 22:40:37 +0000 (22:40 +0000)
committerJoerg Mueller <nexyon@gmail.com>
Sun, 10 Apr 2011 22:40:37 +0000 (22:40 +0000)
-> The feature was completely missing o_O
Also fixed an ffmpeg seeking bug.

intern/audaspace/ffmpeg/AUD_FFMPEGReader.cpp
intern/audaspace/intern/AUD_C-API.cpp
intern/audaspace/intern/AUD_C-API.h
intern/audaspace/intern/AUD_SequencerFactory.cpp
intern/audaspace/intern/AUD_SequencerFactory.h
intern/audaspace/intern/AUD_SequencerReader.cpp
source/blender/blenkernel/BKE_sound.h
source/blender/blenkernel/intern/sound.c
source/blender/makesrna/intern/rna_scene.c

index 078a10a68cbd8e49898042b2d10eb397d670da48..0dc525b0e5a1268fb58256ab0687231d49d77b23 100644 (file)
@@ -253,7 +253,7 @@ void AUD_FFMPEGReader::seek(int position)
        if(position >= 0)
        {
                uint64_t st_time = m_formatCtx->start_time;
-               uint64_t seek_pos = position * AV_TIME_BASE / m_specs.rate;
+               uint64_t seek_pos = ((uint64_t)position) * ((uint64_t)AV_TIME_BASE) / ((uint64_t)m_specs.rate);
 
                if (seek_pos < 0) {
                        seek_pos = 0;
index 3fb11e31c37b3accd120722cea5f67f8e32a4763..0119bb105d80065f10ed48bb69b2fa9b582ca053 100644 (file)
@@ -864,7 +864,7 @@ AUD_Channel* AUD_pauseAfter(AUD_Channel* handle, float seconds)
        }
 }
 
-AUD_Sound* AUD_createSequencer(void* data, AUD_volumeFunction volume)
+AUD_Sound* AUD_createSequencer(int muted, void* data, AUD_volumeFunction volume)
 {
 /* AUD_XXX should be this: but AUD_createSequencer is called before the device
  * is initialized.
@@ -874,7 +874,7 @@ AUD_Sound* AUD_createSequencer(void* data, AUD_volumeFunction volume)
        AUD_Specs specs;
        specs.channels = AUD_CHANNELS_STEREO;
        specs.rate = AUD_RATE_44100;
-       return new AUD_SequencerFactory(specs, data, volume);
+       return new AUD_SequencerFactory(specs, muted, data, volume);
 }
 
 void AUD_destroySequencer(AUD_Sound* sequencer)
@@ -882,6 +882,11 @@ void AUD_destroySequencer(AUD_Sound* sequencer)
        delete ((AUD_SequencerFactory*)sequencer);
 }
 
+void AUD_setSequencerMuted(AUD_Sound* sequencer, int muted)
+{
+       ((AUD_SequencerFactory*)sequencer)->mute(muted);
+}
+
 AUD_SequencerEntry* AUD_addSequencer(AUD_Sound** sequencer, AUD_Sound* sound,
                                                                 float begin, float end, float skip, void* data)
 {
index 04343bb9c4cd538c84fa449f844103f883bd7293..b2242f09547f904fb13c63f1d036f6e9b462f4b5 100644 (file)
@@ -459,10 +459,12 @@ extern float* AUD_readSoundBuffer(const char* filename, float low, float high,
  */
 extern AUD_Channel* AUD_pauseAfter(AUD_Channel* handle, float seconds);
 
-extern AUD_Sound* AUD_createSequencer(void* data, AUD_volumeFunction volume);
+extern AUD_Sound* AUD_createSequencer(int muted, void* data, AUD_volumeFunction volume);
 
 extern void AUD_destroySequencer(AUD_Sound* sequencer);
 
+extern void AUD_setSequencerMuted(AUD_Sound* sequencer, int muted);
+
 extern AUD_SequencerEntry* AUD_addSequencer(AUD_Sound** sequencer, AUD_Sound* sound,
                                                                                float begin, float end, float skip, void* data);
 
index 77d83458c683478369b850e31d932cc1108fb4f0..f49dd94fe111c62c140717766538fd901c867b80 100644 (file)
 
 typedef std::list<AUD_SequencerReader*>::iterator AUD_ReaderIterator;
 
-AUD_SequencerFactory::AUD_SequencerFactory(AUD_Specs specs, void* data,
+AUD_SequencerFactory::AUD_SequencerFactory(AUD_Specs specs, bool muted,
+                                                                                  void* data,
                                                                                   AUD_volumeFunction volume) :
        m_specs(specs),
+       m_muted(muted),
        m_data(data),
        m_volume(volume)
 {
@@ -62,6 +64,16 @@ AUD_SequencerFactory::~AUD_SequencerFactory()
        }
 }
 
+void AUD_SequencerFactory::mute(bool muted)
+{
+       m_muted = muted;
+}
+
+bool AUD_SequencerFactory::getMute() const
+{
+       return m_muted;
+}
+
 AUD_IReader* AUD_SequencerFactory::newReader()
 {
        AUD_SequencerReader* reader = new AUD_SequencerReader(this, m_entries,
index 5eea95eb6ef3f7bd854f5e19f23b4fe77ce4eb9c..8f3466f75ce6830f23df015680ba1f9e58354ece 100644 (file)
@@ -63,6 +63,7 @@ private:
 
        std::list<AUD_SequencerEntry*> m_entries;
        std::list<AUD_SequencerReader*> m_readers;
+       bool m_muted;
        void* m_data;
        AUD_volumeFunction m_volume;
 
@@ -73,9 +74,11 @@ private:
        AUD_SequencerFactory& operator=(const AUD_SequencerFactory&);
 
 public:
-       AUD_SequencerFactory(AUD_Specs specs, void* data, AUD_volumeFunction volume);
+       AUD_SequencerFactory(AUD_Specs specs, bool muted, void* data, AUD_volumeFunction volume);
        ~AUD_SequencerFactory();
 
+       void mute(bool muted);
+       bool getMute() const;
        AUD_SequencerEntry* add(AUD_IFactory** sound, float begin, float end, float skip, void* data);
        void remove(AUD_SequencerEntry* entry);
        void move(AUD_SequencerEntry* entry, float begin, float end, float skip);
index c02f9e02b3380ce051dd96a9586d70e33b181e88..95e0dca63238e0efcbfda2481442e396f82c6c70 100644 (file)
@@ -182,55 +182,58 @@ void AUD_SequencerReader::read(int & length, sample_t* & buffer)
                m_buffer.resize(size);
        buffer = m_buffer.getBuffer();
 
-       for(AUD_StripIterator i = m_strips.begin(); i != m_strips.end(); i++)
+       if(!m_factory->getMute())
        {
-               strip = *i;
-               if(!strip->entry->muted)
+               for(AUD_StripIterator i = m_strips.begin(); i != m_strips.end(); i++)
                {
-                       if(strip->old_sound != *strip->entry->sound)
+                       strip = *i;
+                       if(!strip->entry->muted)
                        {
-                               strip->old_sound = *strip->entry->sound;
-                               if(strip->reader)
-                                       delete strip->reader;
-
-                               if(strip->old_sound)
+                               if(strip->old_sound != *strip->entry->sound)
                                {
-                                       try
+                                       strip->old_sound = *strip->entry->sound;
+                                       if(strip->reader)
+                                               delete strip->reader;
+
+                                       if(strip->old_sound)
                                        {
-                                               strip->reader = m_mixer->prepare(strip->old_sound->createReader());
+                                               try
+                                               {
+                                                       strip->reader = m_mixer->prepare(strip->old_sound->createReader());
+                                               }
+                                               catch(AUD_Exception)
+                                               {
+                                                       strip->reader = NULL;
+                                               }
                                        }
-                                       catch(AUD_Exception)
-                                       {
+                                       else
                                                strip->reader = NULL;
-                                       }
                                }
-                               else
-                                       strip->reader = NULL;
-                       }
 
-                       if(strip->reader)
-                       {
-                               end = floor(strip->entry->end * rate);
-                               if(m_position < end)
+                               if(strip->reader)
                                {
-                                       start = floor(strip->entry->begin * rate);
-                                       if(m_position + length > start)
+                                       end = floor(strip->entry->end * rate);
+                                       if(m_position < end)
                                        {
-                                               current = m_position - start;
-                                               if(current < 0)
+                                               start = floor(strip->entry->begin * rate);
+                                               if(m_position + length > start)
                                                {
-                                                       skip = -current;
-                                                       current = 0;
+                                                       current = m_position - start;
+                                                       if(current < 0)
+                                                       {
+                                                               skip = -current;
+                                                               current = 0;
+                                                       }
+                                                       else
+                                                               skip = 0;
+                                                       current += strip->entry->skip * rate;
+                                                       len = length > end - m_position ? end - m_position : length;
+                                                       len -= skip;
+                                                       if(strip->reader->getPosition() != current)
+                                                               strip->reader->seek(current);
+                                                       strip->reader->read(len, buf);
+                                                       m_mixer->add(buf, skip, len, m_volume(m_data, strip->entry->data, (float)m_position / (float)rate));
                                                }
-                                               else
-                                                       skip = 0;
-                                               current += strip->entry->skip * rate;
-                                               len = length > end - m_position ? end - m_position : length;
-                                               len -= skip;
-                                               if(strip->reader->getPosition() != current)
-                                                       strip->reader->seek(current);
-                                               strip->reader->read(len, buf);
-                                               m_mixer->add(buf, skip, len, m_volume(m_data, strip->entry->data, (float)m_position / (float)rate));
                                        }
                                }
                        }
index acd4718a65a20a84ca3b2485b44a0c6f7b41713c..04597fd666e1e0e6de4d2cddcd02a9f419966054 100644 (file)
@@ -78,6 +78,8 @@ void sound_create_scene(struct Scene *scene);
 
 void sound_destroy_scene(struct Scene *scene);
 
+void sound_mute_scene(struct Scene *scene, int muted);
+
 void* sound_scene_add_scene_sound(struct Scene *scene, struct Sequence* sequence, int startframe, int endframe, int frameskip);
 
 void* sound_add_scene_sound(struct Scene *scene, struct Sequence* sequence, int startframe, int endframe, int frameskip);
index 52e1faaabeeccdc9672629a5d3106b52d150e624..e0e456a371e213531cf2783f7ddcc53a3df173a6 100644 (file)
@@ -347,7 +347,7 @@ AUD_Device* sound_mixdown(struct Scene *scene, AUD_DeviceSpecs specs, int start,
 
 void sound_create_scene(struct Scene *scene)
 {
-       scene->sound_scene = AUD_createSequencer(scene, (AUD_volumeFunction)&sound_get_volume);
+       scene->sound_scene = AUD_createSequencer(scene->audio.flag & AUDIO_MUTE, scene, (AUD_volumeFunction)&sound_get_volume);
 }
 
 void sound_destroy_scene(struct Scene *scene)
@@ -358,6 +358,12 @@ void sound_destroy_scene(struct Scene *scene)
                AUD_destroySequencer(scene->sound_scene);
 }
 
+void sound_mute_scene(struct Scene *scene, int muted)
+{
+       if(scene->sound_scene)
+               AUD_setSequencerMuted(scene->sound_scene, muted);
+}
+
 void* sound_scene_add_scene_sound(struct Scene *scene, struct Sequence* sequence, int startframe, int endframe, int frameskip)
 {
        if(scene != sequence->scene)
index 331d9cfa95713e4220988e85ab3d0e54625da247..35177daeb9b9246de439c019fe9df438db6c1bad 100644 (file)
@@ -912,6 +912,24 @@ static void rna_Scene_simplify_update(Main *bmain, Scene *scene, PointerRNA *ptr
                rna_Scene_use_simplify_update(bmain, scene, ptr);
 }
 
+static int rna_Scene_use_audio_get(PointerRNA *ptr)
+{
+       Scene *scene= (Scene*)ptr->data;
+       return scene->audio.flag & AUDIO_MUTE;
+}
+
+static void rna_Scene_use_audio_set(PointerRNA *ptr, int value)
+{
+       Scene *scene= (Scene*)ptr->data;
+
+       if(value)
+               scene->audio.flag |= AUDIO_MUTE;
+       else
+               scene->audio.flag &= ~AUDIO_MUTE;
+
+       sound_mute_scene(scene, value);
+}
+
 static int rna_Scene_sync_mode_get(PointerRNA *ptr)
 {
        Scene *scene= (Scene*)ptr->data;
@@ -3350,7 +3368,7 @@ void RNA_def_scene(BlenderRNA *brna)
 
        /* Audio Settings */
        prop= RNA_def_property(srna, "use_audio", PROP_BOOLEAN, PROP_NONE);
-       RNA_def_property_boolean_negative_sdna(prop, NULL, "audio.flag", AUDIO_MUTE);
+       RNA_def_property_boolean_funcs(prop, "rna_Scene_use_audio_get", "rna_Scene_use_audio_set");
        RNA_def_property_ui_text(prop, "Audio Muted", "Play back of audio from Sequence Editor will be muted");
        RNA_def_property_update(prop, NC_SCENE, NULL);