BEAST/BSE - Better Audio System and Sound Engine  0.8.2
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines
gsldatahandle.hh
Go to the documentation of this file.
00001  // Licensed GNU LGPL v2.1 or later: http://www.gnu.org/licenses/lgpl.html
00002 #ifndef __GSL_DATA_HANDLE_H__
00003 #define __GSL_DATA_HANDLE_H__
00004 
00005 #include <bse/bseutils.hh>
00006 
00007 G_BEGIN_DECLS
00008 
00009 
00010 /* --- macros --- */
00011 #define GSL_DATA_HANDLE_OPENED(handle)      (((GslDataHandle*) (handle))->open_count > 0)
00012 #define GSL_DATA_HANDLE_READ_LINEAR(handle) (((GslDataHandle*) (handle))->vtable->coarse_seek != NULL)
00013 
00014 
00015 /* --- typedefs & structures --- */
00016 typedef struct {
00017   guint         n_channels;
00018   int64         n_values;
00019   gchar       **xinfos;
00020   guint         bit_depth : 8;
00021   guint         needs_cache : 1;
00022   gfloat        mix_freq;
00023 } GslDataHandleSetup;
00024 struct _GslDataHandle
00025 {
00026   /* constant members */
00027   GslDataHandleFuncs *vtable;
00028   gchar              *name;
00029   /* common members */
00030   Bse::Spinlock       spinlock;
00031   guint               ref_count;
00032   guint               open_count;
00033   /* opened data handle setup (open_count > 0) */
00034   GslDataHandleSetup  setup;
00035 };
00036 typedef void (*GslDataHandleRecurse)    (GslDataHandle          *data_handle,
00037                                          gpointer                data);
00038 struct _GslDataHandleFuncs
00039 {
00040   BseErrorType   (*open)                (GslDataHandle          *data_handle,
00041                                          GslDataHandleSetup     *setup);
00042   int64          (*read)                (GslDataHandle          *data_handle,
00043                                          int64                   voffset, /* in values */
00044                                          int64                   n_values,
00045                                          gfloat                 *values);
00046   void           (*close)               (GslDataHandle          *data_handle);
00047   GslDataHandle* (*get_source)          (GslDataHandle          *data_handle);
00048   int64          (*get_state_length)    (GslDataHandle          *data_handle);
00049   void           (*destroy)             (GslDataHandle          *data_handle);
00050 };
00051 
00052 
00053 
00054 /* --- standard functions --- */
00055 GslDataHandle*    gsl_data_handle_ref               (GslDataHandle        *dhandle);
00056 void              gsl_data_handle_unref             (GslDataHandle        *dhandle);
00057 BseErrorType      gsl_data_handle_open              (GslDataHandle        *dhandle);
00058 void              gsl_data_handle_close             (GslDataHandle        *dhandle);
00059 int64             gsl_data_handle_length            (GslDataHandle        *data_handle);
00060 #define           gsl_data_handle_n_values(          dh) \
00061                                                      gsl_data_handle_length (dh)
00062 guint             gsl_data_handle_n_channels        (GslDataHandle        *data_handle);
00063 guint             gsl_data_handle_bit_depth         (GslDataHandle        *data_handle);
00064 gfloat            gsl_data_handle_mix_freq          (GslDataHandle        *data_handle);
00065 gfloat            gsl_data_handle_osc_freq          (GslDataHandle        *data_handle);
00066 gfloat            gsl_data_handle_volume            (GslDataHandle        *data_handle);
00067 gfloat            gsl_data_handle_fine_tune         (GslDataHandle        *data_handle);
00068 const gchar*      gsl_data_handle_name              (GslDataHandle        *data_handle);
00069 int64             gsl_data_handle_read              (GslDataHandle        *data_handle,
00070                                                      int64                 value_offset,
00071                                                      int64                 n_values,
00072                                                      gfloat               *values);
00073 int64             gsl_data_handle_get_state_length  (GslDataHandle        *dhandle);
00074 GslDataHandle*    gsl_data_handle_get_source        (GslDataHandle        *dhandle);
00075 GslDataHandle*    gsl_data_handle_new_scale         (GslDataHandle        *src_handle,
00076                                                      double                factor);
00077 GslDataHandle*    gsl_data_handle_new_cut           (GslDataHandle        *src_handle,
00078                                                      int64                 cut_offset,
00079                                                      int64                 n_cut_values);
00080 GslDataHandle*    gsl_data_handle_new_crop          (GslDataHandle        *src_handle,
00081                                                      int64                 n_head_cut,
00082                                                      int64                 n_tail_cut);
00083 GslDataHandle*    gsl_data_handle_new_reverse       (GslDataHandle        *src_handle);
00084 GslDataHandle*    gsl_data_handle_new_insert        (GslDataHandle        *src_handle,
00085                                                      guint                 pasted_bit_depth,
00086                                                      int64                 insertion_offset,
00087                                                      int64                 n_paste_values,
00088                                                      const gfloat         *paste_values,
00089                                                      void                (*free) (gpointer values));
00090 GslDataHandle*    gsl_data_handle_new_mem           (guint                 n_channels,
00091                                                      guint                 bit_depth,
00092                                                      gfloat                mix_freq,
00093                                                      gfloat                osc_freq,
00094                                                      int64                 n_values,
00095                                                      const gfloat         *values,
00096                                                      void                (*free) (gpointer values));
00097 GslDataHandle*    gsl_data_handle_new_dcached       (GslDataCache         *dcache);
00098 /* cheap and inefficient, testpurpose only */
00099 GslDataHandle*    gsl_data_handle_new_looped        (GslDataHandle        *src_handle,
00100                                                      int64                 loop_first,
00101                                                      int64                 loop_last);
00102 
00103 /* --- factor 2 resampling datahandles --- */
00104 GslDataHandle*    bse_data_handle_new_upsample2     (GslDataHandle  *src_handle,        // implemented in bsedatahandle-resample.cc
00105                                                      int             precision_bits);
00106 GslDataHandle*    bse_data_handle_new_downsample2   (GslDataHandle  *src_handle,
00107                                                      int             precision_bits);   // implemented in bsedatahandle-resample.cc
00108 
00109 GslDataHandle*    bse_data_handle_new_fir_highpass  (GslDataHandle *src_handle,         // implemented in bsedatahandle-fir.cc
00110                                                      gdouble        cutoff_freq,
00111                                                      guint          order);
00112 GslDataHandle*    bse_data_handle_new_fir_lowpass   (GslDataHandle *src_handle,         // implemented in bsedatahandle-fir.cc
00113                                                      gdouble        cutoff_freq,
00114                                                      guint          order);
00115 gdouble           bse_data_handle_fir_response_db   (GslDataHandle *fir_handle,         // implemented in bsedatahandle-fir.cc
00116                                                      gdouble        freq);
00117 
00118 /* --- xinfo handling --- */
00119 GslDataHandle* gsl_data_handle_new_add_xinfos       (GslDataHandle *src_handle,
00120                                                      gchar        **xinfos);
00121 GslDataHandle* gsl_data_handle_new_remove_xinfos    (GslDataHandle *src_handle,
00122                                                      gchar        **xinfos);
00123 GslDataHandle* gsl_data_handle_new_clear_xinfos     (GslDataHandle *src_handle);
00124 
00125 
00126 /* --- wave specific functions --- */
00127 typedef enum    /*< skip >*/
00128 {
00129   GSL_WAVE_FORMAT_NONE,
00130   GSL_WAVE_FORMAT_UNSIGNED_8,
00131   GSL_WAVE_FORMAT_SIGNED_8,
00132   GSL_WAVE_FORMAT_ALAW,
00133   GSL_WAVE_FORMAT_ULAW,
00134   GSL_WAVE_FORMAT_UNSIGNED_12,
00135   GSL_WAVE_FORMAT_SIGNED_12,
00136   GSL_WAVE_FORMAT_UNSIGNED_16,
00137   GSL_WAVE_FORMAT_SIGNED_16,
00138   GSL_WAVE_FORMAT_SIGNED_24,
00139   GSL_WAVE_FORMAT_SIGNED_24_PAD4,
00140   GSL_WAVE_FORMAT_SIGNED_32,
00141   GSL_WAVE_FORMAT_FLOAT,
00142   GSL_WAVE_FORMAT_LAST
00143 } GslWaveFormatType;
00144 #define GSL_WAVE_FORMAT_IS_LAW(f)       ((f) == GSL_WAVE_FORMAT_ALAW || (f) == GSL_WAVE_FORMAT_ULAW)
00145 
00146 const gchar*      gsl_wave_format_to_string     (GslWaveFormatType format);
00147 GslWaveFormatType gsl_wave_format_from_string   (const gchar      *string);
00148 GslDataHandle*    gsl_wave_handle_new           (const gchar      *file_name,
00149                                                  guint             n_channels,
00150                                                  GslWaveFormatType format,
00151                                                  guint             byte_order,
00152                                                  gfloat            mix_freq,
00153                                                  gfloat            osc_freq,
00154                                                  int64             byte_offset,
00155                                                  int64             n_values,
00156                                                  gchar           **xinfos);
00157 GslDataHandle*    gsl_wave_handle_new_zoffset   (const gchar      *file_name,
00158                                                  guint             n_channels,
00159                                                  GslWaveFormatType format,
00160                                                  guint             byte_order,
00161                                                  gfloat            mix_freq,
00162                                                  gfloat            osc_freq,
00163                                                  int64             byte_offset,
00164                                                  int64             byte_size,
00165                                                  gchar           **xinfos);
00166 guint             gsl_wave_format_bit_depth     (GslWaveFormatType format);
00167 guint             gsl_wave_format_byte_width    (GslWaveFormatType format);
00168 
00169 
00170 /* --- data handle optimization jobs --- */
00171 gboolean        gsl_data_handle_needs_cache     (GslDataHandle  *data_handle);
00172 
00173 
00174 /* --- auxillary functions --- */
00175 gboolean        gsl_data_handle_common_init     (GslDataHandle    *dhandle,
00176                                                  const gchar      *file_name);
00177 void            gsl_data_handle_common_free     (GslDataHandle    *dhandle);
00178 
00179 
00180 G_END_DECLS
00181 
00182 #endif /* __GSL_DATA_HANDLE_H__ */
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines