-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrecord_audio.h
53 lines (42 loc) · 1.31 KB
/
record_audio.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
#ifndef RECORD_AUDIO_H
#define RECORD_AUDIO_H
#include <windows.h>
#include <mmsystem.h>
#include <stdio.h>
#define FORMAT_TAG 1 // PCM
#define SAMPLERATE 16000 // in hertz
#define BITSPERSAMPLE 16 // 16-bit
#define NCHANNELS 1 // 1 Channel mono audio
#define BLOCK_ALIGN NCHANNELS * (BITSPERSAMPLE / 8)
#define AVG_BYTE_PER_SECOND BLOCK_ALIGN * SAMPLERATE
#define BLOCK_SIZE 8000 // amount of bytes per audio chunk
struct WAV_HEADER {
int formatTag;
int sampleRate;
int bitsPerSample;
int nChannels;
int blockAlign;
int avgBytesPerSecond;
int blockSize;
};
static struct WAV_HEADER wav = {
FORMAT_TAG,
SAMPLERATE,
BITSPERSAMPLE,
NCHANNELS,
BLOCK_ALIGN,
AVG_BYTE_PER_SECOND,
BLOCK_SIZE
};
// for list all available devices
void list_output_devices();
void list_input_devices();
// initialize the audio i/o devices
int init_input_device(int id);
int init_output_device(int id);
// play or record
int record(char *data, int length);
int play(char *data, int length);
// close all
void close_audio();
#endif