-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbrb.h
More file actions
44 lines (37 loc) · 1.35 KB
/
Copy pathbrb.h
File metadata and controls
44 lines (37 loc) · 1.35 KB
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
#ifndef __BRB_H__
#define __BRB_H__
#include <complex.h>
#include <pthread.h>
#include <stdbool.h>
#include <stdint.h>
/* ---------------------------------------------------------------
* BUF_ELEM_2: バッファのサンプル数(2の冪乗)
* ---------------------------------------------------------------*/
#define BUF_ELEM_2 1024 // 2^10
#define BUF_MASK_2 (BUF_ELEM_2 - 1)
// BUF_ELEM_2が2の冪乗でない場合はコンパイルエラー
#if ((BUF_ELEM_2 & BUF_MASK_2) != 0)
#error "BUF_ELEM_2 must be a power of 2"
#endif
// Buffer要素構造体
typedef struct {
double complex *ptr; // mallocされた配列(2次元配列だが1次元配列として扱う)のポインタ
int rows; // 行数(チャネル数)
int cols; // 列数(時間スロット数)
} BrbElem;
// BlockingRingBuffer構造体
typedef struct {
BrbElem buf[BUF_ELEM_2];
int write_pos;
int read_pos;
pthread_mutex_t mutex;
pthread_cond_t not_empty;
pthread_cond_t not_full;
volatile bool stop;
} BlockingRingBuffer;
bool brb_init(BlockingRingBuffer *rb);
bool brb_write(BlockingRingBuffer *rb, double complex *src, int rows, int cols);
bool brb_read(BlockingRingBuffer *rb, double complex **dst, int *rows, int *cols);
bool brb_stop(BlockingRingBuffer *rb);
bool brb_destroy(BlockingRingBuffer *rb);
#endif // __BRB_H__