Skip to content

Commit e886c8a

Browse files
author
Clement Champetier
committed
AudioGenerator: fixed assign of audio buffer of silence
* This was an old bug, which occured if we try to generate silence, after transcoding a real audio stream with a last packet very small. * Add pyTest to check this execution. * It could be much beffer to reallocate the given frame of the generator, and put in it more samples of silence.
1 parent 90bcf03 commit e886c8a

File tree

2 files changed

+44
-1
lines changed

2 files changed

+44
-1
lines changed

src/AvTranscoder/decoder/AudioGenerator.cpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,9 +54,12 @@ bool AudioGenerator::decodeNextFrame(Frame& frameBuffer)
5454
msg << "sample format = " << getSampleFormatName(_silent->getSampleFormat()) << std::endl;
5555
msg << "number of samples per channel = " << _silent->getNbSamplesPerChannel() << std::endl;
5656
LOG_INFO(msg.str())
57+
58+
// Set the number of samples of silence to the number of samples of the given frame
59+
// (which was allocated to expect this number of samples).
60+
_silent->setNbSamplesPerChannel(frameBuffer.getAVFrame().nb_samples);
5761
}
5862
LOG_DEBUG("Copy data of the silence when decode next frame")
59-
frameBuffer.getAVFrame().nb_samples = _silent->getAVFrame().nb_samples;
6063
frameBuffer.copyData(*_silent);
6164
}
6265
// Take audio frame from _inputFrame

test/pyTest/testTranscoderTranscodeAudioWave.py

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ def testTranscodeWave24b48k5_1():
4343
assert_equals( 48000, dst_audioStream.getSampleRate() )
4444
assert_equals( 6, dst_audioStream.getNbChannels() )
4545

46+
4647
def testTranscodeWave24b48kstereo():
4748
"""
4849
Transcode one audio stream (profile wave24b48kstereo).
@@ -76,6 +77,7 @@ def testTranscodeWave24b48kstereo():
7677
assert_equals( 48000, dst_audioStream.getSampleRate() )
7778
assert_equals( 2, dst_audioStream.getNbChannels() )
7879

80+
7981
def testTranscodeWave24b48kmono():
8082
"""
8183
Transcode one audio stream (profile wave24b48kmono).
@@ -109,6 +111,7 @@ def testTranscodeWave24b48kmono():
109111
assert_equals( 48000, dst_audioStream.getSampleRate() )
110112
assert_equals( 1, dst_audioStream.getNbChannels() )
111113

114+
112115
def testTranscodeWave16b48kmono():
113116
"""
114117
Transcode one audio stream (profile wave16b48kmono).
@@ -141,3 +144,40 @@ def testTranscodeWave16b48kmono():
141144
assert_equals( "signed 16 bits", dst_audioStream.getSampleFormatLongName() )
142145
assert_equals( 48000, dst_audioStream.getSampleRate() )
143146
assert_equals( 1, dst_audioStream.getNbChannels() )
147+
148+
149+
def testTranscodeWave16b48kmonoWithSilence():
150+
"""
151+
Transcode one audio stream (profile wave16b48kmono).
152+
Complete with silence.
153+
"""
154+
inputFileName = os.environ['AVTRANSCODER_TEST_AUDIO_WAVE_FILE']
155+
outputFileName = "testTranscodeWave16b48kmonoWithSilence.wav"
156+
outputDuration = 50
157+
158+
ouputFile = av.OutputFile( outputFileName )
159+
transcoder = av.Transcoder( ouputFile )
160+
transcoder.setProcessMethod( av.eProcessMethodBasedOnDuration, 0, outputDuration )
161+
162+
inputFile = av.InputFile( inputFileName )
163+
src_audioStream = inputFile.getProperties().getAudioProperties()[0]
164+
audioStreamIndex = src_audioStream.getStreamIndex()
165+
transcoder.add( inputFileName, audioStreamIndex, "wave16b48kmono" )
166+
167+
progress = av.ConsoleProgress()
168+
processStat = transcoder.process( progress )
169+
170+
# check process stat returned
171+
audioStat = processStat.getAudioStat(0)
172+
assert_almost_equals( audioStat.getDuration(), outputDuration, delta=0.01 )
173+
174+
# get dst file of transcode
175+
dst_inputFile = av.InputFile( outputFileName )
176+
dst_properties = dst_inputFile.getProperties()
177+
dst_audioStream = dst_properties.getAudioProperties()[0]
178+
179+
assert_equals( "pcm_s16le", dst_audioStream.getCodecName() )
180+
assert_equals( "s16", dst_audioStream.getSampleFormatName() )
181+
assert_equals( "signed 16 bits", dst_audioStream.getSampleFormatLongName() )
182+
assert_equals( 48000, dst_audioStream.getSampleRate() )
183+
assert_equals( 1, dst_audioStream.getNbChannels() )

0 commit comments

Comments
 (0)