]>
Commit | Line | Data |
---|---|---|
3d4d16f4 PD |
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 "sysemu/replay.h" | |
15 | #include "replay-internal.h" | |
3d4d16f4 PD |
16 | #include "audio/audio.h" |
17 | ||
18 | void replay_audio_out(int *played) | |
19 | { | |
20 | if (replay_mode == REPLAY_MODE_RECORD) { | |
d759c951 | 21 | g_assert(replay_mutex_locked()); |
3d4d16f4 | 22 | replay_save_instructions(); |
3d4d16f4 PD |
23 | replay_put_event(EVENT_AUDIO_OUT); |
24 | replay_put_dword(*played); | |
3d4d16f4 | 25 | } else if (replay_mode == REPLAY_MODE_PLAY) { |
d759c951 | 26 | g_assert(replay_mutex_locked()); |
3d4d16f4 | 27 | replay_account_executed_instructions(); |
3d4d16f4 PD |
28 | if (replay_next_event_is(EVENT_AUDIO_OUT)) { |
29 | *played = replay_get_dword(); | |
30 | replay_finish_event(); | |
3d4d16f4 | 31 | } else { |
3d4d16f4 PD |
32 | error_report("Missing audio out event in the replay log"); |
33 | abort(); | |
34 | } | |
35 | } | |
36 | } | |
37 | ||
38 | void replay_audio_in(int *recorded, void *samples, int *wpos, int size) | |
39 | { | |
40 | int pos; | |
41 | uint64_t left, right; | |
42 | if (replay_mode == REPLAY_MODE_RECORD) { | |
d759c951 | 43 | g_assert(replay_mutex_locked()); |
3d4d16f4 | 44 | replay_save_instructions(); |
3d4d16f4 PD |
45 | replay_put_event(EVENT_AUDIO_IN); |
46 | replay_put_dword(*recorded); | |
47 | replay_put_dword(*wpos); | |
48 | for (pos = (*wpos - *recorded + size) % size ; pos != *wpos | |
49 | ; pos = (pos + 1) % size) { | |
50 | audio_sample_to_uint64(samples, pos, &left, &right); | |
51 | replay_put_qword(left); | |
52 | replay_put_qword(right); | |
53 | } | |
3d4d16f4 | 54 | } else if (replay_mode == REPLAY_MODE_PLAY) { |
d759c951 | 55 | g_assert(replay_mutex_locked()); |
3d4d16f4 | 56 | replay_account_executed_instructions(); |
3d4d16f4 PD |
57 | if (replay_next_event_is(EVENT_AUDIO_IN)) { |
58 | *recorded = replay_get_dword(); | |
59 | *wpos = replay_get_dword(); | |
60 | for (pos = (*wpos - *recorded + size) % size ; pos != *wpos | |
61 | ; pos = (pos + 1) % size) { | |
62 | left = replay_get_qword(); | |
63 | right = replay_get_qword(); | |
64 | audio_sample_from_uint64(samples, pos, left, right); | |
65 | } | |
66 | replay_finish_event(); | |
3d4d16f4 | 67 | } else { |
3d4d16f4 PD |
68 | error_report("Missing audio in event in the replay log"); |
69 | abort(); | |
70 | } | |
71 | } | |
72 | } |