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

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

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

revision 2 by schoenebeck, Sat Oct 25 20:15:04 2003 UTC revision 666 by persson, Sun Jun 19 15:18:59 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 by Christian Schoenebeck                           *   *   Copyright (C) 2003-2005 by Christian Schoenebeck                      *
6   *                         <cuse@users.sourceforge.net>                    *   *                              <cuse@users.sourceforge.net>               *
7   *                                                                         *   *                                                                         *
8   *   This library is free software; you can redistribute it and/or modify  *   *   This library 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 59  namespace DLS { Line 59  namespace DLS {
59          pConnections = new Connection[Connections];          pConnections = new Connection[Connections];
60          Connection::conn_block_t connblock;          Connection::conn_block_t connblock;
61          for (uint32_t i = 0; i <= Connections; i++) {          for (uint32_t i = 0; i <= Connections; i++) {
62              artList->Read(&connblock, 1, sizeof(Connection::conn_block_t));              artList->Read(&connblock.source, 1, 2);
63                artList->Read(&connblock.control, 1, 2);
64                artList->Read(&connblock.destination, 1, 2);
65                artList->Read(&connblock.transform, 1, 2);
66                artList->Read(&connblock.scale, 1, 4);
67              pConnections[i].Init(&connblock);              pConnections[i].Init(&connblock);
68          }          }
69      }      }
# Line 163  namespace DLS { Line 167  namespace DLS {
167          RIFF::Chunk* ckDLSID = lstResource->GetSubChunk(CHUNK_ID_DLID);          RIFF::Chunk* ckDLSID = lstResource->GetSubChunk(CHUNK_ID_DLID);
168          if (ckDLSID) {          if (ckDLSID) {
169              pDLSID = new dlsid_t;              pDLSID = new dlsid_t;
170              ckDLSID->Read(pDLSID, 1, sizeof(dlsid_t));              ckDLSID->Read(&pDLSID->ulData1, 1, 4);
171                ckDLSID->Read(&pDLSID->usData2, 1, 2);
172                ckDLSID->Read(&pDLSID->usData3, 1, 2);
173                ckDLSID->Read(pDLSID->abData, 8, 1);
174          }          }
175          else pDLSID = NULL;          else pDLSID = NULL;
176      }      }
# Line 192  namespace DLS { Line 199  namespace DLS {
199          pSampleLoops            = (SampleLoops) ? new sample_loop_t[SampleLoops] : NULL;          pSampleLoops            = (SampleLoops) ? new sample_loop_t[SampleLoops] : NULL;
200          wsmp->SetPos(headersize);          wsmp->SetPos(headersize);
201          for (uint32_t i = 0; i < SampleLoops; i++) {          for (uint32_t i = 0; i < SampleLoops; i++) {
202              wsmp->Read(pSampleLoops + i, 1, sizeof(sample_loop_t));              wsmp->Read(pSampleLoops + i, 4, 4);
203              if (pSampleLoops[i].Size > sizeof(sample_loop_t)) { // if loop struct was extended              if (pSampleLoops[i].Size > sizeof(sample_loop_t)) { // if loop struct was extended
204                  wsmp->SetPos(pSampleLoops[i].Size - sizeof(sample_loop_t), RIFF::stream_curpos);                  wsmp->SetPos(pSampleLoops[i].Size - sizeof(sample_loop_t), RIFF::stream_curpos);
205              }              }
# Line 271  namespace DLS { Line 278  namespace DLS {
278       */       */
279      unsigned long Sample::Read(void* pBuffer, unsigned long SampleCount) {      unsigned long Sample::Read(void* pBuffer, unsigned long SampleCount) {
280          if (FormatTag != WAVE_FORMAT_PCM) return 0; // failed: wave data not PCM format          if (FormatTag != WAVE_FORMAT_PCM) return 0; // failed: wave data not PCM format
281          return pCkData->Read(pBuffer, SampleCount, FrameSize);          return pCkData->Read(pBuffer, SampleCount, FrameSize); // FIXME: channel inversion due to endian correction?
282      }      }
283    
284    
# Line 283  namespace DLS { Line 290  namespace DLS {
290          pCkRegion = rgnList;          pCkRegion = rgnList;
291    
292          RIFF::Chunk* rgnh = rgnList->GetSubChunk(CHUNK_ID_RGNH);          RIFF::Chunk* rgnh = rgnList->GetSubChunk(CHUNK_ID_RGNH);
293          rgnh->Read(&KeyRange, 1, sizeof(range_t));          rgnh->Read(&KeyRange, 2, 2);
294          rgnh->Read(&VelocityRange, 1, sizeof(range_t));          rgnh->Read(&VelocityRange, 2, 2);
295          uint16_t optionflags = rgnh->ReadUint16();          uint16_t optionflags = rgnh->ReadUint16();
296          SelfNonExclusive = optionflags & F_RGN_OPTION_SELFNONEXCLUSIVE;          SelfNonExclusive = optionflags & F_RGN_OPTION_SELFNONEXCLUSIVE;
297          KeyGroup = rgnh->ReadUint16();          KeyGroup = rgnh->ReadUint16();
# Line 332  namespace DLS { Line 339  namespace DLS {
339          if (!insh) throw DLS::Exception("Mandatory chunks in <lins> list chunk not found.");          if (!insh) throw DLS::Exception("Mandatory chunks in <lins> list chunk not found.");
340          Regions = insh->ReadUint32();          Regions = insh->ReadUint32();
341          midi_locale_t locale;          midi_locale_t locale;
342          insh->Read(&locale, 1, sizeof(midi_locale_t));          insh->Read(&locale, 2, 4);
343          MIDIProgram    = locale.instrument;          MIDIProgram    = locale.instrument;
344          IsDrum         = locale.bank & DRUM_TYPE_MASK;          IsDrum         = locale.bank & DRUM_TYPE_MASK;
345          MIDIBankCoarse = (uint8_t) MIDI_BANK_COARSE(locale.bank);          MIDIBankCoarse = (uint8_t) MIDI_BANK_COARSE(locale.bank);
# Line 393  namespace DLS { Line 400  namespace DLS {
400          RIFF::Chunk* ckVersion = pRIFF->GetSubChunk(CHUNK_ID_VERS);          RIFF::Chunk* ckVersion = pRIFF->GetSubChunk(CHUNK_ID_VERS);
401          if (ckVersion) {          if (ckVersion) {
402              pVersion = new version_t;              pVersion = new version_t;
403              ckVersion->Read(pVersion, 1, sizeof(version_t));              ckVersion->Read(pVersion, 4, 2);
404          }          }
405          else pVersion = NULL;          else pVersion = NULL;
406    
# Line 406  namespace DLS { Line 413  namespace DLS {
413          uint32_t headersize = ptbl->ReadUint32();          uint32_t headersize = ptbl->ReadUint32();
414          WavePoolCount  = ptbl->ReadUint32();          WavePoolCount  = ptbl->ReadUint32();
415          pWavePoolTable = new uint32_t[WavePoolCount];          pWavePoolTable = new uint32_t[WavePoolCount];
416            pWavePoolTableHi = new uint32_t[WavePoolCount];
417          ptbl->SetPos(headersize);          ptbl->SetPos(headersize);
418          ptbl->Read(pWavePoolTable, WavePoolCount, sizeof(uint32_t));  
419            // Check for 64 bit offsets (used in gig v3 files)
420            if (ptbl->GetSize() - headersize == WavePoolCount * 8) {
421                for (int i = 0 ; i < WavePoolCount ; i++) {
422                    pWavePoolTableHi[i] = ptbl->ReadUint32();
423                    pWavePoolTable[i] = ptbl->ReadUint32();
424                    if (pWavePoolTable[i] & 0x80000000)
425                        throw DLS::Exception("Files larger than 2 GB not yet supported");
426                }
427            }
428            else {
429                ptbl->Read(pWavePoolTable, WavePoolCount, sizeof(uint32_t));
430                for (int i = 0 ; i < WavePoolCount ; i++) pWavePoolTableHi[i] = 0;
431            }
432    
433          pSamples     = NULL;          pSamples     = NULL;
434          pInstruments = NULL;          pInstruments = NULL;
         Instruments  = 0;  
435      }      }
436    
437      File::~File() {      File::~File() {
# Line 436  namespace DLS { Line 456  namespace DLS {
456          }          }
457    
458          if (pWavePoolTable) delete[] pWavePoolTable;          if (pWavePoolTable) delete[] pWavePoolTable;
459            if (pWavePoolTableHi) delete[] pWavePoolTableHi;
460          if (pVersion) delete pVersion;          if (pVersion) delete pVersion;
461      }      }
462    
# Line 522  namespace DLS { Line 543  namespace DLS {
543          std::cout << "DLS::Exception: " << Message << std::endl;          std::cout << "DLS::Exception: " << Message << std::endl;
544      }      }
545    
546    
547    // *************** functions ***************
548    // *
549    
550        /**
551         * Returns the name of this C++ library. This is usually "libgig" of
552         * course. This call is equivalent to RIFF::libraryName() and
553         * gig::libraryName().
554         */
555        String libraryName() {
556            return PACKAGE;
557        }
558    
559        /**
560         * Returns version of this C++ library. This call is equivalent to
561         * RIFF::libraryVersion() and gig::libraryVersion().
562         */
563        String libraryVersion() {
564            return VERSION;
565        }
566    
567  } // namespace DLS  } // namespace DLS

Legend:
Removed from v.2  
changed lines
  Added in v.666

  ViewVC Help
Powered by ViewVC