1 |
schoenebeck |
53 |
/*************************************************************************** |
2 |
|
|
* * |
3 |
|
|
* LinuxSampler - modular, streaming capable sampler * |
4 |
|
|
* * |
5 |
schoenebeck |
56 |
* Copyright (C) 2003, 2004 by Benno Senoner and Christian Schoenebeck * |
6 |
schoenebeck |
970 |
* Copyright (C) 2005, 2006 Christian Schoenebeck * |
7 |
schoenebeck |
53 |
* * |
8 |
|
|
* This program is free software; you can redistribute it and/or modify * |
9 |
|
|
* it under the terms of the GNU General Public License as published by * |
10 |
|
|
* the Free Software Foundation; either version 2 of the License, or * |
11 |
|
|
* (at your option) any later version. * |
12 |
|
|
* * |
13 |
|
|
* This program is distributed in the hope that it will be useful, * |
14 |
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of * |
15 |
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * |
16 |
|
|
* GNU General Public License for more details. * |
17 |
|
|
* * |
18 |
|
|
* You should have received a copy of the GNU General Public License * |
19 |
|
|
* along with this program; if not, write to the Free Software * |
20 |
|
|
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, * |
21 |
|
|
* MA 02111-1307 USA * |
22 |
|
|
***************************************************************************/ |
23 |
|
|
|
24 |
|
|
#ifndef __LS_GIG_DISKTHREAD_H__ |
25 |
|
|
#define __LS_GIG_DISKTHREAD_H__ |
26 |
|
|
|
27 |
|
|
#include "../../common/global.h" |
28 |
|
|
|
29 |
schoenebeck |
505 |
#include <gig.h> |
30 |
|
|
|
31 |
schoenebeck |
53 |
#include "../../common/Thread.h" |
32 |
|
|
#include "../../common/RingBuffer.h" |
33 |
|
|
#include "Stream.h" |
34 |
|
|
#include "Voice.h" |
35 |
|
|
|
36 |
|
|
namespace LinuxSampler { namespace gig { |
37 |
|
|
|
38 |
|
|
int CompareStreamWriteSpace(const void* a, const void* b); |
39 |
|
|
|
40 |
schoenebeck |
563 |
/** @brief Disk Reader Thread |
41 |
|
|
* |
42 |
|
|
* The disk reader thread is responsible for periodically refilling |
43 |
|
|
* disk streams in parallel to the audio thread's rendering process. |
44 |
persson |
1038 |
* |
45 |
|
|
* There is also a function for releasing parts of instruments not |
46 |
|
|
* in use anymore (as this is not real time safe, the audio thread |
47 |
|
|
* cannot do it directly). |
48 |
schoenebeck |
563 |
*/ |
49 |
schoenebeck |
53 |
class DiskThread : public Thread { |
50 |
|
|
public: |
51 |
|
|
// Methods |
52 |
persson |
1038 |
DiskThread(uint BufferWrapElements, InstrumentResourceManager* pInstruments); |
53 |
letz |
502 |
virtual ~DiskThread(); |
54 |
schoenebeck |
53 |
void Reset(); |
55 |
|
|
String GetBufferFillBytes(); |
56 |
|
|
String GetBufferFillPercentage(); |
57 |
persson |
865 |
int OrderNewStream(Stream::reference_t* pStreamRef, ::gig::DimensionRegion* pDimRgn, unsigned long SampleOffset, bool DoLoop); |
58 |
schoenebeck |
53 |
int OrderDeletionOfStream(Stream::reference_t* pStreamRef); |
59 |
persson |
1038 |
int OrderDeletionOfDimreg(::gig::DimensionRegion* dimreg); |
60 |
schoenebeck |
53 |
Stream* AskForCreatedStream(Stream::OrderID_t StreamOrderID); |
61 |
|
|
|
62 |
|
|
// the number of streams currently in usage |
63 |
|
|
// printed on the console the main thread (along with the active voice count) |
64 |
|
|
int ActiveStreamCount; |
65 |
|
|
int ActiveStreamCountMax; |
66 |
|
|
|
67 |
|
|
protected: |
68 |
schoenebeck |
385 |
::gig::buffer_t DecompressionBuffer; ///< Used for thread safe streaming. |
69 |
|
|
|
70 |
schoenebeck |
53 |
int Main(); ///< Implementation of virtual method from class Thread |
71 |
schoenebeck |
385 |
|
72 |
|
|
friend class Stream; |
73 |
schoenebeck |
53 |
private: |
74 |
|
|
// Private Types |
75 |
|
|
struct create_command_t { |
76 |
|
|
Stream::OrderID_t OrderID; |
77 |
|
|
Stream::Handle hStream; |
78 |
|
|
Stream::reference_t* pStreamRef; |
79 |
persson |
865 |
::gig::DimensionRegion* pDimRgn; |
80 |
schoenebeck |
53 |
unsigned long SampleOffset; |
81 |
|
|
bool DoLoop; |
82 |
|
|
}; |
83 |
|
|
struct delete_command_t { |
84 |
|
|
Stream* pStream; |
85 |
|
|
Stream::Handle hStream; |
86 |
|
|
Stream::OrderID_t OrderID; |
87 |
|
|
}; |
88 |
|
|
|
89 |
|
|
// Attributes |
90 |
|
|
bool IsIdle; |
91 |
|
|
uint Streams; |
92 |
schoenebeck |
970 |
RingBuffer<create_command_t,false>* CreationQueue; ///< Contains commands to create streams |
93 |
|
|
RingBuffer<delete_command_t,false>* DeletionQueue; ///< Contains commands to delete streams |
94 |
|
|
RingBuffer<Stream::Handle,false>* GhostQueue; ///< Contains handles to streams that are not used anymore and weren't deletable immediately |
95 |
persson |
1038 |
RingBuffer< ::gig::DimensionRegion*,false>* DeleteDimregQueue; ///< Contains dimension regions that are not used anymore and should be handed back to the instrument resource manager |
96 |
schoenebeck |
53 |
unsigned int RefillStreamsPerRun; ///< How many streams should be refilled in each loop run |
97 |
iliev |
724 |
Stream* pStreams[CONFIG_MAX_STREAMS]; ///< Contains all disk streams (whether used or unused) |
98 |
schoenebeck |
554 |
Stream* pCreatedStreams[CONFIG_MAX_STREAMS + 1]; ///< This is where the voice (audio thread) picks up it's meanwhile hopefully created disk stream. |
99 |
schoenebeck |
53 |
static Stream* SLOT_RESERVED; ///< This value is used to mark an entry in pCreatedStreams[] as reserved. |
100 |
persson |
1038 |
InstrumentResourceManager* pInstruments; ///< The instrument resource manager of the engine that is using this disk thread. Used by the dimension region deletion feature. |
101 |
schoenebeck |
53 |
|
102 |
|
|
// Methods |
103 |
|
|
void CreateStream(create_command_t& Command); |
104 |
|
|
void DeleteStream(delete_command_t& Command); |
105 |
|
|
void RefillStreams(); |
106 |
|
|
Stream::Handle CreateHandle(); |
107 |
|
|
Stream::OrderID_t CreateOrderID(); |
108 |
|
|
}; |
109 |
|
|
|
110 |
|
|
}} // namespace LinuxSampler::gig |
111 |
|
|
|
112 |
|
|
#endif // __LS_GIG_DISKTHREAD_H__ |