@@ -74,17 +74,19 @@ ReaderStatusUpdate CachingReaderWorker::processReadRequest(
7474 }
7575 }
7676
77- // This call here assumes that the caching reader will read the first sound cue at
78- // one of the first chunks. The check serves as a sanity check to ensure that the
79- // sample data has not changed since it has ben analyzed. This could happen because
80- // of a change in actual audio data or because the file was decoded using a different
81- // decoder
82- // This is part of a first prove of concept and needs to be replaces with a different
83- // solution which is still under discussion. This might be also extended
84- // to further checks whether a automatic offset adjustment is possible or a the
85- // sample position metadata shall be treated as outdated.
86- // Failures of the sanity check only result in an entry into the log at the moment.
87- verifyFirstSound (pChunk, m_pAudioSource->getSignalInfo ().getChannelCount ());
77+ if (status == CHUNK_READ_SUCCESS ) {
78+ // This call here assumes that the caching reader will read the first sound cue at
79+ // one of the first chunks. The check serves as a sanity check to ensure that the
80+ // sample data has not changed since it has ben analyzed. This could happen because
81+ // of a change in actual audio data or because the file was decoded using a different
82+ // decoder
83+ // This is part of a first prove of concept and needs to be replaces with a different
84+ // solution which is still under discussion. This might be also extended
85+ // to further checks whether a automatic offset adjustment is possible or a the
86+ // sample position metadata shall be treated as outdated.
87+ // Failures of the sanity check only result in an entry into the log at the moment.
88+ verifyFirstSound (pChunk, m_pAudioSource->getSignalInfo ().getChannelCount ());
89+ }
8890
8991 ReaderStatusUpdate result;
9092 result.init (status, pChunk, m_pAudioSource ? m_pAudioSource->frameIndexRange () : mixxx::IndexRange ());
@@ -319,10 +321,18 @@ void CachingReaderWorker::verifyFirstSound(const CachingReaderChunk* pChunk,
319321 .value ()));
320322 if (pChunk->getIndex () == firstSoundIndex) {
321323 mixxx::SampleBuffer sampleBuffer (kNumSoundFrameToVerify * channelCount);
322- SINT end = static_cast <SINT >(m_firstSoundFrameToVerify.toLowerFrameBoundary ().value ());
323- pChunk->readBufferedSampleFrames (sampleBuffer.data (),
324- channelCount,
325- mixxx::IndexRange::forward (end - 1 , kNumSoundFrameToVerify ));
324+ // We read two frames, the last silence frame and the first non-silence frame from
325+ // m_firstSoundFrameToVerify. end points to one position after them.
326+ SINT end = static_cast <SINT >(m_firstSoundFrameToVerify.toLowerFrameBoundary ().value ()) + 1 ;
327+ mixxx::IndexRange probeFrameIndexRange =
328+ mixxx::IndexRange::between (end - kNumSoundFrameToVerify , end);
329+ mixxx::IndexRange bufferedFrameIndexRange =
330+ pChunk->readBufferedSampleFrames (
331+ sampleBuffer.data (), channelCount, probeFrameIndexRange);
332+ VERIFY_OR_DEBUG_ASSERT (bufferedFrameIndexRange == probeFrameIndexRange) {
333+ qWarning () << " skipping verifyFirstSound()" ;
334+ return ;
335+ }
326336 if (AnalyzerSilence::verifyFirstSound (sampleBuffer.span (),
327337 mixxx::audio::FramePos (1 ),
328338 channelCount)) {
0 commit comments