/[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 1953 by schoenebeck, Thu Jul 30 08:16:02 2009 UTC revision 2465 by schoenebeck, Thu Sep 5 03:01:51 2013 UTC
# Line 2  Line 2 
2   *                                                                         *   *                                                                         *
3   *   libgig - C++ cross-platform Gigasampler format file access library    *   *   libgig - C++ cross-platform Gigasampler format file access library    *
4   *                                                                         *   *                                                                         *
5   *   Copyright (C) 2003-2009 by Christian Schoenebeck                      *   *   Copyright (C) 2003-2013 by Christian Schoenebeck                      *
6   *                              <cuse@users.sourceforge.net>               *   *                              <cuse@users.sourceforge.net>               *
7   *                                                                         *   *                                                                         *
8   *   This program is part of libgig.                                       *   *   This program is part of libgig.                                       *
# Line 87  string Revision(); Line 87  string Revision();
87  void PrintVersion();  void PrintVersion();
88  void PrintUsage();  void PrintUsage();
89  void ExtractSamples(gig::File* gig, char* destdir, OrderMap* ordered);  void ExtractSamples(gig::File* gig, char* destdir, OrderMap* ordered);
90  int writeWav(const char* filename, void* samples, long samplecount, int channels, int bitdepth, long rate);  int writeWav(gig::Sample* sample, const char* filename, void* samples, long samplecount, int channels, int bitdepth, long rate);
91  string ToString(int i);  string ToString(int i);
92    
93  #if !HAVE_SNDFILE // use libaudiofile  #if !HAVE_SNDFILE // use libaudiofile
# Line 177  int main(int argc, char *argv[]) { Line 177  int main(int argc, char *argv[]) {
177      return EXIT_SUCCESS;      return EXIT_SUCCESS;
178  }  }
179    
180    static std::string getLoopTypeText(gig::loop_type_t type) {
181        switch (type) {
182            case gig::loop_type_normal:
183                return "normal";
184            case gig::loop_type_bidirectional:
185                return "pingpong";
186            case gig::loop_type_backward:
187                return "backward";
188            default:
189                return "INVALID";
190        }
191    }
192    
193  void ExtractSamples(gig::File* gig, char* destdir, OrderMap* ordered) {  void ExtractSamples(gig::File* gig, char* destdir, OrderMap* ordered) {
194  #if !HAVE_SNDFILE // use libaudiofile  #if !HAVE_SNDFILE // use libaudiofile
195      hAFlib = NULL;      hAFlib = NULL;
# Line 216  void ExtractSamples(gig::File* gig, char Line 229  void ExtractSamples(gig::File* gig, char
229          filename += ".wav";          filename += ".wav";
230          if (pSample->Compressed) cout << "Decompressing ";          if (pSample->Compressed) cout << "Decompressing ";
231          else                     cout << "Extracting ";          else                     cout << "Extracting ";
232          cout << "Sample " << samples << ") " << name << " (" << pSample->BitDepth <<"Bits, " << pSample->SamplesPerSecond << "Hz, " << pSample->Channels << " Channels, " << pSample->SamplesTotal << " Samples)..." << flush;          cout << "Sample " << samples << ") " << name << " (" << pSample->BitDepth <<"Bits, " << pSample->SamplesPerSecond << "Hz, " << pSample->Channels << " Channels, " << pSample->SamplesTotal << " Samples";
233            if (pSample->Loops > 0) {
234                cout << ", LoopType "  << getLoopTypeText(pSample->LoopType)
235                     << ", LoopStart " << pSample->LoopStart
236                     << ", LoopEnd "   << pSample->LoopEnd;
237            }
238            cout << ")..." << flush;
239    
240    
241  #if USE_DISK_STREAMING  #if USE_DISK_STREAMING
# Line 282  void ExtractSamples(gig::File* gig, char Line 301  void ExtractSamples(gig::File* gig, char
301                  }                  }
302              }              }
303    
304              int res = writeWav(filename.c_str(),              int res = writeWav(pSample,
305                                   filename.c_str(),
306                                 pSample->BitDepth == 24 ? static_cast<void*>(pIntWave) : pWave,                                 pSample->BitDepth == 24 ? static_cast<void*>(pIntWave) : pWave,
307                                 pSample->SamplesTotal,                                 pSample->SamplesTotal,
308                                 pSample->Channels,                                 pSample->Channels,
# Line 307  void ExtractSamples(gig::File* gig, char Line 327  void ExtractSamples(gig::File* gig, char
327  #endif // !HAVE_SNDFILE  #endif // !HAVE_SNDFILE
328  }  }
329    
330  int writeWav(const char* filename, void* samples, long samplecount, int channels, int bitdepth, long rate) {  int writeWav(gig::Sample* sample, const char* filename, void* samples, long samplecount, int channels, int bitdepth, long rate) {
331  #if HAVE_SNDFILE  #if HAVE_SNDFILE
332      SNDFILE* hfile;      SNDFILE* hfile;
333      SF_INFO  sfinfo;      SF_INFO  sfinfo;
334        SF_INSTRUMENT instr;
335      int format = SF_FORMAT_WAV;      int format = SF_FORMAT_WAV;
336      switch (bitdepth) {      switch (bitdepth) {
337          case 8:          case 8:
# Line 330  int writeWav(const char* filename, void* Line 351  int writeWav(const char* filename, void*
351              return -1;              return -1;
352      }      }
353      memset(&sfinfo, 0, sizeof (sfinfo));      memset(&sfinfo, 0, sizeof (sfinfo));
354        memset(&instr, 0, sizeof (instr));
355      sfinfo.samplerate = rate;      sfinfo.samplerate = rate;
356      sfinfo.frames     = samplecount;      sfinfo.frames     = samplecount;
357      sfinfo.channels   = channels;      sfinfo.channels   = channels;
# Line 338  int writeWav(const char* filename, void* Line 360  int writeWav(const char* filename, void*
360          cerr << "Error: Unable to open output file \'" << filename << "\'.\n" << flush;          cerr << "Error: Unable to open output file \'" << filename << "\'.\n" << flush;
361          return -1;          return -1;
362      }      }
363        instr.basenote = sample->MIDIUnityNote;
364        instr.detune = sample->FineTune;
365        if (sample->Loops > 0) {
366            instr.loop_count = 1;
367            switch (sample->LoopType) {
368                case gig::loop_type_normal:
369                    instr.loops[0].mode = SF_LOOP_FORWARD;
370                    break;
371                case gig::loop_type_bidirectional:
372                    instr.loops[0].mode = SF_LOOP_ALTERNATING;
373                    break;
374                case gig::loop_type_backward:
375                    instr.loops[0].mode = SF_LOOP_BACKWARD;
376                    break;
377                default:
378                    instr.loops[0].mode = SF_LOOP_NONE;
379                    break;
380            }
381            instr.loops[0].start = sample->LoopStart;
382            instr.loops[0].end   = sample->LoopEnd;
383            instr.loops[0].count = sample->LoopPlayCount;
384        }
385        sf_command(hfile, SFC_SET_INSTRUMENT, &instr, sizeof(instr));
386      sf_count_t res = bitdepth == 24 ?      sf_count_t res = bitdepth == 24 ?
387          sf_write_int(hfile, static_cast<int*>(samples), channels * samplecount) :          sf_write_int(hfile, static_cast<int*>(samples), channels * samplecount) :
388          sf_write_short(hfile, static_cast<short*>(samples), channels * samplecount);          sf_write_short(hfile, static_cast<short*>(samples), channels * samplecount);

Legend:
Removed from v.1953  
changed lines
  Added in v.2465

  ViewVC Help
Powered by ViewVC