1 |
/*************************************************************************** |
2 |
* * |
3 |
* LinuxSampler - modular, streaming capable sampler * |
4 |
* * |
5 |
* Copyright (C) 2003 by Benno Senoner * |
6 |
* * |
7 |
* This program is free software; you can redistribute it and/or modify * |
8 |
* it under the terms of the GNU General Public License as published by * |
9 |
* the Free Software Foundation; either version 2 of the License, or * |
10 |
* (at your option) any later version. * |
11 |
* * |
12 |
* This program is distributed in the hope that it will be useful, * |
13 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of * |
14 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * |
15 |
* GNU General Public License for more details. * |
16 |
* * |
17 |
* You should have received a copy of the GNU General Public License * |
18 |
* along with this program; if not, write to the Free Software * |
19 |
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, * |
20 |
* MA 02111-1307 USA * |
21 |
***************************************************************************/ |
22 |
|
23 |
#ifndef __DISKTHREAD_H__ |
24 |
#define __DISKTHREAD_H__ |
25 |
|
26 |
#define REFILL_STREAMS_PER_RUN 4 ///< number of streams that should be refilled with each disk thread cycle |
27 |
#define MIN_REFILL_SIZE 1024 ///< if no buffer was filled up more than this bottom limit, the disk thread will go to sleep |
28 |
#define MAX_REFILL_SIZE 65536 ///< maximum of samples a buffer should be refilled in one cycle (256kB, as 16 bit stereo) |
29 |
#define STREAM_BUFFER_SIZE 131072 ///< the diskstream ringbuffer size (256kB as sample_t is 16bit) |
30 |
#define MAX_INPUT_STREAMS 100 ///< number of streams that should be allocated |
31 |
|
32 |
#include "global.h" |
33 |
#include "thread.h" |
34 |
#include "voice.h" |
35 |
#include "ringbuffer.h" |
36 |
#include "stream.h" |
37 |
|
38 |
int CompareStreamWriteSpace(const void* a, const void* b); |
39 |
|
40 |
class DiskThread : public Thread { |
41 |
public: |
42 |
// Methods |
43 |
DiskThread(uint BufferWrapElements); |
44 |
~DiskThread(); |
45 |
void Reset(); |
46 |
String GetBufferFillBytes(); |
47 |
String GetBufferFillPercentage(); |
48 |
int OrderNewStream(Stream::reference_t* pStreamRef, gig::Sample* pSample, unsigned long SampleOffset, bool DoLoop); |
49 |
int OrderDeletionOfStream(Stream::reference_t* pStreamRef); |
50 |
Stream* AskForCreatedStream(Stream::OrderID_t StreamOrderID); |
51 |
|
52 |
// the number of streams currently in usage |
53 |
// printed on the console the main thread (along with the active voice count) |
54 |
int ActiveStreamCount; |
55 |
int ActiveStreamCountMax; |
56 |
|
57 |
protected: |
58 |
int Main(); ///< Implementation of virtual method from class Thread |
59 |
private: |
60 |
// Private Types |
61 |
struct create_command_t { |
62 |
Stream::OrderID_t OrderID; |
63 |
Stream::Handle hStream; |
64 |
Stream::reference_t* pStreamRef; |
65 |
gig::Sample* pSample; |
66 |
unsigned long SampleOffset; |
67 |
bool DoLoop; |
68 |
}; |
69 |
struct delete_command_t { |
70 |
Stream* pStream; |
71 |
Stream::Handle hStream; |
72 |
Stream::OrderID_t OrderID; |
73 |
}; |
74 |
|
75 |
// Attributes |
76 |
bool IsIdle; |
77 |
uint Streams; |
78 |
RingBuffer<create_command_t>* CreationQueue; ///< Contains commands to create streams |
79 |
RingBuffer<delete_command_t>* DeletionQueue; ///< Contains commands to delete streams |
80 |
RingBuffer<Stream::Handle>* GhostQueue; ///< Contains handles to streams that are not used anymore and weren't deletable immediately |
81 |
unsigned int RefillStreamsPerRun; ///< How many streams should be refilled in each loop run |
82 |
Stream* pStreams[MAX_INPUT_STREAMS]; ///< Contains all disk streams (wether used or unused) |
83 |
Stream* pCreatedStreams[MAX_INPUT_STREAMS + 1]; ///< This is where the voice (audio thread) picks up it's meanwhile hopefully created disk stream. |
84 |
static Stream* SLOT_RESERVED; ///< This value is used to mark an entry in pCreatedStreams[] as reserved. |
85 |
|
86 |
// Methods |
87 |
void CreateStream(create_command_t& Command); |
88 |
void DeleteStream(delete_command_t& Command); |
89 |
void RefillStreams(); |
90 |
Stream::Handle CreateHandle(); |
91 |
Stream::OrderID_t CreateOrderID(); |
92 |
}; |
93 |
|
94 |
#endif // __DISKTHREAD_H__ |