SoundRecorder.h 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149
  1. #ifndef _SoundRecorder_h_
  2. #define _SoundRecorder_h_
  3. /* SoundRecorder.h
  4. *
  5. * Copyright (C) 1992-2011,2012,2013,2015,2017 Paul Boersma
  6. *
  7. * This code is free software; you can redistribute it and/or modify
  8. * it under the terms of the GNU General Public License as published by
  9. * the Free Software Foundation; either version 2 of the License, or (at
  10. * your option) any later version.
  11. *
  12. * This code is distributed in the hope that it will be useful, but
  13. * WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  15. * See the GNU General Public License for more details.
  16. *
  17. * You should have received a copy of the GNU General Public License
  18. * along with this work. If not, see <http://www.gnu.org/licenses/>.
  19. */
  20. /* An editor-like object that allows the user to record sounds. */
  21. #include "Editor.h"
  22. #include "Sound.h"
  23. #include "SoundRecorder_enums.h"
  24. #include "../external/portaudio/portaudio.h"
  25. #if defined (_WIN32)
  26. #elif defined (macintosh)
  27. #elif defined (linux)
  28. #include <sys/types.h>
  29. #include <sys/stat.h>
  30. #include <sys/ioctl.h>
  31. #include <fcntl.h>
  32. #include <unistd.h>
  33. #if ! defined (NO_AUDIO)
  34. #if defined (__OpenBSD__) || defined (__NetBSD__)
  35. #include <soundcard.h>
  36. #else
  37. #include <sys/soundcard.h>
  38. #endif
  39. #endif
  40. #endif
  41. struct SoundRecorder_Device {
  42. char32 name [1+40];
  43. bool canDo;
  44. GuiRadioButton button;
  45. };
  46. struct SoundRecorder_Fsamp {
  47. double fsamp;
  48. bool canDo;
  49. GuiRadioButton button;
  50. };
  51. #define SoundRecorder_IDEVICE_MAX 8
  52. #define SoundRecorder_IFSAMP_8000 1
  53. #define SoundRecorder_IFSAMP_9800 2
  54. #define SoundRecorder_IFSAMP_11025 3
  55. #define SoundRecorder_IFSAMP_12000 4
  56. #define SoundRecorder_IFSAMP_16000 5
  57. #define SoundRecorder_IFSAMP_22050 6
  58. #define SoundRecorder_IFSAMP_22254 7
  59. #define SoundRecorder_IFSAMP_24000 8
  60. #define SoundRecorder_IFSAMP_32000 9
  61. #define SoundRecorder_IFSAMP_44100 10
  62. #define SoundRecorder_IFSAMP_48000 11
  63. #define SoundRecorder_IFSAMP_64000 12
  64. #define SoundRecorder_IFSAMP_96000 13
  65. #define SoundRecorder_IFSAMP_192000 14
  66. #define SoundRecorder_IFSAMP_MAX 14
  67. Thing_define (SoundRecorder, Editor) {
  68. int numberOfChannels;
  69. integer nsamp, nmax;
  70. bool fakeMono, synchronous, recording;
  71. int lastLeftMaximum, lastRightMaximum;
  72. integer numberOfInputDevices;
  73. struct SoundRecorder_Device devices [1+SoundRecorder_IDEVICE_MAX];
  74. struct SoundRecorder_Fsamp fsamps [1+SoundRecorder_IFSAMP_MAX];
  75. short *buffer;
  76. GuiRadioButton monoButton, stereoButton;
  77. GuiDrawingArea meter;
  78. GuiScale progressScale;
  79. GuiButton recordButton, stopButton, playButton;
  80. GuiText soundName;
  81. GuiButton cancelButton, applyButton, okButton;
  82. GuiMenuItem meterIntensityButton, meterCentreOfGravityVersusIntensityButton;
  83. autoGraphics graphics;
  84. bool inputUsesPortAudio;
  85. const PaDeviceInfo *deviceInfos [1+SoundRecorder_IDEVICE_MAX];
  86. PaDeviceIndex deviceIndices [1+SoundRecorder_IDEVICE_MAX];
  87. PaStream *portaudioStream;
  88. #if cocoa
  89. CFRunLoopTimerRef d_cocoaTimer;
  90. #elif motif
  91. XtWorkProcId workProcId;
  92. #endif
  93. #if defined (_WIN32)
  94. HWAVEIN hWaveIn;
  95. WAVEFORMATEX waveFormat;
  96. WAVEHDR waveHeader [3];
  97. MMRESULT err;
  98. short buffertje1 [1000*2], buffertje2 [1000*2];
  99. #elif defined (macintosh)
  100. short macSource [1+8];
  101. Str255 hybridDeviceNames [1+8];
  102. int32 refNum;
  103. #elif defined (linux)
  104. int fd;
  105. #else
  106. int fd;
  107. #endif
  108. void v_destroy () noexcept
  109. override;
  110. bool v_editable ()
  111. override { return false; }
  112. bool v_scriptable ()
  113. override { return false; }
  114. void v_createChildren ()
  115. override;
  116. void v_createMenus ()
  117. override;
  118. void v_createHelpMenuItems (EditorMenu menu)
  119. override;
  120. #include "SoundRecorder_prefs.h"
  121. };
  122. autoSoundRecorder SoundRecorder_create (int numberOfChannels);
  123. /*
  124. Function:
  125. create a SoundRecorder, which is an interactive window
  126. for recording in 16-bit mono or stereo.
  127. */
  128. void SoundRecorder_preferences ();
  129. int SoundRecorder_getBufferSizePref_MB ();
  130. void SoundRecorder_setBufferSizePref_MB (int size);
  131. /* End of file SoundRecorder.h */
  132. #endif