first init of 0.9

This commit is contained in:
cnjinhao
2014-12-11 03:32:35 +08:00
commit d0a317bd45
206 changed files with 69773 additions and 0 deletions

View File

@@ -0,0 +1,53 @@
#ifndef NANA_AUDIO_DETAIL_AUDIO_DEVICE_HPP
#define NANA_AUDIO_DETAIL_AUDIO_DEVICE_HPP
#include <nana/deploy.hpp>
#include <nana/audio/detail/buffer_preparation.hpp>
#include <vector>
#if defined(NANA_WINDOWS)
#include <windows.h>
#elif defined(NANA_LINUX)
#include <alsa/asoundlib.h>
#endif
namespace nana{ namespace audio
{
namespace detail
{
class audio_device
{
public:
audio_device();
~audio_device();
bool empty() const;
bool open(std::size_t channels, std::size_t rate, std::size_t bits_per_sample);
void close();
void prepare(buffer_preparation & buf_prep);
void write(buffer_preparation::meta * m);
void wait_for_drain() const;
private:
#if defined(NANA_WINDOWS)
static void __stdcall _m_dev_callback(HWAVEOUT handle, UINT msg, audio_device * self, DWORD_PTR, DWORD_PTR);
#endif
#if defined(NANA_WINDOWS)
HWAVEOUT handle_;
std::recursive_mutex queue_lock_;
std::vector<buffer_preparation::meta*> done_queue_;
#elif defined(NANA_LINUX)
snd_pcm_t * handle_;
std::size_t rate_;
std::size_t channels_;
std::size_t bytes_per_sample_;
std::size_t bytes_per_frame_;
#endif
buffer_preparation * buf_prep_;
};
}//end namespace detail
}//end namespace audio
}//end namespace nana
#endif

View File

@@ -0,0 +1,81 @@
#ifndef NANA_AUDIO_DETAIL_AUDIO_STREAM_HPP
#define NANA_AUDIO_DETAIL_AUDIO_STREAM_HPP
#include <fstream>
#include <nana/deploy.hpp>
namespace nana{ namespace audio{
namespace detail
{
namespace wave_spec
{
#if defined(NANA_WINDOWS)
#pragma pack(1)
struct master_riff_chunk
{
unsigned long ckID; //"RIFF"
unsigned long cksize;
unsigned long waveID; //"WAVE"
};
struct format_chunck
{
unsigned long ckID; //"fmt "
unsigned long cksize;
unsigned short wFormatTag;
unsigned short nChannels;
unsigned long nSamplePerSec;
unsigned long nAvgBytesPerSec;
unsigned short nBlockAlign;
unsigned short wBitsPerSample;
};
#pragma pack()
#elif defined(NANA_LINUX)
struct master_riff_chunk
{
unsigned long ckID; //"RIFF"
unsigned long cksize;
unsigned long waveID; //"WAVE"
}__attribute__((packed));
struct format_chunck
{
unsigned long ckID; //"fmt "
unsigned long cksize;
unsigned short wFormatTag;
unsigned short nChannels;
unsigned long nSamplePerSec;
unsigned long nAvgBytesPerSec;
unsigned short nBlockAlign;
unsigned short wBitsPerSample;
}__attribute__((packed));
#endif
}
class audio_stream
{
struct chunck
{
unsigned long ckID;
unsigned long cksize;
};
public:
bool open(const nana::string& file);
void close();
bool empty() const;
const wave_spec::format_chunck & format() const;
std::size_t data_length() const;
void locate();
std::size_t read(void * buf, std::size_t len);
private:
std::size_t _m_locate_chunck(unsigned ckID);
private:
std::ifstream fs_;
wave_spec::format_chunck ck_format_;
std::size_t pcm_data_pos_;
std::size_t pcm_data_size_;
std::size_t data_size_;
}; //end class audio_stream
}
}//end namespace audio
}//end namespace nana
#endif

View File

@@ -0,0 +1,65 @@
#ifndef NANA_AUDIO_DETAIL_BUFFER_PREPARATION_HPP
#define NANA_AUDIO_DETAIL_BUFFER_PREPARATION_HPP
#include <nana/deploy.hpp>
#include <nana/audio/detail/audio_stream.hpp>
#if defined(NANA_MINGW) && defined(STD_THREAD_NOT_SUPPORTED)
#include <nana/std_thread.hpp>
#include <nana/std_mutex.hpp>
#include <nana/std_condition_variable.hpp>
#else
#include <mutex>
#include <condition_variable>
#include <thread>
#endif
#include <sstream>
#include <vector>
#if defined(NANA_WINDOWS)
#include <windows.h>
#endif
namespace nana{ namespace audio
{
namespace detail
{
class buffer_preparation
{
public:
#if defined(NANA_WINDOWS)
typedef WAVEHDR meta;
#elif defined(NANA_LINUX)
struct meta
{
char * buf;
std::size_t bufsize;
};
#endif
public:
buffer_preparation(audio_stream& as, std::size_t seconds);
~buffer_preparation();
meta * read();
//Revert the meta that returned by read()
void revert(meta * m);
bool data_finished() const;
private:
void _m_prepare_routine();
private:
volatile bool running_;
volatile bool wait_for_buffer_;
std::thread thr_;
mutable std::mutex token_buffer_, token_prepared_;
mutable std::condition_variable cond_buffer_, cond_prepared_;
std::vector<meta*> buffer_, prepared_;
std::size_t block_size_;
audio_stream & as_;
};
}//end namespace detail
}//end namespace audio
}//end namespace nana
#endif

View File

@@ -0,0 +1,25 @@
#ifndef NANA_AUDIO_PLAYER_HPP
#define NANA_AUDIO_PLAYER_HPP
#include <nana/traits.hpp>
#include <nana/deploy.hpp>
namespace nana{ namespace audio
{ /// play an audio file in Windows WAV format
class player
: private nana::noncopyable
{
struct implementation;
public:
player();
player(const nana::string& file);
~player();
bool open(const nana::string& file);
void play();
void close();
private:
implementation* impl_;
};
}//end namespace audio
}//end namespace nana
#endif