use resampler

This commit is contained in:
Glenn Maynard
2003-04-23 07:19:58 +00:00
parent e6dfa1f081
commit eb4c7625d6
2 changed files with 27 additions and 18 deletions
+22 -13
View File
@@ -42,11 +42,16 @@ bool SoundReader_SDL_Sound::Open(CString filename_)
Sound_AudioInfo sound_desired; Sound_AudioInfo sound_desired;
sound_desired.channels = channels; sound_desired.channels = channels;
sound_desired.format = AUDIO_S16SYS; sound_desired.format = AUDIO_S16SYS;
sound_desired.rate = samplerate; sound_desired.rate = 0; // samplerate;
Sample = Sound_NewSampleFromFile(filename.GetString(), Sample = Sound_NewSampleFromFile(filename.GetString(),
&sound_desired, read_block_size); &sound_desired, read_block_size);
resamp.reset();
resamp.SetInputChannels(2);
resamp.SetOutputChannels(2);
resamp.SetInputSampleRate(Sample->actual.rate);
resamp.SetOutputSampleRate(samplerate);
if(Sample) if(Sample)
return true; return true;
@@ -82,6 +87,7 @@ int SoundReader_SDL_Sound::GetLength_Fast() const
int SoundReader_SDL_Sound::SetPosition(int ms, bool accurate) int SoundReader_SDL_Sound::SetPosition(int ms, bool accurate)
{ {
resamp.reset();
if(ms == 0) if(ms == 0)
{ {
Sound_Rewind(Sample); Sound_Rewind(Sample);
@@ -118,7 +124,16 @@ int SoundReader_SDL_Sound::Read(char *buf, unsigned len)
int bytes_read = 0; int bytes_read = 0;
while(len) while(len)
{ {
if(!avail) int size = resamp.read(buf, len);
if(size == -1)
break;
buf += size;
len -= size;
bytes_read += size;
if(size == 0)
{ {
/* Don't read at all if we've already hit EOF (it'll whine). */ /* Don't read at all if we've already hit EOF (it'll whine). */
if(Sample->flags & SOUND_SAMPLEFLAG_EOF) if(Sample->flags & SOUND_SAMPLEFLAG_EOF)
@@ -127,7 +142,10 @@ int SoundReader_SDL_Sound::Read(char *buf, unsigned len)
int cnt = Sound_Decode(Sample); int cnt = Sound_Decode(Sample);
if(Sample->flags & SOUND_SAMPLEFLAG_EOF) if(Sample->flags & SOUND_SAMPLEFLAG_EOF)
return bytes_read; /* EOF */ {
resamp.eof();
continue;
}
if(Sample->flags & SOUND_SAMPLEFLAG_ERROR) if(Sample->flags & SOUND_SAMPLEFLAG_ERROR)
{ {
@@ -135,17 +153,8 @@ int SoundReader_SDL_Sound::Read(char *buf, unsigned len)
return -1; return -1;
} }
avail = cnt; resamp.write(Sample->buffer, cnt);
inbuf = (const char *) Sample->buffer;
} }
unsigned size = min(avail, len);
memcpy(buf, inbuf, size);
buf += size;
len -= size;
inbuf += size;
avail -= size;
bytes_read += size;
} }
return bytes_read; return bytes_read;
+4 -4
View File
@@ -3,6 +3,7 @@
#include "RageSoundReader.h" #include "RageSoundReader.h"
#include "SDL_sound-1.0.0/SDL_sound.h" #include "SDL_sound-1.0.0/SDL_sound.h"
#include "RageSoundResampler.h"
class SoundReader_SDL_Sound: public SoundReader { class SoundReader_SDL_Sound: public SoundReader {
Sound_Sample *Sample; Sound_Sample *Sample;
@@ -10,6 +11,7 @@ class SoundReader_SDL_Sound: public SoundReader {
unsigned avail; unsigned avail;
int SetPosition(int ms, bool accurate); int SetPosition(int ms, bool accurate);
CString filename; CString filename;
RageSoundResampler resamp;
public: public:
bool Open(CString filename); bool Open(CString filename);
@@ -24,8 +26,6 @@ public:
#endif #endif
/* /*
------------------------------------------------------------------------------ * Copyright (c) 2002-2003 by the person(s) listed below. All rights reserved.
Copyright (c) 2002-2003 by the person(s) listed below. All rights reserved. * Glenn Maynard
Glenn Maynard
------------------------------------------------------------------------------
*/ */