/[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 538 - (hide annotations) (download) (as text)
Wed May 11 20:02:17 2005 UTC (18 years, 11 months ago) by schoenebeck
File MIME type: text/x-c++hdr
File size: 5847 byte(s)
just some cleanup

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 schoenebeck 505 #include <gig.h>
34    
35 schoenebeck 53 #define REFILL_STREAMS_PER_RUN 4 ///< number of streams that should be refilled with each disk thread cycle
36     #define MIN_REFILL_SIZE 1024 ///< if no buffer was filled up more than this bottom limit, the disk thread will go to sleep
37     #define MAX_REFILL_SIZE 65536 ///< maximum of samples a buffer should be refilled in one cycle (256kB, as 16 bit stereo)
38 schoenebeck 538 #define STREAM_BUFFER_SIZE 262144 ///< the diskstream ringbuffer size (512kB as sample_t is 16bit)
39     #define MAX_INPUT_STREAMS 90 ///< number of streams that should be allocated
40 schoenebeck 53
41     #include "../../common/Thread.h"
42     #include "../../common/RingBuffer.h"
43     #include "Stream.h"
44     #include "Voice.h"
45    
46     namespace LinuxSampler { namespace gig {
47    
48     int CompareStreamWriteSpace(const void* a, const void* b);
49    
50     class DiskThread : public Thread {
51     public:
52     // Methods
53     DiskThread(uint BufferWrapElements);
54 letz 502 virtual ~DiskThread();
55 schoenebeck 53 void Reset();
56     String GetBufferFillBytes();
57     String GetBufferFillPercentage();
58     int OrderNewStream(Stream::reference_t* pStreamRef, ::gig::Sample* pSample, unsigned long SampleOffset, bool DoLoop);
59     int OrderDeletionOfStream(Stream::reference_t* pStreamRef);
60     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     ::gig::Sample* pSample;
80     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     RingBuffer<create_command_t>* CreationQueue; ///< Contains commands to create streams
93     RingBuffer<delete_command_t>* DeletionQueue; ///< Contains commands to delete streams
94     RingBuffer<Stream::Handle>* GhostQueue; ///< Contains handles to streams that are not used anymore and weren't deletable immediately
95     unsigned int RefillStreamsPerRun; ///< How many streams should be refilled in each loop run
96     Stream* pStreams[MAX_INPUT_STREAMS]; ///< Contains all disk streams (wether used or unused)
97     Stream* pCreatedStreams[MAX_INPUT_STREAMS + 1]; ///< This is where the voice (audio thread) picks up it's meanwhile hopefully created disk stream.
98     static Stream* SLOT_RESERVED; ///< This value is used to mark an entry in pCreatedStreams[] as reserved.
99    
100     // Methods
101     void CreateStream(create_command_t& Command);
102     void DeleteStream(delete_command_t& Command);
103     void RefillStreams();
104     Stream::Handle CreateHandle();
105     Stream::OrderID_t CreateOrderID();
106     };
107    
108     }} // namespace LinuxSampler::gig
109    
110     #endif // __LS_GIG_DISKTHREAD_H__

  ViewVC Help
Powered by ViewVC