Changeset 193

Show
Ignore:
Timestamp:
05/12/06 09:09:06 (17 years ago)
Author:
pieterpalmers
Message:

minor cleanups

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/alsa-plugin/freebob/pcm_freebob.c

    r184 r193  
    3636#include <pthread.h> 
    3737 
    38 #define FREEBOB_PLUGIN_VERSION "0.0.7
     38#define FREEBOB_PLUGIN_VERSION "0.0.8
    3939 
    4040#define FREEBOB_USE_RT                  1 
     
    4646#define FREEBOB_RT_PRIORITY_MIDI        59 
    4747 
     48// undef this to disable midi support 
    4849#define FREEBOB_WITH_MIDI 
    4950 
     
    122123#endif 
    123124 
    124 // unused 
    125 static snd_pcm_sframes_t snd_pcm_freebob_write(snd_pcm_ioplug_t *io, 
    126                                    const snd_pcm_channel_area_t *areas, 
    127                                    snd_pcm_uframes_t offset, 
    128                                    snd_pcm_uframes_t size) 
    129 
    130         PRINT_FUNCTION_ENTRY; 
    131  
    132         int retval=0; 
    133         int i=0; 
    134          
    135         snd_pcm_sframes_t frames; 
     125static int snd_pcm_freebob_hw_params(snd_pcm_ioplug_t *io, snd_pcm_hw_params_t *params) { 
     126 
     127        PRINT_FUNCTION_ENTRY; 
    136128 
    137129        snd_pcm_freebob_t *freebob = io->private_data; 
    138         const char *buf; 
    139         ssize_t result; 
    140  
    141         int sampleswritten; 
    142  
    143         freebob_streaming_transfer_playback_buffers(freebob->streaming_device); 
    144  
    145         for(i=0;i<freebob->channels;i++) { 
    146                 freebob_sample_t *buff=(freebob_sample_t *)((char *)areas[i].addr + (areas[i].step * offset / 8)); 
    147                 sampleswritten=freebob_streaming_write(freebob->streaming_device, i, buff, freebob->dev_options.period_size); 
    148         } 
    149  
    150         frames = sampleswritten / freebob->channels; 
    151  
    152         freebob->hw_ptr += frames; 
    153         freebob->hw_ptr %= io->buffer_size; 
    154  
    155         return frames ; 
    156 
    157  
    158 static int snd_pcm_freebob_hw_params(snd_pcm_ioplug_t *io, snd_pcm_hw_params_t *params) { 
    159  
    160         PRINT_FUNCTION_ENTRY; 
    161  
    162         snd_pcm_freebob_t *freebob = io->private_data; 
    163         int i=0; 
     130        unsigned int i=0; 
    164131 
    165132        freebob->channels=0; 
    166133        if (freebob->stream == SND_PCM_STREAM_PLAYBACK) { 
    167134                //fixme: assumes that the audio streams are always the first streams 
    168                 for (i=0;i<freebob_streaming_get_nb_playback_streams(freebob->streaming_device);i++) { 
     135                for (i=0;i < (unsigned int)freebob_streaming_get_nb_playback_streams(freebob->streaming_device);i++) { 
    169136                        if(freebob_streaming_get_playback_stream_type(freebob->streaming_device,i)==freebob_stream_type_audio) { 
    170137                                freebob->channels++; 
     
    177144        } else { 
    178145                //fixme: assumes that the audio streams are always the first streams 
    179                 for (i=0;i<freebob_streaming_get_nb_capture_streams(freebob->streaming_device);i++) { 
     146                for (i=0;i < (unsigned int)freebob_streaming_get_nb_capture_streams(freebob->streaming_device);i++) { 
    180147                        if(freebob_streaming_get_capture_stream_type(freebob->streaming_device,i)==freebob_stream_type_audio) { 
    181148                                freebob->channels++; 
     
    200167        snd_pcm_ioplug_t *io=&freebob->io; 
    201168        const snd_pcm_channel_area_t *areas; 
    202         snd_pcm_uframes_t xfer = 0; 
    203         int i; 
     169        unsigned int i; 
    204170 
    205171        assert(freebob); 
     
    213179        } 
    214180 
    215  
    216181        areas = snd_pcm_ioplug_mmap_areas(io); 
    217182 
     
    279244        PRINT_FUNCTION_ENTRY; 
    280245        if (freebob) { 
    281 //              if (freebob->client) 
    282 //                      jack_client_close(freebob->client); 
    283246                if(freebob->fb_handle) 
    284247                        freebob_destroy_handle(freebob->fb_handle ); 
     
    286249                close(freebob->fd); 
    287250                close(freebob->io.poll_fd); 
    288 //              free(freebob->areas); 
    289251                free(freebob); 
    290252        } 
     
    312274        snd_pcm_freebob_t *freebob = io->private_data; 
    313275 
    314 //      printf("%d\n", freebob->hw_ptr); 
    315276        return freebob->hw_ptr; 
    316277} 
     
    348309static int snd_pcm_freebob_prepare(snd_pcm_ioplug_t *io) 
    349310{ 
    350       snd_pcm_freebob_t *freebob = io->private_data; 
     311//    snd_pcm_freebob_t *freebob = io->private_data; 
    351312        PRINT_FUNCTION_ENTRY; 
    352313 
     
    359320        .stop = snd_pcm_freebob_stop, 
    360321        .pointer = snd_pcm_freebob_pointer, 
    361 //      .transfer = snd_pcm_freebob_write, 
    362322        .hw_params = snd_pcm_freebob_hw_params, 
    363323        .prepare = snd_pcm_freebob_prepare, 
    364324        .poll_revents = snd_pcm_freebob_poll_revents, 
    365325}; 
    366 /* 
    367 static snd_pcm_ioplug_callback_t jack_pcm_callback = { 
    368         .close = snd_pcm_jack_close, 
    369         .start = snd_pcm_jack_start, 
    370         .stop = snd_pcm_jack_stop, 
    371         .pointer = snd_pcm_jack_pointer, 
    372         .prepare = snd_pcm_jack_prepare, 
    373         .poll_revents = snd_pcm_jack_poll_revents, 
    374 }; 
    375 */ 
     326 
    376327#define ARRAY_SIZE(ary) (sizeof(ary)/sizeof(ary[0])) 
    377328 
     
    383334                SND_PCM_ACCESS_RW_NONINTERLEAVED, 
    384335        }; 
    385 /* 
    386         unsigned int rate_list[] = { 
    387                 44100, 
    388                 48000, 
    389                 88200, 
    390                 96000, 
    391         }; 
    392 */ 
     336 
    393337        unsigned int *rate_list=NULL; 
    394         unsigned int nb_rates; 
    395338 
    396339        unsigned int format = SND_PCM_FORMAT_S24; 
     
    398341        int i; 
    399342 
    400         // FIXME: this fixes the plugin to the first discovered device! 
     343        // FIXME: this restricts the plugin to the first discovered device! 
    401344        freebob->dev_options.node_id=freebob_get_device_node_id(freebob->fb_handle, 0); 
    402345 
    403346        freebob_supported_stream_format_info_t* stream_info; 
    404         printf("  port = %d, node_id = %d\n", freebob->dev_options.port, freebob->dev_options.node_id); 
    405  
     347         
     348//      printf("  port = %d, node_id = %d\n", freebob->dev_options.port, freebob->dev_options.node_id); 
     349 
     350        // find the supported samplerate nb channels combinations 
    406351        stream_info = freebob_get_supported_stream_format_info( freebob->fb_handle,  
    407352                                                                freebob->dev_options.node_id,  
    408353                                                                freebob->stream == SND_PCM_STREAM_PLAYBACK ? 1 : 0 ); 
    409          
    410  
    411  
    412         freebob_print_supported_stream_format_info( stream_info );       
     354 
     355//      debug statement 
     356//      freebob_print_supported_stream_format_info( stream_info );       
    413357 
    414358        if(!(rate_list=calloc(stream_info->nb_formats, sizeof(unsigned int)))) { 
     
    434378        } 
    435379 
    436         SNDERR("minchannels: %d \n",min_channels); 
    437         SNDERR("maxchannels: %d \n",max_channels); 
    438  
     380//      SNDERR("minchannels: %d \n",min_channels); 
     381//      SNDERR("maxchannels: %d \n",max_channels); 
    439382 
    440383        freebob_free_supported_stream_format_info( stream_info ); 
     
    442385        freebob->sample_bits = snd_pcm_format_physical_width(format); 
    443386 
     387        // setup the plugin capabilities 
    444388        if ((err = snd_pcm_ioplug_set_param_list(&freebob->io, SND_PCM_IOPLUG_HW_ACCESS, 
    445389                                                 ARRAY_SIZE(access_list), access_list)) < 0 || 
     
    470414        int err; 
    471415        int fd[2]; 
    472         static unsigned int num = 0; 
    473416 
    474417        printf("FreeBob plugin for ALSA\n  version %s compiled %s %s\n  using %s\n",  
     
    494437                 
    495438        if ( freebob_discover_devices( freebob->fb_handle, 0 ) != 0 ) { 
    496 //      if ( freebob_discover_devices( freebob->fb_handle ) != 0 ) { 
    497439            SNDERR("Could not discover devices\n" ); 
    498440            freebob_destroy_handle( freebob->fb_handle ); 
     
    527469#endif 
    528470 
    529 /* 
    530         freebob->playback_channels = 0; 
    531         if (freebob->channels == 0) { 
    532                 snd_pcm_freebob_free(freebob); 
    533                 return -EINVAL; 
    534         } 
    535 */ 
    536 /* 
    537         freebob->areas = calloc(freebob->channels, sizeof(snd_pcm_channel_area_t)); 
    538         if (! freebob->areas) { 
    539                 snd_pcm_freebob_free(jack); 
    540                 return -ENOMEM; 
    541         } 
    542 */ 
    543  
    544  
    545471        socketpair(AF_LOCAL, SOCK_STREAM, 0, fd); 
    546472         
     
    575501{ 
    576502        snd_config_iterator_t i, next; 
    577 //      snd_config_t *playback_conf = NULL; 
    578 //      snd_config_t *capture_conf = NULL; 
    579503        int err; 
    580504        long tmp_int; 
     
    588512        dev_options.period_size=512; 
    589513        dev_options.nb_buffers=3; 
    590         dev_options.iso_buffers=100; 
    591         dev_options.iso_prebuffers=0; 
    592         dev_options.iso_irq_interval=4; 
    593514 
    594515        /* packetizer thread options */ 
     
    628549                        continue; 
    629550                } 
    630 /* 
    631                 if (strcmp(id, "playback_ports") == 0) { 
    632                         if (snd_config_get_type(n) != SND_CONFIG_TYPE_COMPOUND) { 
    633                                 SNDERR("Invalid type for %s", id); 
    634                                 return -EINVAL; 
    635                         } 
    636                         playback_conf = n; 
    637                         continue; 
    638                 } 
    639                 if (strcmp(id, "capture_ports") == 0) { 
    640                         if (snd_config_get_type(n) != SND_CONFIG_TYPE_COMPOUND) { 
    641                                 SNDERR("Invalid type for %s", id); 
    642                                 return -EINVAL; 
    643                         } 
    644                         capture_conf = n; 
    645                         continue; 
    646                 } 
    647 */ 
     551 
    648552                SNDERR("Unknown field %s", id); 
    649553                return -EINVAL;