/[svn]/libgig/trunk/src/gigextract.cpp
ViewVC logotype

Diff of /libgig/trunk/src/gigextract.cpp

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

revision 365 by persson, Thu Feb 10 19:16:31 2005 UTC revision 608 by schoenebeck, Fri Jun 3 14:35:44 2005 UTC
# Line 2  Line 2 
2   *                                                                         *   *                                                                         *
3   *   libgig - C++ cross-platform Gigasampler format file loader library    *   *   libgig - C++ cross-platform Gigasampler format file loader library    *
4   *                                                                         *   *                                                                         *
5   *   Copyright (C) 2003, 2004 by Christian Schoenebeck                     *   *   Copyright (C) 2003-2005 by Christian Schoenebeck                      *
6   *                               <cuse@users.sourceforge.net>              *   *                              <cuse@users.sourceforge.net>               *
7   *                                                                         *   *                                                                         *
8   *   This program is free software; you can redistribute it and/or modify  *   *   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  *   *   it under the terms of the GNU General Public License as published by  *
# Line 40  Line 40 
40  #include <iostream>  #include <iostream>
41  #include <cstdlib>  #include <cstdlib>
42  #include <string.h>  #include <string.h>
43    #include <string>
44  #include <stdlib.h>  #include <stdlib.h>
45  #include <sys/types.h>  #include <sys/types.h>
46  #include <sys/stat.h>  #include <sys/stat.h>
# Line 52  Line 53 
53  # define HAVE_SNDFILE 1  # define HAVE_SNDFILE 1
54  #endif // WIN32  #endif // WIN32
55    
56    // abort compilation here if neither libsndfile nor libaudiofile are available
57    #if !HAVE_SNDFILE && !HAVE_AUDIOFILE
58    # error "Neither libsndfile nor libaudiofile seem to be available!"
59    # error "(HAVE_SNDFILE and HAVE_AUDIOFILE are both false)"
60    #endif
61    
62  // we prefer libsndfile before libaudiofile  // we prefer libsndfile before libaudiofile
63  #if HAVE_SNDFILE  #if HAVE_SNDFILE
64  # include <sndfile.h>  # include <sndfile.h>
# Line 66  using namespace std; Line 73  using namespace std;
73  typedef map<unsigned int, bool> OrderMap;  typedef map<unsigned int, bool> OrderMap;
74  OrderMap* pOrderedSamples = NULL;  OrderMap* pOrderedSamples = NULL;
75    
76    string Revision();
77    void PrintVersion();
78  void PrintUsage();  void PrintUsage();
79  void ExtractSamples(gig::File* gig, char* destdir, OrderMap* ordered);  void ExtractSamples(gig::File* gig, char* destdir, OrderMap* ordered);
80  int writeWav(const char* filename, void* samples, long samplecount, int channels, int bitdepth, long rate);  int writeWav(const char* filename, void* samples, long samplecount, int channels, int bitdepth, long rate);
81  string ToString(int i);  string ToString(int i);
82    
83  #ifndef HAVE_SNDFILE  #if !HAVE_SNDFILE // use libaudiofile
84  void* hAFlib; // handle to libaudiofile  void* hAFlib; // handle to libaudiofile
85  void openAFlib(void);  void openAFlib(void);
86  void closeAFlib(void);  void closeAFlib(void);
# Line 88  int(*_afCloseFile)(AFfilehandle file); Line 97  int(*_afCloseFile)(AFfilehandle file);
97  #endif // !HAVE_SNDFILE  #endif // !HAVE_SNDFILE
98    
99  int main(int argc, char *argv[]) {  int main(int argc, char *argv[]) {
100         if (argc >= 2) {
101            if (argv[1][0] == '-') {
102                switch (argv[1][1]) {
103                    case 'v':
104                        PrintVersion();
105                        return EXIT_SUCCESS;
106                }
107            }
108        }
109      if (argc < 3) {      if (argc < 3) {
110          PrintUsage();          PrintUsage();
111          return EXIT_FAILURE;          return EXIT_FAILURE;
# Line 149  int main(int argc, char *argv[]) { Line 167  int main(int argc, char *argv[]) {
167  }  }
168    
169  void ExtractSamples(gig::File* gig, char* destdir, OrderMap* ordered) {  void ExtractSamples(gig::File* gig, char* destdir, OrderMap* ordered) {
170  #ifndef HAVE_SNDFILE  #if !HAVE_SNDFILE // use libaudiofile
171      hAFlib = NULL;      hAFlib = NULL;
172      openAFlib();      openAFlib();
173  #endif // !HAVE_SNDFILE  #endif // !HAVE_SNDFILE
# Line 241  void ExtractSamples(gig::File* gig, char Line 259  void ExtractSamples(gig::File* gig, char
259          pSample = gig->GetNextSample();          pSample = gig->GetNextSample();
260      }      }
261      if (pWave) delete[] (uint8_t*) pWave;      if (pWave) delete[] (uint8_t*) pWave;
262  #ifndef HAVE_SNDFILE  #if !HAVE_SNDFILE // use libaudiofile
263      closeAFlib();      closeAFlib();
264  #endif // !HAVE_SNDFILE  #endif // !HAVE_SNDFILE
265  }  }
# Line 287  int writeWav(const char* filename, void* Line 305  int writeWav(const char* filename, void*
305          return -1;          return -1;
306      }      }
307      sf_close(hfile);      sf_close(hfile);
308  #else  #else // use libaudiofile
309      AFfilesetup setup = _afNewFileSetup();      AFfilesetup setup = _afNewFileSetup();
310      _afInitFileFormat(setup, AF_FILE_WAVE);      _afInitFileFormat(setup, AF_FILE_WAVE);
311      _afInitChannels(setup, AF_DEFAULT_TRACK, channels);      _afInitChannels(setup, AF_DEFAULT_TRACK, channels);
# Line 304  int writeWav(const char* filename, void* Line 322  int writeWav(const char* filename, void*
322      return 0; // success      return 0; // success
323  }  }
324    
325  #ifndef HAVE_SNDFILE  #if !HAVE_SNDFILE // use libaudiofile
326  void openAFlib() {  void openAFlib() {
327      hAFlib = dlopen("libaudiofile.so", RTLD_NOW);      hAFlib = dlopen("libaudiofile.so", RTLD_NOW);
328      if (!hAFlib) {      if (!hAFlib) {
# Line 328  void closeAFlib() { Line 346  void closeAFlib() {
346  }  }
347  #endif // !HAVE_SNDFILE  #endif // !HAVE_SNDFILE
348    
349    string Revision() {
350        string s = "$Revision: 1.7 $";
351        return s.substr(11, s.size() - 13); // cut dollar signs, spaces and CVS macro keyword
352    }
353    
354    void PrintVersion() {
355        cout << "gigextract revision " << Revision() << endl;
356        cout << "using " << gig::libraryName() << " " << gig::libraryVersion();
357        #if HAVE_SNDFILE
358        char versionBuffer[128];
359        sf_command(NULL, SFC_GET_LIB_VERSION, versionBuffer, 128);
360        cout << ", " << versionBuffer;
361        #else // use libaudiofile
362        cout << "\nbuilt against libaudiofile "
363             << LIBAUDIOFILE_MAJOR_VERSION << "." << LIBAUDIOFILE_MINOR_VERSION;
364        # ifdef LIBAUDIOFILE_MICRO_VERSION
365        cout << "." << LIBAUDIOFILE_MICRO_VERSION;
366        # endif // LIBAUDIOFILE_MICRO_VERSION
367        #endif // HAVE_SNDFILE
368        cout << endl;
369    }
370    
371  void PrintUsage() {  void PrintUsage() {
372      cout << "gigextract - extracts samples from a Gigasampler file." << endl;      cout << "gigextract - extracts samples from a Gigasampler file." << endl;
373      cout << endl;      cout << endl;
374      cout << "Usage: gigextract GIGFILE DESTDIR [SAMPLENR] [ [SAMPLENR] ...]" << endl;      cout << "Usage: gigextract [-v] GIGFILE DESTDIR [SAMPLENR] [ [SAMPLENR] ...]" << endl;
375      cout << endl;      cout << endl;
376      cout << "   GIGFILE  Input Gigasampler (.gig) file." << endl;      cout << "   GIGFILE  Input Gigasampler (.gig) file." << endl;
377      cout << endl;      cout << endl;
# Line 341  void PrintUsage() { Line 381  void PrintUsage() {
381      cout << "            If no sample indices are given, all samples will be extracted" << endl;      cout << "            If no sample indices are given, all samples will be extracted" << endl;
382      cout << "            (use gigdump to look for available samples)." << endl;      cout << "            (use gigdump to look for available samples)." << endl;
383      cout << endl;      cout << endl;
384        cout << "   -v       Print version and exit." << endl;
385        cout << endl;
386  }  }
387    
388  string ToString(int i) {  string ToString(int i) {

Legend:
Removed from v.365  
changed lines
  Added in v.608

  ViewVC Help
Powered by ViewVC