CWaveLoader.cpp
上传用户:snevogroup
上传日期:2008-06-06
资源大小:432k
文件大小:1k
源码类别:

Symbian

开发平台:

C/C++

  1. #include "CWaveLoader.h"
  2. #include <e32svr.h>
  3. #include <f32file.h>
  4. #include <aknutils.h>
  5. // Construct and Destruct
  6. /// NewL()
  7. CWavLoader* CWavLoader::NewL()
  8. {
  9. CWavLoader* self = NewLC();
  10. CleanupStack::Pop(self);
  11. return self;
  12. }
  13. // NewLC()
  14. CWavLoader* CWavLoader::NewLC()
  15. {
  16. CWavLoader* self = new (ELeave) CWavLoader;
  17. CleanupStack::PushL(self);
  18. self->ConstructL();
  19. return self;
  20. }
  21. /// ~
  22. CWavLoader::~CWavLoader()
  23. {}
  24. /// CWavLoader()
  25. CWavLoader::CWavLoader()
  26. {}
  27. /// ConstructL()
  28. void CWavLoader::ConstructL()
  29. {}
  30. /// LoadL()
  31. TSample CWavLoader::LoadL(const TFileName& aFileName)
  32. {
  33. TFileName name(aFileName);
  34. CompleteWithAppPath(name);
  35. RFs fs;
  36. RFile file;
  37. fs.Connect();
  38. CleanupClosePushL(fs);
  39. CleanupClosePushL(file);
  40. User::LeaveIfError(file.Open(fs, name, EFileStream | EFileRead));
  41. // get the file size
  42. TInt size;
  43. User::LeaveIfError(file.Size(size));
  44. TUint8* tbuf = new (ELeave) TUint8[size];
  45. TPtr8 ptr( (TUint8*)tbuf, size );
  46. User::LeaveIfError(file.Read(ptr));
  47. CleanupStack::PopAndDestroy( 2 ); // fs, file
  48. // convert to 16-bit
  49. TInt16* buf = new( ELeave )TInt16[size];
  50. TInt i;
  51. for(i = 0; i < size; i++)
  52. {
  53. TInt v = tbuf[i];
  54. v -= 128;
  55. buf[i] = ( TInt16 )( v << 8 );
  56. }
  57. delete tbuf;
  58. TSample sample;
  59. sample.iData = buf;
  60. sample.iLength = size;
  61. sample.iRepStart = 0;
  62. sample.iRepEnd = 0;
  63. return sample;
  64. }