forked from avTranscoder/avTranscoder
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAudioGenerator.cpp
More file actions
60 lines (51 loc) · 1.77 KB
/
Copy pathAudioGenerator.cpp
File metadata and controls
60 lines (51 loc) · 1.77 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
#include "AudioGenerator.hpp"
#include <AvTranscoder/util.hpp>
#include <sstream>
namespace avtranscoder
{
AudioGenerator::AudioGenerator(const AudioFrameDesc& frameDesc)
: _inputFrame(NULL)
, _silent(NULL)
, _frameDesc(frameDesc)
{
}
AudioGenerator::~AudioGenerator()
{
delete _silent;
}
bool AudioGenerator::decodeNextFrame(IFrame& frameBuffer)
{
// Generate silent
if(!_inputFrame)
{
// Generate the silent only once
if(!_silent)
{
_silent = new AudioFrame(_frameDesc);
std::stringstream msg;
msg << "Generate a silence with the following features:" << std::endl;
msg << "sample rate = " << _silent->getSampleRate() << std::endl;
msg << "number of channels = " << _silent->getNbChannels() << std::endl;
msg << "sample format = " << getSampleFormatName(_silent->getSampleFormat()) << std::endl;
msg << "number of samples per channel = " << _silent->getNbSamplesPerChannel() << std::endl;
LOG_INFO(msg.str())
// Set the number of samples of silence to the number of samples of the given frame
// (which was allocated to expect this number of samples).
_silent->setNbSamplesPerChannel(frameBuffer.getAVFrame().nb_samples);
}
LOG_DEBUG("Copy data of the silence when decode next frame")
frameBuffer.copyData(*_silent);
}
// Take audio frame from _inputFrame
else
{
LOG_DEBUG("Convert data of the audio specified when decode next frame")
_audioTransform.convert(*_inputFrame, frameBuffer);
}
return true;
}
bool AudioGenerator::decodeNextFrame(IFrame& frameBuffer, const std::vector<size_t> channelIndexArray)
{
return decodeNextFrame(frameBuffer);
}
}