CWaveLoader.cpp
上传用户:snevogroup
上传日期:2008-06-06
资源大小:432k
文件大小:1k
- #include "CWaveLoader.h"
- #include <e32svr.h>
- #include <f32file.h>
- #include <aknutils.h>
- // Construct and Destruct
- /// NewL()
- CWavLoader* CWavLoader::NewL()
- {
- CWavLoader* self = NewLC();
- CleanupStack::Pop(self);
- return self;
- }
- // NewLC()
- CWavLoader* CWavLoader::NewLC()
- {
- CWavLoader* self = new (ELeave) CWavLoader;
- CleanupStack::PushL(self);
- self->ConstructL();
- return self;
- }
- /// ~
- CWavLoader::~CWavLoader()
- {}
- /// CWavLoader()
- CWavLoader::CWavLoader()
- {}
- /// ConstructL()
- void CWavLoader::ConstructL()
- {}
- /// LoadL()
- TSample CWavLoader::LoadL(const TFileName& aFileName)
- {
- TFileName name(aFileName);
- CompleteWithAppPath(name);
- RFs fs;
- RFile file;
- fs.Connect();
- CleanupClosePushL(fs);
- CleanupClosePushL(file);
- User::LeaveIfError(file.Open(fs, name, EFileStream | EFileRead));
-
- // get the file size
- TInt size;
- User::LeaveIfError(file.Size(size));
-
- TUint8* tbuf = new (ELeave) TUint8[size];
- TPtr8 ptr( (TUint8*)tbuf, size );
- User::LeaveIfError(file.Read(ptr));
-
- CleanupStack::PopAndDestroy( 2 ); // fs, file
- // convert to 16-bit
- TInt16* buf = new( ELeave )TInt16[size];
- TInt i;
- for(i = 0; i < size; i++)
- {
- TInt v = tbuf[i];
- v -= 128;
- buf[i] = ( TInt16 )( v << 8 );
- }
- delete tbuf;
-
- TSample sample;
- sample.iData = buf;
- sample.iLength = size;
- sample.iRepStart = 0;
- sample.iRepEnd = 0;
-
- return sample;
- }