Skip to content

Commit b6d8224

Browse files
committed
Auto push on 2024-05-08 12:41:53
1 parent 85bb6f3 commit b6d8224

File tree

1 file changed

+21
-14
lines changed

1 file changed

+21
-14
lines changed

samples/darwin/enc_mp3_file/enc_mp3_file.cpp

Lines changed: 21 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -21,30 +21,37 @@ using namespace std;
2121

2222
primo::ref<MediaSocket> createOutputSocket(Options& opt)
2323
{
24-
auto socket = primo::make_ref(Library::createMediaSocket());
25-
socket->setFile(primo::ustring(opt.outputFile));
26-
socket->setStreamType(StreamType::MPEG_Audio);
27-
socket->setStreamSubType(StreamSubType::MPEG_Audio_Layer3);
28-
29-
auto pin = primo::make_ref(Library::createMediaPin());
30-
socket->pins()->add(pin.get());
31-
24+
// create stream info to describe the output audio stream
3225
auto asi = primo::make_ref(Library::createAudioStreamInfo());
33-
pin->setStreamInfo(asi.get());
34-
3526
asi->setStreamType(StreamType::MPEG_Audio);
3627
asi->setStreamSubType(StreamSubType::MPEG_Audio_Layer3);
3728

38-
// Change the encoding bitrate with the following line. The default bitrate is 128000. You can set it to 192000, 256000, etc.
29+
// The default bitrate is 128000. You can set it to 192000, 256000, etc.
3930
// asi->setBitrate(192000);
4031

41-
// Change the sampling rate and the number of the channels, e.g. Mono, 44.1 Khz
42-
// asi->setChannels(1);
32+
// Optionally set the sampling rate and the number of the channels, e.g. 44.1 Khz, Mono
4333
// asi->setSampleRate(44100);
34+
// asi->setChannels(1);
4435

45-
// Change the stereo mode, e.g. Joint Stereo
36+
// create a pin using the stream info
37+
auto pin = primo::make_ref(Library::createMediaPin());
38+
pin->setStreamInfo(asi.get());
39+
40+
// the pin allows you to specify additional parameters for the encoder
41+
// for example, change the stereo mode, e.g. Joint Stereo
4642
// pin->params()->addInt(Param::Encoder::Audio::MPEG1::StereoMode, StereoMode::Joint);
4743

44+
// finally create a socket for the output container format which is MP3 in this case
45+
auto socket = primo::make_ref(Library::createMediaSocket());
46+
socket->setStreamType(StreamType::MPEG_Audio);
47+
socket->setStreamSubType(StreamSubType::MPEG_Audio_Layer3);
48+
49+
socket->pins()->add(pin.get());
50+
51+
// output to a file
52+
auto output_file = primo::ustring(opt.outputFile);
53+
socket->setFile(output_file);
54+
4855
return socket;
4956
}
5057

0 commit comments

Comments
 (0)