Debian Codegraph @

melder/melder_audio.h

raw
1 #ifndef _melder_audio_h_
2 #define _melder_audio_h_
3 /* melder_audio.h
4 *
5 * Copyright (C) 1992-2019,2021 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
21 void MelderAudio_setInputSoundSystem (enum kMelder_inputSoundSystem inputSoundSystem);
22 enum kMelder_inputSoundSystem MelderAudio_getInputSoundSystem ();
23
24 void MelderAudio_setOutputSoundSystem (enum kMelder_outputSoundSystem outputSoundSystem);
25 enum kMelder_outputSoundSystem MelderAudio_getOutputSoundSystem ();
26
27 #if defined (_WIN32)
28 #define kMelderAudio_outputSilenceBefore_DEFAULT 0.0
29 #define kMelderAudio_outputSilenceAfter_DEFAULT 0.1
30 // in order to get rid of the click on some cards
31 #elif defined (macintosh)
32 #define kMelderAudio_outputSilenceBefore_DEFAULT 0.0
33 // in order to switch off the BOING caused by the automatic gain control
34 #define kMelderAudio_outputSilenceAfter_DEFAULT 0.0
35 // in order to reduce the BOING caused by the automatic gain control when the user replays immediately after a sound has finished
36 #elif defined (linux)
37 #define kMelderAudio_outputSilenceBefore_DEFAULT 0.0
38 #define kMelderAudio_outputSilenceAfter_DEFAULT 0.1
39 // in order to get rid of double playing of a sounding buffer (?)
40 #else
41 #define kMelderAudio_outputSilenceBefore_DEFAULT 0.0
42 #define kMelderAudio_outputSilenceAfter_DEFAULT 0.0
43 #endif
44 void MelderAudio_setOutputSilenceBefore (double silenceBefore);
45 double MelderAudio_getOutputSilenceBefore ();
46 void MelderAudio_setOutputSilenceAfter (double silenceAfter);
47 double MelderAudio_getOutputSilenceAfter ();
48
49 integer MelderAudio_getOutputBestSampleRate (integer fsamp);
50
51 inline bool MelderAudio_isPlaying;
52 inline bool MelderAudio_hasBeenInitialized;
53 void MelderAudio_play16 (int16 *buffer, integer sampleRate, integer numberOfSamples, integer numberOfChannels,
54 bool (*playCallback) (void *playClosure, integer numberOfSamplesPlayed), // return true to continue, false to stop
55 void *playClosure);
56 bool MelderAudio_stopPlaying (bool isExplicit); // returns true if sound was playing
57 #define MelderAudio_IMPLICIT false
58 #define MelderAudio_EXPLICIT true
59 integer MelderAudio_getSamplesPlayed ();
60 bool MelderAudio_stopWasExplicit ();
61
62 void Melder_audio_prefs (); // in init file
63
64 #pragma mark - ASYNCHRONICITY
65
66 void MelderAudio_setOutputMaximumAsynchronicity (enum kMelder_asynchronicityLevel maximumAsynchronicity);
67 enum kMelder_asynchronicityLevel MelderAudio_getOutputMaximumAsynchronicity ();
68
69 class autoMelderAudioSaveMaximumAsynchronicity {
70 bool _disowned;
71 enum kMelder_asynchronicityLevel _savedAsynchronicity;
72 public:
73 autoMelderAudioSaveMaximumAsynchronicity () {
74 our _savedAsynchronicity = MelderAudio_getOutputMaximumAsynchronicity ();
75 trace (U"value was ", (int) our _savedAsynchronicity);
76 our _disowned = false;
77 }
78 ~autoMelderAudioSaveMaximumAsynchronicity () {
79 MelderAudio_setOutputMaximumAsynchronicity (our _savedAsynchronicity);
80 trace (U"value set to ", (int) our _savedAsynchronicity);
81 }
82 /*
83 Disable copying.
84 */
85 autoMelderAudioSaveMaximumAsynchronicity (const autoMelderAudioSaveMaximumAsynchronicity&) = delete; // disable copy constructor
86 autoMelderAudioSaveMaximumAsynchronicity& operator= (const autoMelderAudioSaveMaximumAsynchronicity&) = delete; // disable copy assignment
87 /*
88 Enable moving.
89 */
90 autoMelderAudioSaveMaximumAsynchronicity (autoMelderAudioSaveMaximumAsynchronicity&& other) noexcept { // enable move constructor
91 our _disowned = other._disowned;
92 our _savedAsynchronicity = other._savedAsynchronicity;
93 other._disowned = true;
94 }
95 autoMelderAudioSaveMaximumAsynchronicity& operator= (autoMelderAudioSaveMaximumAsynchronicity&& other) noexcept { // enable move assignment
96 if (& other != this) {
97 our _disowned = other._disowned;
98 our _savedAsynchronicity = other._savedAsynchronicity;
99 other._disowned = true; // needed only if you insist on keeping the source in a valid state
100 }
101 return *this;
102 }
103 autoMelderAudioSaveMaximumAsynchronicity&& move () noexcept { return static_cast <autoMelderAudioSaveMaximumAsynchronicity&&> (*this); }
104 void releaseToAmbiguousOwner () {
105 our _disowned = true;
106 }
107 };
108
109 /*
110 True if specified by the "asynchronous" directive in a script.
111 */
112 inline bool Melder_asynchronous;
113
114 class autoMelderAsynchronous {
115 bool _disowned;
116 bool _savedAsynchronicity;
117 public:
118 autoMelderAsynchronous () {
119 our _savedAsynchronicity = Melder_asynchronous;
120 Melder_asynchronous = true;
121 our _disowned = false;
122 }
123 ~autoMelderAsynchronous () {
124 if (! _disowned) {
125 Melder_asynchronous = _savedAsynchronicity;
126 }
127 }
128 /*
129 Disable copying.
130 */
131 autoMelderAsynchronous (const autoMelderAsynchronous&) = delete; // disable copy constructor
132 autoMelderAsynchronous& operator= (const autoMelderAsynchronous&) = delete; // disable copy assignment
133 /*
134 Enable moving.
135 */
136 autoMelderAsynchronous (autoMelderAsynchronous&& other) noexcept { // enable move constructor
137 our _disowned = other._disowned;
138 our _savedAsynchronicity = other._savedAsynchronicity;
139 other._disowned = true;
140 }
141 autoMelderAsynchronous& operator= (autoMelderAsynchronous&& other) noexcept { // enable move assignment
142 if (& other != this) {
143 our _disowned = other._disowned;
144 our _savedAsynchronicity = other._savedAsynchronicity;
145 other._disowned = true; // needed only if you insist on keeping the source in a valid state
146 }
147 return *this;
148 }
149 autoMelderAsynchronous&& move () noexcept { return static_cast <autoMelderAsynchronous&&> (*this); }
150 void releaseToAmbiguousOwner () {
151 our _disowned = true;
152 }
153 };
154
155 /* End of file melder_audio.h */
156 #endif