38 |
::gig::Sample* pSample = pDimRgn->pSample; |
::gig::Sample* pSample = pDimRgn->pSample; |
39 |
long total_readsamples = 0, readsamples = 0; |
long total_readsamples = 0, readsamples = 0; |
40 |
long samplestoread = SampleCount / pSample->Channels; |
long samplestoread = SampleCount / pSample->Channels; |
41 |
sample_t* pBuf = pRingBuffer->get_write_ptr(); |
uint8_t* pBuf = pRingBuffer->get_write_ptr(); |
42 |
bool endofsamplereached; |
bool endofsamplereached; |
43 |
|
|
44 |
// refill the disk stream buffer |
// refill the disk stream buffer |
52 |
pSample->SetPos(this->SampleOffset); // recover old position |
pSample->SetPos(this->SampleOffset); // recover old position |
53 |
|
|
54 |
do { |
do { |
55 |
readsamples = pSample->Read(&pBuf[total_readsamples * pSample->Channels], samplestoread, pDecompressionBuffer); |
readsamples = pSample->Read(&pBuf[total_readsamples * pSample->FrameSize], samplestoread, pDecompressionBuffer); |
56 |
samplestoread -= readsamples; |
samplestoread -= readsamples; |
57 |
total_readsamples += readsamples; |
total_readsamples += readsamples; |
58 |
} while (samplestoread && readsamples > 0); |
} while (samplestoread && readsamples > 0); |
66 |
|
|
67 |
// we must delay the increment_write_ptr_with_wrap() after the while() loop because we need to |
// we must delay the increment_write_ptr_with_wrap() after the while() loop because we need to |
68 |
// ensure that we read exactly SampleCount sample, otherwise the buffer wrapping code will fail |
// ensure that we read exactly SampleCount sample, otherwise the buffer wrapping code will fail |
69 |
pRingBuffer->increment_write_ptr_with_wrap(total_readsamples * pSample->Channels); |
pRingBuffer->increment_write_ptr_with_wrap(total_readsamples * pSample->FrameSize); |
70 |
|
|
71 |
// update stream state |
// update stream state |
72 |
if (endofsamplereached) SetState(state_end); |
if (endofsamplereached) SetState(state_end); |
76 |
} |
} |
77 |
|
|
78 |
void Stream::WriteSilence(unsigned long SilenceSampleWords) { |
void Stream::WriteSilence(unsigned long SilenceSampleWords) { |
79 |
memset(pRingBuffer->get_write_ptr(), 0, SilenceSampleWords * 2); |
memset(pRingBuffer->get_write_ptr(), 0, SilenceSampleWords * BytesPerSample); |
80 |
pRingBuffer->increment_write_ptr_with_wrap(SilenceSampleWords); |
pRingBuffer->increment_write_ptr_with_wrap(SilenceSampleWords * BytesPerSample); |
81 |
} |
} |
82 |
|
|
83 |
Stream::Stream( ::gig::buffer_t* pDecompressionBuffer, uint BufferSize, uint BufferWrapElements) { |
Stream::Stream( ::gig::buffer_t* pDecompressionBuffer, uint BufferSize, uint BufferWrapElements) { |
88 |
this->SampleOffset = 0; |
this->SampleOffset = 0; |
89 |
this->PlaybackState.position = 0; |
this->PlaybackState.position = 0; |
90 |
this->PlaybackState.reverse = false; |
this->PlaybackState.reverse = false; |
91 |
this->pRingBuffer = new RingBuffer<sample_t>(BufferSize, BufferWrapElements); |
this->pRingBuffer = new RingBuffer<uint8_t>(BufferSize * 3, BufferWrapElements * 3); |
92 |
this->pDecompressionBuffer = pDecompressionBuffer; |
this->pDecompressionBuffer = pDecompressionBuffer; |
93 |
UnusedStreams++; |
UnusedStreams++; |
94 |
TotalStreams++; |
TotalStreams++; |
112 |
this->PlaybackState.reverse = false; |
this->PlaybackState.reverse = false; |
113 |
this->PlaybackState.loop_cycles_left = pDimRgn->pSample->LoopPlayCount; |
this->PlaybackState.loop_cycles_left = pDimRgn->pSample->LoopPlayCount; |
114 |
this->DoLoop = DoLoop; |
this->DoLoop = DoLoop; |
115 |
|
BytesPerSample = pDimRgn->pSample->BitDepth / 8; |
116 |
SetState(state_active); |
SetState(state_active); |
117 |
} |
} |
118 |
|
|