cwAudioTransforms.h : Added validate_srate()
This commit is contained in:
parent
c42c9aac76
commit
5b1e7d1b82
@ -1261,7 +1261,6 @@ namespace cw
|
|||||||
unsigned posn_smp_idx; // The location of this sample in the original audio file.
|
unsigned posn_smp_idx; // The location of this sample in the original audio file.
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
template< typename sample_t >
|
template< typename sample_t >
|
||||||
sample_t table_read_2( const sample_t* tab, double frac )
|
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<sample_t,srate_t>* p, srate_t expected_srate)
|
||||||
|
{ return p->wt != nullptr && p->wt->srate == expected_srate; }
|
||||||
|
|
||||||
template< typename sample_t, typename srate_t >
|
template< typename sample_t, typename srate_t >
|
||||||
bool is_init(const struct obj_str<sample_t,srate_t>* p)
|
bool is_init(const struct obj_str<sample_t,srate_t>* p)
|
||||||
{ return p->wt != nullptr; }
|
{ return p->wt != nullptr; }
|
||||||
@ -1452,6 +1455,17 @@ namespace cw
|
|||||||
return rc;
|
return rc;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
template< typename sample_t, typename srate_t >
|
||||||
|
bool validate_srate(const struct obj_str<sample_t,srate_t>* p, srate_t expected_srate)
|
||||||
|
{
|
||||||
|
if( p->wt_seq == nullptr )
|
||||||
|
return false;
|
||||||
|
for(unsigned i=0; i<p->wt_seq->wtN; ++i)
|
||||||
|
if( p->wt_seq->wtA[i].srate != expected_srate )
|
||||||
|
return false;
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
template< typename sample_t, typename srate_t >
|
template< typename sample_t, typename srate_t >
|
||||||
bool is_init( const struct obj_str<sample_t,srate_t>* p )
|
bool is_init( const struct obj_str<sample_t,srate_t>* 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 >
|
template< typename sample_t, typename srate_t >
|
||||||
rc_t create(struct obj_str<sample_t,srate_t>* p, unsigned maxChN, const struct multi_ch_wt_seq_str<sample_t,srate_t>* mcs=nullptr )
|
rc_t create(struct obj_str<sample_t,srate_t>* p, unsigned maxChN, const struct multi_ch_wt_seq_str<sample_t,srate_t>* mcs=nullptr, srate_t expected_srate=0 )
|
||||||
{
|
{
|
||||||
rc_t rc = kOkRC;
|
rc_t rc = kOkRC;
|
||||||
|
|
||||||
@ -1595,8 +1610,9 @@ namespace cw
|
|||||||
return rc;
|
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 >
|
template< typename sample_t, typename srate_t >
|
||||||
rc_t setup( struct obj_str<sample_t,srate_t>* p, const struct multi_ch_wt_seq_str<sample_t,srate_t>* mcs )
|
rc_t setup( struct obj_str<sample_t,srate_t>* p, const struct multi_ch_wt_seq_str<sample_t,srate_t>* mcs, srate_t expected_srate=0 )
|
||||||
{
|
{
|
||||||
rc_t rc = kOkRC;
|
rc_t rc = kOkRC;
|
||||||
|
|
||||||
@ -1606,7 +1622,6 @@ namespace cw
|
|||||||
goto errLabel;
|
goto errLabel;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
p->mcs = mcs;
|
p->mcs = mcs;
|
||||||
p->done_fl = false;
|
p->done_fl = false;
|
||||||
p->chN = mcs->chN;
|
p->chN = mcs->chN;
|
||||||
@ -1614,6 +1629,13 @@ namespace cw
|
|||||||
if((rc = wt_seq_osc::init(p->chA+i,mcs->chA + i)) != kOkRC )
|
if((rc = wt_seq_osc::init(p->chA+i,mcs->chA + i)) != kOkRC )
|
||||||
goto errLabel;
|
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:
|
errLabel:
|
||||||
if( rc != kOkRC )
|
if( rc != kOkRC )
|
||||||
rc = cwLogError(rc,"multi-ch-wt-osc setup failed.");
|
rc = cwLogError(rc,"multi-ch-wt-osc setup failed.");
|
||||||
@ -1621,6 +1643,19 @@ namespace cw
|
|||||||
return rc;
|
return rc;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
template< typename sample_t, typename srate_t >
|
||||||
|
bool validate_srate(const struct obj_str<sample_t,srate_t>* p, srate_t expected_srate)
|
||||||
|
{
|
||||||
|
if( p->chA == nullptr )
|
||||||
|
return false;
|
||||||
|
|
||||||
|
for(unsigned i=0; i<p->chN; ++i)
|
||||||
|
if( !validate_srate(p->chA+i,expected_srate) )
|
||||||
|
return false;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
template< typename sample_t, typename srate_t >
|
template< typename sample_t, typename srate_t >
|
||||||
rc_t is_done( struct obj_str<sample_t,srate_t>* p )
|
rc_t is_done( struct obj_str<sample_t,srate_t>* p )
|
||||||
{ return p->done_fl; }
|
{ return p->done_fl; }
|
||||||
|
Loading…
Reference in New Issue
Block a user