3 ==============================================================================
5 Copyright 2005-11 by Satoshi Fujiwara.
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.
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.
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
21 ==============================================================================
24 #include "exception.h"
25 #include <mmdeviceapi.h>
26 #include <AudioClient.h>
27 #include <audiopolicy.h>
29 #define _USE_MATH_DEFINES
32 #pragma comment(lib, "winmm.lib")
33 #pragma comment(lib, "Avrt.lib")
35 #include "audio_base.h"
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));
47 IMMDeviceEnumeratorPtr mm_device_enumerator;
51 /// WASAPI
\8f\88\97\9d\83N
\83\89\83X
52 struct wasapi_shared_timer : public audio_base
54 explicit wasapi_shared_timer(::WAVEFORMATEXTENSIBLE& wfx);
55 virtual ~wasapi_shared_timer();
57 bool is_enabled () const {return is_enabled_;}
59 ///
\83e
\83X
\83g
\97p
\83T
\83C
\83\93\94g
\83f
\81[
\83^
\82Ì
\90¶
\90¬
60 void create_wave_data();
62 ///
\83T
\83E
\83\93\83h
\8dÄ
\90¶
\8f\88\97\9d
63 void play_buffer(BYTE* buffer);
66 uint32_t get_buffer_byte_size () const { return buffer_size_ * num_of_frames_;}
67 win32_error_exception* const result() {return exception_holder_.get(); }
70 IMMDeviceEnumeratorPtr device_enumerator_;
71 IMMDevicePtr current_device_;
72 IAudioClientPtr audio_client_;
73 IAudioRenderClientPtr audio_render_client_;
74 //handle_holder buffer_control_event_;
75 WAVEFORMATEXTENSIBLE mix_format_;
78 boost::shared_ptr<win32_error_exception> exception_holder_;
79 boost::uint32_t num_of_frames_;
80 boost::uint32_t buffer_size_;
82 std::vector<short> tone_buffer_;
84 //
\8dÄ
\90¶
\83\8c\83C
\83e
\83\93\83V
85 static const uint32_t latency_ms_ = 50;/* ms */
86 //
\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
87 static const uint32_t periods_per_buffer_ = 4;