pvplay.h 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233
  1. /*
  2. * Copyright (c) 1983-2020 Richard Dobson and Composers Desktop Project Ltd
  3. * http://www.rwdobson.com
  4. * http://www.composersdesktop.com
  5. * This file is part of the CDP System.
  6. * The CDP System is free software; you can redistribute it
  7. * and/or modify it under the terms of the GNU Lesser General Public
  8. * License as published by the Free Software Foundation; either
  9. * version 2.1 of the License, or (at your option) any later version.
  10. *
  11. * The CDP System is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  14. * See the GNU Lesser General Public License for more details.
  15. * You should have received a copy of the GNU Lesser General Public
  16. * License along with the CDP System; if not, write to the Free Software
  17. * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  18. *
  19. */
  20. //
  21. // pvplay.h
  22. //
  23. //
  24. // Created by Archer on 28/01/2013.
  25. // Copyright (c) 2013 __MyCompanyName__. All rights reserved.
  26. //
  27. #ifndef _pvthreads_h
  28. #define _pvthreads_h
  29. #include <stdio.h>
  30. #include <stdlib.h>
  31. #include <memory.h>
  32. #include <time.h>
  33. #include <signal.h>
  34. #include <assert.h>
  35. #include "portaudio.h"
  36. //#include "porttime.h"
  37. #include "pa_ringbuffer.h"
  38. #include "pa_util.h"
  39. #ifdef _WIN32
  40. #define _WIN32_WINNT 0x0500
  41. #include <windows.h>
  42. #include <conio.h>
  43. #include <process.h>
  44. #include "pa_win_wmme.h"
  45. #include "pa_win_ds.h"
  46. #endif
  47. #ifdef unix
  48. #include <sys/types.h>
  49. #include <sys/timeb.h>
  50. #include <sys/time.h>
  51. #include <pthread.h>
  52. #include <ctype.h>
  53. /* in portsf.lib */
  54. int stricmp(const char *a, const char *b);
  55. int strnicmp(const char *a, const char *b, const int length);
  56. #endif
  57. #ifdef CPLONG64
  58. #define MYLONG int
  59. #else
  60. #define MYLONG long
  61. #endif
  62. /* need this to avoid clashes of GUID defs, etc */
  63. #ifdef _WIN32
  64. #ifndef _WINDOWS
  65. #define _WINDOWS
  66. #endif
  67. #endif
  68. /* sfsys just for analysis files! */
  69. #ifdef __cplusplus
  70. extern "C" {
  71. #endif
  72. #include "sfsys.h"
  73. #include "fmdcode.h"
  74. #include "pvfileio.h"
  75. #ifdef __cplusplus
  76. }
  77. #endif
  78. #include "pvpp.h"
  79. #if defined MAC || defined unix
  80. #include <aaio.h>
  81. #endif
  82. #ifdef MAC
  83. #include <libkern/OSAtomic.h>
  84. #endif
  85. #ifndef min
  86. #define min(x,y) ((x) < (y) ? (x) : (y))
  87. #endif
  88. #ifdef _WIN32
  89. extern HANDLE ghEvent;
  90. #endif
  91. // paplayt
  92. //typedef struct {
  93. // int sfd;
  94. // int chans;
  95. // psf_buffer *outbuf;
  96. // unsigned long frames_played;
  97. // int last_buffer; /* init to 1; at detected eof send one extra buffer to flush, and set this to 0 */
  98. //} psfdata;
  99. typedef struct {
  100. float *buffer;
  101. long nframes;
  102. MYLONG used;
  103. }
  104. psf_buffer;
  105. typedef struct {
  106. PaUtilRingBuffer ringbuf;
  107. PaStream *stream;
  108. PaTime startTime;
  109. PaTime lastTime;
  110. float *ringbufData;
  111. float *inbuf; //for decoding and other tx; used as temp working buffer for read thread func.
  112. /* for memory read func */
  113. float *membuf;
  114. /* analysis file vars */
  115. // pv objects
  116. phasevocoder *pv_l;
  117. phasevocoder *pv_r;
  118. float *analframe1;
  119. float *analframe2;
  120. int anal_framesize; // in floats
  121. int fftsize; // sample frames from resynthesis of analysis frame(s)
  122. float *outbuf_l; // stereo pvx files - needed?
  123. float *outbuf_r;
  124. // float** orderptr; // for chan mapping;
  125. #ifdef _WIN32
  126. void *hThread;
  127. HANDLE hTimer;
  128. HANDLE hTimerCount;
  129. #endif
  130. #ifdef unix
  131. pthread_t hThread;
  132. #endif
  133. fmhdecodefunc decodefunc;
  134. fmhcopyfunc copyfunc;
  135. double gain;
  136. unsigned long frames_played; // for .ana, .pvx files, these are analysis frames
  137. unsigned long from_frame;
  138. unsigned long to_frame;
  139. unsigned long memFramelength;
  140. unsigned long memFramePos;
  141. unsigned long inbuflen;
  142. unsigned long current_frame;
  143. int srate;
  144. int inchans;
  145. int outchans;
  146. int flag;
  147. int ifd; // soundfiles, .ana files
  148. int pvfile; // pvx file
  149. pvoc_frametype inframetype;
  150. #ifdef DEBUG
  151. int ofd;
  152. #endif
  153. int do_decode;
  154. // int do_mapping;
  155. int play_looped;
  156. int finished;
  157. } psfdata;
  158. #ifdef NOTDEF
  159. typedef struct {
  160. PaStream *stream;
  161. PaTime starttime /* = Pa_GetStreamTime(stream)*/;
  162. } ptimedata;
  163. #endif
  164. //extern int file_playing;
  165. //extern psfdata *g_pdata = NULL; // for timer interrupt routine
  166. void stereo_interls(const float *in_l,const float *in_r,float *out,long insize);
  167. int show_devices(void);
  168. /* handlers */
  169. void playhandler(int sig);
  170. void finishedCallback(void *userData);
  171. #ifdef unix
  172. void alarm_wakeup (int i);
  173. #endif
  174. #ifdef _WIN32
  175. VOID CALLBACK TimerCallback(PVOID lpParam, BOOLEAN TimerOrWaitFired);
  176. #endif
  177. /* playback thread functions */
  178. #ifdef unix
  179. // TODO: unix return type should be void*
  180. typedef void* (*threadfunc)(void*);
  181. void* threadFunctionReadFromRawFile(void* ptr);
  182. void* threadFunctionReadFromAnalFile(void* ptr);
  183. void* threadFunctionReadFromPVXFile(void* ptr);
  184. #endif
  185. #ifdef _WIN32
  186. typedef unsigned int (__stdcall *threadfunc)(void*);
  187. // soundfile
  188. unsigned int __stdcall threadFunctionReadFromRawFile(void* ptr);
  189. unsigned int __stdcall threadFunctionReadFromAnalFile(void* ptr);
  190. unsigned int __stdcall threadFunctionReadFromPVXFile(void* ptr);
  191. #endif
  192. #endif