Switch Controller
Loading...
Searching...
No Matches
TestAudio.h
Go to the documentation of this file.
1#pragma once
2
3#include "pch.h"
4
8
9#include <boost/program_options.hpp>
10
11void TestAudio(const boost::program_options::variables_map &vm,
12 const std::map<std::string, std::string> &ffmpegOptions) {
13 auto inputFormat = vm["inputFormat"].as<std::string>();
14 auto deviceName = vm["deviceName"].as<std::string>();
15 int recordTime = vm["testAudio"].as<int>();
16 int loopRecordTime = vm["audioLoopTime"].as<int>();
17
18 // ffplay -f s16le -ar 48k -ac 1 test.pcm
19
20 std::vector<std::unique_ptr<FFmpegFrameSink>> sinks;
21 AVChannelLayout channel_layout = AV_CHANNEL_LAYOUT_MONO;
22 sinks.push_back(std::make_unique<AudioFrameSink>(
23 channel_layout, AV_SAMPLE_FMT_S16, 48000, loopRecordTime != -1,
24 48000 * (loopRecordTime != -1 ? loopRecordTime : recordTime)));
25 auto audioSink = sinks[0].get();
26
27 {
28 FFmpegRecorder recorder(inputFormat, deviceName, ffmpegOptions, sinks);
29 std::this_thread::sleep_for(std::chrono::seconds(recordTime));
30 }
31
32 std::vector<uint8_t> data;
33 audioSink->getData(data);
34
35 std::cout << "Enter the output filename:\n";
36 std::string audioFilename;
37 std::getline(std::cin, audioFilename);
38
39 std::ofstream outfile(audioFilename, std::ios::out | std::ios::binary);
40 outfile.write(reinterpret_cast<char *>(data.data()),
41 static_cast<std::streamsize>(data.size()));
42}
void TestAudio(const boost::program_options::variables_map &vm, const std::map< std::string, std::string > &ffmpegOptions)
Definition: TestAudio.h:11
Definition: FFmpegRecorder.h:12