// File: /workspace/github_c_makefile_star2_O0/FredTheDino[P]Fog/src/engine/platform/mixer.cpp
// Function: Mixer::init()
b8 init() {
    OTHER_THREAD(AUDIO);
    OTHER_THREAD(AUDIO_SOURCES);
    OTHER_THREAD(AUDIO_EFFECTS);

    audio_mixer.arena = Util::request_arena();

    audio_struct.num_free_sources = NUM_SOURCES;
    for (u32 i = 0; i < NUM_SOURCES; i++)
        audio_struct.free_sources[i] = i;

    for (u32 i = 0; i < NUM_CHANNELS; i++)
        audio_struct.channels[i].buffer = audio_mixer.arena->push<f32>(CHANNEL_BUFFER_LENGTH);

    SDL_AudioSpec want = {};
    want.freq = AUDIO_SAMPLE_RATE;
    want.format = AUDIO_F32;
    want.samples = AUDIO_SAMPLES_WANT;
    want.channels = 2;
    want.callback = audio_callback;
    audio_struct.time_step = 1.0 / (f32) AUDIO_SAMPLE_RATE;
    want.userdata = (void *) &audio_struct;

    // Let SDL handle the translation for us.
    SDL_AudioSpec have;
    audio_struct.dev = SDL_OpenAudioDevice(NULL, 0, &want, &have, 0);
    if (audio_struct.dev <= 0) {
        ERR("%s", SDL_GetError());
        return false;
    }

    SDL_PauseAudioDevice(audio_struct.dev, 0);
    return true;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x60, %rsp
movl $0x7, %edi
callq 0x30dd0
movl $0x8, %edi
callq 0x30dd0
movl $0x9, %edi
callq 0x30dd0
xorl %edi, %edi
callq 0x10890
movq %rax, %rcx
leaq 0x4f621(%rip), %rax     # 0x85318
movq %rcx, 0x10(%rax)
leaq 0x3367e(%rip), %rax     # 0x69380
movw $0x20, 0x600(%rax)
movl $0x0, -0x8(%rbp)
cmpl $0x20, -0x8(%rbp)
jae 0x35d3d
movl -0x8(%rbp), %eax
movw %ax, %dx
movl -0x8(%rbp), %eax
movl %eax, %ecx
leaq 0x33656(%rip), %rax     # 0x69380
movw %dx, 0x602(%rax,%rcx,2)
movl -0x8(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x8(%rbp)
jmp 0x35d12
movl $0x0, -0xc(%rbp)
cmpl $0xa, -0xc(%rbp)
jae 0x35d89
leaq 0x4f5c7(%rip), %rax     # 0x85318
movq 0x10(%rax), %rdi
movl $0x46500, %esi          # imm = 0x46500
callq 0x43a00
movq %rax, %rcx
movl -0xc(%rbp), %eax
movl %eax, %edx
leaq 0x33612(%rip), %rax     # 0x69380
addq $0x648, %rax            # imm = 0x648
imulq $0x58, %rdx, %rdx
addq %rdx, %rax
movq %rcx, (%rax)
movl -0xc(%rbp), %eax
addl $0x1, %eax
movl %eax, -0xc(%rbp)
jmp 0x35d44
leaq -0x30(%rbp), %rdi
xorl %esi, %esi
movl $0x20, %edx
callq 0x21c0
movl $0xbb80, -0x30(%rbp)    # imm = 0xBB80
movw $0x8120, -0x2c(%rbp)    # imm = 0x8120
movw $0x800, -0x28(%rbp)     # imm = 0x800
movb $0x2, -0x2a(%rbp)
leaq -0xb57(%rip), %rax      # 0x35260
movq %rax, -0x20(%rbp)
leaq 0x335be(%rip), %rax     # 0x69380
movss 0xf492(%rip), %xmm0     # 0x4525c
movss %xmm0, 0x9c8(%rax)
leaq 0x335a7(%rip), %rax     # 0x69380
movq %rax, -0x18(%rbp)
xorl %eax, %eax
movl %eax, %edi
xorl %r8d, %r8d
leaq -0x30(%rbp), %rdx
leaq -0x50(%rbp), %rcx
movl %r8d, %esi
callq 0x2410
movl %eax, %ecx
leaq 0x33583(%rip), %rax     # 0x69380
movl %ecx, 0x9cc(%rax)
leaq 0x33576(%rip), %rax     # 0x69380
cmpl $0x0, 0x9cc(%rax)
ja 0x35e5c
movq 0x331c6(%rip), %rax     # 0x68fe0
movq (%rax), %rax
movq %rax, -0x58(%rbp)
callq 0x24a0
movq -0x58(%rbp), %rsi
leaq 0xfe3e(%rip), %rdi      # 0x45c6f
leaq 0x10d42(%rip), %rdx     # 0x46b7a
movl $0x147, %ecx            # imm = 0x147
leaq 0xfd73(%rip), %r8       # 0x45bb7
leaq 0x10430(%rip), %r9      # 0x4627b
movq %rax, (%rsp)
movb $0x0, %al
callq 0xb100
movb $0x0, -0x1(%rbp)
jmp 0x35e74
leaq 0x3351d(%rip), %rax     # 0x69380
movl 0x9cc(%rax), %edi
xorl %esi, %esi
callq 0x21a0
movb $0x1, -0x1(%rbp)
movb -0x1(%rbp), %al
addq $0x60, %rsp
popq %rbp
retq
nopl (%rax)