2 |
* * |
* * |
3 |
* LinuxSampler - modular, streaming capable sampler * |
* LinuxSampler - modular, streaming capable sampler * |
4 |
* * |
* * |
5 |
* Copyright (C) 2003, 2004 by Benno Senoner and Christian Schoenebeck * |
* Copyright (C) 2003,2004 by Benno Senoner and Christian Schoenebeck * |
6 |
* Copyright (C) 2005 Christian Schoenebeck * |
* Copyright (C) 2005-2009 Christian Schoenebeck * |
7 |
|
* Copyright (C) 2009 Grigor Iliev * |
8 |
* * |
* * |
9 |
* This program is free software; you can redistribute it and/or modify * |
* This program is free software; you can redistribute it and/or modify * |
10 |
* it under the terms of the GNU General Public License as published by * |
* it under the terms of the GNU General Public License as published by * |
23 |
***************************************************************************/ |
***************************************************************************/ |
24 |
|
|
25 |
#ifndef __LS_GIG_DISKTHREAD_H__ |
#ifndef __LS_GIG_DISKTHREAD_H__ |
26 |
#define __LS_GIG_DISKTHREAD_H__ |
#define __LS_GIG_DISKTHREAD_H__ |
|
|
|
|
#include "../../common/global.h" |
|
27 |
|
|
28 |
|
#include "../InstrumentManagerBase.h" |
29 |
|
#include "../common/DiskThreadBase.h" |
30 |
|
#include "InstrumentResourceManager.h" |
31 |
#include <gig.h> |
#include <gig.h> |
32 |
|
|
|
#include "../../common/Thread.h" |
|
|
#include "../../common/RingBuffer.h" |
|
|
#include "Stream.h" |
|
|
#include "Voice.h" |
|
|
|
|
33 |
namespace LinuxSampler { namespace gig { |
namespace LinuxSampler { namespace gig { |
34 |
|
|
35 |
int CompareStreamWriteSpace(const void* a, const void* b); |
class DiskThread: public LinuxSampler::DiskThreadBase< ::gig::DimensionRegion, InstrumentResourceManager> { |
|
|
|
|
class DiskThread : public Thread { |
|
|
public: |
|
|
// Methods |
|
|
DiskThread(uint BufferWrapElements); |
|
|
virtual ~DiskThread(); |
|
|
void Reset(); |
|
|
String GetBufferFillBytes(); |
|
|
String GetBufferFillPercentage(); |
|
|
int OrderNewStream(Stream::reference_t* pStreamRef, ::gig::Sample* pSample, unsigned long SampleOffset, bool DoLoop); |
|
|
int OrderDeletionOfStream(Stream::reference_t* pStreamRef); |
|
|
Stream* AskForCreatedStream(Stream::OrderID_t StreamOrderID); |
|
|
|
|
|
// the number of streams currently in usage |
|
|
// printed on the console the main thread (along with the active voice count) |
|
|
int ActiveStreamCount; |
|
|
int ActiveStreamCountMax; |
|
|
|
|
36 |
protected: |
protected: |
37 |
::gig::buffer_t DecompressionBuffer; ///< Used for thread safe streaming. |
::gig::buffer_t DecompressionBuffer; ///< Used for thread safe streaming. |
38 |
|
|
39 |
int Main(); ///< Implementation of virtual method from class Thread |
virtual LinuxSampler::Stream* CreateStream(long BufferSize, uint BufferWrapElements); |
40 |
|
|
41 |
friend class Stream; |
virtual void LaunchStream ( |
42 |
private: |
LinuxSampler::Stream* pStream, |
43 |
// Private Types |
Stream::Handle hStream, |
44 |
struct create_command_t { |
Stream::reference_t* pExportReference, |
45 |
Stream::OrderID_t OrderID; |
::gig::DimensionRegion* pRgn, |
46 |
Stream::Handle hStream; |
unsigned long SampleOffset, |
47 |
Stream::reference_t* pStreamRef; |
bool DoLoop |
48 |
::gig::Sample* pSample; |
); |
49 |
unsigned long SampleOffset; |
|
50 |
bool DoLoop; |
public: |
51 |
}; |
DiskThread(int MaxStreams, uint BufferWrapElements, InstrumentResourceManager* pInstruments); |
52 |
struct delete_command_t { |
virtual ~DiskThread(); |
|
Stream* pStream; |
|
|
Stream::Handle hStream; |
|
|
Stream::OrderID_t OrderID; |
|
|
}; |
|
|
|
|
|
// Attributes |
|
|
bool IsIdle; |
|
|
uint Streams; |
|
|
RingBuffer<create_command_t>* CreationQueue; ///< Contains commands to create streams |
|
|
RingBuffer<delete_command_t>* DeletionQueue; ///< Contains commands to delete streams |
|
|
RingBuffer<Stream::Handle>* GhostQueue; ///< Contains handles to streams that are not used anymore and weren't deletable immediately |
|
|
unsigned int RefillStreamsPerRun; ///< How many streams should be refilled in each loop run |
|
|
Stream* pStreams[CONFIG_MAX_STREAMS]; ///< Contains all disk streams (wether used or unused) |
|
|
Stream* pCreatedStreams[CONFIG_MAX_STREAMS + 1]; ///< This is where the voice (audio thread) picks up it's meanwhile hopefully created disk stream. |
|
|
static Stream* SLOT_RESERVED; ///< This value is used to mark an entry in pCreatedStreams[] as reserved. |
|
|
|
|
|
// Methods |
|
|
void CreateStream(create_command_t& Command); |
|
|
void DeleteStream(delete_command_t& Command); |
|
|
void RefillStreams(); |
|
|
Stream::Handle CreateHandle(); |
|
|
Stream::OrderID_t CreateOrderID(); |
|
53 |
}; |
}; |
54 |
|
|
55 |
|
|
56 |
}} // namespace LinuxSampler::gig |
}} // namespace LinuxSampler::gig |
57 |
|
|
58 |
#endif // __LS_GIG_DISKTHREAD_H__ |
#endif /* __LS_GIG_STREAM_H__ */ |
59 |
|
|