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_desired.channels = channels;
sound_desired.format = AUDIO_S16SYS;
sound_desired.rate = samplerate;
sound_desired.rate = 0; // samplerate;
Sample = Sound_NewSampleFromFile(filename.GetString(),
&sound_desired, read_block_size);
resamp.reset();
resamp.SetInputChannels(2);
resamp.SetOutputChannels(2);
resamp.SetInputSampleRate(Sample->actual.rate);
resamp.SetOutputSampleRate(samplerate);
if(Sample)
return true;
@@ -82,6 +87,7 @@ int SoundReader_SDL_Sound::GetLength_Fast() const
int SoundReader_SDL_Sound::SetPosition(int ms, bool accurate)
{
resamp.reset();
if(ms == 0)
{
Sound_Rewind(Sample);
@@ -118,7 +124,16 @@ int SoundReader_SDL_Sound::Read(char *buf, unsigned len)
int bytes_read = 0;
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). */
if(Sample->flags & SOUND_SAMPLEFLAG_EOF)
@@ -127,7 +142,10 @@ int SoundReader_SDL_Sound::Read(char *buf, unsigned len)
int cnt = Sound_Decode(Sample);
if(Sample->flags & SOUND_SAMPLEFLAG_EOF)
return bytes_read; /* EOF */
{
resamp.eof();
continue;
}
if(Sample->flags & SOUND_SAMPLEFLAG_ERROR)
{
@@ -135,17 +153,8 @@ int SoundReader_SDL_Sound::Read(char *buf, unsigned len)
return -1;
}
avail = cnt;
inbuf = (const char *) Sample->buffer;
resamp.write(Sample->buffer, cnt);
}
unsigned size = min(avail, len);
memcpy(buf, inbuf, size);
buf += size;
len -= size;
inbuf += size;
avail -= size;
bytes_read += size;
}
return bytes_read;
+5 -5
View File
@@ -3,6 +3,7 @@
#include "RageSoundReader.h"
#include "SDL_sound-1.0.0/SDL_sound.h"
#include "RageSoundResampler.h"
class SoundReader_SDL_Sound: public SoundReader {
Sound_Sample *Sample;
@@ -10,6 +11,7 @@ class SoundReader_SDL_Sound: public SoundReader {
unsigned avail;
int SetPosition(int ms, bool accurate);
CString filename;
RageSoundResampler resamp;
public:
bool Open(CString filename);
@@ -24,8 +26,6 @@ public:
#endif
/*
------------------------------------------------------------------------------
Copyright (c) 2002-2003 by the person(s) listed below. All rights reserved.
Glenn Maynard
------------------------------------------------------------------------------
*/
* Copyright (c) 2002-2003 by the person(s) listed below. All rights reserved.
* Glenn Maynard
*/