From 5b1e7d1b8239f48ad3ae608a1b7b930c442ee1a9 Mon Sep 17 00:00:00 2001 From: kevin Date: Fri, 2 Aug 2024 13:34:15 -0400 Subject: [PATCH] cwAudioTransforms.h : Added validate_srate() --- cwAudioTransforms.h | 43 +++++++++++++++++++++++++++++++++++++++---- 1 file changed, 39 insertions(+), 4 deletions(-) diff --git a/cwAudioTransforms.h b/cwAudioTransforms.h index 52c78ee..81dbbb4 100644 --- a/cwAudioTransforms.h +++ b/cwAudioTransforms.h @@ -1261,7 +1261,6 @@ namespace cw unsigned posn_smp_idx; // The location of this sample in the original audio file. }; - template< typename sample_t > sample_t table_read_2( const sample_t* tab, double frac ) { @@ -1297,6 +1296,10 @@ namespace cw }; + template< typename sample_t, typename srate_t > + bool validate_srate(const struct obj_str* p, srate_t expected_srate) + { return p->wt != nullptr && p->wt->srate == expected_srate; } + template< typename sample_t, typename srate_t > bool is_init(const struct obj_str* p) { return p->wt != nullptr; } @@ -1452,6 +1455,17 @@ namespace cw return rc; } + template< typename sample_t, typename srate_t > + bool validate_srate(const struct obj_str* p, srate_t expected_srate) + { + if( p->wt_seq == nullptr ) + return false; + for(unsigned i=0; iwt_seq->wtN; ++i) + if( p->wt_seq->wtA[i].srate != expected_srate ) + return false; + + return true; + } template< typename sample_t, typename srate_t > bool is_init( const struct obj_str* p ) @@ -1565,8 +1579,9 @@ namespace cw }; + // if mcs != nullptr and expected_srate is non-zero then the expected_srate will be validated template< typename sample_t, typename srate_t > - rc_t create(struct obj_str* p, unsigned maxChN, const struct multi_ch_wt_seq_str* mcs=nullptr ) + rc_t create(struct obj_str* p, unsigned maxChN, const struct multi_ch_wt_seq_str* mcs=nullptr, srate_t expected_srate=0 ) { rc_t rc = kOkRC; @@ -1595,8 +1610,9 @@ namespace cw return rc; } + // if mcs != nullptr and expected_srate is non-zero then the expected_srate will be validated template< typename sample_t, typename srate_t > - rc_t setup( struct obj_str* p, const struct multi_ch_wt_seq_str* mcs ) + rc_t setup( struct obj_str* p, const struct multi_ch_wt_seq_str* mcs, srate_t expected_srate=0 ) { rc_t rc = kOkRC; @@ -1605,7 +1621,6 @@ namespace cw rc = cwLogError(kInvalidArgRC,"Invalid multi-ch-wt-osc channel count. (%i > %i)",mcs->chN,p->chAllocN); goto errLabel; } - p->mcs = mcs; p->done_fl = false; @@ -1614,6 +1629,13 @@ namespace cw if((rc = wt_seq_osc::init(p->chA+i,mcs->chA + i)) != kOkRC ) goto errLabel; + if( mcs != nullptr && expected_srate != 0 ) + if( !validate_srate(p,expected_srate) ) + { + rc = cwLogError(kInvalidArgRC,"The srate is not valid. All wave tables do not share the same sample rate."); + goto errLabel; + } + errLabel: if( rc != kOkRC ) rc = cwLogError(rc,"multi-ch-wt-osc setup failed."); @@ -1621,6 +1643,19 @@ namespace cw return rc; } + template< typename sample_t, typename srate_t > + bool validate_srate(const struct obj_str* p, srate_t expected_srate) + { + if( p->chA == nullptr ) + return false; + + for(unsigned i=0; ichN; ++i) + if( !validate_srate(p->chA+i,expected_srate) ) + return false; + return true; + } + + template< typename sample_t, typename srate_t > rc_t is_done( struct obj_str* p ) { return p->done_fl; }