alstreamcb.cpp 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568
  1. /*
  2. * OpenAL Callback-based Stream Example
  3. *
  4. * Copyright (c) 2020 by Chris Robinson <[email protected]>
  5. *
  6. * Permission is hereby granted, free of charge, to any person obtaining a copy
  7. * of this software and associated documentation files (the "Software"), to deal
  8. * in the Software without restriction, including without limitation the rights
  9. * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  10. * copies of the Software, and to permit persons to whom the Software is
  11. * furnished to do so, subject to the following conditions:
  12. *
  13. * The above copyright notice and this permission notice shall be included in
  14. * all copies or substantial portions of the Software.
  15. *
  16. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  17. * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  18. * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  19. * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  20. * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  21. * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  22. * THE SOFTWARE.
  23. */
  24. /* This file contains a streaming audio player using a callback buffer. */
  25. #include <algorithm>
  26. #include <atomic>
  27. #include <cassert>
  28. #include <chrono>
  29. #include <cstddef>
  30. #include <cstdlib>
  31. #include <cstdio>
  32. #include <cstring>
  33. #include <memory>
  34. #include <stdexcept>
  35. #include <string>
  36. #include <string_view>
  37. #include <thread>
  38. #include <vector>
  39. #include "sndfile.h"
  40. #include "AL/al.h"
  41. #include "AL/alc.h"
  42. #include "AL/alext.h"
  43. #include "alspan.h"
  44. #include "alstring.h"
  45. #include "common/alhelpers.h"
  46. #include "win_main_utf8.h"
  47. namespace {
  48. using std::chrono::seconds;
  49. using std::chrono::nanoseconds;
  50. LPALBUFFERCALLBACKSOFT alBufferCallbackSOFT;
  51. struct StreamPlayer {
  52. /* A lockless ring-buffer (supports single-provider, single-consumer
  53. * operation).
  54. */
  55. std::vector<std::byte> mBufferData;
  56. std::atomic<size_t> mReadPos{0};
  57. std::atomic<size_t> mWritePos{0};
  58. size_t mSamplesPerBlock{1};
  59. size_t mBytesPerBlock{1};
  60. enum class SampleType {
  61. Int16, Float, IMA4, MSADPCM
  62. };
  63. SampleType mSampleFormat{SampleType::Int16};
  64. /* The buffer to get the callback, and source to play with. */
  65. ALuint mBuffer{0}, mSource{0};
  66. size_t mStartOffset{0};
  67. /* Handle for the audio file to decode. */
  68. SNDFILE *mSndfile{nullptr};
  69. SF_INFO mSfInfo{};
  70. size_t mDecoderOffset{0};
  71. /* The format of the callback samples. */
  72. ALenum mFormat{};
  73. StreamPlayer()
  74. {
  75. alGenBuffers(1, &mBuffer);
  76. if(alGetError() != AL_NO_ERROR)
  77. throw std::runtime_error{"alGenBuffers failed"};
  78. alGenSources(1, &mSource);
  79. if(alGetError() != AL_NO_ERROR)
  80. {
  81. alDeleteBuffers(1, &mBuffer);
  82. throw std::runtime_error{"alGenSources failed"};
  83. }
  84. }
  85. ~StreamPlayer()
  86. {
  87. alDeleteSources(1, &mSource);
  88. alDeleteBuffers(1, &mBuffer);
  89. if(mSndfile)
  90. sf_close(mSndfile);
  91. }
  92. void close()
  93. {
  94. if(mSamplesPerBlock > 1)
  95. alBufferi(mBuffer, AL_UNPACK_BLOCK_ALIGNMENT_SOFT, 0);
  96. if(mSndfile)
  97. {
  98. alSourceRewind(mSource);
  99. alSourcei(mSource, AL_BUFFER, 0);
  100. sf_close(mSndfile);
  101. mSndfile = nullptr;
  102. }
  103. }
  104. bool open(const std::string &filename)
  105. {
  106. close();
  107. /* Open the file and figure out the OpenAL format. */
  108. mSndfile = sf_open(filename.c_str(), SFM_READ, &mSfInfo);
  109. if(!mSndfile)
  110. {
  111. fprintf(stderr, "Could not open audio in %s: %s\n", filename.c_str(),
  112. sf_strerror(mSndfile));
  113. return false;
  114. }
  115. switch((mSfInfo.format&SF_FORMAT_SUBMASK))
  116. {
  117. case SF_FORMAT_PCM_24:
  118. case SF_FORMAT_PCM_32:
  119. case SF_FORMAT_FLOAT:
  120. case SF_FORMAT_DOUBLE:
  121. case SF_FORMAT_VORBIS:
  122. case SF_FORMAT_OPUS:
  123. case SF_FORMAT_ALAC_20:
  124. case SF_FORMAT_ALAC_24:
  125. case SF_FORMAT_ALAC_32:
  126. case 0x0080/*SF_FORMAT_MPEG_LAYER_I*/:
  127. case 0x0081/*SF_FORMAT_MPEG_LAYER_II*/:
  128. case 0x0082/*SF_FORMAT_MPEG_LAYER_III*/:
  129. if(alIsExtensionPresent("AL_EXT_FLOAT32"))
  130. mSampleFormat = SampleType::Float;
  131. break;
  132. case SF_FORMAT_IMA_ADPCM:
  133. if(mSfInfo.channels <= 2 && (mSfInfo.format&SF_FORMAT_TYPEMASK) == SF_FORMAT_WAV
  134. && alIsExtensionPresent("AL_EXT_IMA4")
  135. && alIsExtensionPresent("AL_SOFT_block_alignment"))
  136. mSampleFormat = SampleType::IMA4;
  137. break;
  138. case SF_FORMAT_MS_ADPCM:
  139. if(mSfInfo.channels <= 2 && (mSfInfo.format&SF_FORMAT_TYPEMASK) == SF_FORMAT_WAV
  140. && alIsExtensionPresent("AL_SOFT_MSADPCM")
  141. && alIsExtensionPresent("AL_SOFT_block_alignment"))
  142. mSampleFormat = SampleType::MSADPCM;
  143. break;
  144. }
  145. int splblocksize{}, byteblocksize{};
  146. if(mSampleFormat == SampleType::IMA4 || mSampleFormat == SampleType::MSADPCM)
  147. {
  148. SF_CHUNK_INFO inf{ "fmt ", 4, 0, nullptr };
  149. SF_CHUNK_ITERATOR *iter = sf_get_chunk_iterator(mSndfile, &inf);
  150. if(!iter || sf_get_chunk_size(iter, &inf) != SF_ERR_NO_ERROR || inf.datalen < 14)
  151. mSampleFormat = SampleType::Int16;
  152. else
  153. {
  154. auto fmtbuf = std::vector<ALubyte>(inf.datalen);
  155. inf.data = fmtbuf.data();
  156. if(sf_get_chunk_data(iter, &inf) != SF_ERR_NO_ERROR)
  157. mSampleFormat = SampleType::Int16;
  158. else
  159. {
  160. byteblocksize = fmtbuf[12] | (fmtbuf[13]<<8u);
  161. if(mSampleFormat == SampleType::IMA4)
  162. {
  163. splblocksize = (byteblocksize/mSfInfo.channels - 4)/4*8 + 1;
  164. if(splblocksize < 1
  165. || ((splblocksize-1)/2 + 4)*mSfInfo.channels != byteblocksize)
  166. mSampleFormat = SampleType::Int16;
  167. }
  168. else
  169. {
  170. splblocksize = (byteblocksize/mSfInfo.channels - 7)*2 + 2;
  171. if(splblocksize < 2
  172. || ((splblocksize-2)/2 + 7)*mSfInfo.channels != byteblocksize)
  173. mSampleFormat = SampleType::Int16;
  174. }
  175. }
  176. }
  177. }
  178. if(mSampleFormat == SampleType::Int16)
  179. {
  180. mSamplesPerBlock = 1;
  181. mBytesPerBlock = static_cast<size_t>(mSfInfo.channels) * 2;
  182. }
  183. else if(mSampleFormat == SampleType::Float)
  184. {
  185. mSamplesPerBlock = 1;
  186. mBytesPerBlock = static_cast<size_t>(mSfInfo.channels) * 4;
  187. }
  188. else
  189. {
  190. mSamplesPerBlock = static_cast<size_t>(splblocksize);
  191. mBytesPerBlock = static_cast<size_t>(byteblocksize);
  192. }
  193. mFormat = AL_NONE;
  194. if(mSfInfo.channels == 1)
  195. {
  196. if(mSampleFormat == SampleType::Int16)
  197. mFormat = AL_FORMAT_MONO16;
  198. else if(mSampleFormat == SampleType::Float)
  199. mFormat = AL_FORMAT_MONO_FLOAT32;
  200. else if(mSampleFormat == SampleType::IMA4)
  201. mFormat = AL_FORMAT_MONO_IMA4;
  202. else if(mSampleFormat == SampleType::MSADPCM)
  203. mFormat = AL_FORMAT_MONO_MSADPCM_SOFT;
  204. }
  205. else if(mSfInfo.channels == 2)
  206. {
  207. if(mSampleFormat == SampleType::Int16)
  208. mFormat = AL_FORMAT_STEREO16;
  209. else if(mSampleFormat == SampleType::Float)
  210. mFormat = AL_FORMAT_STEREO_FLOAT32;
  211. else if(mSampleFormat == SampleType::IMA4)
  212. mFormat = AL_FORMAT_STEREO_IMA4;
  213. else if(mSampleFormat == SampleType::MSADPCM)
  214. mFormat = AL_FORMAT_STEREO_MSADPCM_SOFT;
  215. }
  216. else if(mSfInfo.channels == 3)
  217. {
  218. if(sf_command(mSndfile, SFC_WAVEX_GET_AMBISONIC, nullptr, 0) == SF_AMBISONIC_B_FORMAT)
  219. {
  220. if(mSampleFormat == SampleType::Int16)
  221. mFormat = AL_FORMAT_BFORMAT2D_16;
  222. else if(mSampleFormat == SampleType::Float)
  223. mFormat = AL_FORMAT_BFORMAT2D_FLOAT32;
  224. }
  225. }
  226. else if(mSfInfo.channels == 4)
  227. {
  228. if(sf_command(mSndfile, SFC_WAVEX_GET_AMBISONIC, nullptr, 0) == SF_AMBISONIC_B_FORMAT)
  229. {
  230. if(mSampleFormat == SampleType::Int16)
  231. mFormat = AL_FORMAT_BFORMAT3D_16;
  232. else if(mSampleFormat == SampleType::Float)
  233. mFormat = AL_FORMAT_BFORMAT3D_FLOAT32;
  234. }
  235. }
  236. if(!mFormat)
  237. {
  238. fprintf(stderr, "Unsupported channel count: %d\n", mSfInfo.channels);
  239. sf_close(mSndfile);
  240. mSndfile = nullptr;
  241. return false;
  242. }
  243. /* Set a 1s ring buffer size. */
  244. size_t numblocks{(static_cast<ALuint>(mSfInfo.samplerate) + mSamplesPerBlock-1)
  245. / mSamplesPerBlock};
  246. mBufferData.resize(static_cast<ALuint>(numblocks * mBytesPerBlock));
  247. mReadPos.store(0, std::memory_order_relaxed);
  248. mWritePos.store(0, std::memory_order_relaxed);
  249. mDecoderOffset = 0;
  250. return true;
  251. }
  252. /* The actual C-style callback just forwards to the non-static method. Not
  253. * strictly needed and the compiler will optimize it to a normal function,
  254. * but it allows the callback implementation to have a nice 'this' pointer
  255. * with normal member access.
  256. */
  257. static ALsizei AL_APIENTRY bufferCallbackC(void *userptr, void *data, ALsizei size) noexcept
  258. { return static_cast<StreamPlayer*>(userptr)->bufferCallback(data, size); }
  259. ALsizei bufferCallback(void *data, ALsizei size) noexcept
  260. {
  261. auto dst = al::span{static_cast<std::byte*>(data), static_cast<ALuint>(size)};
  262. /* NOTE: The callback *MUST* be real-time safe! That means no blocking,
  263. * no allocations or deallocations, no I/O, no page faults, or calls to
  264. * functions that could do these things (this includes calling to
  265. * libraries like SDL_sound, libsndfile, ffmpeg, etc). Nothing should
  266. * unexpectedly stall this call since the audio has to get to the
  267. * device on time.
  268. */
  269. ALsizei got{0};
  270. size_t roffset{mReadPos.load(std::memory_order_acquire)};
  271. while(!dst.empty())
  272. {
  273. /* If the write offset == read offset, there's nothing left in the
  274. * ring-buffer. Break from the loop and give what has been written.
  275. */
  276. const size_t woffset{mWritePos.load(std::memory_order_relaxed)};
  277. if(woffset == roffset) break;
  278. /* If the write offset is behind the read offset, the readable
  279. * portion wrapped around. Just read up to the end of the buffer in
  280. * that case, otherwise read up to the write offset. Also limit the
  281. * amount to copy given how much is remaining to write.
  282. */
  283. size_t todo{((woffset < roffset) ? mBufferData.size() : woffset) - roffset};
  284. todo = std::min(todo, dst.size());
  285. /* Copy from the ring buffer to the provided output buffer. Wrap
  286. * the resulting read offset if it reached the end of the ring-
  287. * buffer.
  288. */
  289. std::copy_n(mBufferData.cbegin()+ptrdiff_t(roffset), todo, dst.begin());
  290. dst = dst.subspan(todo);
  291. got += static_cast<ALsizei>(todo);
  292. roffset += todo;
  293. if(roffset == mBufferData.size())
  294. roffset = 0;
  295. }
  296. /* Finally, store the updated read offset, and return how many bytes
  297. * have been written.
  298. */
  299. mReadPos.store(roffset, std::memory_order_release);
  300. return got;
  301. }
  302. bool prepare()
  303. {
  304. if(mSamplesPerBlock > 1)
  305. alBufferi(mBuffer, AL_UNPACK_BLOCK_ALIGNMENT_SOFT, static_cast<int>(mSamplesPerBlock));
  306. alBufferCallbackSOFT(mBuffer, mFormat, mSfInfo.samplerate, bufferCallbackC, this);
  307. alSourcei(mSource, AL_BUFFER, static_cast<ALint>(mBuffer));
  308. if(ALenum err{alGetError()})
  309. {
  310. fprintf(stderr, "Failed to set callback: %s (0x%04x)\n", alGetString(err), err);
  311. return false;
  312. }
  313. return true;
  314. }
  315. bool update()
  316. {
  317. ALenum state;
  318. ALint pos;
  319. alGetSourcei(mSource, AL_SAMPLE_OFFSET, &pos);
  320. alGetSourcei(mSource, AL_SOURCE_STATE, &state);
  321. size_t woffset{mWritePos.load(std::memory_order_acquire)};
  322. if(state != AL_INITIAL)
  323. {
  324. const size_t roffset{mReadPos.load(std::memory_order_relaxed)};
  325. const size_t readable{((woffset >= roffset) ? woffset : (mBufferData.size()+woffset)) -
  326. roffset};
  327. /* For a stopped (underrun) source, the current playback offset is
  328. * the current decoder offset excluding the readable buffered data.
  329. * For a playing/paused source, it's the source's offset including
  330. * the playback offset the source was started with.
  331. */
  332. const size_t curtime{((state == AL_STOPPED)
  333. ? (mDecoderOffset-readable) / mBytesPerBlock * mSamplesPerBlock
  334. : (static_cast<ALuint>(pos) + mStartOffset/mBytesPerBlock*mSamplesPerBlock))
  335. / static_cast<ALuint>(mSfInfo.samplerate)};
  336. printf("\r%3zus (%3zu%% full)", curtime, readable * 100 / mBufferData.size());
  337. }
  338. else
  339. fputs("Starting...", stdout);
  340. fflush(stdout);
  341. while(!sf_error(mSndfile))
  342. {
  343. size_t read_bytes;
  344. const size_t roffset{mReadPos.load(std::memory_order_relaxed)};
  345. if(roffset > woffset)
  346. {
  347. /* Note that the ring buffer's writable space is one byte less
  348. * than the available area because the write offset ending up
  349. * at the read offset would be interpreted as being empty
  350. * instead of full.
  351. */
  352. const size_t writable{(roffset-woffset-1) / mBytesPerBlock};
  353. if(!writable) break;
  354. if(mSampleFormat == SampleType::Int16)
  355. {
  356. sf_count_t num_frames{sf_readf_short(mSndfile,
  357. reinterpret_cast<short*>(&mBufferData[woffset]),
  358. static_cast<sf_count_t>(writable*mSamplesPerBlock))};
  359. if(num_frames < 1) break;
  360. read_bytes = static_cast<size_t>(num_frames) * mBytesPerBlock;
  361. }
  362. else if(mSampleFormat == SampleType::Float)
  363. {
  364. sf_count_t num_frames{sf_readf_float(mSndfile,
  365. reinterpret_cast<float*>(&mBufferData[woffset]),
  366. static_cast<sf_count_t>(writable*mSamplesPerBlock))};
  367. if(num_frames < 1) break;
  368. read_bytes = static_cast<size_t>(num_frames) * mBytesPerBlock;
  369. }
  370. else
  371. {
  372. sf_count_t numbytes{sf_read_raw(mSndfile, &mBufferData[woffset],
  373. static_cast<sf_count_t>(writable*mBytesPerBlock))};
  374. if(numbytes < 1) break;
  375. read_bytes = static_cast<size_t>(numbytes);
  376. }
  377. woffset += read_bytes;
  378. }
  379. else
  380. {
  381. /* If the read offset is at or behind the write offset, the
  382. * writeable area (might) wrap around. Make sure the sample
  383. * data can fit, and calculate how much can go in front before
  384. * wrapping.
  385. */
  386. const size_t writable{(!roffset ? mBufferData.size()-woffset-1 :
  387. (mBufferData.size()-woffset)) / mBytesPerBlock};
  388. if(!writable) break;
  389. if(mSampleFormat == SampleType::Int16)
  390. {
  391. sf_count_t num_frames{sf_readf_short(mSndfile,
  392. reinterpret_cast<short*>(&mBufferData[woffset]),
  393. static_cast<sf_count_t>(writable*mSamplesPerBlock))};
  394. if(num_frames < 1) break;
  395. read_bytes = static_cast<size_t>(num_frames) * mBytesPerBlock;
  396. }
  397. else if(mSampleFormat == SampleType::Float)
  398. {
  399. sf_count_t num_frames{sf_readf_float(mSndfile,
  400. reinterpret_cast<float*>(&mBufferData[woffset]),
  401. static_cast<sf_count_t>(writable*mSamplesPerBlock))};
  402. if(num_frames < 1) break;
  403. read_bytes = static_cast<size_t>(num_frames) * mBytesPerBlock;
  404. }
  405. else
  406. {
  407. sf_count_t numbytes{sf_read_raw(mSndfile, &mBufferData[woffset],
  408. static_cast<sf_count_t>(writable*mBytesPerBlock))};
  409. if(numbytes < 1) break;
  410. read_bytes = static_cast<size_t>(numbytes);
  411. }
  412. woffset += read_bytes;
  413. if(woffset == mBufferData.size())
  414. woffset = 0;
  415. }
  416. mWritePos.store(woffset, std::memory_order_release);
  417. mDecoderOffset += read_bytes;
  418. }
  419. if(state != AL_PLAYING && state != AL_PAUSED)
  420. {
  421. /* If the source is not playing or paused, it either underrun
  422. * (AL_STOPPED) or is just getting started (AL_INITIAL). If the
  423. * ring buffer is empty, it's done, otherwise play the source with
  424. * what's available.
  425. */
  426. const size_t roffset{mReadPos.load(std::memory_order_relaxed)};
  427. const size_t readable{((woffset >= roffset) ? woffset : (mBufferData.size()+woffset)) -
  428. roffset};
  429. if(readable == 0)
  430. return false;
  431. /* Store the playback offset that the source will start reading
  432. * from, so it can be tracked during playback.
  433. */
  434. mStartOffset = mDecoderOffset - readable;
  435. alSourcePlay(mSource);
  436. if(alGetError() != AL_NO_ERROR)
  437. return false;
  438. }
  439. return true;
  440. }
  441. };
  442. int main(al::span<std::string_view> args)
  443. {
  444. /* A simple RAII container for OpenAL startup and shutdown. */
  445. struct AudioManager {
  446. AudioManager(al::span<std::string_view> &args_)
  447. {
  448. if(InitAL(args_) != 0)
  449. throw std::runtime_error{"Failed to initialize OpenAL"};
  450. }
  451. ~AudioManager() { CloseAL(); }
  452. };
  453. /* Print out usage if no arguments were specified */
  454. if(args.size() < 2)
  455. {
  456. fprintf(stderr, "Usage: %.*s [-device <name>] <filenames...>\n", al::sizei(args[0]),
  457. args[0].data());
  458. return 1;
  459. }
  460. args = args.subspan(1);
  461. AudioManager almgr{args};
  462. if(!alIsExtensionPresent("AL_SOFT_callback_buffer"))
  463. {
  464. fprintf(stderr, "AL_SOFT_callback_buffer extension not available\n");
  465. return 1;
  466. }
  467. alBufferCallbackSOFT = reinterpret_cast<LPALBUFFERCALLBACKSOFT>(
  468. alGetProcAddress("alBufferCallbackSOFT"));
  469. ALCint refresh{25};
  470. alcGetIntegerv(alcGetContextsDevice(alcGetCurrentContext()), ALC_REFRESH, 1, &refresh);
  471. auto player = std::make_unique<StreamPlayer>();
  472. /* Play each file listed on the command line */
  473. for(size_t i{0};i < args.size();++i)
  474. {
  475. if(!player->open(std::string{args[i]}))
  476. continue;
  477. /* Get the name portion, without the path, for display. */
  478. auto namepart = args[i];
  479. if(auto sep = namepart.rfind('/'); sep < namepart.size())
  480. namepart = namepart.substr(sep+1);
  481. else if(sep = namepart.rfind('\\'); sep < namepart.size())
  482. namepart = namepart.substr(sep+1);
  483. printf("Playing: %.*s (%s, %dhz)\n", al::sizei(namepart), namepart.data(),
  484. FormatName(player->mFormat), player->mSfInfo.samplerate);
  485. fflush(stdout);
  486. if(!player->prepare())
  487. {
  488. player->close();
  489. continue;
  490. }
  491. while(player->update())
  492. std::this_thread::sleep_for(nanoseconds{seconds{1}} / refresh);
  493. putc('\n', stdout);
  494. /* All done with this file. Close it and go to the next */
  495. player->close();
  496. }
  497. /* All done. */
  498. printf("Done.\n");
  499. return 0;
  500. }
  501. } // namespace
  502. int main(int argc, char **argv)
  503. {
  504. assert(argc >= 0);
  505. auto args = std::vector<std::string_view>(static_cast<unsigned int>(argc));
  506. std::copy_n(argv, args.size(), args.begin());
  507. return main(al::span{args});
  508. }