Repository navigation
Expand file tree
/
Copy pathsimple_audio_upsample.cpp
More file actions
61 lines (49 loc) · 2.01 KB
/
Copy pathsimple_audio_upsample.cpp
File metadata and controls
61 lines (49 loc) · 2.01 KB
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
#include <primo/avblocks/avb.h>
#include <primo/platform/reference++.h>
#include <primo/platform/ustring.h>
using namespace primo;
using namespace primo::codecs;
using namespace primo::avblocks;
int main(int argc, const char *argv[]) {
Library::initialize();
auto inputFile = primo::ustring(L"kahvi011_kennybeltrey-hydrate.mp3");
auto outputFile = primo::ustring(L"kahvi011_kennybeltrey-hydrate_48Khz.mp3");
auto inputInfo = primo::make_ref(Library::createMediaInfo());
inputInfo->inputs()->at(0)->setFile(inputFile);
if (inputInfo->open()) {
auto inputSocket = primo::make_ref(
Library::createMediaSocket(inputInfo.get())
);
// Start with the same output as the input
auto outputSocket = primo::make_ref(inputSocket->clone());
outputSocket->setFile(outputFile);
// Get the output audio pin
auto outAudioPin = outputSocket->pins()->at(0);
// Set output sampling rate to 48 KHz
auto outAudioStream = (AudioStreamInfo*)outAudioPin->streamInfo();
outAudioStream->setSampleRate(48000);
// Create Transcoder and configure it with
// the input and output sockets
auto transcoder = primo::make_ref(Library::createTranscoder());
transcoder->inputs()->add(inputSocket.get());
transcoder->outputs()->add(outputSocket.get());
// Allow demo mode for the transcoder when
// using the demo version of the library
transcoder->setAllowDemoMode(true);
// Run the transcoder
if (transcoder->open()) {
transcoder->run();
transcoder->close();
} else {
std::cerr << "transcoder->open() failed: "
<< primo::ustring(transcoder->error()->message())
<< std::endl;
}
} else {
std::cerr << "inputInfo->open() failed: "
<< primo::ustring(inputInfo->error()->message())
<< std::endl;
}
Library::shutdown();
return 0;
}