Aufgrund eines Versionsupdates wird GitLab am 01.04. zwischen 9:00 und 9:30 Uhr kurzzeitig nicht zur Verfügung stehen. / Due to a version upgrade, GitLab won't be accessible at 01.04. between 9:00 and 9:30 a.m.

ITASampleFrame.cpp 14.8 KB
Newer Older
Jonas Stienen's avatar
Jonas Stienen committed
1 2
#include <ITASampleFrame.h>
#include <ITAAudiofileReader.h>
3
#include <ITAAudiofileWriter.h>
Jonas Stienen's avatar
Jonas Stienen committed
4 5 6 7 8 9 10

#include <assert.h>
#include <sstream>

#include <ITAException.h>

ITASampleFrame::ITASampleFrame()
11 12 13 14
	: m_iChannels( 0 )
	, m_iLength( 0 )
{
}
Jonas Stienen's avatar
Jonas Stienen committed
15

16
ITASampleFrame::ITASampleFrame( const int iChannels, const int iLength, const bool bZeroinit /* = true */)
17 18
	: m_iChannels( 0 )
	, m_iLength( 0 )
Jonas Stienen's avatar
Jonas Stienen committed
19
{
20
	Init( iChannels, iLength, bZeroinit );
Jonas Stienen's avatar
Jonas Stienen committed
21 22 23
}


24 25 26
ITASampleFrame::ITASampleFrame( const ITASampleFrame* pSource )
	: m_iChannels( 0 )
	, m_iLength( 0 )
Jonas Stienen's avatar
Jonas Stienen committed
27 28 29 30
{
	*this = *pSource;
}

31 32 33
ITASampleFrame::ITASampleFrame( const ITASampleFrame& sbSource )
	: m_iChannels( 0 )
	, m_iLength( 0 )
Jonas Stienen's avatar
Jonas Stienen committed
34 35 36 37
{
	*this = sbSource;
}

38
ITASampleFrame::ITASampleFrame( const std::string& sFilePath )
Jonas Stienen's avatar
Jonas Stienen committed
39
{
40
	Load( sFilePath );
Jonas Stienen's avatar
Jonas Stienen committed
41 42
}

43 44
ITASampleFrame::~ITASampleFrame()
{
Jonas Stienen's avatar
Jonas Stienen committed
45 46
}

47 48 49
bool ITASampleFrame::empty() const
{
	return ( ( m_iChannels == 0 ) || ( m_iLength == 0 ) );
Jonas Stienen's avatar
Jonas Stienen committed
50 51
}

52
int ITASampleFrame::GetNumChannels() const
53
{
Jonas Stienen's avatar
Jonas Stienen committed
54 55 56
	return m_iChannels;
}

57 58
int ITASampleFrame::length() const
{
Jonas Stienen's avatar
Jonas Stienen committed
59 60 61
	return m_iLength;
}

62
void ITASampleFrame::Init( int iChannels, int iLength, bool bZeroinit )
Jonas Stienen's avatar
Jonas Stienen committed
63 64 65 66 67 68
{
	assert( iChannels >= 0 );
	assert( iLength >= 0 );

	// TODO: Mit ein wenig cleverness knnte dies ohne Vollstndiges Abrumen gehen.
	//       Die Frage ist: Wer's braucht?
69
	if( ( m_iChannels > 0 ) || ( m_iLength > 0 ) ) free();
Jonas Stienen's avatar
Jonas Stienen committed
70

71 72 73 74 75 76
	m_vChannels.resize( iChannels );
	for( int i = 0; i < iChannels; i++ )
	{
		m_vChannels[ i ].m_pParent = NULL;
		m_vChannels[ i ].Init( iLength, bZeroinit );
		m_vChannels[ i ].m_pParent = this;
Jonas Stienen's avatar
Jonas Stienen committed
77 78 79 80 81 82
	}

	m_iChannels = iChannels;
	m_iLength = iLength;
}

83 84 85 86 87 88 89
void ITASampleFrame::Load( const std::string& sFilePath )
{
	double dSampleRate;
	Load( sFilePath, dSampleRate );
}

void ITASampleFrame::Load( const std::string& sFilePath, double& dSampleRate )
Jonas Stienen's avatar
Jonas Stienen committed
90
{
91
#ifdef ITABASE_WITH_SNDFILE
Jonas Stienen's avatar
Jonas Stienen committed
92
	ITAAudiofileReader* pReader( NULL );
93 94
	try
	{
Jonas Stienen's avatar
Jonas Stienen committed
95
		// Datei ffnen
96
		pReader = ITAAudiofileReader::create( sFilePath );
Jonas Stienen's avatar
Jonas Stienen committed
97
		ITAAudiofileProperties oProps = pReader->getAudiofileProperties();
98
		dSampleRate = oProps.dSampleRate;
99
		init( ( int ) oProps.iChannels, ( int ) oProps.iLength, false );
Jonas Stienen's avatar
Jonas Stienen committed
100 101

		// Zielzeiger zusammenstellen
102 103
		std::vector<float*> vpfDest( oProps.iChannels );
		for( int i = 0; i < oProps.iChannels; i++ )
Jonas Stienen's avatar
Jonas Stienen committed
104 105 106
			vpfDest[ i ] = m_vChannels[ i ].GetData();

		// Daten einlesen
107
		pReader->read( oProps.iLength, vpfDest );
Jonas Stienen's avatar
Jonas Stienen committed
108 109

	}
110 111
	catch( ... )
	{
Jonas Stienen's avatar
Jonas Stienen committed
112 113 114 115 116 117 118
		// Alle Daten verwerfen
		delete pReader;
		free();
		throw;
	}

	delete pReader;
119 120 121
#else
	ITA_EXCEPT1( NOT_IMPLEMENTED, "ITASampleFrame::Store() function not available without libsndfile" );
#endif
Jonas Stienen's avatar
Jonas Stienen committed
122 123
}

124 125 126 127 128 129
void ITASampleFrame::Store( const std::string& sFilePath, double dSamplingRate ) const
{
#ifdef ITABASE_WITH_SNDFILE
	ITAAudiofileWriter* pWriter( NULL );
	try
	{
Jonas Stienen's avatar
Jonas Stienen committed
130
		ITAAudiofileProperties oProps;
131 132 133
		oProps.dSampleRate = dSamplingRate;
		oProps.eDomain = ITADomain::ITA_TIME_DOMAIN;
		oProps.eQuantization = ITAQuantization::ITA_FLOAT;
134 135
		oProps.iChannels = ( unsigned int ) m_iChannels;
		oProps.iLength = ( unsigned int ) m_iLength;
136
		pWriter = ITAAudiofileWriter::create( sFilePath, oProps );
137

138 139 140
		std::vector< const float* > vpfDest( oProps.iChannels );
		for( int i = 0; i < oProps.iChannels; i++ )
			vpfDest[ i ] = m_vChannels[ i ].data();
Jonas Stienen's avatar
Jonas Stienen committed
141

142
		pWriter->write( oProps.iLength, vpfDest );
Jonas Stienen's avatar
Jonas Stienen committed
143

144
	}
145
	catch( ... )
146
	{
Jonas Stienen's avatar
Jonas Stienen committed
147 148 149 150 151
		delete pWriter;
		throw;
	}

	delete pWriter;
152 153 154
#else
	ITA_EXCEPT1( NOT_IMPLEMENTED, "ITASampleFrame::Store() function not available without libsndfile" );
#endif
Jonas Stienen's avatar
Jonas Stienen committed
155 156
}

157 158 159 160 161 162 163
void ITASampleFrame::free()
{
	m_vChannels.clear();
	m_iChannels = 0;
	m_iLength = 0;
};

164 165
void ITASampleFrame::fill( float fValue )
{
166 167
	for( ch_it it = m_vChannels.begin(); it != m_vChannels.end(); ++it )
		it->Fill( fValue );
Jonas Stienen's avatar
Jonas Stienen committed
168 169
}

170 171 172 173
void ITASampleFrame::fill( int iOffset, int iCount, float fValue )
{
	for( ch_it it = m_vChannels.begin(); it != m_vChannels.end(); ++it )
		it->Fill( iOffset, iCount, fValue );
Jonas Stienen's avatar
Jonas Stienen committed
174 175 176
}

void ITASampleFrame::zero() {
177
	fill( 0 );
Jonas Stienen's avatar
Jonas Stienen committed
178 179
}

180
void ITASampleFrame::zero( int iOffset, int iCount )
181
{
182
	fill( iOffset, iCount, 0.0f );
Jonas Stienen's avatar
Jonas Stienen committed
183 184 185
}

void ITASampleFrame::identity() {
186 187
	for( ch_it it = m_vChannels.begin(); it != m_vChannels.end(); ++it )
		it->Identity();
Jonas Stienen's avatar
Jonas Stienen committed
188 189
}

190 191 192 193
void ITASampleFrame::fade( int iOffset, int iCount, int iFadeDirection, int iFadeFunction )
{
	for( int i = 0; i < m_iChannels; i++ )
		m_vChannels[ i ].Fade( iOffset, iCount, iFadeDirection, iFadeFunction );
Jonas Stienen's avatar
Jonas Stienen committed
194 195
}

196 197 198 199
void ITASampleFrame::crossfade( const ITASampleFrame* psfSrc, int iOffset, int iCount, int iFadeDirection, int iFadeFunction )
{
	if( !psfSrc ) ITA_EXCEPT1( INVALID_PARAMETER, "Nullpointer passed" );
	if( psfSrc->channels() != m_iChannels )  ITA_EXCEPT1( INVALID_PARAMETER, "Number of channels do not match" );
Jonas Stienen's avatar
Jonas Stienen committed
200

201 202
	for( int i = 0; i < m_iChannels; i++ )
		m_vChannels[ i ].Crossfade( ( *psfSrc )[ i ], iOffset, iCount, iFadeDirection, iFadeFunction );
Jonas Stienen's avatar
Jonas Stienen committed
203 204
}

205 206
void ITASampleFrame::crossfade( const ITASampleFrame& sfSrc, int iOffset, int iCount, int iFadeDirection, int iFadeFunction )
{
Jonas Stienen's avatar
Jonas Stienen committed
207 208 209
	crossfade( &sfSrc, iOffset, iCount, iFadeDirection, iFadeFunction );
}

210 211
void ITASampleFrame::envelope( float fGain0, float fGain1 ) {
	if( empty() ) return;
Jonas Stienen's avatar
Jonas Stienen committed
212

213 214
	for( int i = 0; i < m_iChannels; i++ )
		m_vChannels[ i ].Envelope( fGain0, fGain1 );
Jonas Stienen's avatar
Jonas Stienen committed
215 216
}

217 218 219 220
void ITASampleFrame::write( const ITASampleFrame* psfSrc, int iCount, int iSrcOffset, int iDestOffset )
{
	if( !psfSrc ) ITA_EXCEPT1( INVALID_PARAMETER, "Nullpointer passed" );
	if( psfSrc->channels() != m_iChannels )  ITA_EXCEPT1( INVALID_PARAMETER, "Number of channels do not match" );
Jonas Stienen's avatar
Jonas Stienen committed
221

222 223
	for( int i = 0; i < m_iChannels; i++ )
		m_vChannels[ i ].write( ( *psfSrc )[ i ], iCount, iSrcOffset, iDestOffset );
Jonas Stienen's avatar
Jonas Stienen committed
224 225
}

226 227 228
void ITASampleFrame::write( const ITASampleFrame& sfSrc, int iCount, int iSrcOffset, int iDestOffset )
{
	write( &sfSrc, iCount, iSrcOffset, iDestOffset );
Jonas Stienen's avatar
Jonas Stienen committed
229 230
}

231 232 233 234
void ITASampleFrame::cyclic_write( const ITASampleFrame* psfSrc, int iCount, int iSrcOffset, int iDestOffset )
{
	if( !psfSrc ) ITA_EXCEPT1( INVALID_PARAMETER, "Nullpointer passed" );
	if( psfSrc->channels() != m_iChannels )  ITA_EXCEPT1( INVALID_PARAMETER, "Number of channels do not match" );
Jonas Stienen's avatar
Jonas Stienen committed
235

236 237
	for( int i = 0; i < m_iChannels; i++ )
		m_vChannels[ i ].cyclic_write( &( ( *psfSrc )[ i ] ), iCount, iSrcOffset, iDestOffset );
Jonas Stienen's avatar
Jonas Stienen committed
238 239
}

240 241 242
void ITASampleFrame::cyclic_write( const ITASampleFrame& sfSrc, int iCount, int iSrcOffset, int iDestOffset )
{
	cyclic_write( &sfSrc, iCount, iSrcOffset, iDestOffset );
Jonas Stienen's avatar
Jonas Stienen committed
243 244
}

245
void ITASampleFrame::CyclicShift( int iCount )
Jonas Stienen's avatar
Jonas Stienen committed
246
{
247 248
	for( int i = 0; i < m_iChannels; i++ )
		m_vChannels[ i ].CyclicShift( iCount );
Jonas Stienen's avatar
Jonas Stienen committed
249 250
}

251 252 253 254
void ITASampleFrame::add_scalar( float fValue )
{
	for( ch_it it = m_vChannels.begin(); it != m_vChannels.end(); ++it )
		it->add_scalar( fValue );
Jonas Stienen's avatar
Jonas Stienen committed
255 256
}

257 258 259 260
void ITASampleFrame::sub_scalar( float fValue )
{
	for( ch_it it = m_vChannels.begin(); it != m_vChannels.end(); ++it )
		it->sub_scalar( fValue );
Jonas Stienen's avatar
Jonas Stienen committed
261 262
}

263 264 265 266
void ITASampleFrame::mul_scalar( float fValue )
{
	for( ch_it it = m_vChannels.begin(); it != m_vChannels.end(); ++it )
		it->mul_scalar( fValue );
Jonas Stienen's avatar
Jonas Stienen committed
267 268
}

269 270 271 272 273 274 275 276 277 278 279 280 281
void ITASampleFrame::div_scalar( float fValue )
{
	for( ch_it it = m_vChannels.begin(); it != m_vChannels.end(); ++it )
		it->div_scalar( fValue );
}

void ITASampleFrame::add_buf( const ITASampleBuffer* psbSource )
{
	if( !psbSource ) ITA_EXCEPT1( INVALID_PARAMETER, "Nullpointer passed" );
	if( psbSource->GetLength() != m_iLength )  ITA_EXCEPT1( INVALID_PARAMETER, "Lengths do not match" );

	for( ch_it it = m_vChannels.begin(); it != m_vChannels.end(); ++it )
		it->add_buf( psbSource );
Jonas Stienen's avatar
Jonas Stienen committed
282 283
}

284 285 286 287
void ITASampleFrame::sub_buf( const ITASampleBuffer* psbSource )
{
	if( !psbSource ) ITA_EXCEPT1( INVALID_PARAMETER, "Nullpointer passed" );
	if( psbSource->GetLength() != m_iLength )  ITA_EXCEPT1( INVALID_PARAMETER, "Lengths do not match" );
Jonas Stienen's avatar
Jonas Stienen committed
288

289 290
	for( ch_it it = m_vChannels.begin(); it != m_vChannels.end(); ++it )
		it->sub_buf( psbSource );
Jonas Stienen's avatar
Jonas Stienen committed
291 292
}

293 294 295 296
void ITASampleFrame::mul_buf( const ITASampleBuffer* psbSource )
{
	if( !psbSource ) ITA_EXCEPT1( INVALID_PARAMETER, "Nullpointer passed" );
	if( psbSource->GetLength() != m_iLength )  ITA_EXCEPT1( INVALID_PARAMETER, "Lengths do not match" );
Jonas Stienen's avatar
Jonas Stienen committed
297

298 299
	for( ch_it it = m_vChannels.begin(); it != m_vChannels.end(); ++it )
		it->sub_buf( psbSource );
Jonas Stienen's avatar
Jonas Stienen committed
300 301
}

302 303 304 305
void ITASampleFrame::div_buf( const ITASampleBuffer* psbSource )
{
	if( !psbSource ) ITA_EXCEPT1( INVALID_PARAMETER, "Nullpointer passed" );
	if( psbSource->GetLength() != m_iLength )  ITA_EXCEPT1( INVALID_PARAMETER, "Lengths do not match" );
Jonas Stienen's avatar
Jonas Stienen committed
306

307 308
	for( ch_it it = m_vChannels.begin(); it != m_vChannels.end(); ++it )
		it->div_buf( psbSource );
Jonas Stienen's avatar
Jonas Stienen committed
309 310
}

311 312 313 314
void ITASampleFrame::add_buf( const ITASampleBuffer& sbSource )
{
	add_buf( &sbSource );
}
Jonas Stienen's avatar
Jonas Stienen committed
315

316 317 318 319 320 321 322 323
void ITASampleFrame::sub_buf( const ITASampleBuffer& sbSource )
{
	sub_buf( &sbSource );
}

void ITASampleFrame::mul_buf( const ITASampleBuffer& sbSource )
{
	mul_buf( &sbSource );
Jonas Stienen's avatar
Jonas Stienen committed
324 325
}

326 327 328 329
void ITASampleFrame::div_buf( const ITASampleBuffer& sbSource )
{
	div_buf( &sbSource );
}
Jonas Stienen's avatar
Jonas Stienen committed
330

331 332 333 334 335
void ITASampleFrame::add_frame( const ITASampleFrame* psfSource )
{
	if( !psfSource ) ITA_EXCEPT1( INVALID_PARAMETER, "Nullpointer passed" );
	if( psfSource->m_iChannels != m_iChannels )  ITA_EXCEPT1( INVALID_PARAMETER, "Number of channels do not match" );
	if( psfSource->m_iLength != m_iLength )  ITA_EXCEPT1( INVALID_PARAMETER, "Lengths do not match" );
Jonas Stienen's avatar
Jonas Stienen committed
336

337 338
	for( int i = 0; i < m_iChannels; ++i )
		m_vChannels[ i ].add_buf( &( psfSource->m_vChannels[ i ] ) );
Jonas Stienen's avatar
Jonas Stienen committed
339 340
}

341
void ITASampleFrame::add_frame( const ITASampleFrame* psfSource, int iPos )
Jonas Stienen's avatar
Jonas Stienen committed
342
{
343 344 345 346 347 348
	if( !psfSource ) ITA_EXCEPT1( INVALID_PARAMETER, "Nullpointer passed" );
	if( psfSource->m_iChannels != m_iChannels )  ITA_EXCEPT1( INVALID_PARAMETER, "Number of channels do not match" );
	if( ( psfSource->m_iLength + iPos ) >= m_iLength )  ITA_EXCEPT1( INVALID_PARAMETER, "Source length + delay exceed length of filter" );

	for( int i = 0; i < m_iChannels; ++i )
		m_vChannels[ i ].add_buf_pos( &( psfSource->m_vChannels[ i ] ), iPos );
Jonas Stienen's avatar
Jonas Stienen committed
349 350 351 352
}



353 354 355 356 357
void ITASampleFrame::sub_frame( const ITASampleFrame* psfSource )
{
	if( !psfSource ) ITA_EXCEPT1( INVALID_PARAMETER, "Nullpointer passed" );
	if( psfSource->m_iChannels != m_iChannels )  ITA_EXCEPT1( INVALID_PARAMETER, "Number of channels do not match" );
	if( psfSource->m_iLength != m_iLength )  ITA_EXCEPT1( INVALID_PARAMETER, "Lengths do not match" );
Jonas Stienen's avatar
Jonas Stienen committed
358

359 360
	for( int i = 0; i < m_iChannels; ++i )
		m_vChannels[ i ].sub_buf( &( psfSource->m_vChannels[ i ] ) );
Jonas Stienen's avatar
Jonas Stienen committed
361 362
}

363 364 365 366 367
void ITASampleFrame::mul_frame( const ITASampleFrame* psfSource )
{
	if( !psfSource ) ITA_EXCEPT1( INVALID_PARAMETER, "Nullpointer passed" );
	if( psfSource->m_iChannels != m_iChannels )  ITA_EXCEPT1( INVALID_PARAMETER, "Number of channels do not match" );
	if( psfSource->m_iLength != m_iLength )  ITA_EXCEPT1( INVALID_PARAMETER, "Lengths do not match" );
Jonas Stienen's avatar
Jonas Stienen committed
368

369 370
	for( int i = 0; i < m_iChannels; ++i )
		m_vChannels[ i ].mul_buf( &( psfSource->m_vChannels[ i ] ) );
Jonas Stienen's avatar
Jonas Stienen committed
371 372
}

373 374 375 376 377
void ITASampleFrame::div_frame( const ITASampleFrame* psfSource )
{
	if( !psfSource ) ITA_EXCEPT1( INVALID_PARAMETER, "Nullpointer passed" );
	if( psfSource->m_iChannels != m_iChannels )  ITA_EXCEPT1( INVALID_PARAMETER, "Number of channels do not match" );
	if( psfSource->m_iLength != m_iLength )  ITA_EXCEPT1( INVALID_PARAMETER, "Lengths do not match" );
Jonas Stienen's avatar
Jonas Stienen committed
378

379 380
	for( int i = 0; i < m_iChannels; ++i )
		m_vChannels[ i ].div_buf( &( psfSource->m_vChannels[ i ] ) );
Jonas Stienen's avatar
Jonas Stienen committed
381 382
}

383 384 385 386
void ITASampleFrame::add_frame( const ITASampleFrame& sfSource )
{
	add_frame( &sfSource );
}
Jonas Stienen's avatar
Jonas Stienen committed
387

388 389 390 391
void ITASampleFrame::sub_frame( const ITASampleFrame& sfSource )
{
	sub_frame( &sfSource );
}
Jonas Stienen's avatar
Jonas Stienen committed
392

393 394 395 396 397 398 399 400
void ITASampleFrame::mul_frame( const ITASampleFrame& sfSource )
{
	mul_frame( &sfSource );
}

void ITASampleFrame::div_frame( const ITASampleFrame& sfSource )
{
	div_frame( &sfSource );
Jonas Stienen's avatar
Jonas Stienen committed
401 402
}

403 404 405 406 407 408 409 410 411 412 413
void ITASampleFrame::muladd_frame( const ITASampleFrame* psfSource, float fScalar, int iSrcOffset, int iDestOffset, int iCount )
{
	if( !psfSource ) ITA_EXCEPT1( INVALID_PARAMETER, "Nullpointer passed" );
	if( psfSource->m_iChannels != m_iChannels )  ITA_EXCEPT1( INVALID_PARAMETER, "Number of channels do not match" );

	for( int i = 0; i < m_iChannels; i++ )
		m_vChannels[ i ].MulAdd( ( *psfSource )[ i ], fScalar, iSrcOffset, iDestOffset, iCount );
}

void ITASampleFrame::muladd_frame( const ITASampleFrame& sfSource, float fScalar, int iSrcOffset, int iDestOffset, int iCount )
{
Jonas Stienen's avatar
Jonas Stienen committed
414 415 416
	muladd_frame( &sfSource, fScalar, iSrcOffset, iDestOffset, iCount );
}

417
float ITASampleFrame::findPeak( int* piChannel, int* piPeakIndex )
418
{
419
	if( ( m_iChannels == 0 ) || ( m_iLength == 0 ) )
420
	{
421
		if( piChannel )
422
			*piChannel = 0;
423
		if( piPeakIndex )
424 425
			*piPeakIndex = 0;

Jonas Stienen's avatar
Jonas Stienen committed
426 427 428 429 430
		return 0;
	}

	float fPeak = 0;
	int iChannel = 0;
431
	int iPeakIndex = 0;
Jonas Stienen's avatar
Jonas Stienen committed
432

433 434
	for( int i = 0; i < m_iChannels; i++ )
	{
Jonas Stienen's avatar
Jonas Stienen committed
435
		int k;
436 437 438
		float x = m_vChannels[ i ].FindPeak( &k );
		if( x > fPeak )
		{
Jonas Stienen's avatar
Jonas Stienen committed
439 440 441 442 443 444
			fPeak = x;
			iChannel = i;
			iPeakIndex = k;
		}
	}

445
	if( piChannel )
446 447
		*piChannel = iChannel;

448
	if( piPeakIndex )
449
		*piPeakIndex = iPeakIndex;
Jonas Stienen's avatar
Jonas Stienen committed
450 451 452 453

	return fPeak;
}

454 455 456
void ITASampleFrame::negate()
{
	for( ch_it it = m_vChannels.begin(); it != m_vChannels.end(); ++it )
Jonas Stienen's avatar
Jonas Stienen committed
457 458 459
		it->Negate();
};

460 461 462
ITASampleBuffer& ITASampleFrame::operator[]( int iChannel )
{
	return m_vChannels[ iChannel ];
Jonas Stienen's avatar
Jonas Stienen committed
463 464
}

465 466 467
const ITASampleBuffer& ITASampleFrame::operator[]( int iChannel ) const
{
	return m_vChannels[ iChannel ];
Jonas Stienen's avatar
Jonas Stienen committed
468 469
}

470 471 472 473 474
ITASampleFrame& ITASampleFrame::operator=( const ITASampleFrame& rhs )
{
	// No self assignment
	if( &rhs == this )
		return *this;
Jonas Stienen's avatar
Jonas Stienen committed
475

476
	init( rhs.channels(), rhs.length(), false );
Jonas Stienen's avatar
Jonas Stienen committed
477

478 479
	for( int i = 0; i < m_iChannels; i++ )
		( *this )[ i ].write( rhs[ i ], this->GetLength() );
Jonas Stienen's avatar
Jonas Stienen committed
480 481 482 483

	return *this;
}

484 485 486
ITASampleFrame& ITASampleFrame::operator+=( const float rhs )
{
	add_scalar( rhs );
Jonas Stienen's avatar
Jonas Stienen committed
487 488 489
	return *this;
}

490 491 492
ITASampleFrame& ITASampleFrame::operator-=( const float rhs )
{
	sub_scalar( rhs );
Jonas Stienen's avatar
Jonas Stienen committed
493 494 495
	return *this;
}

496 497 498
ITASampleFrame& ITASampleFrame::operator*=( const float rhs )
{
	mul_scalar( rhs );
Jonas Stienen's avatar
Jonas Stienen committed
499 500 501 502
	return *this;

}

503 504 505
ITASampleFrame& ITASampleFrame::operator/=( const float rhs )
{
	div_scalar( rhs );
Jonas Stienen's avatar
Jonas Stienen committed
506 507 508
	return *this;
}

509 510 511
ITASampleFrame& ITASampleFrame::operator+=( const ITASampleBuffer& rhs )
{
	add_buf( rhs );
Jonas Stienen's avatar
Jonas Stienen committed
512 513 514
	return *this;
}

515 516 517
ITASampleFrame& ITASampleFrame::operator-=( const ITASampleBuffer& rhs )
{
	sub_buf( rhs );
Jonas Stienen's avatar
Jonas Stienen committed
518 519 520
	return *this;
}

521 522 523
ITASampleFrame& ITASampleFrame::operator*=( const ITASampleBuffer& rhs )
{
	mul_buf( rhs );
Jonas Stienen's avatar
Jonas Stienen committed
524 525 526
	return *this;
}

527 528 529
ITASampleFrame& ITASampleFrame::operator/=( const ITASampleBuffer& rhs )
{
	div_buf( rhs );
Jonas Stienen's avatar
Jonas Stienen committed
530 531 532
	return *this;
}

533 534 535
ITASampleFrame& ITASampleFrame::operator+=( const ITASampleFrame& rhs )
{
	add_frame( rhs );
Jonas Stienen's avatar
Jonas Stienen committed
536 537 538
	return *this;
}

539 540 541
ITASampleFrame& ITASampleFrame::operator-=( const ITASampleFrame& rhs )
{
	sub_frame( rhs );
Jonas Stienen's avatar
Jonas Stienen committed
542 543 544
	return *this;
}

545 546
ITASampleFrame& ITASampleFrame::operator*=( const ITASampleFrame& rhs ) {
	mul_frame( rhs );
Jonas Stienen's avatar
Jonas Stienen committed
547 548 549
	return *this;
}

550 551 552
ITASampleFrame& ITASampleFrame::operator/=( const ITASampleFrame& rhs )
{
	div_frame( rhs );
Jonas Stienen's avatar
Jonas Stienen committed
553 554 555
	return *this;
}

556 557
std::string ITASampleFrame::toString() const
{
Jonas Stienen's avatar
Jonas Stienen committed
558 559
	std::stringstream ss;
	ss << "Sample frame { ";
560
	if( empty() )
Jonas Stienen's avatar
Jonas Stienen committed
561 562 563 564 565 566 567
		ss << "emtpy";
	else
		ss << m_iChannels << " channels of " << m_iLength << " samples";
	ss << " }";
	return ss.str();
}

568
float ITASampleFrame::Normalize()
Jonas Stienen's avatar
Jonas Stienen committed
569
{
570
	int c, s;
Jonas Stienen's avatar
Jonas Stienen committed
571
	findPeak( &c, &s );
572 573 574
	float fP = m_vChannels[ c ][ s ];
	for( int i = 0; i < m_iChannels; i++ )
		m_vChannels[ i ].div_scalar( fP );
Jonas Stienen's avatar
Jonas Stienen committed
575 576 577

	return fP;
}