Changeset 246 for trunk

Show
Ignore:
Timestamp:
03/28/08 11:54:44 (4 years ago)
Author:
ath
Message:

Work on the sync implementation.

Location:
trunk
Files:
17 modified

Legend:

Unmodified
Added
Removed
  • trunk/fm_gui/src/base.c

    r228 r246  
    4040        rgc_remote_object_new_async (fm_cdj_created_cb, data, 
    4141                            "FmInputCDJ", "input", NULL); 
    42         rgc_remote_object_new_async (fm_cdj_created_cb, data, 
    43                             "FmInputCDJ", "input", NULL); 
     42/*      rgc_remote_object_new_async (fm_cdj_created_cb, data, 
     43                            "FmInputCDJ", "input", NULL);*/ 
    4444/*      rgc_remote_object_new_async (fm_beatgen_created_cb, data, 
    4545                            "FmInputBeatgen", "input", NULL);*/ 
  • trunk/fm_server/src/fm_buffer.c

    r245 r246  
    6060 
    6161        buffer->timestamp_ns = 0; 
    62         buffer->timestamp_samples = 0; 
     62//      buffer->timestamp_samples = 0; 
    6363        buffer->duration = 0; 
    6464         
     
    121121        buffer->silence = FALSE; 
    122122        buffer->timestamp_ns = -1; 
    123         buffer->timestamp_samples = -1; 
     123//      buffer->timestamp_samples = -1; 
    124124        buffer->duration = 0;    
    125125} 
  • trunk/fm_server/src/fm_buffer.h

    r245 r246  
    5151 
    5252        gint64          timestamp_ns;           // real timestamp from start of the song 
    53         gint64          timestamp_samples; 
     53//      gint64          timestamp_samples; 
    5454        guint64         duration;               // real duration of AUDIO (not silence) in the buffer  
    5555}; 
  • trunk/fm_server/src/fm_djmixer.c

    r196 r246  
    158158        djm->master_level = fm_level_meter_new (); 
    159159 
     160        g_object_set_data (G_OBJECT (djm->mixer), "name", g_strdup_printf ("mixer")); 
     161        g_object_set_data (G_OBJECT (djm->master_gain), "name", g_strdup_printf ("master_gain")); 
     162        g_object_set_data (G_OBJECT (djm->master_level), "name", g_strdup_printf ("master_level")); 
     163 
    160164        fm_element_connect_src (FM_ELEMENT (djm->master_level), FM_ELEMENT (djm->master_gain)); 
    161165        fm_element_connect_src (FM_ELEMENT (djm->master_gain), FM_ELEMENT (djm->mixer)); 
     
    224228        FmDJMixer *djm = FM_DJMIXER (element); 
    225229 
     230        static gint serial = 0; 
    226231        FmDJMixerChannel *chan = g_new0 (FmDJMixerChannel, 1); 
    227232        chan->owner = djm; 
     
    232237        chan->fader = fm_effect_gain_new (); 
    233238 
     239        g_object_set_data (G_OBJECT (chan->fader), "name", g_strdup_printf ("chan_fader%d", serial)); 
     240        g_object_set_data (G_OBJECT (chan->meter), "name", g_strdup_printf ("chan_meter%d", serial)); 
     241        g_object_set_data (G_OBJECT (chan->pan), "name", g_strdup_printf ("chan_pan%d", serial)); 
     242        g_object_set_data (G_OBJECT (chan->gain), "name", g_strdup_printf ("chan_gain%d", serial)); 
     243        serial++; 
     244         
    234245        fm_pipeline_add_element (element->pipeline, FM_ELEMENT (chan->fader)); 
    235246        fm_pipeline_add_element (element->pipeline, FM_ELEMENT (chan->meter)); 
     
    308319        FmDJMixer *djm = FM_DJMIXER (element); 
    309320 
    310         fm_element_get_buffer (FM_ELEMENT (djm->master_level), buffer, element->sync_ref); 
     321        fm_element_get_buffer (FM_ELEMENT (djm->master_level), buffer, element->sync_data); 
    311322} 
    312323 
     
    321332 
    322333        FmElement *mixer_el = FM_ELEMENT (djm->mixer); 
    323         mixer_el->sync_ref = sync; 
    324 } 
     334        mixer_el->sync_data = sync; 
     335} 
  • trunk/fm_server/src/fm_effect_rubber/fm_effect_rubber.c

    r245 r246  
    270270        if ((rubber->last_timestamp == start_timestamp) && (start_timestamp == -1)) 
    271271                return; 
    272         g_print ("%s pos %ld\n", fm_element_get_name (element), buffer->timestamp_ns); 
     272//      g_print ("%s pos %ld\n", fm_element_get_name (element), buffer->timestamp_ns); 
    273273        rubber->last_timestamp = buffer->timestamp_ns; 
    274274} 
  • trunk/fm_server/src/fm_effect_rubber/fm_rubber_wrapper.cpp

    r238 r246  
    1111*fm_rubber_wrapper_new                  (void) 
    1212{ 
    13         g_print ("RRRRRRRRRUUUUUUUBBBBBBBEEEEEEERRRRRR\n"); 
    14  
    1513        FmRubberWrapper *wrap = g_new0 (FmRubberWrapper, 1); 
    1614        RubberBandStretcher *ts = new RubberBandStretcher (44100, 2, RubberBandStretcher::OptionProcessRealTime, 1.0, 1.0); 
  • trunk/fm_server/src/fm_element.c

    r245 r246  
    159159 
    160160        element->pipeline = NULL; 
    161         element->sync_ref = NULL; 
     161        element->sync_data = NULL; 
    162162        element->sync_master = FALSE; 
     163        element->sync_slave = FALSE; 
     164        element->sync_ref = FALSE; 
    163165} 
    164166 
     
    445447        g_print ("fm_element_become_sync_ref on %p!\n", element); 
    446448 
    447         element->sync_ref = g_new0 (FmSync, 1); 
     449        element->sync_data = g_new0 (FmSync, 1); 
     450        element->sync_ref = TRUE; 
    448451} 
    449452 
     
    457460        g_return_if_fail (klass->become_sync_master); 
    458461 
    459         g_print ("new sync master is %p %s\n", peer_sync_master, peer_sync_master->name); 
     462        g_print ("new sync master is %p %s\n", peer_sync_master, fm_element_get_name (peer_sync_master)); 
    460463 
    461464        reference->peer_sync_master = peer_sync_master; 
    462465        peer_sync_master->sync_master = TRUE; 
    463         (*klass->become_sync_master) (peer_sync_master, reference->sync_ref); 
     466        (*klass->become_sync_master) (peer_sync_master, reference->sync_data); 
    464467} 
    465468 
  • trunk/fm_server/src/fm_element.h

    r245 r246  
    6060typedef struct _FmSync FmSync; 
    6161struct _FmSync { 
    62         gboolean        in_use; 
     62        gboolean        valid; 
    6363 
    6464        FmElement       *master; 
     
    7474        gint            bar; 
    7575        gint            beat; 
    76         gfloat          beat_offset_ns; 
     76        gint            beat_offset_ns; 
     77        gfloat          beat_offset_float; 
    7778 
    7879        gdouble         bpm_new; 
     
    9899        gpointer        pipeline; 
    99100 
    100         FmSync          *sync_ref; 
    101         gboolean        sync_master; 
     101        FmSync          *sync_data;             // owned by sync_ref 
     102 
     103        gboolean        sync_master;            // the element leads the sync 
     104        gboolean        sync_slave;             // the element follows the sync 
     105        gboolean        sync_ref;               // the mixer element used as a base for sync 
    102106}; 
    103107 
     
    111115        gboolean (*activate)            (FmElement      *element); 
    112116        gboolean (*deactivate)          (FmElement      *element); 
     117        void (*become_sync_master)      (FmElement      *element, 
     118                                         FmSync         *sync); 
     119        void (*become_sync_slave)       (FmElement      *element, 
     120                                         FmSync         *sync); 
    113121        void (*become_sync_ref)         (FmElement      *element, 
    114                                          FmSync         *sync); 
    115         void (*become_sync_master)      (FmElement      *element, 
    116122                                         FmSync         *sync); 
    117123        void (*get_buffer)              (FmElement      *element, 
  • trunk/fm_server/src/fm_input_cdj.c

    r245 r246  
    289289{ 
    290290        g_print ("FmInputCDJ has become sync master!\n"); 
    291  
    292         sync->in_use = TRUE; 
    293  
    294         sync->bpm = 120.0; 
    295         sync->beat_per_bar = 4; 
    296291} 
    297292 
     
    316311 
    317312 
     313        FmBeatSection *beat_sect = fm_sync_get_beatsection (input_cdj->beat_info, buffer->timestamp_ns); 
     314 
    318315 
    319316        if (fm_element_is_sync_master (element)) { 
    320                 if (FM_BUFFER_DISCONT (buffer)) { 
     317                /*if (beat_sect) 
     318                        sync->valid = TRUE; 
     319                else { 
     320                        sync->valid = FALSE; 
     321                        return; 
     322                }*/ 
     323 
     324                fm_sync_update_pos (sync, beat_sect, buffer->timestamp_ns); 
     325 
     326                /*if (FM_BUFFER_DISCONT (buffer)) { 
    321327                        g_print ("**************************************************************************************************\n"); 
    322328                        g_print ("DISCONT buffer! new pos %llu\n", (long long unsigned int) buffer->timestamp_ns); 
     
    326332                        fm_sync_master_played_ns (sync, FM_BUFFER_DURATION (buffer)); 
    327333                        fm_sync_update_cycle (sync); 
    328                 } 
    329  
    330                 if (FM_BUFFER_DURATION (buffer) > 0) 
     334                }*/ 
     335 
     336                if (buffer->timestamp_ns >= 0) 
    331337                        fm_sync_show_pos (sync); 
    332338        } 
     
    387393fm_input_cdj_update_bpm                 (FmInputCDJ     *input_cdj) 
    388394{ 
    389         gdouble bpm; 
     395        /*gdouble bpm; 
    390396        if (input_cdj->beat_section) 
    391397                bpm = input_cdj->beat_section->bpm / fm_effect_rubber_get_time_ratio (input_cdj->rate); 
     
    394400        GValue *val = g_value_init_double (bpm); 
    395401        rgc_signal_emit (input_cdj, "bpm_changed", val, NULL); 
    396         g_value_destroy (val); 
     402        g_value_destroy (val);*/ 
    397403} 
    398404 
     
    407413        g_value_destroy(fn); 
    408414 
    409         FmBeatInfo *beat_info = fm_song_db_get_beatinfo (global_song_db, filename); 
    410  
    411         if (!beat_info) { 
     415        input_cdj->beat_info = fm_song_db_get_beatinfo (global_song_db, filename); 
     416 
     417        if (!input_cdj->beat_info) { 
    412418                g_print ("Song \"%s\" isn't in the song database\n", filename); 
    413                 input_cdj->beat_section = NULL; 
    414419                return; 
    415420        } 
    416421 
    417         if (!beat_info->beatsections) { 
     422        if (!input_cdj->beat_info->beatsections) { 
    418423                g_print ("Song \"%s\" doesn't have beat information\n", filename); 
    419                 input_cdj->beat_section = NULL; 
    420424                return; 
    421425        } 
    422426 
    423         FmBeatSection *beat_section = beat_info->beatsections->data; 
     427        fm_sync_dump_beatsections (input_cdj->beat_info); 
     428        /*FmBeatSection *beat_section = beat_info->beatsections->data; 
    424429        input_cdj->beat_section = beat_section; 
    425430        g_print ("Beat info: start %lld, end %lld, bpm %lf\n", (long long int) beat_section->start, (long long int) beat_section->end, beat_section->bpm); 
    426         fm_input_cdj_update_bpm (input_cdj); 
     431        fm_input_cdj_update_bpm (input_cdj);*/ 
    427432} 
    428433 
  • trunk/fm_server/src/fm_input_cdj.h

    r238 r246  
    3838        FmEffectRubber  *rate; 
    3939 
    40         FmBeatSection   *beat_section; 
     40        FmBeatInfo      *beat_info; 
    4141}; 
    4242 
  • trunk/fm_server/src/fm_input_gst/fm_input_gst.c

    r245 r246  
    617617//              g_print ("FILL\n"); 
    618618                buffer->timestamp_ns = -1; 
    619                 buffer->timestamp_samples = -1; 
     619//              buffer->timestamp_samples = -1; 
    620620                return; 
    621621        } 
     
    650650        chk->samples_read += useful_read_samples; 
    651651 
    652         buffer->timestamp_samples = current_pos_samples_old; 
    653         buffer->timestamp_ns = samples_to_ns (common, buffer->timestamp_samples); 
     652//      buffer->timestamp_samples = current_pos_samples_old; 
     653        buffer->timestamp_ns = samples_to_ns (common, current_pos_samples_old); 
    654654        buffer->used_samples = buffer->requested_samples; 
    655655        buffer->duration = samples_to_ns (common, useful_read_samples); 
  • trunk/fm_server/src/fm_mixer.c

    r196 r246  
    243243                FM_BUFFER_REQUESTED (mixer->buffers[i]) = FM_BUFFER_REQUESTED (buffer); 
    244244                 
     245                g_print ("Getting data from master port\n"); 
    245246                fm_element_get_buffer (element->peer_sync_master, mixer->buffers[i++], sync); 
    246247        } 
  • trunk/fm_server/src/fm_song_db/fm_song_db.c

    r199 r246  
    9090fm_song_db_init                         (FmSongDB       *song_db) 
    9191{ 
    92 #define FILENAME "/tmp/song_db.xml" 
     92#define FILENAME "/home/ath/Projects/FreeMix/song_db.xml" 
    9393 
    9494        fm_xml_db_init (); 
     
    9696        song_db->xml_db = fm_xml_db_new (FILENAME); 
    9797 
    98         g_print ("alright! %p\n", song_db->xml_db); 
    99  
    100         //fm_xml_db_dump (song_db->xml_db); 
     98        g_print ("Song database loaded, %p\n", song_db->xml_db); 
    10199 
    102100        /*gint res; 
     
    126124 
    127125        gint count = fm_xml_db_get_beatsection_count (song_db->xml_db, filename); 
     126        //fm_xml_db_dump (song_db->xml_db, filename); 
    128127 
    129128        if (count == -1) 
     
    131130         
    132131        info = g_new0 (FmBeatInfo, 1); 
     132        info->current = NULL; 
    133133        gint i; 
    134134 
  • trunk/fm_server/src/fm_song_db/fm_xml_db.c

    r199 r246  
    109109 
    110110void 
    111 fm_xml_db_dump                          (FmXmlDb        *db) 
     111fm_xml_db_dump                          (FmXmlDb        *db, 
     112                                         const gchar    *song_filename) 
    112113{ 
    113114        xmlNode *nod = fm_xml_db_search_song (db, "lady.mp3"); 
    114115 
    115116        g_print ("%p\n", nod); 
    116         //print_element_names(db->root_element); 
     117        print_element_names(db->root_element); 
    117118} 
    118119 
  • trunk/fm_server/src/fm_song_db/fm_xml_db.h

    r199 r246  
    3939 
    4040void 
    41 fm_xml_db_dump                          (FmXmlDb        *db); 
     41fm_xml_db_dump                          (FmXmlDb        *db, 
     42                                         const gchar    *song_filename); 
    4243 
    4344gint 
  • trunk/fm_server/src/fm_sync.c

    r195 r246  
    3333 
    3434 
    35 void 
     35/*void 
    3636fm_sync_update_cycle                    (FmSync         *sync) 
    3737{ 
     
    4646        } 
    4747 
    48 //      guint sample_rate = /* fm_pipeline_get_sample_rate() */ 44100; 
     48//      guint sample_rate = 44100; 
    4949//      sync->ns_per_sample = (1.0 / sample_rate) * NS_PER_SEC; 
    5050        sync->ns_per_beat = NS_PER_SEC / (sync->bpm / 60.0); 
     
    6565                sync->beat = 0; 
    6666        } 
    67 } 
     67}*/ 
    6868 
    6969 
    70 void 
     70/*void 
    7171fm_sync_master_played_ns                (FmSync         *sync, 
    7272                                         guint          ns) 
    7373{ 
    7474        sync->played_ns_new = ns; 
    75 } 
     75}*/ 
    7676 
    7777 
    78 void 
     78/*void 
    7979fm_sync_master_set_bpm                  (FmSync         *sync, 
    8080                                         gdouble        bpm) 
    8181{ 
    8282        sync->bpm_new = bpm; 
    83 } 
     83}*/ 
    8484 
    85 void 
     85/*void 
    8686fm_sync_set                             (FmSync         *sync, 
    8787                                         guint64        offset, 
     
    9494        sync->beat_offset_ns = realstamp - (beats * sync->ns_per_beat); 
    9595 
    96 } 
     96}*/ 
    9797 
    98 gdouble 
     98/*gdouble 
    9999fm_sync_ns_to_next_beat                 (FmSync         *sync) 
    100100{ 
    101101        return (sync->ns_per_beat - sync->beat_offset_ns); 
    102 } 
     102}*/ 
    103103 
    104104 
    105 gint 
     105/*gint 
    106106fm_sync_next_beat_is                    (FmSync         *sync) 
    107107{ 
     
    112112 
    113113        return next_beat; 
    114 } 
     114}*/ 
    115115 
    116116void 
    117117fm_sync_show_pos                        (FmSync         *sync) 
    118118{ 
    119         g_print ("bpm: %lf pos: bar %d beat %d beat_offset_ns %f\n", sync->bpm, sync->bar, sync->beat, sync->beat_offset_ns); 
     119        if (!sync->valid) 
     120                return; 
     121 
     122        g_print ("bpm: %.3lf pos: bar %d beat %d beat_offset %.5f\n", sync->bpm, sync->bar, sync->beat, sync->beat_offset_float); 
    120123} 
     124 
     125void 
     126fm_sync_dump_beatsections               (FmBeatInfo     *info) 
     127{ 
     128        g_return_if_fail (info); 
     129 
     130        GList *sections = info->beatsections; 
     131        while (sections) { 
     132                FmBeatSection *sect = sections->data; 
     133 
     134                g_print ("Beat info: start %lld, end %lld, bpm %lf\n", 
     135                         (long long int) sect->start, (long long int) sect->end, sect->bpm); 
     136 
     137                sections = sections->next; 
     138        } 
     139 
     140} 
     141 
     142FmBeatSection * 
     143fm_sync_get_beatsection                 (FmBeatInfo     *info, 
     144                                         guint64        ns) 
     145{ 
     146        if (!info) 
     147                return NULL; 
     148 
     149        g_return_val_if_fail (info->beatsections, NULL); 
     150 
     151        if ((info->current) && 
     152            (info->current->start <= ns) && (info->current->start <= ns)) 
     153                return info->current; 
     154 
     155        info->current = NULL; 
     156 
     157        GList *sections = info->beatsections; 
     158        while (sections) { 
     159                FmBeatSection *sect = sections->data; 
     160 
     161                if ((sect->start <= ns) && (sect->start <= ns))  
     162                        info->current = sect; 
     163 
     164                sections = sections->next; 
     165        } 
     166 
     167        return info->current; 
     168} 
     169 
     170 
     171void 
     172fm_sync_update_pos                      (FmSync         *sync, 
     173                                         FmBeatSection  *sect, 
     174                                         gint64         pos) 
     175{ 
     176        g_return_if_fail (sync); 
     177 
     178        if ((!sect) || (pos < 0)) { 
     179                sync->valid = FALSE; 
     180                return; 
     181        } 
     182 
     183        sync->valid = TRUE; 
     184         
     185        sync->beat_per_bar = 4; 
     186        sync->bpm = sect->bpm; 
     187 
     188        sync->ns_per_beat = NS_PER_SEC / (sync->bpm / 60.0); 
     189 
     190        guint beat = pos / sync->ns_per_beat; 
     191 
     192        sync->bar = beat / sync->beat_per_bar; 
     193        sync->beat = beat - (sync->bar * sync->beat_per_bar); 
     194        sync->beat_offset_ns = pos - (beat * sync->ns_per_beat); 
     195        sync->beat_offset_float = sync->beat_offset_ns / sync->ns_per_beat; 
     196} 
  • trunk/fm_server/src/fm_sync.h

    r195 r246  
    3535struct _FmBeatInfo { 
    3636        GList           *beatsections; 
     37 
     38        FmBeatSection   *current; 
    3739}; 
    3840 
     
    5557 
    5658/* The sync reference has to call this after calling fm_get_buffer() on its peer_sync_master port */ 
    57 void 
    58 fm_sync_update_cycle                    (FmSync         *sync); 
     59/*void 
     60fm_sync_update_cycle                    (FmSync         *sync);*/ 
    5961 
    6062/* Callable from get_buffer, takes effect from next cycle */ 
    61 void 
     63/*void 
    6264fm_sync_master_played_ns                (FmSync         *sync, 
    63                                          guint          samples); 
     65                                         guint          samples);*/ 
    6466 
    6567/* Callable outside of get_buffer, take effect from next cycle */ 
    66 void 
     68/*void 
    6769fm_sync_master_set_bpm                  (FmSync         *sync, 
    68                                          gdouble        bpm); 
     70                                         gdouble        bpm);*/ 
    6971 
    70 void 
     72/*void 
    7173fm_sync_set                             (FmSync         *sync, 
    7274                                         guint64        offset, 
    73                                          guint64        timestamp); 
     75                                         guint64        timestamp);*/ 
    7476 
    7577/* Callable from get_buffer */ 
    76 gdouble 
    77 fm_sync_ns_to_next_beat                 (FmSync         *sync); 
     78/*gdouble 
     79fm_sync_ns_to_next_beat                 (FmSync         *sync);*/ 
    7880 
    79 gint 
    80 fm_sync_next_beat_is                    (FmSync         *sync); 
     81/*gint 
     82fm_sync_next_beat_is                    (FmSync         *sync);*/ 
    8183 
    8284void 
    8385fm_sync_show_pos                        (FmSync         *sync); 
     86 
     87void 
     88fm_sync_dump_beatsections               (FmBeatInfo     *info); 
     89 
     90FmBeatSection * 
     91fm_sync_get_beatsection                 (FmBeatInfo     *info, 
     92                                         guint64        ns); 
     93 
     94void 
     95fm_sync_update_pos                      (FmSync         *sync, 
     96                                         FmBeatSection  *sect, 
     97                                         gint64         pos);