summaryrefslogblamecommitdiffstats
path: root/src/audio_core/renderer/audio_device.h
blob: 4242dad30538aa52dbce908c4860339aa8ed6eb6 (plain) (tree)
1
2
3
4
5
6




                                                               
                      











                                            
                    





                                                                  
                                       
 

                                                           


         





                                                                                          

                                              
                                                                         





                                                                             

                                              
                                                                               














                                                                                    
                                                     









                                           
                       
                        
// SPDX-FileCopyrightText: Copyright 2022 yuzu Emulator Project
// SPDX-License-Identifier: GPL-2.0-or-later

#pragma once

#include <string_view>

#include "audio_core/audio_render_manager.h"

namespace Core {
class System;
}

namespace AudioCore {
namespace Sink {
class Sink;
}

namespace Renderer {
/**
 * An interface to an output audio device available to the Switch.
 */
class AudioDevice {
public:
    struct AudioDeviceName {
        std::array<char, 0x100> name{};

        constexpr AudioDeviceName(std::string_view name_) {
            name_.copy(name.data(), name.size() - 1);
        }
    };

    explicit AudioDevice(Core::System& system, u64 applet_resource_user_id, u32 revision);

    /**
     * Get a list of the available output devices.
     *
     * @param out_buffer - Output buffer to write the available device names.
     * @return Number of device names written.
     */
    u32 ListAudioDeviceName(std::span<AudioDeviceName> out_buffer) const;

    /**
     * Get a list of the available output devices.
     * Different to above somehow...
     *
     * @param out_buffer - Output buffer to write the available device names.
     * @return Number of device names written.
     */
    u32 ListAudioOutputDeviceName(std::span<AudioDeviceName> out_buffer) const;

    /**
     * Set the volume of all streams in the backend sink.
     *
     * @param volume - Volume to set.
     */
    void SetDeviceVolumes(f32 volume);

    /**
     * Get the volume for a given device name.
     * Note: This is not fully implemented, we only assume 1 device for all streams.
     *
     * @param name - Name of the device to check. Unused.
     * @return Volume of the device.
     */
    f32 GetDeviceVolume(std::string_view name) const;

private:
    /// Backend output sink for the device
    Sink::Sink& output_sink;
    /// Resource id this device is used for
    const u64 applet_resource_user_id;
    /// User audio renderer revision
    const u32 user_revision;
};

} // namespace Renderer
} // namespace AudioCore