Changeset 112

Show
Ignore:
Timestamp:
09/04/06 20:29:59 (5 years ago)
Author:
ath
Message:

Use some decent float-integer converstion routines, and make FmPipeline more useful.

Location:
fm_server/trunk/src
Files:
10 modified

Legend:

Unmodified
Added
Removed
  • fm_server/trunk/src/Makefile.am

    r111 r112  
    1616        fm_utils.c\ 
    1717        fm_utils.h\ 
     18        src_type_conv.c\ 
     19        src_type_conv.h\ 
    1820        fm_input.c\ 
    1921        fm_input.h\ 
  • fm_server/trunk/src/Makefile.in

    r111 r112  
    6161PROGRAMS = $(bin_PROGRAMS) 
    6262am__fm_server_SOURCES_DIST = main.c types.h fm_utils.c fm_utils.h \ 
    63         fm_input.c fm_input.h fm_output.c fm_output.h fm_effect.c \ 
    64         fm_effect.h fm_element.c fm_element.h fm_pipeline.c \ 
    65         fm_pipeline.h fm_input_test.c fm_input_test.h fm_input_cdj.c \ 
    66         fm_input_cdj.h fm_marshal.c fm_marshal.h fm_effect_gain.c \ 
    67         fm_effect_gain.h fm_effect_rate.c fm_effect_rate.h fm_mixer.c \ 
    68         fm_mixer.h fm_djmixer.c fm_djmixer.h fm_buffer.c fm_buffer.h \ 
     63        src_type_conv.c src_type_conv.h fm_input.c fm_input.h \ 
     64        fm_output.c fm_output.h fm_effect.c fm_effect.h fm_element.c \ 
     65        fm_element.h fm_pipeline.c fm_pipeline.h fm_input_test.c \ 
     66        fm_input_test.h fm_input_cdj.c fm_input_cdj.h fm_marshal.c \ 
     67        fm_marshal.h fm_effect_gain.c fm_effect_gain.h \ 
     68        fm_effect_rate.c fm_effect_rate.h fm_mixer.c fm_mixer.h \ 
     69        fm_djmixer.c fm_djmixer.h fm_buffer.c fm_buffer.h \ 
    6970        fm_effect_pan.c fm_effect_pan.h fm_output_alsa.c \ 
    7071        fm_output_alsa.h fm_output_jack.c fm_output_jack.h 
     
    7273@HAVE_JACK_TRUE@am__objects_2 = fm_output_jack.$(OBJEXT) 
    7374am_fm_server_OBJECTS = main.$(OBJEXT) fm_utils.$(OBJEXT) \ 
    74         fm_input.$(OBJEXT) fm_output.$(OBJEXT) fm_effect.$(OBJEXT) \ 
    75         fm_element.$(OBJEXT) fm_pipeline.$(OBJEXT) \ 
     75        src_type_conv.$(OBJEXT) fm_input.$(OBJEXT) fm_output.$(OBJEXT) \ 
     76        fm_effect.$(OBJEXT) fm_element.$(OBJEXT) fm_pipeline.$(OBJEXT) \ 
    7677        fm_input_test.$(OBJEXT) fm_input_cdj.$(OBJEXT) \ 
    7778        fm_marshal.$(OBJEXT) fm_effect_gain.$(OBJEXT) \ 
     
    257258SUBDIRS = fm_input_gst 
    258259INCLUDES = $(FM_SERVER_CFLAGS) 
    259 fm_server_SOURCES = main.c types.h fm_utils.c fm_utils.h fm_input.c \ 
    260         fm_input.h fm_output.c fm_output.h fm_effect.c fm_effect.h \ 
    261         fm_element.c fm_element.h fm_pipeline.c fm_pipeline.h \ 
    262         fm_input_test.c fm_input_test.h fm_input_cdj.c fm_input_cdj.h \ 
    263         fm_marshal.c fm_marshal.h fm_effect_gain.c fm_effect_gain.h \ 
     260fm_server_SOURCES = main.c types.h fm_utils.c fm_utils.h \ 
     261        src_type_conv.c src_type_conv.h fm_input.c fm_input.h \ 
     262        fm_output.c fm_output.h fm_effect.c fm_effect.h fm_element.c \ 
     263        fm_element.h fm_pipeline.c fm_pipeline.h fm_input_test.c \ 
     264        fm_input_test.h fm_input_cdj.c fm_input_cdj.h fm_marshal.c \ 
     265        fm_marshal.h fm_effect_gain.c fm_effect_gain.h \ 
    264266        fm_effect_rate.c fm_effect_rate.h fm_mixer.c fm_mixer.h \ 
    265267        fm_djmixer.c fm_djmixer.h fm_buffer.c fm_buffer.h \ 
     
    357359@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/fm_utils.Po@am__quote@ 
    358360@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/main.Po@am__quote@ 
     361@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/src_type_conv.Po@am__quote@ 
    359362 
    360363.c.o: 
  • fm_server/trunk/src/fm_element.c

    r61 r112  
    135135{ 
    136136        element->name = NULL; 
    137 //      element->src_pads = PAD_NONE; 
    138137        element->src_ports = NULL; 
    139 //      element->sink_pads = PAD_NONE; 
    140138        element->sink_ports = NULL; 
    141139         
    142140        element->active = FALSE;         
    143141        element->dispose_has_run = FALSE; 
     142 
     143        element->pipeline = NULL; 
    144144} 
    145145 
  • fm_server/trunk/src/fm_element.h

    r58 r112  
    8181        gboolean        active; 
    8282        gboolean        dispose_has_run; 
     83 
     84        // yes, I know this is an hack 
     85        gpointer        pipeline; 
    8386}; 
    8487 
  • fm_server/trunk/src/fm_input_gst/fm_input_gst.c

    r109 r112  
    1111#include "../fm_element.h" 
    1212#include "../fm_input.h" 
     13#include "../fm_output.h" 
     14#include "../fm_pipeline.h" 
    1315 
    1416#include "fm_input_gst_common.h" 
     
    350352        common->sem = fm_sem_new (1); 
    351353        common->gst_seek_to_sample = -1; 
     354//      common->sample_rate = fm_pipeline_get_sample_rate (FM_PIPELINE (element->pipeline)); 
     355 
    352356 
    353357        /* setup */ 
  • fm_server/trunk/src/fm_input_gst/fm_input_gst_common.h

    r107 r112  
    3131{ 
    3232        gpointer        input_gst; 
     33        guint           sample_rate; 
    3334 
    3435        GstElement      *pipeline; 
  • fm_server/trunk/src/fm_output_alsa.c

    r111 r112  
    77#include <alsa/asoundlib.h> 
    88 
     9#include "src_type_conv.h" 
    910#include "fm_buffer.h" 
    1011#include "fm_element.h" 
     
    1415 
    1516#define ALSA_DEFAULT_DEVICE "default" 
     17#define ALSA_DEFAULT_SAMPLE_RATE 44100 
    1618#define ALSA_DEFAULT_BUFFER_TIME 22000 
    1719#define ALSA_DEFAULT_PERIOD_TIME 10000 
     
    407409                fm_element_get_buffer_from_src(element, output_alsa->main_buffer); 
    408410         
    409                 guint i; 
    410                 gint16 *ptr = output_alsa->buffer_int; 
    411                 for (i = 0; i < output_alsa->buffer_size_samples; i++) { 
    412                         *(ptr++) = FLOAT_TO_INT (output_alsa->main_buffer->channel_data[0][i]); 
    413                         *(ptr++) = FLOAT_TO_INT (output_alsa->main_buffer->channel_data[1][i]); 
    414                 } 
    415          
     411                src_float_to_short_array_stereo (output_alsa->main_buffer->channel_data[0], 
     412                                                 output_alsa->main_buffer->channel_data[1], 
     413                                                 output_alsa->buffer_int, output_alsa->buffer_size_samples); 
     414 
    416415                gint err = 0; 
    417416                 
  • fm_server/trunk/src/fm_pipeline.c

    r109 r112  
    8787                             rgc_marshal_VOID__ELEMENT, 
    8888                             1, G_TYPE_STRING); 
     89 
     90        rgc_method_register ("add_element", 
     91                             FM_TYPE_PIPELINE, 
     92                             G_CALLBACK (fm_pipeline_add_element), 
     93                             rgc_marshal_VOID__ELEMENT, 
     94                             1, G_TYPE_STRING); 
    8995         
    9096        rgc_method_register ("activate", 
     
    112118fm_pipeline_class_init                  (FmPipelineClass        *klass) 
    113119{ 
    114         /*GObjectClass *gobject_class = G_OBJECT_CLASS (klass); 
    115          
    116         gobject_class->set_property = fm_pipeline_set_property; 
    117         gobject_class->get_property = fm_pipeline_get_property;*/ 
     120        //GObjectClass *gobject_class = G_OBJECT_CLASS (klass); 
    118121} 
    119122 
     
    122125fm_pipeline_init                        (FmPipeline     *pipeline) 
    123126{ 
    124         GError *err = NULL; 
    125          
    126         g_print ("a1"); 
    127          
    128         pipeline->start = g_mutex_new (); 
    129         g_mutex_lock (pipeline->start); 
    130  
    131         g_print ("a2"); 
    132          
    133         pipeline->pipe_thread = g_thread_create ((GThreadFunc) fm_pipeline_thread_entry, 
    134                                               (gpointer) pipeline, FALSE, &err); 
    135  
    136127        g_print ("new pipeline created\n"); 
    137128 
    138129        /* Start with a reasonable default, the output element will alter this if it needs to */ 
    139130        pipeline->sample_rate = 48000; 
    140          
    141         return; 
    142131} 
    143132 
     
    156145fm_pipeline_activate                    (FmPipeline     *pipeline) 
    157146{ 
    158         //gint samples_per_buffer; 
    159147        g_assert (FM_IS_PIPELINE (pipeline)); 
    160148        g_return_if_fail (FM_IS_ELEMENT (pipeline->sink)); 
     
    164152        pipeline->sample_rate = fm_output_get_sample_rate(pipeline->sink); 
    165153        fm_element_activate(FM_ELEMENT(pipeline->sink)); 
    166  
    167         // OSS uses 4096 samples_per_buffer 
    168 /*      samples_per_buffer = 0fm_output_get_spb (FM_OUTPUT (pipeline->sink)); 
    169         g_print ("output set a %d samples per buffer\n", samples_per_buffer);*/ 
    170          
    171         //g_assert_not_reached (); 
    172          
    173 /*      pipeline->buffer = fm_buffer_new (MAX_SAMPLES, FM_SAMPLES_FLOAT, 
    174                                           FM_INTERLEAVING_NORMAL, FM_CHANNELS_STEREO); 
    175         FM_BUFFER_REQUESTED (pipeline->buffer) = samples_per_buffer;*/ 
    176          
    177         return; 
    178154} 
    179155 
     
    183159                                         FmElement      *sink) 
    184160{ 
    185         g_assert (FM_IS_PIPELINE (pipeline)); 
     161        g_return_if_fail (FM_IS_PIPELINE (pipeline)); 
    186162        FmOutput *out = FM_OUTPUT(sink); 
    187         g_assert (FM_IS_OUTPUT (out)); 
     163        g_return_if_fail (FM_IS_OUTPUT (out)); 
    188164         
    189165        pipeline->sink = FM_OUTPUT(sink); 
    190166         
    191167        return; 
     168} 
     169 
     170 
     171void 
     172fm_pipeline_add_element                 (FmPipeline     *pipeline, 
     173                                         FmElement      *element) 
     174{ 
     175        g_return_if_fail (FM_IS_PIPELINE (pipeline)); 
     176        g_return_if_fail (FM_IS_ELEMENT (element)); 
     177 
     178        element->pipeline = pipeline; 
    192179} 
    193180 
     
    201188        g_debug("Starting pipeline..."); 
    202189        fm_output_start(pipeline->sink); 
    203          
    204         /*g_assert (pipeline); 
    205          
    206         if (pipeline->sink == NULL) 
    207                 g_print ("Audiodevice is not set!\n"); 
    208          
    209         pipeline->running = TRUE; 
    210          
    211         // Let the thread start 
    212         g_print ("MAIN - Unlocking mutex\n"); 
    213         g_mutex_unlock (pipeline->start);*/ 
    214          
    215         return; 
    216190} 
    217191 
     
    225199        g_debug("Stopping pipeline..."); 
    226200        fm_output_stop(pipeline->sink); 
    227         /*g_mutex_unlock (pipeline->start); 
    228         g_print ("MAIN - Locking again mutex\n"); 
    229         g_mutex_lock (pipeline->start); 
    230         g_print ("MAIN - Locked mutex\n"); 
    231         pipeline->running = FALSE;*/ 
    232          
    233         return; 
    234 } 
    235  
    236  
    237 GThreadFunc 
    238 fm_pipeline_thread_entry                (gpointer       data) 
    239 { 
    240         /*g_print ("in new thread\n"); 
    241          
    242         FmPipeline *pipeline = FM_PIPELINE (data); 
    243      
    244         fm_pipeline_loop (pipeline);*/ 
    245      
    246         return (NULL); 
    247 } 
    248  
    249  
    250 void 
    251 fm_pipeline_loop                        (FmPipeline     *pipeline) 
    252 { 
    253         /*g_print ("Waiting...\n"); 
    254         g_mutex_lock (pipeline->start); 
    255         g_print ("Go!\n"); 
    256         fm_output_start(pipeline->sink);*/ 
    257          
    258         /*buffer_elems = samples_per_buffer; 
    259         buffer_int_size = (sizeof (int16_t) * buffer_elems); 
    260         buffer_fp_size = (sizeof (gfloat) * buffer_elems);*/ 
    261          
    262 //      guint samples_per_buffer = fm_output_get_spb (FM_OUTPUT (pipeline->sink)); 
    263          
    264         /*while (TRUE) { 
    265                 if (pipeline->running == FALSE) { 
    266                         g_print ("ENGINE - Locking mutex\n"); 
    267                         fm_output_stop(pipeline->sink); 
    268                         g_mutex_lock (pipeline->start); 
    269                         g_print ("ENGINE - Mutex was unlocked\n"); 
    270                         fm_output_start(pipeline->sink); 
    271                 } 
    272                 g_thread_yield();*/ 
    273 /*              fm_element_get_buffer (pipeline->sink, pipeline->buffer); 
    274                 fm_output_play (FM_OUTPUT (pipeline->sink), pipeline->buffer); 
    275                 g_print ("iterating...\n");*/ 
    276         /*}*/ 
    277201} 
    278202 
  • fm_server/trunk/src/fm_pipeline.h

    r29 r112  
    4545        FmOutput        *sink; 
    4646         
    47         FmBuffer        *buffer; 
    48          
    49         GMutex          *start; 
    50         GThread         *pipe_thread; 
    51          
    52         gboolean        running; 
    53         gboolean        working; 
    54  
    5547        guint           sample_rate; 
    5648}; 
     
    7971 
    8072void 
     73fm_pipeline_add_element                 (FmPipeline     *pipeline, 
     74                                         FmElement      *element); 
     75 
     76void 
    8177fm_pipeline_run                         (FmPipeline     *pipeline); 
    8278 
     
    8480fm_pipeline_stop                        (FmPipeline     *pipeline); 
    8581 
    86 GThreadFunc 
    87 fm_pipeline_thread_entry                (gpointer       data); 
    88  
    89 void 
    90 fm_pipeline_loop                        (FmPipeline     *pipeline); 
     82guint 
     83fm_pipeline_get_sample_rate             (FmPipeline     *pipeline); 
    9184 
    9285 
  • fm_server/trunk/src/main.c

    r111 r112  
    8686 
    8787 
    88  
    89 //gint buffer_elems = 0;                // element = 1 * channels_n 
    90 //gint buffer_int_size = 0;     // buffer_int_size = sizeof (int16_t) * buffer_elems 
    91 //gint buffer_fp_size = 0;      // buffer_int_size = sizeof (gfloat) * buffer_elems 
    92  
    93 gboolean 
    94 timeout                                 (gpointer       user_data) 
    95 { 
    96         /*g_print ("Timeout!\n"); 
    97          
    98         FmEngine *data = (FmEngine *) user_data; 
    99          
    100         if (fm_engine_is_running (data)) 
    101                 fm_engine_stop (data); 
    102         else 
    103                 fm_engine_start (data); 
    104         */ 
    105          
    106         exit (0); 
    107         return (TRUE); 
    108 } 
    109  
    110  
    11188gint 
    11289main                                    (gint           argc, 
     
    152129        fm_mixer_class_register (); 
    153130        fm_djmixer_class_register (); 
    154 /*      fm_effect_pan_class_register (); 
    155  
    156         fm_mixer_dj_class_register ();*/ 
     131        fm_effect_pan_class_register (); 
    157132#if HAVE_ALSA_ASOUNDLIB_H 
    158133        fm_output_alsa_class_register (); 
    159134#endif 
    160         //fm_output_oss_class_register (); 
    161135 
    162 //      test_case (); 
    163          
    164         /*RgcMessageNew *mess1; 
    165         mess1 = rgc_message_new_create ("cdj1", "FmInputCDJ"); 
    166         rgc_message_execute_new (mess1)*/ 
    167          
    168136        GMainLoop *main_loop; 
    169137        main_loop = g_main_loop_new (NULL, FALSE);       
    170138 
    171139        /*unlink ("/tmp/fmraw.raw"); 
    172         temp_fd = open ("/tmp/fmraw.raw", (O_WRONLY && O_SYNC));*/ 
    173         g_assert (temp_fd != -1); 
     140        temp_fd = open ("/tmp/fmraw.raw", (O_WRONLY && O_SYNC)); 
     141        g_assert (temp_fd != -1);*/ 
    174142 
    175         /*main_conn = fm_connection_unix_new ("/tmp/fm"); 
    176         main_connection = FM_CONNECTION (main_conn); 
    177         g_idle_add ((GSourceFunc) fm_connection_start, main_conn);*/ 
    178                  
    179         //g_timeout_add (100000, timeout, NULL); 
    180          
    181143        g_main_loop_run (main_loop); 
    182144         
     
    195157 
    196158 
    197 /*void 
    198 test_case                               (void) 
    199 { 
    200         FmPipeline *pipeline; 
    201         FmElement *input; 
    202         FmElement *output; 
    203          
    204         pipeline = fm_pipeline_new (); 
    205         input = FM_ELEMENT (fm_input_cdj_new ()); 
    206         output = FM_ELEMENT (fm_output_oss_new ()); 
    207          
    208         fm_element_connect_src (output, input); 
    209          
    210         fm_pipeline_set_sink (pipeline, output); 
    211          
    212         fm_pipeline_activate (pipeline); 
    213          
    214         fm_pipeline_run (pipeline); 
    215          
    216         g_object_set (G_OBJECT (input), "filename", "/tmp/b.mp3", NULL); 
    217          
    218         fm_input_cdj_load (FM_INPUT_CDJ (input)); 
    219 }*/ 
    220  
    221  
    222 /*void 
    223 test_case                               (void) 
    224 { 
    225         FmElement *input; 
    226          
    227         input = FM_ELEMENT (fm_input_cdj_new ()); 
    228          
    229         fm_element_activate (input); 
    230          
    231         g_object_set (G_OBJECT (input), "filename", "/tmp/b.mp3", NULL); 
    232         fm_input_cdj_load (FM_INPUT_CDJ (input)); 
    233          
    234         FmBuffer *buffer = fm_buffer_new (MAX_SAMPLES, FM_SAMPLES_FLOAT, 
    235                                           FM_INTERLEAVING_NORMAL, FM_CHANNELS_STEREO); 
    236         FM_BUFFER_REQUESTED (buffer) = 32; 
    237          
    238         FmBuffer *out_buffer = fm_buffer_new (MAX_SAMPLES, FM_SAMPLES_INT16, 
    239                                     FM_INTERLEAVING_NORMAL, FM_CHANNELS_STEREO); 
    240          
    241         while (TRUE) { 
    242                 fm_element_get_buffer (input, buffer); 
    243  
    244                 fm_buffer_convert (buffer, out_buffer); 
    245                                  
    246                 fm_buffer_dump_to_file (out_buffer, temp_fd); 
    247         } 
    248          
    249         fm_buffer_destroy (buffer); 
    250         fm_buffer_destroy (out_buffer); 
    251 }*/ 
    252  
    253 #define SEGMENT_SIZE 64 
    254  
    255 /*void 
    256 test_case                               (void) 
    257 { 
    258         FmGstThread *thread; 
    259          
    260         thread = fm_gst_thread_new (); 
    261          
    262         fm_gst_thread_load (thread, "/tmp/b.mp3"); 
    263          
    264                  
    265         FmBuffer *buffer = NULL; 
    266         buffer = fm_buffer_new (SEGMENT_SIZE, FM_SAMPLES_INT16, 
    267                                 FM_INTERLEAVING_NORMAL, FM_CHANNELS_STEREO); 
    268  
    269         FmBuffer *float_buffer = NULL; 
    270         float_buffer = fm_buffer_new (SEGMENT_SIZE, FM_SAMPLES_FLOAT, 
    271                                       FM_INTERLEAVING_NORMAL, FM_CHANNELS_STEREO); 
    272  
    273         FmBuffer *out_buffer = NULL;//g_print ("%d\n", BUF_READ); 
    274         out_buffer = fm_buffer_new (SEGMENT_SIZE, FM_SAMPLES_INT16, 
    275                                     FM_INTERLEAVING_NORMAL, FM_CHANNELS_STEREO); 
    276          
    277         while (TRUE) { 
    278                 fm_gst_thread_get_buffer (thread, buffer); 
    279                  
    280                 fm_buffer_convert (buffer, float_buffer); 
    281                 fm_buffer_convert (float_buffer, out_buffer); 
    282                                  
    283                 fm_buffer_dump_to_file (out_buffer, temp_fd); 
    284         } 
    285          
    286         fm_buffer_destroy (buffer); 
    287         fm_buffer_destroy (float_buffer); 
    288         fm_buffer_destroy (out_buffer); 
    289 }*/