/[svn]/linuxsampler/trunk/src/engines/gig/Stream.cpp
ViewVC logotype

Annotation of /linuxsampler/trunk/src/engines/gig/Stream.cpp

Parent Directory Parent Directory | Revision Log Revision Log


Revision 3054 - (hide annotations) (download)
Thu Dec 15 12:47:45 2016 UTC (7 years, 4 months ago) by schoenebeck
File size: 5200 byte(s)
* Fixed numerous compiler warnings.
* Bumped version (2.0.0.svn32).

1 schoenebeck 53 /***************************************************************************
2     * *
3     * LinuxSampler - modular, streaming capable sampler *
4     * *
5 iliev 2012 * Copyright (C) 2003,2004 by Benno Senoner and Christian Schoenebeck *
6     * Copyright (C) 2005-2009 Christian Schoenebeck *
7 schoenebeck 3054 * Copyright (C) 2009 Christian Schoenebeck and Grigor Iliev *
8     * Copyright (C) 2016 Christian Schoenebeck *
9 schoenebeck 53 * *
10     * This program is free software; you can redistribute it and/or modify *
11     * it under the terms of the GNU General Public License as published by *
12     * the Free Software Foundation; either version 2 of the License, or *
13     * (at your option) any later version. *
14     * *
15     * This program is distributed in the hope that it will be useful, *
16     * but WITHOUT ANY WARRANTY; without even the implied warranty of *
17     * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
18     * GNU General Public License for more details. *
19     * *
20     * You should have received a copy of the GNU General Public License *
21     * along with this program; if not, write to the Free Software *
22     * Foundation, Inc., 59 Temple Place, Suite 330, Boston, *
23     * MA 02111-1307 USA *
24     ***************************************************************************/
25    
26     #include "Stream.h"
27 schoenebeck 1424 #include "../../common/global_private.h"
28    
29 schoenebeck 53 namespace LinuxSampler { namespace gig {
30    
31 iliev 2012 Stream::Stream (
32     ::gig::buffer_t* pDecompressionBuffer,
33     uint BufferSize,
34     uint BufferWrapElements) : LinuxSampler::StreamBase< ::gig::DimensionRegion>(BufferSize, BufferWrapElements)
35     {
36     this->pDecompressionBuffer = pDecompressionBuffer;
37     }
38 schoenebeck 53
39 iliev 2012 long Stream::Read(uint8_t* pBuf, long SamplesToRead) {
40     ::gig::Sample* pSample = pRegion->pSample;
41 schoenebeck 53 long total_readsamples = 0, readsamples = 0;
42     bool endofsamplereached;
43    
44     // refill the disk stream buffer
45     if (this->DoLoop) { // honor looping
46 iliev 2012 ::gig::playback_state_t pbs;
47     pbs.position = PlaybackState.position;
48     pbs.reverse = PlaybackState.reverse;
49     pbs.loop_cycles_left = PlaybackState.loop_cycles_left;
50    
51     total_readsamples = pSample->ReadAndLoop(pBuf, SamplesToRead, &pbs, pRegion, pDecompressionBuffer);
52     PlaybackState.position = pbs.position;
53     PlaybackState.reverse = pbs.reverse;
54     PlaybackState.loop_cycles_left = pbs.loop_cycles_left;
55 schoenebeck 53 endofsamplereached = (this->PlaybackState.position >= pSample->SamplesTotal);
56 persson 2837 dmsg(5,("Refilled stream %d with %ld (SamplePos: %lu)", this->hThis, total_readsamples, this->PlaybackState.position));
57 schoenebeck 53 }
58     else { // normal forward playback
59    
60     pSample->SetPos(this->SampleOffset); // recover old position
61    
62     do {
63 iliev 2012 readsamples = pSample->Read(&pBuf[total_readsamples * pSample->FrameSize], SamplesToRead, pDecompressionBuffer);
64     SamplesToRead -= readsamples;
65 schoenebeck 53 total_readsamples += readsamples;
66 iliev 2012 } while (SamplesToRead && readsamples > 0);
67 schoenebeck 53
68     // we have to store the position within the sample, because other streams might use the same sample
69     this->SampleOffset = pSample->GetPos();
70    
71     endofsamplereached = (SampleOffset >= pSample->SamplesTotal);
72 persson 2837 dmsg(5,("Refilled stream %d with %ld (SamplePos: %lu)", this->hThis, total_readsamples, this->SampleOffset));
73 schoenebeck 53 }
74    
75     // update stream state
76     if (endofsamplereached) SetState(state_end);
77     else SetState(state_active);
78    
79     return total_readsamples;
80     }
81    
82 iliev 2012 void Stream::Launch (
83     Stream::Handle hStream,
84     reference_t* pExportReference,
85     ::gig::DimensionRegion* pRgn,
86     unsigned long SampleOffset,
87     bool DoLoop
88     ) {
89     SampleDescription info;
90     info.ChannelsPerFrame = pRgn->pSample->Channels;
91     info.FrameSize = pRgn->pSample->FrameSize;
92     info.BytesPerSample = pRgn->pSample->BitDepth / 8;
93 schoenebeck 3054 info.TotalSampleCount = (int)pRgn->pSample->SamplesTotal;
94 schoenebeck 53
95 iliev 2012 Sample::PlaybackState playbackState;
96     playbackState.position = SampleOffset;
97     playbackState.reverse = false;
98     playbackState.loop_cycles_left = pRgn->pSample->LoopPlayCount;
99 schoenebeck 53
100 iliev 2012 LinuxSampler::StreamBase< ::gig::DimensionRegion>::Launch (
101     hStream, pExportReference, pRgn, info, playbackState, SampleOffset, DoLoop
102     );
103 schoenebeck 53 }
104    
105     }} // namespace LinuxSampler::gig

  ViewVC Help
Powered by ViewVC