[beast: 11/13] BSE: move Bse.collect_stats methods into bseapi.idl and fix offset guard
- From: Tim Janik <timj src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [beast: 11/13] BSE: move Bse.collect_stats methods into bseapi.idl and fix offset guard
- Date: Thu, 31 Aug 2017 23:04:14 +0000 (UTC)
commit 80b29b1b8cce5df5612e4d9cd41acd9d36e40d17
Author: Tim Janik <timj gnu org>
Date: Fri Sep 1 00:58:24 2017 +0200
BSE: move Bse.collect_stats methods into bseapi.idl and fix offset guard
Signed-off-by: Tim Janik <timj gnu org>
bse/Makefile.am | 1 -
bse/bseapi.idl | 2 +-
bse/bseeditablesample.cc | 49 ++++++++++++++++++++++++
bse/bseeditablesample.hh | 15 ++++---
bse/bseeditablesample.proc | 90 --------------------------------------------
5 files changed, 58 insertions(+), 99 deletions(-)
---
diff --git a/bse/Makefile.am b/bse/Makefile.am
index 57fe7cc..fed5ad8 100644
--- a/bse/Makefile.am
+++ b/bse/Makefile.am
@@ -113,7 +113,6 @@ idl_dummy_files = $(strip \
)
# BSE procedure sources
bse_proc_sources = $(strip \
- bseeditablesample.proc \
bsejanitor.proc \
bsesource.proc \
bseitem.proc \
diff --git a/bse/bseapi.idl b/bse/bseapi.idl
index 721b8fc..942ee39 100644
--- a/bse/bseapi.idl
+++ b/bse/bseapi.idl
@@ -817,7 +817,7 @@ interface EditableSample : Item {
* @param max-pairs Maximum number of (min, max) pairs to collect
* @return Block of samples
*/
- //FloatSeq collect_stats (int64 voffset, float64 offset_scale, int64 block_size, int64 stepping, int64
max_pairs);
+ FloatSeq collect_stats (int64 voffset, float64 offset_scale, int64 block_size, int64 stepping, int64
max_pairs);
void close (); ///< Close an opened sample.
int64 get_length (); ///< Return the number of values in the sample.
int64 get_n_channels (); ///< Return the number of channels in the sample.
diff --git a/bse/bseeditablesample.cc b/bse/bseeditablesample.cc
index 6235a58..ccc68af 100644
--- a/bse/bseeditablesample.cc
+++ b/bse/bseeditablesample.cc
@@ -238,4 +238,53 @@ EditableSampleImpl::open ()
return error;
}
+FloatSeq
+EditableSampleImpl::collect_stats (int64 voffset, double offset_scale, int64 block_size, int64 stepping,
int64 max_pairs)
+{
+ BseEditableSample *self = as<BseEditableSample*>();
+ GslDataCache *dcache = NULL;
+ if (BSE_EDITABLE_SAMPLE_OPENED (self) && self->wchunk)
+ dcache = self->wchunk->dcache;
+ FloatSeq floats;
+ floats.resize (max_pairs * 2, 0);
+ const ssize_t dhandle_length = gsl_data_handle_length (dcache->dhandle);
+ if (stepping < 1 || !dcache || voffset + block_size > dhandle_length)
+ return floats;
+ GslDataCacheNode *dnode = gsl_data_cache_ref_node (dcache, voffset, GSL_DATA_CACHE_DEMAND_LOAD);
+ ssize_t j, dnode_length = dcache->node_size;
+ for (j = 0; j < max_pairs; j++)
+ {
+ ssize_t i, cur_offset = j * offset_scale;
+ float min = +1, max = -1;
+ // keep alignment across offset scaling
+ cur_offset /= stepping;
+ cur_offset = voffset + cur_offset * stepping;
+ // collect stats for one block
+ for (i = cur_offset; i < cur_offset + block_size; i += stepping)
+ {
+ size_t pos;
+ if (i < dnode->offset || i >= dnode->offset + dnode_length)
+ {
+ gsl_data_cache_unref_node (dcache, dnode);
+ if (i >= dhandle_length)
+ dnode = NULL;
+ else
+ dnode = gsl_data_cache_ref_node (dcache, i, // demand_load the first block (j==0)
+ j == 0 ? GSL_DATA_CACHE_DEMAND_LOAD : GSL_DATA_CACHE_PEEK);
+ if (!dnode)
+ goto break_loops;
+ }
+ pos = i - dnode->offset;
+ min = MIN (min, dnode->data[pos]);
+ max = MAX (max, dnode->data[pos]);
+ }
+ floats[j * 2] = min;
+ floats[j * 2 + 1] = max;
+ }
+ gsl_data_cache_unref_node (dcache, dnode);
+ break_loops:
+ floats.resize (j * 2);
+ return floats;
+}
+
} // Bse
diff --git a/bse/bseeditablesample.hh b/bse/bseeditablesample.hh
index 28c76f4..94d6e05 100644
--- a/bse/bseeditablesample.hh
+++ b/bse/bseeditablesample.hh
@@ -30,14 +30,15 @@ namespace Bse {
class EditableSampleImpl : public ItemImpl, public virtual EditableSampleIface {
protected:
- virtual ~EditableSampleImpl ();
+ virtual ~EditableSampleImpl ();
public:
- explicit EditableSampleImpl (BseObject*);
- virtual void close () override;
- virtual int64 get_length () override;
- virtual int64 get_n_channels () override;
- virtual double get_osc_freq () override;
- virtual Error open () override;
+ explicit EditableSampleImpl (BseObject*);
+ virtual FloatSeq collect_stats (int64 voffset, double offset_scale, int64 block_size, int64
stepping, int64 max_pairs) override;
+ virtual void close () override;
+ virtual int64 get_length () override;
+ virtual int64 get_n_channels () override;
+ virtual double get_osc_freq () override;
+ virtual Error open () override;
};
} // Bse
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]