forked from mikebrady/shairport-sync
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathaudio_dummy.c
52 lines (39 loc) · 1.04 KB
/
audio_dummy.c
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
#include <stdio.h>
#include <unistd.h>
#include <sys/time.h>
#include "audio.h"
int Fs;
long long starttime, samples_played;
static int dummy_init(int argc, char **argv) {
return 0;
}
static void dummy_deinit(void) {
}
static void dummy_start(int sample_rate) {
Fs = sample_rate;
starttime = 0;
samples_played = 0;
printf("dummy audio output started at Fs=%d Hz\n", sample_rate);
}
static void dummy_play(short buf[], int samples) {
struct timeval tv;
// this is all a bit expensive but it's long-term stable.
gettimeofday(&tv, NULL);
long long nowtime = tv.tv_usec + 1e6*tv.tv_sec;
if (!starttime)
starttime = nowtime;
samples_played += samples;
long long finishtime = starttime + samples_played * 1e6 / Fs;
usleep(finishtime - nowtime);
}
static void dummy_stop(void) {
printf("dummy audio stopped\n");
}
audio_ops audio_dummy = {
.init = &dummy_init,
.deinit = &dummy_deinit,
.start = &dummy_start,
.stop = &dummy_stop,
.play = &dummy_play,
.volume = NULL
};