/[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 2012 by iliev, Fri Oct 23 17:53:17 2009 UTC revision 2119 by persson, Fri Aug 27 16:27:16 2010 UTC
# Line 22  Line 22 
22   ***************************************************************************/   ***************************************************************************/
23    
24  #include "SampleFile.h"  #include "SampleFile.h"
25    #include "../../common/global_private.h"
26  #include "../../common/Exception.h"  #include "../../common/Exception.h"
27    
28  #include <cstring>  #include <cstring>
# Line 46  namespace LinuxSampler { Line 47  namespace LinuxSampler {
47          ChannelCount = sfInfo.channels;          ChannelCount = sfInfo.channels;
48          Format = sfInfo.format;          Format = sfInfo.format;
49    
50          switch(Format & 0xF) {          switch(Format & SF_FORMAT_SUBMASK) {
51              case SF_FORMAT_PCM_S8:              case SF_FORMAT_PCM_S8:
52              case SF_FORMAT_PCM_U8:              case SF_FORMAT_PCM_U8:
             case SF_FORMAT_PCM_16:  
53              case SF_FORMAT_DPCM_8:              case SF_FORMAT_DPCM_8:
54                    FrameSize = ChannelCount;
55                    break;
56                case SF_FORMAT_PCM_16:
57              case SF_FORMAT_DPCM_16:              case SF_FORMAT_DPCM_16:
58                  FrameSize = sizeof(short) * ChannelCount;                  FrameSize = 2 * ChannelCount;
59                    break;
60                case SF_FORMAT_PCM_24:
61                case SF_FORMAT_DWVW_24:
62                    FrameSize = 3 * ChannelCount;
63                  break;                  break;
64              default:              default:
65                  FrameSize = sizeof(int) * ChannelCount;                  FrameSize = 2 * ChannelCount;
66          }          }
67          TotalFrameCount = sfInfo.frames;          TotalFrameCount = sfInfo.frames;
68    
# Line 64  namespace LinuxSampler { Line 71  namespace LinuxSampler {
71    
72      SampleFile::~SampleFile() {      SampleFile::~SampleFile() {
73          Close();          Close();
74            ReleaseSampleData();
75      }      }
76    
77      void SampleFile::Open() {      void SampleFile::Open() {
# Line 138  namespace LinuxSampler { Line 146  namespace LinuxSampler {
146    
147      long SampleFile::Read(void* pBuffer, unsigned long FrameCount) {      long SampleFile::Read(void* pBuffer, unsigned long FrameCount) {
148          Open();          Open();
149          if(FrameSize == sizeof(short) * ChannelCount) {  
150              return sf_readf_short(pSndFile, (short*)pBuffer, FrameCount);          // ogg files must be read with sf_readf, not sf_read_raw. On
151          } else {          // big endian machines, sf_readf_short is also used for 16 bit
152              return sf_readf_int(pSndFile, (int*)pBuffer, FrameCount);          // wav files, to get automatic endian conversion (for 24 bit
153            // samples this is handled in Synthesize::GetSample instead).
154    
155    #if WORDS_BIGENDIAN || HAVE_DECL_SF_FORMAT_VORBIS
156            if (
157    #if WORDS_BIGENDIAN
158                FrameSize == 2 * ChannelCount
159    #else
160                (Format & SF_FORMAT_SUBMASK) == SF_FORMAT_VORBIS
161    #endif
162                ) {
163                return sf_readf_short(pSndFile, static_cast<short*>(pBuffer), FrameCount);
164            } else
165    #endif
166            {
167                int bytes = sf_read_raw(pSndFile, pBuffer, FrameCount * GetFrameSize());
168                return bytes / GetFrameSize();
169          }          }
170      }      }
171    
# Line 152  namespace LinuxSampler { Line 176  namespace LinuxSampler {
176      ) {      ) {
177          // TODO:          // TODO:
178          SetPos(pPlaybackState->position);          SetPos(pPlaybackState->position);
179          Read(pBuffer, FrameCount);          unsigned long count = Read(pBuffer, FrameCount);
180          pPlaybackState->position = GetPos();          pPlaybackState->position = GetPos();
181            return count;
182      }      }
183    
184      void SampleFile::ReleaseSampleData() {      void SampleFile::ReleaseSampleData() {

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

  ViewVC Help
Powered by ViewVC