PulseAudioPlaybackRecorder.cpp 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604
  1. #include "PulseAudioPlaybackRecorder.h"
  2. #include "WallpaperEngine/Data/Utils/FloatCompare.h"
  3. #include "WallpaperEngine/Logging/Log.h"
  4. #include "WallpaperEngine/Logging/ThreadGuard.h"
  5. #include <algorithm>
  6. #include <chrono>
  7. #include <cmath>
  8. #include <cstdlib>
  9. #include <ctime>
  10. #include <iomanip>
  11. #include <pulse/rtclock.h>
  12. #include <sstream>
  13. namespace WallpaperEngine::Audio::Drivers::Recorders {
  14. namespace {
  15. constexpr int CAPTURE_RATE = 44100;
  16. constexpr int CAPTURE_CHANNELS = 2;
  17. constexpr auto CAPTURE_TIMEOUT = std::chrono::milliseconds (1000);
  18. constexpr auto SILENCE_HOLD = std::chrono::milliseconds (50);
  19. std::string wallClockTimestamp () {
  20. const auto now = std::chrono::system_clock::now ();
  21. const auto ms = std::chrono::duration_cast<std::chrono::milliseconds> (now.time_since_epoch ()) % 1000;
  22. const std::time_t t = std::chrono::system_clock::to_time_t (now);
  23. std::tm tmBuf {};
  24. localtime_r (&t, &tmBuf);
  25. std::ostringstream oss;
  26. oss << std::put_time (&tmBuf, "%H:%M:%S") << '.' << std::setfill ('0') << std::setw (3) << ms.count ();
  27. return oss.str ();
  28. }
  29. }
  30. void pa_server_info_cb (pa_context* ctx, const pa_server_info* info, void* userdata);
  31. static void pa_retry_capture_cb (pa_mainloop_api* api, pa_time_event* event, const struct timeval*, void* userdata) {
  32. auto* recorder = static_cast<PulseAudioPlaybackRecorder::PulseAudioData*> (userdata);
  33. api->time_free (event);
  34. if (recorder->captureStream == nullptr) {
  35. return;
  36. }
  37. // a failed stream has let go of its context by now
  38. pa_context* ctx = recorder->context;
  39. if (ctx == nullptr || pa_context_get_state (ctx) != PA_CONTEXT_READY) {
  40. return;
  41. }
  42. if (pa_operation* o = pa_context_get_server_info (ctx, &pa_server_info_cb, userdata)) {
  43. pa_operation_unref (o);
  44. }
  45. }
  46. static void pa_stream_notify_cb (pa_stream* stream, void* userdata) {
  47. auto* recorder = static_cast<PulseAudioPlaybackRecorder::PulseAudioData*> (userdata);
  48. switch (pa_stream_get_state (stream)) {
  49. case PA_STREAM_FAILED:
  50. case PA_STREAM_TERMINATED:
  51. if (stream != recorder->captureStream) {
  52. break;
  53. }
  54. // the server can drop the monitor stream while sinks change state (a hotswap starting or stopping
  55. // sounds) and nothing else may follow to re-take it, so retry on our own
  56. if (!recorder->captureLost) {
  57. recorder->captureLost = true;
  58. sLog.error ("Audio capture stream lost, retrying every second");
  59. }
  60. if (recorder->context != nullptr) {
  61. pa_context_rttime_new (
  62. recorder->context, pa_rtclock_now () + PA_USEC_PER_SEC, &pa_retry_capture_cb, userdata
  63. );
  64. }
  65. break;
  66. case PA_STREAM_READY:
  67. if (recorder->captureLost) {
  68. recorder->captureLost = false;
  69. sLog.out ("Audio capture stream restored");
  70. }
  71. sLog.debug ("[", wallClockTimestamp (), "] Audio processing: capture stream ready");
  72. break;
  73. default:
  74. break;
  75. }
  76. }
  77. static void pa_stream_read_cb (pa_stream* stream, const size_t, void* userdata) {
  78. auto* recorder = static_cast<PulseAudioPlaybackRecorder::PulseAudioData*> (userdata);
  79. const void* data = nullptr;
  80. size_t currentSize;
  81. if (pa_stream_peek (stream, &data, &currentSize) != 0) {
  82. sLog.error ("Failed to peek at stream data...");
  83. return;
  84. }
  85. if (data == nullptr && currentSize == 0) {
  86. return;
  87. }
  88. if (data == nullptr && currentSize > 0) {
  89. recorder->owner->dropBlock ();
  90. if (pa_stream_drop (stream) != 0) {
  91. sLog.error ("Failed to drop a hole while capturing!");
  92. return;
  93. }
  94. return;
  95. }
  96. if (currentSize > 0 && data) {
  97. recorder->owner->consumeSamples (
  98. reinterpret_cast<const float*> (data), currentSize / (sizeof (float) * CAPTURE_CHANNELS)
  99. );
  100. }
  101. if (pa_stream_drop (stream) != 0) {
  102. sLog.error ("Failed to drop data after peeking");
  103. }
  104. }
  105. static void
  106. retakeCapture (PulseAudioPlaybackRecorder::PulseAudioData* recorder, pa_context* ctx, const std::string& source) {
  107. recorder->context = ctx;
  108. if (recorder->captureStream) {
  109. // sink/source events also fire for volume and state changes (another wallpaper starting its sounds),
  110. // only re-take the stream when the source moved or the old one died
  111. const bool alive = PA_STREAM_IS_GOOD (pa_stream_get_state (recorder->captureStream));
  112. if (alive && source == recorder->monitorName) {
  113. return;
  114. }
  115. // the context keeps a connected stream alive, unref alone left it feeding the same buffer
  116. pa_stream_set_state_callback (recorder->captureStream, nullptr, nullptr);
  117. pa_stream_set_read_callback (recorder->captureStream, nullptr, nullptr);
  118. pa_stream_disconnect (recorder->captureStream);
  119. pa_stream_unref (recorder->captureStream);
  120. recorder->captureStream = nullptr;
  121. }
  122. recorder->monitorName = source;
  123. pa_sample_spec spec;
  124. // WE's loopback capture is float stereo, 44.1kHz gives exactly its FFT size (it scales with the rate)
  125. spec.format = PA_SAMPLE_FLOAT32NE;
  126. spec.rate = CAPTURE_RATE;
  127. spec.channels = CAPTURE_CHANNELS;
  128. recorder->captureStream = pa_stream_new (ctx, "output monitor", &spec, nullptr);
  129. pa_stream_set_state_callback (recorder->captureStream, &pa_stream_notify_cb, recorder);
  130. pa_stream_set_read_callback (recorder->captureStream, &pa_stream_read_cb, recorder);
  131. pa_buffer_attr attr {};
  132. size_t bytesPerSec = pa_bytes_per_second (&spec);
  133. attr.fragsize = bytesPerSec * 10 / 1000;
  134. attr.maxlength = attr.fragsize + bytesPerSec * 750 / 1000;
  135. sLog.debug ("Audio processing: capturing from source '", source, "'");
  136. if (pa_stream_connect_record (recorder->captureStream, source.c_str (), &attr, PA_STREAM_ADJUST_LATENCY) != 0) {
  137. sLog.error ("Failed to connect to input for recording");
  138. }
  139. }
  140. static void pa_source_list_cb (pa_context* ctx, const pa_source_info* info, int eol, void* userdata) {
  141. auto* recorder = static_cast<PulseAudioPlaybackRecorder::PulseAudioData*> (userdata);
  142. if (eol == 0 && info != nullptr) {
  143. const std::string name = info->name;
  144. const std::string description = info->description != nullptr ? info->description : "";
  145. const std::string& wanted = recorder->wantedInput;
  146. if (name == wanted) {
  147. recorder->foundSource = name;
  148. recorder->exactMatch = true;
  149. } else if (
  150. !recorder->exactMatch && recorder->foundSource.empty ()
  151. && (description == wanted || name == wanted + ".monitor")
  152. ) {
  153. recorder->foundSource = name;
  154. }
  155. return;
  156. }
  157. std::string target = recorder->foundSource;
  158. // the next list starts clean, a lookup that overlaps this one must not see its result
  159. recorder->foundSource.clear ();
  160. recorder->exactMatch = false;
  161. if (target.empty ()) {
  162. target = recorder->defaultMonitor;
  163. if (!recorder->missingLogged) {
  164. recorder->missingLogged = true;
  165. if (target.empty ()) {
  166. sLog.error (
  167. "Audio input '", recorder->wantedInput, "' not found and there is no default output to capture"
  168. );
  169. } else {
  170. sLog.error (
  171. "Audio input '", recorder->wantedInput, "' not found, capturing the default output instead"
  172. );
  173. }
  174. }
  175. if (target.empty ()) {
  176. return;
  177. }
  178. } else {
  179. recorder->missingLogged = false;
  180. }
  181. retakeCapture (recorder, ctx, target);
  182. }
  183. void pa_server_info_cb (pa_context* ctx, const pa_server_info* info, void* userdata) {
  184. if (info == nullptr) {
  185. return;
  186. }
  187. auto* recorder = static_cast<PulseAudioPlaybackRecorder::PulseAudioData*> (userdata);
  188. recorder->context = ctx;
  189. // without a default sink there is no monitor to follow, a named source can still be captured
  190. recorder->defaultMonitor
  191. = info->default_sink_name != nullptr ? std::string (info->default_sink_name) + ".monitor" : std::string ();
  192. if (recorder->wantedInput.empty () || recorder->wantedInput == "default") {
  193. if (!recorder->defaultMonitor.empty ()) {
  194. retakeCapture (recorder, ctx, recorder->defaultMonitor);
  195. }
  196. return;
  197. }
  198. recorder->foundSource.clear ();
  199. recorder->exactMatch = false;
  200. if (pa_operation* o = pa_context_get_source_info_list (ctx, &pa_source_list_cb, userdata)) {
  201. pa_operation_unref (o);
  202. }
  203. }
  204. static void pa_context_subscribe_cb (pa_context* ctx, pa_subscription_event_type_t t, uint32_t idx, void* userdata) {
  205. const auto* recorder = static_cast<PulseAudioPlaybackRecorder::PulseAudioData*> (userdata);
  206. const auto facility = t & PA_SUBSCRIPTION_EVENT_FACILITY_MASK;
  207. // volume and state changes of a sink or source cannot move the capture, skip the lookups they would cost
  208. if ((t & PA_SUBSCRIPTION_EVENT_TYPE_MASK) == PA_SUBSCRIPTION_EVENT_CHANGE
  209. && (facility == PA_SUBSCRIPTION_EVENT_SINK || facility == PA_SUBSCRIPTION_EVENT_SOURCE)
  210. && recorder->captureStream != nullptr && PA_STREAM_IS_GOOD (pa_stream_get_state (recorder->captureStream))) {
  211. return;
  212. }
  213. pa_operation* o = pa_context_get_server_info (ctx, &pa_server_info_cb, userdata);
  214. if (o) {
  215. pa_operation_unref (o);
  216. }
  217. }
  218. static void pa_context_notify_cb (pa_context* ctx, void* userdata) {
  219. switch (pa_context_get_state (ctx)) {
  220. case PA_CONTEXT_READY:
  221. {
  222. pa_context_set_subscribe_callback (ctx, pa_context_subscribe_cb, userdata);
  223. pa_operation* o = pa_context_subscribe (
  224. ctx,
  225. static_cast<pa_subscription_mask_t> (
  226. PA_SUBSCRIPTION_MASK_SINK | PA_SUBSCRIPTION_MASK_SOURCE | PA_SUBSCRIPTION_MASK_SERVER
  227. ),
  228. nullptr, nullptr
  229. );
  230. if (o) {
  231. pa_operation_unref (o);
  232. }
  233. pa_operation* o2 = pa_context_get_server_info (ctx, &pa_server_info_cb, userdata);
  234. if (o2) {
  235. pa_operation_unref (o2);
  236. }
  237. break;
  238. }
  239. case PA_CONTEXT_FAILED:
  240. sLog.error ("PulseAudio context initialization failed. Audio processing is disabled");
  241. break;
  242. default:
  243. break;
  244. }
  245. }
  246. PulseAudioPlaybackRecorder::PulseAudioPlaybackRecorder () : PulseAudioPlaybackRecorder (Input {}) { }
  247. PulseAudioPlaybackRecorder::PulseAudioPlaybackRecorder (const Input& input) :
  248. m_captureData ({ .owner = this, .captureStream = nullptr, .captureLost = false }), m_analyzer (CAPTURE_RATE) {
  249. this->m_inputDevice = input.device;
  250. this->m_captureData.wantedInput = input.device;
  251. this->m_threshold.store (input.threshold, std::memory_order_relaxed);
  252. this->m_analyzer.setInputVolume (input.volume);
  253. this->m_stats.enabled = std::getenv ("LWE_AUDIO_STATS") != nullptr;
  254. this->m_dataMutex = SDL_CreateMutex ();
  255. this->m_mainloop = pa_mainloop_new ();
  256. this->m_mainloopApi = pa_mainloop_get_api (this->m_mainloop);
  257. this->m_context = pa_context_new (this->m_mainloopApi, "wallpaperengine-audioprocessing");
  258. pa_context_set_state_callback (this->m_context, &pa_context_notify_cb, &this->m_captureData);
  259. if (pa_context_connect (this->m_context, nullptr, PA_CONTEXT_NOFLAGS, nullptr) < 0) {
  260. sLog.error ("PulseAudio connection failed! Audio processing is disabled");
  261. return;
  262. }
  263. // wait until the context is ready, a server that goes away mid-handshake would otherwise spin here forever
  264. while (pa_context_get_state (this->m_context) != PA_CONTEXT_READY) {
  265. if (!PA_CONTEXT_IS_GOOD (pa_context_get_state (this->m_context))) {
  266. sLog.error ("PulseAudio connection failed! Audio processing is disabled");
  267. return;
  268. }
  269. pa_mainloop_iterate (this->m_mainloop, 1, nullptr);
  270. }
  271. // capture on its own thread: pumped from the render loop a slow frame stalled it and the server force-dropped the
  272. // backlog
  273. this->m_captureThread = std::thread ([this] {
  274. WallpaperEngine::Logging::guardThread ("Audio capture", [this] { this->captureLoop (); });
  275. });
  276. }
  277. PulseAudioPlaybackRecorder::~PulseAudioPlaybackRecorder () {
  278. this->m_running.store (false, std::memory_order_relaxed);
  279. if (this->m_mainloop) {
  280. pa_mainloop_wakeup (this->m_mainloop);
  281. }
  282. if (this->m_captureThread.joinable ()) {
  283. this->m_captureThread.join ();
  284. }
  285. if (m_captureData.captureStream) {
  286. pa_stream_set_state_callback (m_captureData.captureStream, nullptr, nullptr);
  287. pa_stream_disconnect (m_captureData.captureStream);
  288. pa_stream_unref (m_captureData.captureStream);
  289. }
  290. pa_context_disconnect (this->m_context);
  291. pa_context_unref (this->m_context);
  292. pa_mainloop_free (this->m_mainloop);
  293. if (this->m_dataMutex) {
  294. SDL_DestroyMutex (this->m_dataMutex);
  295. }
  296. }
  297. std::optional<std::vector<PulseAudioPlaybackRecorder::InputInfo>> PulseAudioPlaybackRecorder::listInputs () {
  298. struct Collected {
  299. std::vector<InputInfo> inputs;
  300. bool done = false;
  301. bool failed = false;
  302. } collected;
  303. pa_mainloop* loop = pa_mainloop_new ();
  304. pa_context* ctx = pa_context_new (pa_mainloop_get_api (loop), "wallpaperengine-list-inputs");
  305. auto finish = [&] () -> std::optional<std::vector<InputInfo>> {
  306. pa_context_disconnect (ctx);
  307. pa_context_unref (ctx);
  308. pa_mainloop_free (loop);
  309. if (!collected.done || collected.failed) {
  310. return std::nullopt;
  311. }
  312. return std::move (collected.inputs);
  313. };
  314. if (pa_context_connect (ctx, nullptr, PA_CONTEXT_NOAUTOSPAWN, nullptr) < 0) {
  315. return finish ();
  316. }
  317. bool asked = false;
  318. const auto deadline = std::chrono::steady_clock::now () + std::chrono::seconds (5);
  319. while (!collected.done && std::chrono::steady_clock::now () < deadline) {
  320. const auto state = pa_context_get_state (ctx);
  321. if (!PA_CONTEXT_IS_GOOD (state)) {
  322. break;
  323. }
  324. if (state == PA_CONTEXT_READY && !asked) {
  325. asked = true;
  326. pa_operation* o = pa_context_get_source_info_list (
  327. ctx,
  328. [] (pa_context*, const pa_source_info* info, int eol, void* userdata) {
  329. auto* result = static_cast<Collected*> (userdata);
  330. if (eol != 0 || info == nullptr) {
  331. result->failed = eol < 0;
  332. result->done = true;
  333. return;
  334. }
  335. result->inputs.push_back (
  336. { info->name, info->description != nullptr ? info->description : "",
  337. info->monitor_of_sink != PA_INVALID_INDEX }
  338. );
  339. },
  340. &collected
  341. );
  342. if (o != nullptr) {
  343. pa_operation_unref (o);
  344. } else {
  345. break;
  346. }
  347. }
  348. if (pa_mainloop_prepare (loop, 100000) < 0 || pa_mainloop_poll (loop) < 0 || pa_mainloop_dispatch (loop) < 0) {
  349. break;
  350. }
  351. }
  352. return finish ();
  353. }
  354. void PulseAudioPlaybackRecorder::setInput (const Input& input) {
  355. this->m_analyzer.setInputVolume (input.volume);
  356. this->m_threshold.store (input.threshold, std::memory_order_relaxed);
  357. {
  358. Debugging::LockGuard guard (this->m_inputMutex);
  359. if (this->m_inputDevice == input.device) {
  360. return;
  361. }
  362. this->m_inputDevice = input.device;
  363. }
  364. this->m_inputChanged.store (true, std::memory_order_release);
  365. pa_mainloop_wakeup (this->m_mainloop);
  366. }
  367. std::string PulseAudioPlaybackRecorder::wantedInput () const {
  368. Debugging::LockGuard guard (this->m_inputMutex);
  369. return this->m_inputDevice;
  370. }
  371. void PulseAudioPlaybackRecorder::lock () const { SDL_LockMutex (this->m_dataMutex); }
  372. void PulseAudioPlaybackRecorder::unlock () const { SDL_UnlockMutex (this->m_dataMutex); }
  373. void PulseAudioPlaybackRecorder::captureLoop () {
  374. bool cleared = false;
  375. while (this->m_running.load (std::memory_order_relaxed)) {
  376. if (pa_mainloop_prepare (this->m_mainloop, 100 * 1000) < 0 || pa_mainloop_poll (this->m_mainloop) < 0
  377. || pa_mainloop_dispatch (this->m_mainloop) < 0) {
  378. break;
  379. }
  380. if (this->m_inputChanged.exchange (false, std::memory_order_acquire)) {
  381. this->m_captureData.wantedInput = this->wantedInput ();
  382. this->m_captureData.missingLogged = false;
  383. sLog.out ("Audio input: ", this->m_captureData.wantedInput);
  384. if (pa_context_get_state (this->m_context) == PA_CONTEXT_READY) {
  385. if (pa_operation* o
  386. = pa_context_get_server_info (this->m_context, &pa_server_info_cb, &this->m_captureData)) {
  387. pa_operation_unref (o);
  388. }
  389. }
  390. }
  391. const bool stale = std::chrono::steady_clock::now () - this->m_lastSamples > CAPTURE_TIMEOUT;
  392. if (stale && !cleared) {
  393. this->m_analyzer.reset ();
  394. this->clearCaptured ();
  395. }
  396. cleared = stale;
  397. this->logStats ();
  398. }
  399. }
  400. void PulseAudioPlaybackRecorder::logStats () {
  401. auto& stats = this->m_stats;
  402. const auto now = std::chrono::steady_clock::now ();
  403. if (!stats.enabled || now - stats.since < std::chrono::seconds (1)) {
  404. return;
  405. }
  406. sLog.out (
  407. "Audio capture: ", stats.packets, " packets, ", stats.holes, " holes, ", stats.blocks, " blocks, peak ",
  408. stats.peak, ", dc ", stats.count > 0.0 ? stats.sum / stats.count : 0.0, ", bands low ", stats.lowMax, " high ",
  409. stats.highMax, ", stream ", this->m_captureData.captureLost ? "lost" : "up"
  410. );
  411. stats = { .enabled = true, .since = now };
  412. }
  413. void PulseAudioPlaybackRecorder::clearCaptured () {
  414. constexpr float silence[128] = {};
  415. this->lock ();
  416. std::fill_n (this->m_captured, 128, 0.0f);
  417. this->unlock ();
  418. this->notifySpectrumListeners (silence);
  419. }
  420. void PulseAudioPlaybackRecorder::dropBlock () {
  421. this->m_stats.holes++;
  422. this->m_analyzer.reset ();
  423. }
  424. void PulseAudioPlaybackRecorder::consumeSamples (const float* samples, std::size_t frames) {
  425. if (this->m_stats.enabled) {
  426. this->m_stats.packets++;
  427. for (std::size_t i = 0; i < frames * CAPTURE_CHANNELS; i++) {
  428. this->m_stats.sum += samples[i];
  429. this->m_stats.peak = std::max (this->m_stats.peak, std::fabs (samples[i]));
  430. }
  431. this->m_stats.count += static_cast<double> (frames * CAPTURE_CHANNELS);
  432. }
  433. // audioinputthreshold: a packet whose loudest left sample (never below 0) stays under it is silence (sub_1400D02B0)
  434. const float threshold = this->m_threshold.load (std::memory_order_relaxed) * 0.001f;
  435. bool belowThreshold = false;
  436. if (threshold > 1.1920929e-7f && frames > 0) {
  437. float loudest = 0.0f;
  438. for (std::size_t i = 0; i < frames; i++) {
  439. loudest = std::max (loudest, samples[i * CAPTURE_CHANNELS]);
  440. }
  441. belowThreshold = threshold > loudest;
  442. }
  443. // WASAPI's loopback sends nothing while nothing plays and WE zeroes the spectrum after a second without data, while
  444. // PipeWire and PulseAudio keep sending zeros: their FFT leaves a 1e-7 residue that pages with their own gain
  445. // (CWAV's monstercat) stretch to full height once the peak they follow has decayed
  446. if (belowThreshold || std::all_of (samples, samples + frames * CAPTURE_CHANNELS, [] (float sample) {
  447. return Data::Utils::isZero (sample);
  448. })) {
  449. const auto now = std::chrono::steady_clock::now ();
  450. if (this->m_silentSince == std::chrono::steady_clock::time_point {}) {
  451. this->m_silentSince = now;
  452. }
  453. this->m_analyzer.reset ();
  454. if (!this->m_silenceCleared && now - this->m_silentSince >= SILENCE_HOLD) {
  455. this->m_silenceCleared = true;
  456. this->clearCaptured ();
  457. }
  458. return;
  459. }
  460. this->m_silentSince = {};
  461. this->m_silenceCleared = false;
  462. this->m_lastSamples = std::chrono::steady_clock::now ();
  463. float bands[SpectrumAnalyzer::BANDS * 2];
  464. if (this->m_analyzer.feed (samples, frames, CAPTURE_CHANNELS, bands)) {
  465. if (this->m_stats.enabled) {
  466. this->m_stats.blocks++;
  467. this->m_stats.lowMax = std::max (this->m_stats.lowMax, *std::max_element (bands, bands + 16));
  468. this->m_stats.highMax = std::max (this->m_stats.highMax, *std::max_element (bands + 16, bands + 64));
  469. }
  470. this->lock ();
  471. std::copy_n (bands, 128, this->m_captured);
  472. this->unlock ();
  473. this->notifySpectrumListeners (bands);
  474. }
  475. }
  476. }