// dsound_render.h
// ~~~~~~~~~~~~~~~
// Copyright (c) 2011 Jack (jack.wgm@gmail.com)

#ifndef __DSOUND_RENDER_H__
#define __DSOUND_RENDER_H__

#if defined(_MSC_VER) && (_MSC_VER >= 1020)
# pragma once

#include "audio_render.h"

class dsound_render
   : public audio_render
   virtual ~dsound_render();

   // 鍒濆鍖栭煶棰戣緭鍑?
   virtual bool init_audio(void* ctx, int channels, int bits_per_sample, int sample_rate, int format);

   // 鎾斁闊抽鏁版嵁.
   virtual int play_audio(uint8_t* data, uint32_t size);

   // 闊抽鎾斁鎺у埗, cmd涓篊ONTROL_寮€濮嬬殑瀹忓畾涔?
   virtual void audio_control(int cmd, void* arg);

   // 閿€姣侀煶棰戣緭鍑虹粍浠?
   virtual void destory_audio();

   int af_fmt2bits(int format);
   char* dserr2str(int err);

   // direct sound object.
   LPDIRECTSOUND8 m_dsound;

   // primary direct sound buffer.
   LPDIRECTSOUNDBUFFER m_dsbuffer_primary;

   // secondary direct sound buffer (stream buffer)
   LPDIRECTSOUNDBUFFER m_dsbuffer_second;

   // wanted device number.
   int m_device_num;

   // size in bytes of the direct sound buffer.
   int m_buffer_size;

   // offset of the write cursor in the direct sound buffer.
   int m_write_offset;

   // if the free space is below this value get_space() will return 0
   int m_min_free_space;

   // 澹伴亾鏁?
   int m_channels;

   // 姣旂壒鐜?
   int m_bitrate;

   // 闊抽鏍煎紡.
   int m_format;

#endif // __DSOUND_RENDER_H__