/[svn]/linuxsampler/trunk/src/engines/common/SampleFile.h
ViewVC logotype

Diff of /linuxsampler/trunk/src/engines/common/SampleFile.h

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 2020 by iliev, Fri Oct 23 17:53:17 2009 UTC revision 2021 by iliev, Fri Oct 30 16:36:20 2009 UTC
# Line 77  namespace LinuxSampler { Line 77  namespace LinuxSampler {
77              buffer_t RAMCache;        ///< Buffers samples (already uncompressed) in RAM.              buffer_t RAMCache;        ///< Buffers samples (already uncompressed) in RAM.
78              long SetPos(unsigned long FrameCount, int Whence);              long SetPos(unsigned long FrameCount, int Whence);
79      };      };
80    
81        template <class R>
82        class SampleFileBase : public SampleFile {
83            public:
84                SampleFileBase(String File, bool DontClose = false) : SampleFile(File, DontClose) { }
85                virtual ~SampleFileBase() { }
86    
87    
88    
89                /**
90                 * Reads \a SampleCount number of sample points from the position stored
91                 * in \a pPlaybackState into the buffer pointed by \a pBuffer and moves
92                 * the position within the sample respectively, this method honors the
93                 * looping informations of the sample (if any). Use this
94                 * method if you don't want to load the sample into RAM, thus for disk
95                 * streaming. All this methods needs to know to proceed with streaming
96                 * for the next time you call this method is stored in \a pPlaybackState.
97                 * You have to allocate and initialize the playback_state_t structure by
98                 * yourself before you use it to stream a sample:
99                 * @code
100                 * PlaybackState playbackstate;
101                 * playbackstate.position         = 0;
102                 * playbackstate.reverse          = false;
103                 * playbackstate.loop_cycles_left = pSample->LoopPlayCount;
104                 * @endcode
105                 * You don't have to take care of things like if there is actually a loop
106                 * defined or if the current read position is located within a loop area.
107                 * The method already handles such cases by itself.
108                 *
109                 * @param pBuffer          destination buffer
110                 * @param FrameCount       number of sample points to read
111                 * @param pPlaybackState   will be used to store and reload the playback
112                 *                         state for the next ReadAndLoop() call
113                 * @returns                number of successfully read sample points
114                 */
115                unsigned long ReadAndLoop (
116                    void*           pBuffer,
117                    unsigned long   FrameCount,
118                    PlaybackState*  pPlaybackState,
119                    R*              pRegion
120                ) {
121                    // TODO: startAddrsCoarseOffset, endAddrsCoarseOffset
122                    unsigned long samplestoread = FrameCount, totalreadsamples = 0, readsamples, samplestoloopend;
123                    uint8_t* pDst = (uint8_t*) pBuffer;
124                    SetPos(pPlaybackState->position);
125                    if (pRegion->HasLoop()) {
126                        do {
127                            samplestoloopend  = pRegion->GetLoopEnd() - GetPos();
128                            readsamples       = Read(&pDst[totalreadsamples * GetFrameSize()], Min(samplestoread, samplestoloopend));
129                            samplestoread    -= readsamples;
130                            totalreadsamples += readsamples;
131                            if (readsamples == samplestoloopend) {
132                                SetPos(pRegion->GetLoopStart());
133                            }
134                        } while (samplestoread && readsamples);
135                    } else {
136                        totalreadsamples = Read(pBuffer, FrameCount);
137                    }
138    
139                    pPlaybackState->position = GetPos();
140    
141                    return totalreadsamples;
142                }
143    
144            protected:
145                inline long Min(long A, long B) { return (A > B) ? B : A; }
146        };
147  } // namespace LinuxSampler  } // namespace LinuxSampler
148    
149  #endif // __LS_SAMPLEFILE_H__  #endif // __LS_SAMPLEFILE_H__

Legend:
Removed from v.2020  
changed lines
  Added in v.2021

  ViewVC Help
Powered by ViewVC