File: alstreamcb.cpp

package info (click to toggle)
openal-soft 1%3A1.25.1-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 7,600 kB
  • sloc: cpp: 90,493; ansic: 5,724; xml: 5,398; python: 1,980; makefile: 18; javascript: 4
file content (590 lines) | stat: -rw-r--r-- 20,698 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
/*
 * OpenAL Callback-based Stream Example
 *
 * Copyright (c) 2020 by Chris Robinson <chris.kcat@gmail.com>
 *
 * Permission is hereby granted, free of charge, to any person obtaining a copy
 * of this software and associated documentation files (the "Software"), to deal
 * in the Software without restriction, including without limitation the rights
 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
 * copies of the Software, and to permit persons to whom the Software is
 * furnished to do so, subject to the following conditions:
 *
 * The above copyright notice and this permission notice shall be included in
 * all copies or substantial portions of the Software.
 *
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
 * THE SOFTWARE.
 */

/* This file contains a streaming audio player using a callback buffer. */

#include "config.h"

#include <algorithm>
#include <atomic>
#include <chrono>
#include <cstddef>
#include <cstdlib>
#include <cstring>
#include <functional>
#include <iostream>
#include <memory>
#include <ranges>
#include <span>
#include <stdexcept>
#include <string>
#include <string_view>
#include <thread>
#include <variant>
#include <vector>

#include "sndfile.h"

#include "alnumeric.h"
#include "common/alhelpers.h"
#include "common/alhelpers.hpp"
#include "fmt/base.h"
#include "fmt/ostream.h"

#include "win_main_utf8.h"

#if HAVE_CXXMODULES
import gsl;
import openal;

#else

#include "AL/al.h"
#include "AL/alc.h"
#include "AL/alext.h"
#include "gsl/gsl"
#endif


namespace {

using std::chrono::seconds;
using std::chrono::nanoseconds;

auto alBufferCallbackSOFT = LPALBUFFERCALLBACKSOFT{};

struct StreamPlayer {
    /* A buffer that can hold int16 or float samples, or raw (ADPCM) bytes. */
    std::variant<std::vector<short>, std::vector<float>, std::vector<std::byte>> mBufferVariant;

    /* A lockless ring-buffer (supports single-provider, single-consumer
     * operation), which aliases the above buffer.
     */
    std::span<std::byte> mBufferData;
    std::atomic<size_t> mReadPos{0_uz};
    std::atomic<size_t> mWritePos{0_uz};

    size_t mSamplesPerBlock{1_uz};
    size_t mBytesPerBlock{1_uz};

    /* The buffer to get the callback, and source to play with. */
    ALuint mBuffer{0u}, mSource{0u};
    size_t mStartOffset{0_uz};

    /* Handle for the audio file to decode. */
    SNDFILE *mSndfile{nullptr};
    SF_INFO mSfInfo{};
    size_t mDecoderOffset{0_uz};

    /* The format of the callback samples. */
    ALenum mFormat{};

    StreamPlayer()
    {
        alGenBuffers(1, &mBuffer);
        if(alGetError() != AL_NO_ERROR)
            throw std::runtime_error{"alGenBuffers failed"};
        alGenSources(1, &mSource);
        if(alGetError() != AL_NO_ERROR)
        {
            alDeleteBuffers(1, &mBuffer);
            throw std::runtime_error{"alGenSources failed"};
        }
    }
    ~StreamPlayer()
    {
        alDeleteSources(1, &mSource);
        alDeleteBuffers(1, &mBuffer);
        if(mSndfile)
            sf_close(mSndfile);
    }
    StreamPlayer(const StreamPlayer&) = delete;
    auto operator=(const StreamPlayer&) -> StreamPlayer& = delete;

    auto open(const std::string &filename) -> bool;
    void close();
    auto bufferCallback(const std::span<std::byte> output) noexcept -> ALsizei;
    auto prepare() -> bool;
    auto update() -> bool;
};

auto StreamPlayer::open(const std::string &filename) -> bool
{
    close();

    /* Open the file and figure out the OpenAL format. */
    mSndfile = sf_open(filename.c_str(), SFM_READ, &mSfInfo);
    if(!mSndfile)
    {
        fmt::println(std::cerr, "Could not open audio in {}: {}", filename,
            sf_strerror(mSndfile));
        return false;
    }

    enum class SampleType {
        Int16, Float, IMA4, MSADPCM
    };
    auto sampleFormat = SampleType{SampleType::Int16};
    switch((mSfInfo.format&SF_FORMAT_SUBMASK))
    {
    case SF_FORMAT_PCM_24:
    case SF_FORMAT_PCM_32:
    case SF_FORMAT_FLOAT:
    case SF_FORMAT_DOUBLE:
    case SF_FORMAT_VORBIS:
    case SF_FORMAT_OPUS:
    case SF_FORMAT_ALAC_20:
    case SF_FORMAT_ALAC_24:
    case SF_FORMAT_ALAC_32:
    case 0x0080/*SF_FORMAT_MPEG_LAYER_I*/:
    case 0x0081/*SF_FORMAT_MPEG_LAYER_II*/:
    case 0x0082/*SF_FORMAT_MPEG_LAYER_III*/:
        if(alIsExtensionPresent("AL_EXT_FLOAT32"))
            sampleFormat = SampleType::Float;
        break;
    case SF_FORMAT_IMA_ADPCM:
        if(mSfInfo.channels <= 2 && (mSfInfo.format&SF_FORMAT_TYPEMASK) == SF_FORMAT_WAV
            && alIsExtensionPresent("AL_EXT_IMA4")
            && alIsExtensionPresent("AL_SOFT_block_alignment"))
            sampleFormat = SampleType::IMA4;
        break;
    case SF_FORMAT_MS_ADPCM:
        if(mSfInfo.channels <= 2 && (mSfInfo.format&SF_FORMAT_TYPEMASK) == SF_FORMAT_WAV
            && alIsExtensionPresent("AL_SOFT_MSADPCM")
            && alIsExtensionPresent("AL_SOFT_block_alignment"))
            sampleFormat = SampleType::MSADPCM;
        break;
    }

    auto splblocksize = int{};
    auto byteblocksize = int{};
    if(sampleFormat == SampleType::IMA4 || sampleFormat == SampleType::MSADPCM)
    {
        auto inf = SF_CHUNK_INFO{.id="fmt ", .id_size=4u, .datalen=0u, .data=nullptr};
        auto *iter = sf_get_chunk_iterator(mSndfile, &inf);
        if(!iter || sf_get_chunk_size(iter, &inf) != SF_ERR_NO_ERROR || inf.datalen < 14)
            sampleFormat = SampleType::Int16;
        else
        {
            auto fmtbuf = std::vector<ALubyte>(inf.datalen);
            inf.data = fmtbuf.data();
            if(sf_get_chunk_data(iter, &inf) != SF_ERR_NO_ERROR)
                sampleFormat = SampleType::Int16;
            else
            {
                byteblocksize = fmtbuf[12] | (fmtbuf[13]<<8u);
                if(sampleFormat == SampleType::IMA4)
                {
                    splblocksize = (byteblocksize/mSfInfo.channels - 4)/4*8 + 1;
                    if(splblocksize < 1
                        || ((splblocksize-1)/2 + 4)*mSfInfo.channels != byteblocksize)
                        sampleFormat = SampleType::Int16;
                }
                else
                {
                    splblocksize = (byteblocksize/mSfInfo.channels - 7)*2 + 2;
                    if(splblocksize < 2
                        || ((splblocksize-2)/2 + 7)*mSfInfo.channels != byteblocksize)
                        sampleFormat = SampleType::Int16;
                }
            }
        }
    }

    switch(sampleFormat)
    {
    case SampleType::Int16:
        mSamplesPerBlock = 1_uz;
        mBytesPerBlock = gsl::narrow<size_t>(mSfInfo.channels) * sizeof(short);
        break;
    case SampleType::Float:
        mSamplesPerBlock = 1_uz;
        mBytesPerBlock = gsl::narrow<size_t>(mSfInfo.channels) * sizeof(float);
        break;
    case SampleType::IMA4:
    case SampleType::MSADPCM:
        mSamplesPerBlock = gsl::narrow<size_t>(splblocksize);
        mBytesPerBlock = gsl::narrow<size_t>(byteblocksize);
        break;
    }

    mFormat = AL_NONE;
    if(mSfInfo.channels == 1)
    {
        switch(sampleFormat)
        {
        case SampleType::Int16: mFormat = AL_FORMAT_MONO16; break;
        case SampleType::Float: mFormat = AL_FORMAT_MONO_FLOAT32; break;
        case SampleType::IMA4: mFormat = AL_FORMAT_MONO_IMA4; break;
        case SampleType::MSADPCM: mFormat = AL_FORMAT_MONO_MSADPCM_SOFT; break;
        }
    }
    else if(mSfInfo.channels == 2)
    {
        switch(sampleFormat)
        {
        case SampleType::Int16: mFormat = AL_FORMAT_STEREO16; break;
        case SampleType::Float: mFormat = AL_FORMAT_STEREO_FLOAT32; break;
        case SampleType::IMA4: mFormat = AL_FORMAT_STEREO_IMA4; break;
        case SampleType::MSADPCM: mFormat = AL_FORMAT_STEREO_MSADPCM_SOFT; break;
        }
    }
    else if(mSfInfo.channels == 3)
    {
        if(sf_command(mSndfile, SFC_WAVEX_GET_AMBISONIC, nullptr, 0) == SF_AMBISONIC_B_FORMAT)
        {
            switch(sampleFormat)
            {
            case SampleType::Int16: mFormat = AL_FORMAT_BFORMAT2D_16; break;
            case SampleType::Float: mFormat = AL_FORMAT_BFORMAT2D_FLOAT32; break;
            case SampleType::IMA4:
            case SampleType::MSADPCM:
                break;
            }
        }
    }
    else if(mSfInfo.channels == 4)
    {
        if(sf_command(mSndfile, SFC_WAVEX_GET_AMBISONIC, nullptr, 0) == SF_AMBISONIC_B_FORMAT)
        {
            switch(sampleFormat)
            {
            case SampleType::Int16: mFormat = AL_FORMAT_BFORMAT3D_16; break;
            case SampleType::Float: mFormat = AL_FORMAT_BFORMAT3D_FLOAT32; break;
            case SampleType::IMA4:
            case SampleType::MSADPCM:
                break;
            }
        }
    }
    if(!mFormat)
    {
        fmt::println(std::cerr, "Unsupported channel count: {}", mSfInfo.channels);
        sf_close(mSndfile);
        mSndfile = nullptr;

        return false;
    }

    /* Set a 1s ring buffer size. */
    const auto numblocks = (gsl::narrow<ALuint>(mSfInfo.samplerate) + mSamplesPerBlock-1_uz)
        / mSamplesPerBlock;
    switch(sampleFormat)
    {
    case SampleType::Int16:
        mBufferVariant.emplace<std::vector<short>>(numblocks * mBytesPerBlock / sizeof(short));
        break;
    case SampleType::Float:
        mBufferVariant.emplace<std::vector<float>>(numblocks * mBytesPerBlock / sizeof(float));
        break;
    case SampleType::IMA4:
    case SampleType::MSADPCM:
        mBufferVariant.emplace<std::vector<std::byte>>(numblocks * mBytesPerBlock);
        break;
    }
    std::visit([this](auto&& vec) { mBufferData = std::as_writable_bytes(std::span{vec}); },
        mBufferVariant);

    mReadPos.store(0_uz, std::memory_order_relaxed);
    mWritePos.store(0_uz, std::memory_order_relaxed);
    mDecoderOffset = 0_uz;

    return true;
}

void StreamPlayer::close()
{
    if(mSamplesPerBlock > 1_uz)
        alBufferi(mBuffer, AL_UNPACK_BLOCK_ALIGNMENT_SOFT, 0);

    if(mSndfile)
    {
        alSourceRewind(mSource);
        alSourcei(mSource, AL_BUFFER, 0);
        sf_close(mSndfile);
        mSndfile = nullptr;
    }
}

auto StreamPlayer::bufferCallback(const std::span<std::byte> output) noexcept -> ALsizei
{
    auto dst = output.begin();

    /* NOTE: The callback *MUST* be real-time safe! That means no blocking, no
     * allocations or deallocations, no I/O, no page faults, or calls to
     * functions that do these things (this includes calling to libraries like
     * SDL_sound, libsndfile, ffmpeg, etc). Nothing should unexpectedly stall
     * this call since the audio has to get to the device on time.
     */

    auto roffset = mReadPos.load(std::memory_order_acquire);
    while(const auto remaining = gsl::narrow<size_t>(std::distance(dst, output.end())))
    {
        /* If the write offset == read offset, there's nothing left in the
         * ring-buffer. Break from the loop and give what has been written.
         * The source will stop after playing what it's been given.
         */
        const auto woffset = mWritePos.load(std::memory_order_relaxed);
        if(woffset == roffset) break;

        /* If the write offset is behind the read offset, the readable portion
         * wrapped around. Just read up to the end of the buffer in that case,
         * otherwise read up to the write offset. Also limit the amount to copy
         * given how much is remaining to write.
         */
        auto todo = ((woffset < roffset) ? mBufferData.size() : woffset) - roffset;
        todo = std::min(todo, remaining);

        /* Copy from the ring buffer to the provided output buffer. Wrap the
         * resulting read offset if it reached the end of the ring buffer.
         */
        const auto input = mBufferData | std::views::drop(roffset) | std::views::take(todo);
        dst = std::ranges::copy(input, dst).out;

        roffset += todo;
        if(roffset == mBufferData.size())
            roffset = 0;
    }
    /* Finally, store the updated read offset, and return how many bytes
     * have been written.
     */
    mReadPos.store(roffset, std::memory_order_release);

    return gsl::narrow<ALsizei>(std::distance(output.begin(), dst));
}

auto StreamPlayer::prepare() -> bool
{
    if(mSamplesPerBlock > 1_uz)
        alBufferi(mBuffer, AL_UNPACK_BLOCK_ALIGNMENT_SOFT, gsl::narrow<int>(mSamplesPerBlock));

    /* A lambda without captures can decay to a normal function pointer,
     * which here just forwards to a normal class method and gives the buffer
     * as a contiguous range/span. Not strictly needed and the compiler will
     * optimize it all to a normal function, but it allows the callback
     * implementation to have a nice 'this' pointer with normal member access.
     */
    static constexpr auto callback = [](void *userptr, void *data, ALsizei size) noexcept
        -> ALsizei
    {
        auto output = std::views::counted(static_cast<std::byte*>(data), size);
        return static_cast<StreamPlayer*>(userptr)->bufferCallback(output);
    };
    alBufferCallbackSOFT(mBuffer, mFormat, mSfInfo.samplerate, callback, this);

    alSourcei(mSource, AL_BUFFER, static_cast<ALint>(mBuffer));
    if(const auto err = alGetError())
    {
        fmt::println(std::cerr, "Failed to set callback: {} ({:#x})", alGetString(err),
            as_unsigned(err));
        return false;
    }
    return true;
}

auto StreamPlayer::update() -> bool
{
    auto state = ALenum{};
    auto pos = ALint{};
    alGetSourcei(mSource, AL_SAMPLE_OFFSET, &pos);
    alGetSourcei(mSource, AL_SOURCE_STATE, &state);

    auto woffset = mWritePos.load(std::memory_order_acquire);
    if(state != AL_INITIAL)
    {
        const auto roffset = mReadPos.load(std::memory_order_relaxed);
        const auto readable = ((woffset >= roffset) ? woffset : (mBufferData.size()+woffset)) -
            roffset;
        /* For a stopped (underrun) source, the current playback offset is the
         * current decoder offset excluding the readable buffered data. For a
         * playing/paused source, it's the source's offset including the
         * playback offset the source was started with.
         */
        const auto curtime = ((state == AL_STOPPED)
            ? (mDecoderOffset-readable) / mBytesPerBlock * mSamplesPerBlock
            : (size_t{gsl::narrow<ALuint>(pos)} + mStartOffset))
            / gsl::narrow<ALuint>(mSfInfo.samplerate);
        fmt::print("\r {}m{:02}s ({:3}% full)", curtime/60, curtime%60,
            readable * 100 / mBufferData.size());
    }
    else
        fmt::println("Starting...");
    std::cout.flush();

    while(!sf_error(mSndfile))
    {
        const auto roffset = mReadPos.load(std::memory_order_relaxed);
        const auto writable = std::invoke([this,roffset,woffset]() noexcept -> size_t
        {
            if(roffset > woffset)
            {
                /* Note that the ring buffer's writable space is one byte less
                 * than the available area because the write offset ending up
                 * at the read offset would be interpreted as being empty
                 * instead of full.
                 */
                return (roffset-woffset-1) / mBytesPerBlock;
            }

            /* If the read offset is at or behind the write offset, the
             * writeable area (might) wrap around. Make sure the sample data
             * can fit, and calculate how much can go in front before wrapping.
             */
            return (mBufferData.size() - (!roffset ? woffset+1 : woffset)) / mBytesPerBlock;
        });
        if(!writable)
            break;

        /* Read samples from the file according to the type of samples
         * being buffered, and get the number of bytes buffered.
         */
        const auto read_bytes = std::visit([this,woffset,writable]<typename T>(T&& data) -> size_t
        {
            using sample_t = std::remove_cvref_t<T>::value_type;
            if constexpr(std::is_same_v<sample_t, short>)
            {
                const auto num_frames = sf_readf_short(mSndfile, &data[woffset/sizeof(short)],
                    gsl::narrow<sf_count_t>(writable*mSamplesPerBlock));
                if(num_frames < 1) return 0_uz;
                return gsl::narrow<size_t>(num_frames) * mBytesPerBlock;
            }
            else if constexpr(std::is_same_v<sample_t, float>)
            {
                const auto num_frames = sf_readf_float(mSndfile, &data[woffset/sizeof(float)],
                    gsl::narrow<sf_count_t>(writable*mSamplesPerBlock));
                if(num_frames < 1) return 0_uz;
                return gsl::narrow<size_t>(num_frames) * mBytesPerBlock;
            }
            else if constexpr(std::is_same_v<sample_t, std::byte>)
            {
                const auto numbytes = sf_read_raw(mSndfile, &data[woffset],
                    gsl::narrow<sf_count_t>(writable*mBytesPerBlock));
                if(numbytes < 1) return size_t{0};
                return gsl::narrow<size_t>(numbytes);
            }
        }, mBufferVariant);
        if(read_bytes == 0)
            break;

        woffset += read_bytes;
        if(woffset == mBufferData.size())
            woffset = 0;

        mWritePos.store(woffset, std::memory_order_release);
        mDecoderOffset += read_bytes;
    }

    if(state != AL_PLAYING && state != AL_PAUSED)
    {
        /* If the source is not playing or paused, it either underrun
         * (AL_STOPPED) or is just getting started (AL_INITIAL). If the ring
         * buffer is empty, it's done, otherwise play the source with what's
         * available.
         */
        const auto roffset = mReadPos.load(std::memory_order_relaxed);
        const auto readable = ((woffset < roffset) ? mBufferData.size()+woffset : woffset) -
            roffset;
        if(readable == 0)
            return false;

        /* Store the playback offset that the source will start reading
         * from, so it can be tracked during playback.
         */
        mStartOffset = (mDecoderOffset-readable) / mBytesPerBlock * mSamplesPerBlock;
        alSourcePlay(mSource);
        if(alGetError() != AL_NO_ERROR)
            return false;
    }
    return true;
}


auto main(std::span<std::string_view> args) -> int
{
    /* Print out usage if no arguments were specified */
    if(args.size() < 2)
    {
        fmt::println(std::cerr, "Usage: {} [-device <name>] <filenames...>", args[0]);
        return 1;
    }
    args = args.subspan(1);

    auto almgr = InitAL(args);
    almgr.printName();

    if(!alIsExtensionPresent("AL_SOFT_callback_buffer"))
    {
        fmt::println(std::cerr, "AL_SOFT_callback_buffer extension not available");
        return 1;
    }

    /* NOLINTNEXTLINE(cppcoreguidelines-pro-type-reinterpret-cast) */
    alBufferCallbackSOFT = reinterpret_cast<LPALBUFFERCALLBACKSOFT>(
        alGetProcAddress("alBufferCallbackSOFT"));

    auto refresh = ALCint{25};
    alcGetIntegerv(alcGetContextsDevice(alcGetCurrentContext()), ALC_REFRESH, 1, &refresh);

    auto player = std::make_unique<StreamPlayer>();

    /* Play each file listed on the command line */
    std::ranges::for_each(args, [refresh,&player](const std::string_view fname)
    {
        if(!player->open(std::string{fname}))
            return;

        /* Get the name portion, without the path, for display. */
        const auto namepart = fname.substr(std::max(fname.rfind('/')+1, fname.rfind('\\')+1));

        fmt::println("Playing: {} ({}, {}hz)", namepart, FormatName(player->mFormat),
            player->mSfInfo.samplerate);
        std::cout.flush();

        if(!player->prepare())
        {
            player->close();
            return;
        }

        while(player->update())
            std::this_thread::sleep_for(nanoseconds{seconds{1}} / refresh);
        fmt::println("");

        /* All done with this file. Close it and go to the next */
        player->close();
    });
    /* All done. */
    fmt::println("Done.");

    return 0;
}

} // namespace

auto main(int argc, char **argv) -> int
{
    auto args = std::vector<std::string_view>(gsl::narrow<unsigned int>(argc));
    std::ranges::copy(std::views::counted(argv, argc), args.begin());
    return main(std::span{args});
}