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> |
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: |
53 |
case SF_FORMAT_DPCM_8: |
case SF_FORMAT_DPCM_8: |
146 |
|
|
147 |
long SampleFile::Read(void* pBuffer, unsigned long FrameCount) { |
long SampleFile::Read(void* pBuffer, unsigned long FrameCount) { |
148 |
Open(); |
Open(); |
149 |
int bytes = sf_read_raw(pSndFile, pBuffer, FrameCount * GetFrameSize()); |
|
150 |
return bytes / GetFrameSize(); |
// ogg files must be read with sf_readf, not sf_read_raw. On |
151 |
|
// big endian machines, sf_readf_short is also used for 16 bit |
152 |
|
// 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 |
|
|
172 |
unsigned long SampleFile::ReadAndLoop ( |
unsigned long SampleFile::ReadAndLoop ( |