OSDN Git Service

とりあえずハリボテは出来たが、不具合あり。
[winaudioj/async.git] / async / wasapi.h
1 #pragma once
2 /*
3   ==============================================================================
4
5    Copyright 2005-11 by Satoshi Fujiwara.
6
7    async can be redistributed and/or modified under the terms of the
8    GNU General Public License, as published by the Free Software Foundation;
9    either version 2 of the License, or (at your option) any later version.
10
11    async is distributed in the hope that it will be useful,
12    but WITHOUT ANY WARRANTY; without even the implied warranty of
13    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14    GNU General Public License for more details.
15
16    You should have received a copy of the GNU General Public License
17    along with async; if not, visit www.gnu.org/licenses or write to the
18    Free Software Foundation, Inc., 59 Temple Place, Suite 330, 
19    Boston, MA 02111-1307 USA
20
21   ==============================================================================
22 */
23 // WASAPI
24 #include "exception.h"
25 #include <mmdeviceapi.h>
26 #include <AudioClient.h>
27 #include <audiopolicy.h>
28
29 #define _USE_MATH_DEFINES
30 #include <math.h>
31 #include <limits.h>
32 #pragma comment(lib, "winmm.lib")
33 #pragma comment(lib, "Avrt.lib")
34
35 #include "audio_base.h"
36
37 // COM Pointer \92è\8b`
38 _COM_SMARTPTR_TYPEDEF(IMMDeviceEnumerator,__uuidof(IMMDeviceEnumerator));
39 _COM_SMARTPTR_TYPEDEF(IMMDevice,__uuidof(IMMDevice));
40 _COM_SMARTPTR_TYPEDEF(IAudioClient,__uuidof(IAudioClient));
41 _COM_SMARTPTR_TYPEDEF(IAudioRenderClient,__uuidof(IAudioRenderClient));
42
43 namespace sf {
44
45 struct device_manager
46 {
47   IMMDeviceEnumeratorPtr mm_device_enumerator;
48 };
49
50
51 /// WASAPI\8f\88\97\9d\83N\83\89\83X
52 struct wasapi_shared_timer : public audio_base
53 {
54   wasapi_shared_timer();
55   virtual ~wasapi_shared_timer();
56
57   bool is_enabled () const {return is_enabled_;}
58  
59   /// \83e\83X\83g\97\83T\83C\83\93\94g\83f\81[\83^\82Ì\90\90¬
60   void create_wave_data();
61
62   /// \83T\83E\83\93\83h\8dÄ\90\8f\88\97\9d
63   void play();
64
65   win32_error_exception* const result() {return exception_holder_.get(); }
66
67 private:
68   IMMDeviceEnumeratorPtr device_enumerator_;
69   IMMDevicePtr current_device_;
70   IAudioClientPtr audio_client_;
71   IAudioRenderClientPtr audio_render_client_;
72   handle_holder buffer_control_event_;
73   co_task_memory<WAVEFORMATEX> mix_format_;
74   bool is_enabled_;
75   boost::shared_ptr<win32_error_exception> exception_holder_;
76   boost::uint32_t num_of_frames_;
77   boost::uint32_t buffer_size_;
78   std::vector<short> tone_buffer_;
79
80   // \8dÄ\90\83\8c\83C\83e\83\93\83V
81   static const uint32_t latency_ms_ = 50;/* ms */
82   // \83o\83b\83t\83@\92\86\82Ì\8bæ\90Ø\82è\90\94\81i\83\8c\83C\83e\83\93\83V\8e\9e\8aÔ\82ª\89½\8cÂ\82 \82é\82©\81j
83   static const uint32_t periods_per_buffer_ = 4;
84 };
85 }
86