pvfileio.h 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154
  1. /*pvfileio.h: header file for PVOC_EX file format */
  2. /*
  3. * Copyright (c) 2000,2022 Richard Dobson and Composers Desktop Project Ltd
  4. * http://www.rwdobson.com
  5. * http://www.composersdesktop.com
  6. *
  7. This file is part of the CDP System.
  8. The CDP System is free software; you can redistribute it
  9. and/or modify it under the terms of the GNU Lesser General Public
  10. License as published by the Free Software Foundation; either
  11. version 2.1 of the License, or (at your option) any later version.
  12. The CDP System is distributed in the hope that it will be useful,
  13. but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  15. GNU Lesser General Public License for more details.
  16. You should have received a copy of the GNU Lesser General Public
  17. License along with the CDP System; if not, write to the Free Software
  18. Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
  19. 02111-1307 USA
  20. *
  21. */
  22. /* Initial Version 0.1 RWD 25:5:2000 all rights reserved: work in progress! */
  23. /* NB a special version of this file is used in Csound - do not auto-replace! */
  24. #ifndef __PVFILEIO_H_INCLUDED
  25. #define __PVFILEIO_H_INCLUDED
  26. #ifdef __cplusplus
  27. extern "C" {
  28. #endif
  29. #ifdef WIN32
  30. #include <windows.h>
  31. #endif
  32. #include <stdint.h>
  33. #include "wavdefs.h"
  34. #include "pvdefs.h"
  35. /* need to skip these defs for osx, use above headers */
  36. #if 0
  37. #ifndef WIN32
  38. #ifndef _WIN32
  39. typedef unsigned short WORD;
  40. typedef unsigned int DWORD;
  41. #endif
  42. typedef struct _GUID
  43. {
  44. DWORD Data1;
  45. WORD Data2;
  46. WORD Data3;
  47. unsigned char Data4[8];
  48. } GUID;
  49. typedef struct /*waveformatex */{
  50. WORD wFormatTag;
  51. WORD nChannels;
  52. DWORD nSamplesPerSec;
  53. DWORD nAvgBytesPerSec;
  54. WORD nBlockAlign;
  55. WORD wBitsPerSample;
  56. WORD cbSize;
  57. } WAVEFORMATEX;
  58. #endif
  59. typedef struct pvoc_data { /* 32 bytes*/
  60. WORD wWordFormat; /* pvoc_wordformat */
  61. WORD wAnalFormat; /* pvoc_frametype */
  62. WORD wSourceFormat; /* WAVE_FORMAT_PCM or WAVE_FORMAT_IEEE_FLOAT*/
  63. WORD wWindowType; /* pvoc_windowtype */
  64. DWORD nAnalysisBins; /* implicit FFT size = (nAnalysisBins-1) * 2*/
  65. DWORD dwWinlen; /* analysis winlen,samples, NB may be <> FFT size */
  66. DWORD dwOverlap; /* samples */
  67. DWORD dwFrameAlign; /* usually nAnalysisBins * 2 * sizeof(float) */
  68. float fAnalysisRate;
  69. float fWindowParam; /* default 0.0f unless needed */
  70. } PVOCDATA;
  71. typedef struct {
  72. WAVEFORMATEX Format; /* 18 bytes: info for renderer as well as for pvoc*/
  73. union { /* 2 bytes*/
  74. WORD wValidBitsPerSample; /* as per standard WAVE_EX: applies to renderer*/
  75. WORD wSamplesPerBlock;
  76. WORD wReserved;
  77. } Samples;
  78. DWORD dwChannelMask; /* 4 bytes : can be used as in standrad WAVE_EX */
  79. GUID SubFormat; /* 16 bytes*/
  80. } WAVEFORMATEXTENSIBLE, *PWAVEFORMATEXTENSIBLE;
  81. typedef struct {
  82. WAVEFORMATEXTENSIBLE wxFormat; /* 40 bytes*/
  83. DWORD dwVersion; /* 4 bytes*/
  84. DWORD dwDataSize; /* 4 bytes: sizeof PVOCDATA data block */
  85. PVOCDATA data; /* 32 bytes*/
  86. } WAVEFORMATPVOCEX; /* total 80 bytes*/
  87. #endif
  88. /* Renderer information: source is presumed to be of this type */
  89. typedef enum pvoc_sampletype {STYPE_16,STYPE_24,STYPE_32,STYPE_IEEE_FLOAT} pv_stype;
  90. /* at least VC++ will give 84 for sizeof(WAVEFORMATPVOCEX), so we need our own version*/
  91. #define SIZEOF_FMTPVOCEX (80)
  92. /* for the same reason:*/
  93. #define SIZEOF_WFMTEX (18)
  94. #define PVX_VERSION (1)
  95. /******* the all-important PVOC GUID
  96. {8312B9C2-2E6E-11d4-A824-DE5B96C3AB21}
  97. **************/
  98. extern const GUID KSDATAFORMAT_SUBTYPE_PVOC;
  99. /* pvoc file handling functions */
  100. /* NB: frame count always disregards chans */
  101. const char *pvoc_errorstr(void);
  102. int32_t init_pvsys(void);
  103. int32_t pvoc_createfile(const char *filename,
  104. DWORD fftlen,DWORD overlap, DWORD chans,
  105. DWORD format,int32_t srate,
  106. pv_stype stype,pv_wtype wtype,float wparam,float *fWindow,DWORD dwWinlen);
  107. int32_t pvoc_getpvxprops(int32_t ifd, PVOCDATA *data);
  108. int32_t pvoc_openfile(const char *filename,PVOCDATA *data,WAVEFORMATEX *fmt);
  109. int32_t pvoc_closefile(int32_t ofd);
  110. int32_t pvoc_putframes(int32_t ofd,const float *frame,int32_t numframes);
  111. int32_t pvoc_getframes(int32_t ifd,float *frames,DWORD nframes);
  112. /* framecount is raw count, if stereo, calc framecount / 2 for stereo-frame value, e.g. to calc duration */
  113. int32_t pvoc_framecount(int32_t ifd);
  114. int32_t pvoc_rewind(int32_t ifd,int32_t skip_first_frame); /* RWD 14:4:2001 */
  115. int32_t pvoc_framepos(int32_t ifd); /* RWD Jan 2014 */
  116. int32_t pvoc_seek_mcframe(int32_t ifd, int32_t offset, int32_t mode);
  117. int32_t pvsys_release(void);
  118. /* tell pvsys to update pvocdata on close; return 0 for success */
  119. int32_t pvoc_set_needsupdate(int32_t ifd);
  120. //returns 0 for success
  121. int32_t pvoc_canupdate(int32_t ifd);
  122. //ONLY when creating new file using 2-stages.called last thing before file close.
  123. // int32_t pvoc_updateprops(int32_t ifd, const PVOCDATA *data);
  124. int32_t pvoc_update_closefile(int ofd, const PVOCDATA *data,const WAVEFORMATEXTENSIBLE *wfx);
  125. int32_t pvoc_getdatasize_bytes(int32_t fd); // mainly for benefit of dirsf etc
  126. #ifdef __cplusplus
  127. }
  128. #endif
  129. #endif