add RageSoundReader_Resample

This commit is contained in:
Glenn Maynard
2003-04-23 19:10:01 +00:00
parent a5e6cd2787
commit 631c00928d
5 changed files with 149 additions and 3 deletions
+1 -1
View File
@@ -38,7 +38,7 @@ RageLog.cpp RageLog.h RageMath.cpp RageMath.h RageSound.cpp RageSound.h \
RageSoundManager.cpp RageSoundManager.h RageSoundReader.h RageSoundReader_SDL_Sound.cpp RageSoundReader_SDL_Sound.h \
RageTexture.cpp RageTexture.h RageTextureManager.cpp RageTextureManager.h RageThreads.cpp RageThreads.h \
RageTimer.cpp RageTimer.h RageTypes.h RageUtil.cpp RageUtil.h RageSoundReader_Preload.cpp RageSoundReader_Preload.h \
RageSoundResampler.cpp RageSoundResampler.h
RageSoundResampler.cpp RageSoundResampler.h RageSoundReader_Resample.cpp RageSoundReader_Resample.h
DataStructures = \
CodeDetector.cpp CodeDetector.h Course.cpp Course.h Font.cpp Font.h FontCharAliases.cpp FontCharAliases.h \
@@ -0,0 +1,98 @@
#include "global.h"
#include "RageSoundReader_Resample.h"
RageSoundReader_Resample::RageSoundReader_Resample()
{
source = NULL;
samplerate = -1;
}
void RageSoundReader_Resample::Open(SoundReader *source_)
{
source = source_;
ASSERT(source);
samplerate = source->GetSampleRate();
resamp.SetInputSampleRate(samplerate);
}
RageSoundReader_Resample::~RageSoundReader_Resample()
{
delete source;
}
void RageSoundReader_Resample::SetSampleRate(int hz)
{
samplerate = hz;
resamp.SetOutputSampleRate(samplerate);
}
int RageSoundReader_Resample::GetLength() const
{
resamp.reset();
return source->GetLength();
}
int RageSoundReader_Resample::GetLength_Fast() const
{
resamp.reset();
return source->GetLength_Fast();
}
int RageSoundReader_Resample::SetPosition_Accurate(int ms)
{
resamp.reset();
return source->SetPosition_Accurate(ms);
}
int RageSoundReader_Resample::SetPosition_Fast(int ms)
{
resamp.reset();
return source->SetPosition_Fast(ms);
}
static const int BUFSIZE = 1024*16;
int RageSoundReader_Resample::Read(char *buf, unsigned len)
{
int bytes_read = 0;
while(len)
{
int size = resamp.read(buf, len);
if(size == -1)
break;
buf += size;
len -= size;
bytes_read += size;
if(size == 0)
{
static char buf[BUFSIZE];
int cnt = source->Read(buf, sizeof(buf));
if(cnt == -1)
{
SetError(source->GetError());
return -1;
}
if(cnt == 0)
resamp.eof();
else
resamp.write(buf, cnt);
}
}
return bytes_read;
}
SoundReader *RageSoundReader_Resample::Copy() const
{
SoundReader *new_source = source->Copy();
RageSoundReader_Resample *ret = new RageSoundReader_Resample;
ret->Open(new_source);
ret->SetSampleRate(samplerate);
return ret;
}
+34
View File
@@ -0,0 +1,34 @@
#ifndef RAGE_SOUND_READER_RESAMPLE
#define RAGE_SOUND_READER_RESAMPLE
#include "RageSoundReader.h"
#include "RageSoundResampler.h"
/* This class changes the sampling rate of a sound. */
class RageSoundReader_Resample: public SoundReader
{
int samplerate;
SoundReader *source;
mutable RageSoundResampler resamp;
public:
/* We own source. */
void Open(SoundReader *source);
int GetLength() const;
int GetLength_Fast() const;
int SetPosition_Accurate(int ms);
int SetPosition_Fast(int ms);
int Read(char *buf, unsigned len);
RageSoundReader_Resample();
virtual ~RageSoundReader_Resample();
SoundReader *Copy() const;
/* Change the actual sample rate of a sound. */
void SetSampleRate(int hz);
int GetSampleRate() const { return samplerate; }
};
#endif
+10 -2
View File
@@ -60,7 +60,7 @@ IntDir=.\../Release6
TargetDir=\temp\stepmania
TargetName=StepMania
SOURCE="$(InputPath)"
PreLink_Cmds=disasm\verinc cl /Zl /nologo /c verstub.cpp /Fo$(IntDir)\
PreLink_Cmds=disasm\verinc cl /Zl /nologo /c verstub.cpp /Fo$(IntDir)\
PostBuild_Cmds=disasm\mapconv $(IntDir)\$(TargetName).map $(TargetDir)\StepMania.vdi ia32.vdi
# End Special Build Tool
@@ -95,7 +95,7 @@ IntDir=.\../Debug6
TargetDir=\temp\stepmania
TargetName=StepMania-debug
SOURCE="$(InputPath)"
PreLink_Cmds=disasm\verinc cl /Zl /nologo /c verstub.cpp /Fo$(IntDir)\
PreLink_Cmds=disasm\verinc cl /Zl /nologo /c verstub.cpp /Fo$(IntDir)\
PostBuild_Cmds=disasm\mapconv $(IntDir)\$(TargetName).map $(TargetDir)\StepMania.vdi ia32.vdi
# End Special Build Tool
@@ -239,6 +239,14 @@ SOURCE=.\RageSoundReader_Preload.h
# End Source File
# Begin Source File
SOURCE=.\RageSoundReader_Resample.cpp
# End Source File
# Begin Source File
SOURCE=.\RageSoundReader_Resample.h
# End Source File
# Begin Source File
SOURCE=.\RageSoundReader_SDL_Sound.cpp
# End Source File
# Begin Source File
+6
View File
@@ -1480,6 +1480,12 @@ cl /Zl /nologo /c verstub.cpp /Fo$(IntDir)\
<File
RelativePath="RageSoundReader_Preload.h">
</File>
<File
RelativePath="RageSoundReader_Resample.cpp">
</File>
<File
RelativePath="RageSoundReader_Resample.h">
</File>
<File
RelativePath="RageSoundReader_SDL_Sound.cpp">
</File>