Enabling AV-sync again. You can now choose between No sync, Frame Dropping or AV-sync.

This commit is contained in:
Joerg Mueller 2010-02-19 12:20:29 +00:00
parent 92927e5f7d
commit f09dc08523
7 changed files with 78 additions and 18 deletions

@ -72,7 +72,7 @@ class TIME_HT_header(bpy.types.Header):
subsub = row.row()
subsub.prop(tools, "record_with_nla", toggle=True)
layout.prop(scene, "sync_audio", text="AV-sync", toggle=True, icon='SPEAKER')
layout.prop(scene, "sync_mode", text="")
layout.separator()
@ -152,6 +152,7 @@ class TIME_MT_playback(bpy.types.Menu):
layout.separator()
layout.prop(scene, "frame_drop", text="Frame Dropping")
layout.prop(scene, "sync_audio", text="AV-sync", icon='SPEAKER')
layout.prop(scene, "mute_audio")
layout.prop(scene, "scrub_audio")

@ -86,6 +86,8 @@ void sound_stop_scene(struct Scene *scene);
void sound_seek_scene(struct bContext *C);
float sound_sync_scene(struct Scene *scene);
int sound_read_sound_buffer(struct bSound* sound, float* buffer, int length);
#endif

@ -394,6 +394,11 @@ void sound_seek_scene(struct bContext *C)
AUD_unlock();
}
float sound_sync_scene(struct Scene *scene)
{
return AUD_getPosition(scene->sound_scene_handle);
}
int sound_read_sound_buffer(bSound* sound, float* buffer, int length)
{
return AUD_readSound(sound->cache, buffer, length);

@ -47,7 +47,7 @@ enum {
ANIMPLAY_FLAG_JUMPED = (1<<1),
/* drop frames as needed to maintain framerate */
ANIMPLAY_FLAG_SYNC = (1<<2),
/* don't drop frames (and ignore AUDIO_SYNC flag) */
/* don't drop frames (and ignore SCE_FRAME_DROP flag) */
ANIMPLAY_FLAG_NO_SYNC = (1<<3),
};

@ -2426,12 +2426,18 @@ static int screen_animation_step(bContext *C, wmOperator *op, wmEvent *event)
/* sync, don't sync, or follow scene setting */
if(sad->flag & ANIMPLAY_FLAG_SYNC) sync= 1;
else if(sad->flag & ANIMPLAY_FLAG_NO_SYNC) sync= 0;
else sync= (scene->audio.flag & AUDIO_SYNC);
else sync= (scene->flag & SCE_FRAME_DROP);
if((scene->audio.flag & AUDIO_SYNC) && !(sad->flag & ANIMPLAY_FLAG_REVERSE))
{
scene->r.cfra = floor(sound_sync_scene(scene) * FPS);
}
else
{
if(sync) {
/* skip frames */
int step = floor(wt->duration * FPS);
if(sad->flag & ANIMPLAY_FLAG_REVERSE) // XXX does this option work with audio?
/* skip frames */
if(sad->flag & ANIMPLAY_FLAG_REVERSE)
scene->r.cfra -= step;
else
scene->r.cfra += step;
@ -2444,6 +2450,7 @@ static int screen_animation_step(bContext *C, wmOperator *op, wmEvent *event)
else
scene->r.cfra++;
}
}
/* reset 'jumped' flag before checking if we need to jump... */
sad->flag &= ~ANIMPLAY_FLAG_JUMPED;

@ -1067,6 +1067,7 @@ typedef struct Scene {
#define SCE_DS_SELECTED (1<<0)
#define SCE_DS_COLLAPSED (1<<1)
#define SCE_NLA_EDIT_ON (1<<2)
#define SCE_FRAME_DROP (1<<3)
/* return flag next_object function */

@ -704,6 +704,32 @@ static void rna_Scene_simplify_update(Main *bmain, Scene *scene, PointerRNA *ptr
WM_main_add_notifier(NC_GEOM|ND_DATA, NULL);
}
static int rna_Scene_sync_mode_get(PointerRNA *ptr)
{
Scene *scene= (Scene*)ptr->data;
if(scene->audio.flag & AUDIO_SYNC)
return AUDIO_SYNC;
return scene->flag & SCE_FRAME_DROP;
}
static void rna_Scene_sync_mode_set(PointerRNA *ptr, int value)
{
Scene *scene= (Scene*)ptr->data;
if(value == AUDIO_SYNC)
scene->audio.flag |= AUDIO_SYNC;
else if(value == SCE_FRAME_DROP)
{
scene->audio.flag &= ~AUDIO_SYNC;
scene->flag |= SCE_FRAME_DROP;
}
else
{
scene->audio.flag &= ~AUDIO_SYNC;
scene->flag &= ~SCE_FRAME_DROP;
}
}
#else
static void rna_def_transform_orientation(BlenderRNA *brna)
@ -2600,6 +2626,12 @@ void RNA_def_scene(BlenderRNA *brna)
{6, "EXPONENT_CLAMPED", 0, "Exponent Clamped", "Exponent distance model with clamping"},
{0, NULL, 0, NULL, NULL}};
static EnumPropertyItem sync_mode_items[] = {
{0, "NONE", 0, "No Sync", "Do not sync, play every frame"},
{SCE_FRAME_DROP, "FRAME_DROP", 0, "Frame Dropping", "Drop frames if playback is too slow"},
{AUDIO_SYNC, "AUDIO_SYNC", 0, "AV-sync", "Sync to audio playback, dropping frames"},
{0, NULL, 0, NULL, NULL}};
/* Struct definition */
srna= RNA_def_struct(brna, "Scene", "ID");
RNA_def_struct_ui_text(srna, "Scene", "Scene consisting objects and defining time and render related settings");
@ -2725,6 +2757,18 @@ void RNA_def_scene(BlenderRNA *brna)
RNA_def_property_ui_text(prop, "NLA TweakMode", "Indicates whether there is any action referenced by NLA being edited. Strictly read-only");
RNA_def_property_update(prop, NC_SPACE|ND_SPACE_GRAPH, NULL);
/* Frame dropping flag for playback and sync enum */
prop= RNA_def_property(srna, "frame_drop", PROP_BOOLEAN, PROP_NONE);
RNA_def_property_boolean_sdna(prop, NULL, "flag", SCE_FRAME_DROP);
RNA_def_property_ui_text(prop, "Frame Dropping", "Play back dropping frames if frame display is too slow");
RNA_def_property_update(prop, NC_SCENE, NULL);
prop= RNA_def_property(srna, "sync_mode", PROP_ENUM, PROP_NONE);
RNA_def_property_enum_funcs(prop, "rna_Scene_sync_mode_get", "rna_Scene_sync_mode_set", NULL);
RNA_def_property_enum_items(prop, sync_mode_items);
RNA_def_property_ui_text(prop, "Sync Mode", "How to sync playback");
RNA_def_property_update(prop, NC_SCENE, NULL);
/* Nodes (Compositing) */
prop= RNA_def_property(srna, "nodetree", PROP_POINTER, PROP_NONE);