Show
Ignore:
Timestamp:
06/06/09 15:59:48 (3 years ago)
Author:
Nedko Arnaudov <nedko@…>
Children:
32f245638cfcf98a8ed5832fdf305da107dc6d7e
Parents:
82d3db57c220e736e7320faeb86381299e1b08e9
git-committer:
Nedko Arnaudov <nedko@arnaudov.name> / 2009-06-06T15:59:48Z+0300
Message:

Stereo plugin

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • lv2filter.c

    r3969583 r6138b26  
    3434#define BANDS_COUNT 4 
    3535 
    36 #define LV2_PORT_AUDIO_IN    0 
    37 #define LV2_PORT_AUDIO_OUT   1 
    38 #define LV2_PORTS_COUNT      (2 + GLOBAL_PARAMETERS_COUNT + BANDS_COUNT * BAND_PARAMETERS_COUNT) 
     36#define LV2_PORT_MONO_AUDIO_IN       0 
     37#define LV2_PORT_MONO_AUDIO_OUT      1 
     38#define LV2_MONO_AUDIO_PORT_COUNT    2 
     39#define LV2_PORTS_COUNT_MONO         (LV2_MONO_AUDIO_PORT_COUNT + GLOBAL_PARAMETERS_COUNT + BANDS_COUNT * BAND_PARAMETERS_COUNT) 
     40 
     41#define LV2_PORT_LEFT_AUDIO_IN       0 
     42#define LV2_PORT_RIGHT_AUDIO_IN      1 
     43#define LV2_PORT_LEFT_AUDIO_OUT      2 
     44#define LV2_PORT_RIGHT_AUDIO_OUT     3 
     45#define LV2_STEREO_AUDIO_PORT_COUNT  4 
     46#define LV2_PORTS_COUNT_STEREO       (LV2_STEREO_AUDIO_PORT_COUNT + GLOBAL_PARAMETERS_COUNT + BANDS_COUNT * BAND_PARAMETERS_COUNT) 
    3947 
    4048struct lv2filter 
    4149{ 
     50  bool stereo; 
    4251  filter_handle filter; 
     52  filter_handle filter_right; 
    4353  char * bundle_path; 
    4454  const float * audio_in; 
     55  const float * audio_in_right; 
    4556  float * audio_out; 
     57  float * audio_out_right; 
    4658  const LV2_Feature * const * host_features; 
    4759}; 
     
    5870 
    5971  LOG_DEBUG("lv2filter_create_plugin_instance() called."); 
     72  LOG_DEBUG("uri = \"%s\"", descriptor->URI); 
    6073  LOG_DEBUG("sample_rate = %f", sample_rate); 
    6174  LOG_DEBUG("bundle_path = \"%s\"", bundle_path); 
     
    7487    goto fail; 
    7588  } 
    76    
     89 
     90  if (strcmp(descriptor->URI, LV2FILTER_STEREO_URI) == 0) 
     91  { 
     92    lv2filter_ptr->stereo = true; 
     93  } 
     94  else if (strcmp(descriptor->URI, LV2FILTER_MONO_URI) == 0) 
     95  { 
     96    lv2filter_ptr->stereo = false; 
     97  } 
     98  else 
     99  { 
     100    assert(false); 
     101    goto fail_free_instance; 
     102  } 
     103 
    77104  lv2filter_ptr->host_features = host_features; 
    78105 
     
    88115  } 
    89116 
     117  if (lv2filter_ptr->stereo) 
     118  { 
     119    if (!filter_create(sample_rate, BANDS_COUNT, &lv2filter_ptr->filter_right)) 
     120    { 
     121      goto fail_destroy_filter; 
     122    } 
     123  } 
     124 
    90125  return (LV2_Handle)lv2filter_ptr; 
     126 
     127fail_destroy_filter: 
     128  filter_destroy(lv2filter_ptr->filter); 
    91129 
    92130fail_free_bundle_path: 
     
    112150  LOG_DEBUG("lv2filter_run"); 
    113151  filter_run( 
    114     lv2filter_ptr->filter,  
     152    lv2filter_ptr->filter, 
    115153    lv2filter_ptr->audio_in, 
    116154    lv2filter_ptr->audio_out, 
    117155    samples_count); 
     156 
     157  if (lv2filter_ptr->stereo) 
     158  { 
     159    filter_run( 
     160      lv2filter_ptr->filter_right, 
     161      lv2filter_ptr->audio_in_right, 
     162      lv2filter_ptr->audio_out_right, 
     163      samples_count); 
     164  } 
    118165} 
    119166 
     
    123170{ 
    124171  filter_destroy(lv2filter_ptr->filter); 
     172 
     173  if (lv2filter_ptr->stereo) 
     174  { 
     175    filter_destroy(lv2filter_ptr->filter_right); 
     176  } 
     177 
    125178  free(lv2filter_ptr->bundle_path); 
    126179  free(lv2filter_ptr); 
     
    135188  LOG_DEBUG("lv2filter_connect_port %u %p", (unsigned int)port, data_location); 
    136189 
    137   if (port >= LV2_PORTS_COUNT) 
    138   { 
    139     assert(0); 
    140     return; 
    141   } 
    142  
    143   if (port == LV2_PORT_AUDIO_IN) 
    144   { 
    145     lv2filter_ptr->audio_in = data_location; 
    146   } 
    147   else if (port == LV2_PORT_AUDIO_OUT) 
    148   { 
    149     lv2filter_ptr->audio_out = data_location; 
     190  if (lv2filter_ptr->stereo) 
     191  { 
     192    if (port >= LV2_PORTS_COUNT_STEREO) 
     193    { 
     194      assert(0); 
     195      return; 
     196    } 
     197 
     198    if (port == LV2_PORT_LEFT_AUDIO_IN) 
     199    { 
     200      lv2filter_ptr->audio_in = data_location; 
     201    } 
     202    else if (port == LV2_PORT_LEFT_AUDIO_OUT) 
     203    { 
     204      lv2filter_ptr->audio_out = data_location; 
     205    } 
     206    else if (port == LV2_PORT_RIGHT_AUDIO_IN) 
     207    { 
     208      lv2filter_ptr->audio_in_right = data_location; 
     209    } 
     210    else if (port == LV2_PORT_RIGHT_AUDIO_OUT) 
     211    { 
     212      lv2filter_ptr->audio_out_right = data_location; 
     213    } 
     214    else 
     215    { 
     216      assert(port >= LV2_STEREO_AUDIO_PORT_COUNT); 
     217      port -= LV2_STEREO_AUDIO_PORT_COUNT; 
     218      if (port < GLOBAL_PARAMETERS_COUNT) 
     219      { 
     220        filter_connect_global_parameter(lv2filter_ptr->filter, port, data_location); 
     221        filter_connect_global_parameter(lv2filter_ptr->filter_right, port, data_location); 
     222      } 
     223      else 
     224      { 
     225        assert(port >= GLOBAL_PARAMETERS_COUNT); 
     226        port -= GLOBAL_PARAMETERS_COUNT; 
     227 
     228        filter_connect_band_parameter(lv2filter_ptr->filter, port / BANDS_COUNT, port % BANDS_COUNT, data_location); 
     229        filter_connect_band_parameter(lv2filter_ptr->filter_right, port / BANDS_COUNT, port % BANDS_COUNT, data_location); 
     230      } 
     231    } 
    150232  } 
    151233  else 
    152234  { 
    153     port -= 2; 
    154     if (port < GLOBAL_PARAMETERS_COUNT) 
    155     { 
    156       filter_connect_global_parameter(lv2filter_ptr->filter, port, data_location); 
     235    if (port >= LV2_PORTS_COUNT_MONO) 
     236    { 
     237      assert(0); 
     238      return; 
     239    } 
     240 
     241    if (port == LV2_PORT_MONO_AUDIO_IN) 
     242    { 
     243      lv2filter_ptr->audio_in = data_location; 
     244    } 
     245    else if (port == LV2_PORT_MONO_AUDIO_OUT) 
     246    { 
     247      lv2filter_ptr->audio_out = data_location; 
    157248    } 
    158249    else 
    159250    { 
    160       port -= GLOBAL_PARAMETERS_COUNT; 
    161  
    162       filter_connect_band_parameter(lv2filter_ptr->filter, port / BANDS_COUNT, port % BANDS_COUNT, data_location); 
     251      port -= LV2_MONO_AUDIO_PORT_COUNT; 
     252      if (port < GLOBAL_PARAMETERS_COUNT) 
     253      { 
     254        filter_connect_global_parameter(lv2filter_ptr->filter, port, data_location); 
     255      } 
     256      else 
     257      { 
     258        port -= GLOBAL_PARAMETERS_COUNT; 
     259 
     260        filter_connect_band_parameter(lv2filter_ptr->filter, port / BANDS_COUNT, port % BANDS_COUNT, data_location); 
     261      } 
    163262    } 
    164263  }