/[svn]/linuxsampler/trunk/src/linuxsampler.cpp
ViewVC logotype

Diff of /linuxsampler/trunk/src/linuxsampler.cpp

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 9 by schoenebeck, Wed Nov 5 14:47:10 2003 UTC revision 20 by schoenebeck, Thu Dec 25 00:02:45 2003 UTC
# Line 25  Line 25 
25  #include <unistd.h>  #include <unistd.h>
26  #include <getopt.h>  #include <getopt.h>
27  #include <signal.h>  #include <signal.h>
28    #include <pthread.h>
29    
30    #include <string>
31    
32  #include "global.h"  #include "global.h"
33  #include "audioio.h"  #include "audioio.h"
# Line 50  AudioIO*         pAudioIO; Line 53  AudioIO*         pAudioIO;
53  DiskThread*      pDiskThread;  DiskThread*      pDiskThread;
54  AudioThread*     pAudioThread;  AudioThread*     pAudioThread;
55  MidiIn*          pMidiInThread;  MidiIn*          pMidiInThread;
   
56  RIFF::File*      pRIFF;  RIFF::File*      pRIFF;
57  gig::File*       pGig;  gig::File*       pGig;
58  gig::Instrument* pInstrument;  gig::Instrument* pInstrument;
59    uint             instrument_index;
60    double           volume;
61    int              num_fragments;
62    int              fragmentsize;
63    std::string      input_client;
64    pthread_t        signalhandlerthread;
65    
66  void parse_options(int argc, char **argv);  void parse_options(int argc, char **argv);
67  void signal_handler(int signal);  void signal_handler(int signal);
68    
 int midi_non_blocking;  
 int num_fragments;  
 int fragmentsize;  
 bool instrument_is_DLS;  
 bool instruemtn_is_gig;  
 char midi_device[40];  
   
69  int main(int argc, char **argv) {  int main(int argc, char **argv) {
70      pAudioIO = NULL;      pAudioIO = NULL;
71      pRIFF    = NULL;      pRIFF    = NULL;
72      pGig     = NULL;      pGig     = NULL;
73    
74      // setting signal handler for catching SIGINT (thus e.g. <CTRL><C>)      // setting signal handler for catching SIGINT (thus e.g. <CTRL><C>)
75        signalhandlerthread = pthread_self();
76      signal(SIGINT, signal_handler);      signal(SIGINT, signal_handler);
77    
78      patch_format      = patch_format_unknown;      patch_format      = patch_format_unknown;
79      midi_non_blocking = 1;      instrument_index  = 0;
80      num_fragments     = AUDIO_FRAGMENTS;      num_fragments     = AUDIO_FRAGMENTS;
81      fragmentsize      = AUDIO_FRAGMENTSIZE;      fragmentsize      = AUDIO_FRAGMENTSIZE;
82      strcpy(midi_device, "/dev/midi00");      volume            = 0.25; // default volume
83    
84      // parse and assign command line options      // parse and assign command line options
85      parse_options(argc, argv);      parse_options(argc, argv);
86    
87      if (patch_format != patch_format_gig) {      if (patch_format != patch_format_gig) {
88          printf("Sorry only Gigasampler loading migrated in LinuxSampler so far, use --gig\n");          printf("Sorry only Gigasampler loading migrated in LinuxSampler so far, use --gig to load a .gig file!\n");
89          printf("to load a .gig file!\n");          printf("Use 'linuxsampler --help' to see all available options.\n");
90          return EXIT_FAILURE;          return EXIT_FAILURE;
91      }      }
92    
93      dmsg(("Initializing audio output..."));      dmsg(1,("Initializing audio output..."));
94      pAudioIO = new AudioIO();      pAudioIO = new AudioIO();
95      int error = pAudioIO->Initialize(AUDIO_CHANNELS, AUDIO_SAMPLERATE, num_fragments, fragmentsize);      int error = pAudioIO->Initialize(AUDIO_CHANNELS, AUDIO_SAMPLERATE, num_fragments, fragmentsize);
96      if (error) return EXIT_FAILURE;      if (error) return EXIT_FAILURE;
97      dmsg(("OK\n"));      dmsg(1,("OK\n"));
98    
99      // Loading gig file      // Loading gig file
100      try {      try {
# Line 100  int main(int argc, char **argv) { Line 102  int main(int argc, char **argv) {
102          fflush(stdout);          fflush(stdout);
103          pRIFF       = new RIFF::File(argv[argc - 1]);          pRIFF       = new RIFF::File(argv[argc - 1]);
104          pGig        = new gig::File(pRIFF);          pGig        = new gig::File(pRIFF);
105          pInstrument = pGig->GetFirstInstrument();          pInstrument = pGig->GetInstrument(instrument_index);
106            if (!pInstrument) {
107                printf("there's no instrument with index %d.\n", instrument_index);
108                exit(EXIT_FAILURE);
109            }
110          pGig->GetFirstSample(); // just to complete instrument loading before we enter the realtime part          pGig->GetFirstSample(); // just to complete instrument loading before we enter the realtime part
111          printf("OK\n");          printf("OK\n");
112          fflush(stdout);          fflush(stdout);
# Line 114  int main(int argc, char **argv) { Line 120  int main(int argc, char **argv) {
120          return EXIT_FAILURE;          return EXIT_FAILURE;
121      }      }
122    
123      DiskThread*  pDiskThread   = new DiskThread(((pAudioIO->FragmentSize << MAX_PITCH) << 1) + 3); //FIXME: assuming stereo      DiskThread*  pDiskThread   = new DiskThread(((pAudioIO->FragmentSize << MAX_PITCH) << 1) + 6); //FIXME: assuming stereo
124      AudioThread* pAudioThread  = new AudioThread(pAudioIO, pDiskThread, pInstrument);      AudioThread* pAudioThread  = new AudioThread(pAudioIO, pDiskThread, pInstrument);
125      MidiIn*      pMidiInThread = new MidiIn(pAudioThread);      MidiIn*      pMidiInThread = new MidiIn(pAudioThread);
126    
127      dmsg(("Starting disk thread..."));      dmsg(1,("Starting disk thread..."));
128      pDiskThread->StartThread();      pDiskThread->StartThread();
129      dmsg(("OK\n"));      dmsg(1,("OK\n"));
130      dmsg(("Starting MIDI in thread..."));      dmsg(1,("Starting MIDI in thread..."));
131        if (input_client.size() > 0) pMidiInThread->SubscribeToClient(input_client.c_str());
132      pMidiInThread->StartThread();      pMidiInThread->StartThread();
133      dmsg(("OK\n"));      dmsg(1,("OK\n"));
134    
135      sleep(1);      sleep(1);
136      dmsg(("Starting audio thread..."));      dmsg(1,("Starting audio thread..."));
137        pAudioThread->Volume = volume;
138      pAudioThread->StartThread();      pAudioThread->StartThread();
139      dmsg(("OK\n"));      dmsg(1,("OK\n"));
140    
141      printf("LinuxSampler initialization completed.\n");      printf("LinuxSampler initialization completed.\n");
142    
143      while(true) sleep(1000);      while(true)  {
144          printf("Voices: %3.3d (Max: %3.3d) Streams: %3.3d (Max: %3.3d, Unused: %3.3d)\r",
145                pAudioThread->ActiveVoiceCount, pAudioThread->ActiveVoiceCountMax,
146                pDiskThread->ActiveStreamCount, pDiskThread->ActiveStreamCountMax, Stream::GetUnusedStreams());
147          fflush(stdout);
148          usleep(500000);
149        }
150    
151      return EXIT_SUCCESS;      return EXIT_SUCCESS;
152  }  }
153    
154  void signal_handler(int signal) {  void signal_handler(int signal) {
155      if (signal == SIGINT) {      if (pthread_equal(pthread_self(), signalhandlerthread) && signal == SIGINT) {
156          // stop all threads          // stop all threads
157          if (pMidiInThread) pMidiInThread->StopThread();          if (pMidiInThread) pMidiInThread->StopThread();
158          if (pAudioThread)  pAudioThread->StopThread();          if (pAudioThread)  pAudioThread->StopThread();
159          if (pDiskThread)   pDiskThread->StopThread();          if (pDiskThread)   pDiskThread->StopThread();
160    
         sleep(1);  
   
161          // free all resources          // free all resources
162          if (pMidiInThread) delete pMidiInThread;          if (pMidiInThread) delete pMidiInThread;
163          if (pAudioThread)  delete pAudioThread;          if (pAudioThread)  delete pAudioThread;
# Line 165  void parse_options(int argc, char **argv Line 178  void parse_options(int argc, char **argv
178          {          {
179              {"numfragments",1,0,0},              {"numfragments",1,0,0},
180              {"fragmentsize",1,0,0},              {"fragmentsize",1,0,0},
181                {"volume",1,0,0},
182              {"dls",0,0,0},              {"dls",0,0,0},
183              {"gig",0,0,0},              {"gig",0,0,0},
184                {"instrument",1,0,0},
185                {"inputclient",1,0,0},
186              {"help",0,0,0},              {"help",0,0,0},
187              {0,0,0,0}              {0,0,0,0}
188          };          };
# Line 183  void parse_options(int argc, char **argv Line 199  void parse_options(int argc, char **argv
199                      fragmentsize = atoi(optarg);                      fragmentsize = atoi(optarg);
200                      break;                      break;
201                  case 2:                  case 2:
202                      patch_format = patch_format_dls;                      volume = atof(optarg);
203                      break;                      break;
204                  case 3:                  case 3:
205                      patch_format = patch_format_gig;                      patch_format = patch_format_dls;
206                      break;                      break;
207                  case 4:                  case 4:
208                        patch_format = patch_format_gig;
209                        break;
210                    case 5:
211                        instrument_index = atoi(optarg);
212                        break;
213                    case 6:
214                        input_client = optarg;
215                        break;
216                    case 7:
217                      printf("usage: linuxsampler [OPTIONS] <INSTRUMENTFILE>\n\n");                      printf("usage: linuxsampler [OPTIONS] <INSTRUMENTFILE>\n\n");
218                        printf("--gig              loads a Gigasampler instrument\n");
219                        printf("--dls              loads a DLS instrument\n");
220                        printf("--instrument       index of the instrument in the instrument file if it\n");
221                        printf("                   contains more than one (default: 0)\n");
222                      printf("--numfragments     sets the number of audio fragments\n");                      printf("--numfragments     sets the number of audio fragments\n");
223                      printf("--fragmentsize     sets the fragment size\n");                      printf("--fragmentsize     sets the fragment size\n");
224                      printf("--dls              loads a DLS instrument\n");                      printf("--volume           sets global volume gain factor (a value > 1.0 means\n");
225                      printf("--gig              loads a Gigasampler instrument\n");                      printf("                   amplification, a value < 1.0 means attenuation,\n");
226                        printf("                   default: 0.25)\n");
227                        printf("--inputclient      connects to an Alsa sequencer input client on startup\n");
228                        printf("                   (e.g. 64:0 to connect to a client with ID 64 and port 0)\n");
229                      exit(0);                      exit(0);
230                      break;                      break;
231              }              }

Legend:
Removed from v.9  
changed lines
  Added in v.20

  ViewVC Help
Powered by ViewVC