diff options
author | Uwe Klotz <uwe_klotz@web.de> | 2017-07-09 22:48:21 +0200 |
---|---|---|
committer | Uwe Klotz <uwe_klotz@web.de> | 2017-11-06 22:27:20 +0100 |
commit | f8e5ddcf950e310d1f26c5b82cd071b1231aaf02 (patch) | |
tree | 73e4b8492f68c904110825eaa2b1a7d51d0631f3 /src/engine/cachingreaderchunk.h | |
parent | 67353de2aeb843965ac21a031914465c4638d745 (diff) |
Introduce AudioSource v2 API
Diffstat (limited to 'src/engine/cachingreaderchunk.h')
-rw-r--r-- | src/engine/cachingreaderchunk.h | 84 |
1 files changed, 34 insertions, 50 deletions
diff --git a/src/engine/cachingreaderchunk.h b/src/engine/cachingreaderchunk.h index 1c5e4cd8d9..869229f7ea 100644 --- a/src/engine/cachingreaderchunk.h +++ b/src/engine/cachingreaderchunk.h @@ -16,23 +16,10 @@ // and the worker. class CachingReaderChunk { public: - static const SINT kChannels; + static const mixxx::AudioSignal::ChannelCount kChannels; static const SINT kFrames; static const SINT kSamples; - // Returns the corresponding chunk index for a frame index - inline static SINT indexForFrame(SINT frameIndex) { - DEBUG_ASSERT(mixxx::AudioSource::getMinFrameIndex() <= frameIndex); - const SINT chunkIndex = frameIndex / kFrames; - return chunkIndex; - } - - // Returns the corresponding chunk index for a frame index - inline static SINT frameForIndex(SINT chunkIndex) { - DEBUG_ASSERT(0 <= chunkIndex); - return chunkIndex * kFrames; - } - // Converts frames to samples inline static SINT frames2samples(SINT frames) { return frames * kChannels; @@ -43,6 +30,15 @@ public: return samples / kChannels; } + // Returns the corresponding chunk index for a frame index + inline static SINT indexForFrame( + /*const mixxx::AudioSourcePointer& pAudioSource,*/ + SINT frameIndex) { + //DEBUG_ASSERT(pAudioSource->frameIndexRange().contains(frameIndex)); + const SINT frameIndexOffset = frameIndex /*- pAudioSource->frameIndexMin()*/; + return frameIndexOffset / kFrames; + } + // Disable copy and move constructors CachingReaderChunk(const CachingReaderChunk&) = delete; CachingReaderChunk(CachingReaderChunk&&) = delete; @@ -51,54 +47,41 @@ public: return m_index; } - bool isValid() const { - return 0 <= getIndex(); - } - - SINT getFrameCount() const { - return m_frameCount; - } - - // Check if the audio source has sample data available - // for this chunk. - bool isReadable( - const mixxx::AudioSourcePointer& pAudioSource, - SINT maxReadableFrameIndex) const; + // Frame index range of this chunk for the given audio source. + mixxx::IndexRange frameIndexRange( + const mixxx::AudioSourcePointer& pAudioSource) const; // Read sample frames from the audio source and return the - // number of frames that have been read. The in/out parameter - // pMaxReadableFrameIndex is adjusted if reading fails. - SINT readSampleFrames( + // range of frames that have been read. + mixxx::IndexRange bufferSampleFrames( const mixxx::AudioSourcePointer& pAudioSource, - SINT* pMaxReadableFrameIndex); + SampleBuffer::WritableSlice tempSampleBuffer); - // Copy sampleCount samples starting at sampleOffset from - // the chunk's internal buffer into sampleBuffer. - void copySamples( + mixxx::IndexRange readBufferedSampleFrames( CSAMPLE* sampleBuffer, - SINT sampleOffset, - SINT sampleCount) const; - - // Copy sampleCount samples in reverse order starting at sampleOffset from - // the chunk's internal buffer into sampleBuffer. - void copySamplesReverse( - CSAMPLE* sampleBuffer, - SINT sampleOffset, - SINT sampleCount) const; + const mixxx::IndexRange& frameIndexRange) const; + mixxx::IndexRange readBufferedSampleFramesReverse( + CSAMPLE* reverseSampleBuffer, + const mixxx::IndexRange& frameIndexRange) const; protected: - explicit CachingReaderChunk(CSAMPLE* sampleBuffer); + explicit CachingReaderChunk( + SampleBuffer::WritableSlice sampleBuffer); virtual ~CachingReaderChunk(); void init(SINT index); private: - volatile SINT m_index; + SINT frameIndexOffset() const { + return m_index * kFrames; + } + + SINT m_index; // The worker thread will fill the sample buffer and - // set the frame count. - CSAMPLE* const m_sampleBuffer; - volatile SINT m_frameCount; + // set the corresponding frame index range. + SampleBuffer::WritableSlice m_sampleBuffer; + mixxx::IndexRange m_bufferedFrameIndexRange; }; // This derived class is only accessible for the cache as the owner, @@ -106,8 +89,9 @@ private: // the worker thread is in control. class CachingReaderChunkForOwner: public CachingReaderChunk { public: - explicit CachingReaderChunkForOwner(CSAMPLE* sampleBuffer); - virtual ~CachingReaderChunkForOwner(); + explicit CachingReaderChunkForOwner( + SampleBuffer::WritableSlice sampleBuffer); + ~CachingReaderChunkForOwner() override; void init(SINT index); void free(); |