ExtendedRead.cpp 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. #include "main.h"
  2. #include "decoder.h"
  3. extern "C"
  4. {
  5. //returns handle!=0 if successful, 0 if error
  6. //size will return the final nb of bytes written to the output, -1 if unknown
  7. __declspec( dllexport ) intptr_t winampGetExtendedRead_openW(const wchar_t *fn, int *size, int *bps, int *nch, int *srate) {
  8. VorbisFile * f = VorbisFile::Create(fn,false);
  9. if(f) {
  10. if(!*bps) *bps=16; // FUCKO HAX
  11. Decoder * d = new Decoder();
  12. d->Init(f, *bps, *nch, false, false);
  13. *nch = (int)d->nch;
  14. *srate = (int)d->sr;
  15. *bps = (int)d->bps;
  16. *size = (int)(f->Length() * (double)((*nch) * (*srate) * (*bps/8)));
  17. return (intptr_t)d;
  18. }
  19. return 0;
  20. }
  21. __declspec( dllexport ) intptr_t winampGetExtendedRead_openW_float(const wchar_t *fn, int *size, int *bps, int *nch, int *srate) {
  22. VorbisFile * f = VorbisFile::Create(fn,false);
  23. if(f) {
  24. Decoder * d = new Decoder();
  25. d->Init(f, *bps, *nch, true, false);
  26. *nch = (int)d->nch;
  27. *srate = (int)d->sr;
  28. *bps = (int)d->bps;
  29. *size = (int)(f->Length() * (double)((*nch) * (*srate) * (*bps/8)));
  30. return (intptr_t)d;
  31. }
  32. return 0;
  33. }
  34. //returns nb of bytes read. -1 if read error (like CD ejected). if (ret<len), EOF is assumed
  35. __declspec( dllexport ) intptr_t winampGetExtendedRead_getData(intptr_t handle, char *dest, size_t len, int *killswitch) {
  36. Decoder * d = (Decoder *)handle;
  37. size_t used = 0;
  38. for(;;) {
  39. used += (UINT)d->Read((UINT)(len - used),dest + used);
  40. if(used >= len) break;
  41. if(!d->DoFrame()) break;
  42. if(*killswitch) break;
  43. if (used)
  44. return used;
  45. }
  46. return used;
  47. }
  48. // return nonzero on success, zero on failure.
  49. __declspec( dllexport ) int winampGetExtendedRead_setTime(intptr_t handle, int millisecs) {
  50. Decoder * d = (Decoder *)handle;
  51. d->Flush();
  52. return !d->Seek(((double)millisecs) / 1000.0);
  53. }
  54. __declspec( dllexport ) void winampGetExtendedRead_close(intptr_t handle) {
  55. Decoder * d = (Decoder *)handle;
  56. d->Flush();
  57. delete d->file;
  58. delete d;
  59. }
  60. }