Fix for [#26652] "Audio Muted" in Time Line Editor is not working

-> The feature was completely missing o_O
Also fixed an ffmpeg seeking bug.
This commit is contained in:
Joerg Mueller 2011-04-10 22:40:37 +00:00
parent 2afae38019
commit e37dc17991
9 changed files with 100 additions and 49 deletions

@ -253,7 +253,7 @@ void AUD_FFMPEGReader::seek(int position)
if(position >= 0) if(position >= 0)
{ {
uint64_t st_time = m_formatCtx->start_time; 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) { if (seek_pos < 0) {
seek_pos = 0; seek_pos = 0;

@ -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 /* AUD_XXX should be this: but AUD_createSequencer is called before the device
* is initialized. * is initialized.
@ -874,7 +874,7 @@ AUD_Sound* AUD_createSequencer(void* data, AUD_volumeFunction volume)
AUD_Specs specs; AUD_Specs specs;
specs.channels = AUD_CHANNELS_STEREO; specs.channels = AUD_CHANNELS_STEREO;
specs.rate = AUD_RATE_44100; 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) void AUD_destroySequencer(AUD_Sound* sequencer)
@ -882,6 +882,11 @@ void AUD_destroySequencer(AUD_Sound* sequencer)
delete ((AUD_SequencerFactory*)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, AUD_SequencerEntry* AUD_addSequencer(AUD_Sound** sequencer, AUD_Sound* sound,
float begin, float end, float skip, void* data) float begin, float end, float skip, void* data)
{ {

@ -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_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_destroySequencer(AUD_Sound* sequencer);
extern void AUD_setSequencerMuted(AUD_Sound* sequencer, int muted);
extern AUD_SequencerEntry* AUD_addSequencer(AUD_Sound** sequencer, AUD_Sound* sound, extern AUD_SequencerEntry* AUD_addSequencer(AUD_Sound** sequencer, AUD_Sound* sound,
float begin, float end, float skip, void* data); float begin, float end, float skip, void* data);

@ -34,9 +34,11 @@
typedef std::list<AUD_SequencerReader*>::iterator AUD_ReaderIterator; 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) : AUD_volumeFunction volume) :
m_specs(specs), m_specs(specs),
m_muted(muted),
m_data(data), m_data(data),
m_volume(volume) 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_IReader* AUD_SequencerFactory::newReader()
{ {
AUD_SequencerReader* reader = new AUD_SequencerReader(this, m_entries, AUD_SequencerReader* reader = new AUD_SequencerReader(this, m_entries,

@ -63,6 +63,7 @@ private:
std::list<AUD_SequencerEntry*> m_entries; std::list<AUD_SequencerEntry*> m_entries;
std::list<AUD_SequencerReader*> m_readers; std::list<AUD_SequencerReader*> m_readers;
bool m_muted;
void* m_data; void* m_data;
AUD_volumeFunction m_volume; AUD_volumeFunction m_volume;
@ -73,9 +74,11 @@ private:
AUD_SequencerFactory& operator=(const AUD_SequencerFactory&); AUD_SequencerFactory& operator=(const AUD_SequencerFactory&);
public: 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(); ~AUD_SequencerFactory();
void mute(bool muted);
bool getMute() const;
AUD_SequencerEntry* add(AUD_IFactory** sound, float begin, float end, float skip, void* data); AUD_SequencerEntry* add(AUD_IFactory** sound, float begin, float end, float skip, void* data);
void remove(AUD_SequencerEntry* entry); void remove(AUD_SequencerEntry* entry);
void move(AUD_SequencerEntry* entry, float begin, float end, float skip); void move(AUD_SequencerEntry* entry, float begin, float end, float skip);

@ -182,55 +182,58 @@ void AUD_SequencerReader::read(int & length, sample_t* & buffer)
m_buffer.resize(size); m_buffer.resize(size);
buffer = m_buffer.getBuffer(); buffer = m_buffer.getBuffer();
for(AUD_StripIterator i = m_strips.begin(); i != m_strips.end(); i++) if(!m_factory->getMute())
{ {
strip = *i; for(AUD_StripIterator i = m_strips.begin(); i != m_strips.end(); i++)
if(!strip->entry->muted)
{ {
if(strip->old_sound != *strip->entry->sound) strip = *i;
if(!strip->entry->muted)
{ {
strip->old_sound = *strip->entry->sound; if(strip->old_sound != *strip->entry->sound)
if(strip->reader)
delete strip->reader;
if(strip->old_sound)
{ {
try strip->old_sound = *strip->entry->sound;
{ if(strip->reader)
strip->reader = m_mixer->prepare(strip->old_sound->createReader()); delete strip->reader;
}
catch(AUD_Exception)
{
strip->reader = NULL;
}
}
else
strip->reader = NULL;
}
if(strip->reader) if(strip->old_sound)
{
end = floor(strip->entry->end * rate);
if(m_position < end)
{
start = floor(strip->entry->begin * rate);
if(m_position + length > start)
{ {
current = m_position - start; try
if(current < 0)
{ {
skip = -current; strip->reader = m_mixer->prepare(strip->old_sound->createReader());
current = 0; }
catch(AUD_Exception)
{
strip->reader = NULL;
}
}
else
strip->reader = NULL;
}
if(strip->reader)
{
end = floor(strip->entry->end * rate);
if(m_position < end)
{
start = floor(strip->entry->begin * rate);
if(m_position + length > start)
{
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));
} }
} }
} }

@ -78,6 +78,8 @@ void sound_create_scene(struct Scene *scene);
void sound_destroy_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_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); void* sound_add_scene_sound(struct Scene *scene, struct Sequence* sequence, int startframe, int endframe, int frameskip);

@ -347,7 +347,7 @@ AUD_Device* sound_mixdown(struct Scene *scene, AUD_DeviceSpecs specs, int start,
void sound_create_scene(struct Scene *scene) 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) void sound_destroy_scene(struct Scene *scene)
@ -358,6 +358,12 @@ void sound_destroy_scene(struct Scene *scene)
AUD_destroySequencer(scene->sound_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) void* sound_scene_add_scene_sound(struct Scene *scene, struct Sequence* sequence, int startframe, int endframe, int frameskip)
{ {
if(scene != sequence->scene) if(scene != sequence->scene)

@ -912,6 +912,24 @@ static void rna_Scene_simplify_update(Main *bmain, Scene *scene, PointerRNA *ptr
rna_Scene_use_simplify_update(bmain, scene, 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) static int rna_Scene_sync_mode_get(PointerRNA *ptr)
{ {
Scene *scene= (Scene*)ptr->data; Scene *scene= (Scene*)ptr->data;
@ -3350,7 +3368,7 @@ void RNA_def_scene(BlenderRNA *brna)
/* Audio Settings */ /* Audio Settings */
prop= RNA_def_property(srna, "use_audio", PROP_BOOLEAN, PROP_NONE); 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_ui_text(prop, "Audio Muted", "Play back of audio from Sequence Editor will be muted");
RNA_def_property_update(prop, NC_SCENE, NULL); RNA_def_property_update(prop, NC_SCENE, NULL);