/src/qemu/replay/replay-audio.c
Line | Count | Source |
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 | 1.93M | { |
19 | 1.93M | if (replay_mode == REPLAY_MODE_RECORD) { |
20 | 0 | g_assert(replay_mutex_locked()); |
21 | 0 | replay_save_instructions(); |
22 | 0 | replay_put_event(EVENT_AUDIO_OUT); |
23 | 0 | replay_put_qword(*played); |
24 | 1.93M | } else if (replay_mode == REPLAY_MODE_PLAY) { |
25 | 0 | g_assert(replay_mutex_locked()); |
26 | 0 | replay_account_executed_instructions(); |
27 | 0 | if (replay_next_event_is(EVENT_AUDIO_OUT)) { |
28 | 0 | *played = replay_get_qword(); |
29 | 0 | replay_finish_event(); |
30 | 0 | } else { |
31 | 0 | error_report("Missing audio out event in the replay log"); |
32 | 0 | abort(); |
33 | 0 | } |
34 | 0 | } |
35 | 1.93M | } |
36 | | |
37 | | void replay_audio_in_start(size_t *nsamples) |
38 | 1.86M | { |
39 | 1.86M | if (replay_mode == REPLAY_MODE_RECORD) { |
40 | 0 | g_assert(replay_mutex_locked()); |
41 | 0 | replay_save_instructions(); |
42 | 0 | replay_put_event(EVENT_AUDIO_IN); |
43 | 0 | replay_put_qword(*nsamples); |
44 | 0 | replay_state.n_audio_samples = *nsamples; |
45 | 1.86M | } else if (replay_mode == REPLAY_MODE_PLAY) { |
46 | 0 | g_assert(replay_mutex_locked()); |
47 | 0 | replay_account_executed_instructions(); |
48 | 0 | if (replay_next_event_is(EVENT_AUDIO_IN)) { |
49 | 0 | *nsamples = replay_get_qword(); |
50 | 0 | replay_state.n_audio_samples = *nsamples; |
51 | 0 | } else { |
52 | 0 | error_report("Missing audio in event in the replay log"); |
53 | 0 | abort(); |
54 | 0 | } |
55 | 0 | } |
56 | 1.86M | } |
57 | | |
58 | | void replay_audio_in_sample_lr(uint64_t *left, uint64_t *right) |
59 | 403M | { |
60 | 403M | if (replay_mode == REPLAY_MODE_RECORD) { |
61 | 0 | replay_put_qword(*left); |
62 | 0 | replay_put_qword(*right); |
63 | 403M | } else if (replay_mode == REPLAY_MODE_PLAY) { |
64 | 0 | *left = replay_get_qword(); |
65 | 0 | *right = replay_get_qword(); |
66 | 403M | } else { |
67 | 403M | return; |
68 | 403M | } |
69 | | |
70 | 403M | assert(replay_state.n_audio_samples > 0); |
71 | 0 | replay_state.n_audio_samples--; |
72 | 0 | } |
73 | | |
74 | | void replay_audio_in_finish(void) |
75 | 1.86M | { |
76 | 1.86M | assert(replay_state.n_audio_samples == 0); |
77 | | |
78 | 1.86M | if (replay_mode == REPLAY_MODE_PLAY) { |
79 | 0 | replay_finish_event(); |
80 | 0 | } |
81 | 1.86M | } |