| 1 |
#ifndef _SoundRecorder_h_ |
| 2 |
#define _SoundRecorder_h_ |
| 3 |
/* SoundRecorder.h |
| 4 |
* |
| 5 |
* Copyright (C) 1992-2005,2008-2013,2015-2017,2020,2022,2023,2025 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 3 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 |
|
| 21 |
/* An editor-like object that allows the user to record sounds. */ |
| 22 |
|
| 23 |
#include "ScriptEditor.h" |
| 24 |
#include "Sound.h" |
| 25 |
|
| 26 |
#include "SoundRecorder_enums.h" |
| 27 |
|
| 28 |
#include "../external/portaudio/portaudio.h" |
| 29 |
#if defined (_WIN32) |
| 30 |
#elif defined (macintosh) |
| 31 |
#elif defined (linux) |
| 32 |
#include <sys/types.h> |
| 33 |
#include <sys/stat.h> |
| 34 |
#include <sys/ioctl.h> |
| 35 |
#include <fcntl.h> |
| 36 |
#include <unistd.h> |
| 37 |
#if ! defined (NO_AUDIO) |
| 38 |
#if defined (__OpenBSD__) || defined (__NetBSD__) |
| 39 |
#include <soundcard.h> |
| 40 |
#else |
| 41 |
#include <sys/soundcard.h> |
| 42 |
#endif |
| 43 |
#endif |
| 44 |
#endif |
| 45 |
|
| 46 |
struct SoundRecorder_Device { |
| 47 |
static constexpr int maximumLengthOfFullName = 60; |
| 48 |
char32 fullName [1+maximumLengthOfFullName]; |
| 49 |
bool canDo; |
| 50 |
GuiRadioButton button; |
| 51 |
}; |
| 52 |
|
| 53 |
struct SoundRecorder_Fsamp { |
| 54 |
double fsamp; |
| 55 |
bool canDo; |
| 56 |
GuiRadioButton button; |
| 57 |
}; |
| 58 |
|
| 59 |
#define SoundRecorder_IDEVICE_MAX 20 |
| 60 |
|
| 61 |
#define SoundRecorder_IFSAMP_8000 1 |
| 62 |
#define SoundRecorder_IFSAMP_9800 2 |
| 63 |
#define SoundRecorder_IFSAMP_11025 3 |
| 64 |
#define SoundRecorder_IFSAMP_12000 4 |
| 65 |
#define SoundRecorder_IFSAMP_16000 5 |
| 66 |
#define SoundRecorder_IFSAMP_22050 6 |
| 67 |
#define SoundRecorder_IFSAMP_22254 7 |
| 68 |
#define SoundRecorder_IFSAMP_24000 8 |
| 69 |
#define SoundRecorder_IFSAMP_32000 9 |
| 70 |
#define SoundRecorder_IFSAMP_44100 10 |
| 71 |
#define SoundRecorder_IFSAMP_48000 11 |
| 72 |
#define SoundRecorder_IFSAMP_64000 12 |
| 73 |
#define SoundRecorder_IFSAMP_96000 13 |
| 74 |
#define SoundRecorder_IFSAMP_192000 14 |
| 75 |
#define SoundRecorder_IFSAMP_MAX 14 |
| 76 |
|
| 77 |
Thing_define (SoundRecorder, Editor) { |
| 78 |
int numberOfChannels; |
| 79 |
integer nsamp, nmax; |
| 80 |
integer firstSample, lastSample; // for the meter |
| 81 |
bool synchronous, recording; |
| 82 |
int lastLeftMaximum, lastRightMaximum; |
| 83 |
integer numberOfInputDevices; |
| 84 |
struct SoundRecorder_Device devices [1+SoundRecorder_IDEVICE_MAX]; |
| 85 |
struct SoundRecorder_Fsamp fsamps [1+SoundRecorder_IFSAMP_MAX]; |
| 86 |
autovector <short> recordBuffer; |
| 87 |
GuiRadioButton monoButton, stereoButton; |
| 88 |
GuiDrawingArea meter; |
| 89 |
GuiScale progressScale; |
| 90 |
GuiButton recordButton, stopButton, playButton; |
| 91 |
GuiText soundName; |
| 92 |
GuiButton cancelButton, applyButton, okButton; |
| 93 |
GuiMenuItem meterIntensityButton, meterCentreOfGravityVersusIntensityButton; |
| 94 |
autoGraphics graphics; |
| 95 |
bool inputUsesPortAudio; |
| 96 |
|
| 97 |
const PaDeviceInfo *deviceInfos [1+SoundRecorder_IDEVICE_MAX]; |
| 98 |
PaDeviceIndex deviceIndices [1+SoundRecorder_IDEVICE_MAX]; |
| 99 |
PaStream *portaudioStream; |
| 100 |
|
| 101 |
#if cocoa |
| 102 |
CFRunLoopTimerRef d_cocoaTimer; |
| 103 |
#elif motif |
| 104 |
XtWorkProcId workProcId; |
| 105 |
#endif |
| 106 |
#if defined (_WIN32) |
| 107 |
HWAVEIN hWaveIn; |
| 108 |
WAVEFORMATEX waveFormat; |
| 109 |
WAVEHDR waveHeader [3]; |
| 110 |
MMRESULT err; |
| 111 |
short buffertje1 [1000*2], buffertje2 [1000*2]; |
| 112 |
#elif defined (macintosh) |
| 113 |
short macSource [1+8]; |
| 114 |
Str255 hybridDeviceNames [1+8]; |
| 115 |
int32 refNum; |
| 116 |
#elif defined (linux) |
| 117 |
int fd; |
| 118 |
#else |
| 119 |
int fd; |
| 120 |
#endif |
| 121 |
|
| 122 |
void v9_destroy () noexcept |
| 123 |
override; |
| 124 |
bool v_hasEditMenu () |
| 125 |
override { return false; } |
| 126 |
bool v_scriptable () |
| 127 |
override { return false; } |
| 128 |
void v_createChildren () |
| 129 |
override; |
| 130 |
void v_createMenus () |
| 131 |
override; |
| 132 |
void v_createMenuItems_help (EditorMenu menu) |
| 133 |
override; |
| 134 |
|
| 135 |
#include "SoundRecorder_prefs.h" |
| 136 |
}; |
| 137 |
|
| 138 |
autoSoundRecorder SoundRecorder_create (int numberOfChannels); |
| 139 |
/* |
| 140 |
Function: |
| 141 |
create a SoundRecorder, which is an interactive window |
| 142 |
for recording in 16-bit mono or stereo. |
| 143 |
*/ |
| 144 |
|
| 145 |
void SoundRecorder_preferences (); |
| 146 |
integer SoundRecorder_getBufferSizePref_MB (); |
| 147 |
void SoundRecorder_setBufferSizePref_MB (integer size); |
| 148 |
|
| 149 |
/* End of file SoundRecorder.h */ |
| 150 |
#endif |