53 lines
934 B
C
53 lines
934 B
C
|
#ifndef _ALSA_DEV_H_
|
||
|
#define _ALSA_DEV_H_
|
||
|
|
||
|
#include <string>
|
||
|
#include <alsa/asoundlib.h>
|
||
|
|
||
|
namespace alsa {
|
||
|
|
||
|
void vol_scaler_run(int16_t *buf, int n, int volume);
|
||
|
|
||
|
struct Config {
|
||
|
char device[20];
|
||
|
int channels;
|
||
|
int rate;
|
||
|
snd_pcm_format_t format;
|
||
|
unsigned int buffer_time;
|
||
|
unsigned int period_time;
|
||
|
};
|
||
|
|
||
|
class AlsaDev
|
||
|
{
|
||
|
public:
|
||
|
|
||
|
AlsaDev();
|
||
|
~AlsaDev();
|
||
|
|
||
|
int applyConfig(Config &config);
|
||
|
int init(snd_pcm_stream_t type);
|
||
|
void destory();
|
||
|
|
||
|
// 样本点大小(字节)
|
||
|
int getSampleSize();
|
||
|
// 一帧的大小(字节)
|
||
|
int getFrameSize();
|
||
|
// 每周期包含的帧数
|
||
|
int getFrames();
|
||
|
// 内部缓冲区大小(帧)
|
||
|
int getHwBufferSize();
|
||
|
// alsa配置转为字符串输出
|
||
|
const char *configToString();
|
||
|
|
||
|
int write(uint8_t *data, size_t bytes);
|
||
|
int read(uint8_t *data, size_t bytes);
|
||
|
private:
|
||
|
class Private;
|
||
|
Private *d_ptr;
|
||
|
};
|
||
|
|
||
|
}
|
||
|
|
||
|
|
||
|
|
||
|
#endif
|