2 Skelton for retropc emulator
4 Author : K.Ohta <whatisthis.sowhat _at_ gmail.com>
7 [ OSD / Sound driver / Template ]
16 #include "../common.h"
17 #include "./sound_buffer_qt.h"
25 class DLL_PREFIX SOUND_OUTPUT_MODULE_BASE : public QObject
30 std::shared_ptr<USING_FLAGS> m_using_flags;
31 std::shared_ptr<CSP_Logger> m_logger;
33 std::atomic_bool m_config_ok;
34 std::atomic<void *> m_extconfig;
35 std::atomic<int> m_rate;
36 std::atomic<int> m_channels;
37 std::atomic<int> m_latency_ms;
38 std::recursive_mutex m_locker;
39 std::atomic<int> m_loglevel;
40 std::atomic<int> m_logdomain;
41 std::string m_device_name;
46 SOUND_OUTPUT_MODULE_BASE(
49 const std::shared_ptr<CSP_Logger> logger,
50 const std::shared_ptr<USING_FLAGS> pflags,
51 int base_rate = 48000,
52 int base_latency_ms = 100,
53 int base_channels = 2,
54 void *extra_config_values = nullptr);
55 ~SOUND_OUTPUT_MODULE_BASE();
57 virtual bool initialize_driver() { return true; }
58 virtual bool release_driver() { return true; }
65 return m_latency_ms.load();
69 return m_channels.load();
71 virtual bool real_reconfig_sound(int& rate,int& channels,int& latency_ms)
75 template <class... Args>
76 bool debug_log(Args... args)
78 _TCHAR buf[512] = {0};
79 my_sprintf_s(buf, sizeof(buf) - 1, args);
80 return do_send_log(m_loglevel.load(), m_logdomain.load(), (const _TCHAR*)buf, (sizeof(buf) / sizeof(_TCHAR)) - 1);
82 template <class... Args>
83 bool debug_log(imt level, int domain, Args... args)
85 _TCHAR buf[512] = {0};
86 my_sprintf_s(buf, sizeof(buf) - 1, args);
87 return do_send_log(level, domain, (const _TCHAR*)buf, (sizeof(buf) / sizeof(_TCHAR)) - 1);
91 return m_config_ok.load();
93 virtual std::list<std::string> get_sound_devices_list()
95 static std::list<std::string> dummy_list;
98 const _TCHAR* get_current_device_name()
100 return (const _TCHAR*)(m_device_name.c_str());
102 virtual void set_logger(const std::shared_ptr<CSP_Logger> logger);
103 virtual void set_system_flags(const std::shared_ptr<USING_FLAGS> p);
106 bool update_rate(int& rate)
108 return reconfig_sound(rate, m_channels, m_latency_ms);
110 bool update_latency(int& latency_ms)
112 return reconfig_sound(m_rate, m_channels, latency_ms);
114 bool update_channels(int& channels)
116 return reconfig_sound(rate, m_channels, m_latency_ms);
118 bool reconfig_sound(int& rate, int& channels, int& latency_ms)
121 std::lock_guard<std::recursive_mutex> locker(m_locker);
122 if((rate != m_rate.load()) || (channels != m_channels.load()) || (latency_ms != m_latency_ms.load())) {
123 if(real_reconfig_sound(rate, channels, latency_ms)) {
125 m_channels = channels;
126 m_latency_ms = latency_ms;
133 void request_to_release();
134 virtual const std::string set_device_sound(const _TCHAR* driver_name, int& rate,int& channels,int& latency_ms)
136 return std::string(_T("Empty Device"));
138 virtual bool do_send_log(imt level, int domain, const _TCHAR* str, int maxlen);
139 virtual void do_set_device_by_name(QString) {};
140 virtual void do_set_device_by_number(int) {};
141 virtual void do_set_device_from_sender_object(void) {};
143 virtual void initialize_sound(int rate, int samples, int* presented_rate, int* presented_samples) {}
144 virtual void release_sound() {}
146 virtual void update_sound(int* extra_frames) {}
148 virtual void mute_sound() {}
149 virtual void stop_sound() {}
152 virtual void do_start_recording_sound() {}
153 virtual void do_stop_recording_sound() {}
154 virtual void do_restart_recording_sound() {}
155 virtual void do_request_capture_sound(int ch) {}
157 virtual void set_osd(OSD_BASE* p);
158 virtual void update_extra_config(void* p);
159 virtual int result_opening_external_file();
163 virtual int64_t wrote_data_to()
167 virtual bool result_closing_external_file()
172 // loglevel, logdomain, message
173 void sig_send_log(int, int, QString);
174 // rate, channels, path
175 void sig_req_open_sound(int, int, QString);
177 void sig_req_close_sound();
178 // samples, channel, data
179 void sig_send_output_sound_data(int64_t, int, int16_t[]);
180 // update device list for ui
181 void sig_clear_sound_device();
182 // add/update device, number and name. If number < 0 append.
183 void sig_add_sound_device_name(int, QString);
184 // Send current device number and name to UI.
185 void sig_send_current_device_description(int, QString);
186 // Notify updating devices list to UI. size, current_device_number, need_to_reconfig
187 void sig_notify_update_devices_list(int, int, bool);
188 // notify device changed status, true = success.
189 void sig_notify_changed_device_status(bool);
190 // notify completed to release sound driver.
191 void sig_released(bool);