/[svn]/linuxsampler/trunk/src/engines/gig/DiskThread.h
ViewVC logotype

Annotation of /linuxsampler/trunk/src/engines/gig/DiskThread.h

Parent Directory Parent Directory | Revision Log Revision Log


Revision 502 - (hide annotations) (download) (as text)
Fri Apr 29 14:20:22 2005 UTC (18 years, 11 months ago) by letz
File MIME type: text/x-c++hdr
File size: 6000 byte(s)
Fix destructor

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 385 * Copyright (C) 2005 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     #if DEBUG_HEADERS
30     # warning DiskThread.h included
31     #endif // DEBUG_HEADERS
32    
33     #define REFILL_STREAMS_PER_RUN 4 ///< number of streams that should be refilled with each disk thread cycle
34     #define MIN_REFILL_SIZE 1024 ///< if no buffer was filled up more than this bottom limit, the disk thread will go to sleep
35     #define MAX_REFILL_SIZE 65536 ///< maximum of samples a buffer should be refilled in one cycle (256kB, as 16 bit stereo)
36    
37 letz 502
38     //#define STREAM_BUFFER_SIZE 131072 ///< the diskstream ringbuffer size (256kB as sample_t is 16bit)
39    
40     #define STREAM_BUFFER_SIZE 262144
41     //#define MAX_INPUT_STREAMS 150 ///< number of streams that should be allocated
42    
43     #define MAX_INPUT_STREAMS 90 ///< number of streams that should be allocated
44    
45    
46 schoenebeck 53 #include "../../common/Thread.h"
47     #include "../../common/RingBuffer.h"
48 schoenebeck 385 #include "../../lib/fileloader/libgig/gig.h"
49 schoenebeck 53 #include "Stream.h"
50     #include "Voice.h"
51    
52     namespace LinuxSampler { namespace gig {
53    
54     int CompareStreamWriteSpace(const void* a, const void* b);
55    
56     class DiskThread : public Thread {
57     public:
58     // Methods
59     DiskThread(uint BufferWrapElements);
60 letz 502 virtual ~DiskThread();
61 schoenebeck 53 void Reset();
62     String GetBufferFillBytes();
63     String GetBufferFillPercentage();
64     int OrderNewStream(Stream::reference_t* pStreamRef, ::gig::Sample* pSample, unsigned long SampleOffset, bool DoLoop);
65     int OrderDeletionOfStream(Stream::reference_t* pStreamRef);
66     Stream* AskForCreatedStream(Stream::OrderID_t StreamOrderID);
67    
68     // the number of streams currently in usage
69     // printed on the console the main thread (along with the active voice count)
70     int ActiveStreamCount;
71     int ActiveStreamCountMax;
72    
73     protected:
74 schoenebeck 385 ::gig::buffer_t DecompressionBuffer; ///< Used for thread safe streaming.
75    
76 schoenebeck 53 int Main(); ///< Implementation of virtual method from class Thread
77 schoenebeck 385
78     friend class Stream;
79 schoenebeck 53 private:
80     // Private Types
81     struct create_command_t {
82     Stream::OrderID_t OrderID;
83     Stream::Handle hStream;
84     Stream::reference_t* pStreamRef;
85     ::gig::Sample* pSample;
86     unsigned long SampleOffset;
87     bool DoLoop;
88     };
89     struct delete_command_t {
90     Stream* pStream;
91     Stream::Handle hStream;
92     Stream::OrderID_t OrderID;
93     };
94    
95     // Attributes
96     bool IsIdle;
97     uint Streams;
98     RingBuffer<create_command_t>* CreationQueue; ///< Contains commands to create streams
99     RingBuffer<delete_command_t>* DeletionQueue; ///< Contains commands to delete streams
100     RingBuffer<Stream::Handle>* GhostQueue; ///< Contains handles to streams that are not used anymore and weren't deletable immediately
101     unsigned int RefillStreamsPerRun; ///< How many streams should be refilled in each loop run
102     Stream* pStreams[MAX_INPUT_STREAMS]; ///< Contains all disk streams (wether used or unused)
103     Stream* pCreatedStreams[MAX_INPUT_STREAMS + 1]; ///< This is where the voice (audio thread) picks up it's meanwhile hopefully created disk stream.
104     static Stream* SLOT_RESERVED; ///< This value is used to mark an entry in pCreatedStreams[] as reserved.
105    
106     // Methods
107     void CreateStream(create_command_t& Command);
108     void DeleteStream(delete_command_t& Command);
109     void RefillStreams();
110     Stream::Handle CreateHandle();
111     Stream::OrderID_t CreateOrderID();
112     };
113    
114     }} // namespace LinuxSampler::gig
115    
116     #endif // __LS_GIG_DISKTHREAD_H__

  ViewVC Help
Powered by ViewVC