forked from avaneev/r8brain-free-src
-
Notifications
You must be signed in to change notification settings - Fork 0
/
example.cpp
80 lines (63 loc) · 1.87 KB
/
example.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
/**
* @file example.cpp
*
* @brief An example C++ file that demonstrates resampler's usage.
*
* This is an example file which you won't be able to compile as it includes
* some undisclosed program code. Please consider this example as a
* pseudo-code demonstrating the use of the library. Here you can find an
* example implementation of the simplest sample rate converter utility.
*
* r8brain-free-src Copyright (c) 2013-2019 Aleksey Vaneev
* See the "License.txt" file for license.
*/
int main()
{
const double OutSampleRate = 96000.0;
CWaveFile inf;
inf.loadFile( "Audio.wav" );
CWaveFile outf;
outf.inheritFormat( inf );
outf.SampleRate = OutSampleRate;
outf.saveFile( "AudioOut.wav" );
const int InBufCapacity = 1024;
CFixedBuffer< double > InBufs[ inf.ChannelCount ];
CPtrKeeper< CDSPResampler24* > Resamps[ inf.ChannelCount ];
int i;
for( i = 0; i < inf.ChannelCount; i++ )
{
InBufs[ i ].alloc( InBufCapacity );
Resamps[ i ] = new CDSPResampler24( inf.SampleRate, OutSampleRate,
InBufCapacity );
}
long long int ol = inf.SampleCount * OutSampleRate / inf.SampleRate;
while( ol > 0 )
{
int ReadCount;
inf.readData( InBufs, InBufCapacity, ReadCount );
if( ReadCount == -1 )
{
ReadCount = InBufCapacity;
for( i = 0; i < inf.ChannelCount; i++ )
{
memset( &InBufs[ i ][ 0 ], 0, ReadCount * sizeof( double ));
}
}
double* opp[ inf.ChannelCount ];
int WriteCount; // At initial steps this variable can be equal to 0
// after resampler. Same number for all channels.
for( i = 0; i < inf.ChannelCount; i++ )
{
WriteCount = Resamps[ i ] -> process(
InBufs[ i ], ReadCount, opp[ i ]);
}
if( WriteCount > ol )
{
WriteCount = (int) ol;
}
outf.writeData( opp, WriteCount );
ol -= WriteCount;
}
outf.finalize();
return( 0 );
}