master
c 81 lines 2.28 KB
Raw
1 /*
2 * replay-audio.c
3 *
4 * Copyright (c) 2010-2017 Institute for System Programming
5 * of the Russian Academy of Sciences.
6 *
7 * This work is licensed under the terms of the GNU GPL, version 2 or later.
8 * See the COPYING file in the top-level directory.
9 *
10 */
11
12 #include "qemu/osdep.h"
13 #include "qemu/error-report.h"
14 #include "system/replay.h"
15 #include "replay-internal.h"
16
17 void replay_audio_out(size_t *played)
18 {
19 if (replay_mode == REPLAY_MODE_RECORD) {
20 g_assert(replay_mutex_locked());
21 replay_save_instructions();
22 replay_put_event(EVENT_AUDIO_OUT);
23 replay_put_qword(*played);
24 } else if (replay_mode == REPLAY_MODE_PLAY) {
25 g_assert(replay_mutex_locked());
26 replay_account_executed_instructions();
27 if (replay_next_event_is(EVENT_AUDIO_OUT)) {
28 *played = replay_get_qword();
29 replay_finish_event();
30 } else {
31 error_report("Missing audio out event in the replay log");
32 abort();
33 }
34 }
35 }
36
37 void replay_audio_in_start(size_t *nsamples)
38 {
39 if (replay_mode == REPLAY_MODE_RECORD) {
40 g_assert(replay_mutex_locked());
41 replay_save_instructions();
42 replay_put_event(EVENT_AUDIO_IN);
43 replay_put_qword(*nsamples);
44 replay_state.n_audio_samples = *nsamples;
45 } else if (replay_mode == REPLAY_MODE_PLAY) {
46 g_assert(replay_mutex_locked());
47 replay_account_executed_instructions();
48 if (replay_next_event_is(EVENT_AUDIO_IN)) {
49 *nsamples = replay_get_qword();
50 replay_state.n_audio_samples = *nsamples;
51 } else {
52 error_report("Missing audio in event in the replay log");
53 abort();
54 }
55 }
56 }
57
58 void replay_audio_in_sample_lr(uint64_t *left, uint64_t *right)
59 {
60 if (replay_mode == REPLAY_MODE_RECORD) {
61 replay_put_qword(*left);
62 replay_put_qword(*right);
63 } else if (replay_mode == REPLAY_MODE_PLAY) {
64 *left = replay_get_qword();
65 *right = replay_get_qword();
66 } else {
67 return;
68 }
69
70 assert(replay_state.n_audio_samples > 0);
71 replay_state.n_audio_samples--;
72 }
73
74 void replay_audio_in_finish(void)
75 {
76 assert(replay_state.n_audio_samples == 0);
77
78 if (replay_mode == REPLAY_MODE_PLAY) {
79 replay_finish_event();
80 }
81 }