/[svn]/linuxsampler/trunk/src/engines/common/SampleFile.cpp
ViewVC logotype

Diff of /linuxsampler/trunk/src/engines/common/SampleFile.cpp

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

revision 2119 by persson, Fri Aug 27 16:27:16 2010 UTC revision 2234 by iliev, Tue Aug 9 18:27:58 2011 UTC
# Line 3  Line 3 
3   *   LinuxSampler - modular, streaming capable sampler                     *   *   LinuxSampler - modular, streaming capable sampler                     *
4   *                                                                         *   *                                                                         *
5   *   Copyright (C) 2003 - 2009 Christian Schoenebeck                       *   *   Copyright (C) 2003 - 2009 Christian Schoenebeck                       *
6   *   Copyright (C) 2009 Grigor Iliev                                       *   *   Copyright (C) 2009 - 2011 Grigor Iliev                                *
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 66  namespace LinuxSampler { Line 66  namespace LinuxSampler {
66          }          }
67          TotalFrameCount = sfInfo.frames;          TotalFrameCount = sfInfo.frames;
68    
69            Loops = 0;
70            LoopStart = 0;
71            LoopEnd = 0;
72            SF_INSTRUMENT instrument;
73            if (sf_command(pSndFile, SFC_GET_INSTRUMENT,
74                           &instrument, sizeof(instrument)) != SF_FALSE) {
75                // TODO: instrument.basenote
76    #if HAVE_SF_INSTRUMENT_LOOPS
77                if (instrument.loop_count && instrument.loops[0].mode != SF_LOOP_NONE) {
78                    Loops = 1;
79                    LoopStart = instrument.loops[0].start;
80                    LoopEnd = instrument.loops[0].end;
81                }
82    #endif
83            }
84          if(!DontClose) Close();          if(!DontClose) Close();
85      }      }
86    
# Line 117  namespace LinuxSampler { Line 132  namespace LinuxSampler {
132      }      }
133    
134      Sample::buffer_t SampleFile::LoadSampleData() {      Sample::buffer_t SampleFile::LoadSampleData() {
135          return LoadSampleDataWithNullSamplesExtension(this->TotalFrameCount, 0); // 0 amount of NullSamples          return LoadSampleDataWithNullSamplesExtension(GetTotalFrameCount(), 0); // 0 amount of NullSamples
136      }      }
137    
138      Sample::buffer_t SampleFile::LoadSampleData(unsigned long FrameCount) {      Sample::buffer_t SampleFile::LoadSampleData(unsigned long FrameCount) {
# Line 125  namespace LinuxSampler { Line 140  namespace LinuxSampler {
140      }      }
141    
142      Sample::buffer_t SampleFile::LoadSampleDataWithNullSamplesExtension(uint NullFrameCount) {      Sample::buffer_t SampleFile::LoadSampleDataWithNullSamplesExtension(uint NullFrameCount) {
143          return LoadSampleDataWithNullSamplesExtension(this->TotalFrameCount, NullFrameCount);          return LoadSampleDataWithNullSamplesExtension(GetTotalFrameCount(), NullFrameCount);
144      }      }
145    
146      Sample::buffer_t SampleFile::LoadSampleDataWithNullSamplesExtension(unsigned long FrameCount, uint NullFramesCount) {      Sample::buffer_t SampleFile::LoadSampleDataWithNullSamplesExtension(unsigned long FrameCount, uint NullFramesCount) {
147          Open();          Open();
148          if (FrameCount > this->TotalFrameCount) FrameCount = this->TotalFrameCount;          if (FrameCount > GetTotalFrameCount()) FrameCount = GetTotalFrameCount();
149            
150            if (Offset > MaxOffset && FrameCount < GetTotalFrameCount()) {
151                FrameCount = FrameCount + Offset > GetTotalFrameCount() ? GetTotalFrameCount() - Offset : FrameCount;
152                // Offset the RAM cache
153                RAMCacheOffset = Offset;
154            }
155          if (RAMCache.pStart) delete[] (int8_t*) RAMCache.pStart;          if (RAMCache.pStart) delete[] (int8_t*) RAMCache.pStart;
156          unsigned long allocationsize = (FrameCount + NullFramesCount) * this->FrameSize;          unsigned long allocationsize = (FrameCount + NullFramesCount) * this->FrameSize;
157          SetPos(0, SEEK_SET); // reset read position to begin of sample          SetPos(RAMCacheOffset, SEEK_SET); // reset read position to playback start point
158          RAMCache.pStart            = new int8_t[allocationsize];          RAMCache.pStart            = new int8_t[allocationsize];
159    
160          RAMCache.Size = Read(RAMCache.pStart, FrameCount) * this->FrameSize;          RAMCache.Size = Read(RAMCache.pStart, FrameCount) * this->FrameSize;
# Line 146  namespace LinuxSampler { Line 167  namespace LinuxSampler {
167    
168      long SampleFile::Read(void* pBuffer, unsigned long FrameCount) {      long SampleFile::Read(void* pBuffer, unsigned long FrameCount) {
169          Open();          Open();
170            
171            if (GetPos() + FrameCount > GetTotalFrameCount()) FrameCount = GetTotalFrameCount() - GetPos(); // For the cases where a different sample end is specified (not the end of the file)
172    
173          // ogg files must be read with sf_readf, not sf_read_raw. On          // ogg files must be read with sf_readf, not sf_read_raw. On
174          // big endian machines, sf_readf_short is also used for 16 bit          // big endian machines, sf_readf_short is also used for 16 bit

Legend:
Removed from v.2119  
changed lines
  Added in v.2234

  ViewVC Help
Powered by ViewVC