]>
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 | ||
7520462b | 18 | void replay_audio_out(size_t *played) |
3d4d16f4 PD |
19 | { |
20 | if (replay_mode == REPLAY_MODE_RECORD) { | |
d759c951 | 21 | g_assert(replay_mutex_locked()); |
3d4d16f4 | 22 | replay_save_instructions(); |
3d4d16f4 | 23 | replay_put_event(EVENT_AUDIO_OUT); |
7520462b | 24 | replay_put_qword(*played); |
3d4d16f4 | 25 | } else if (replay_mode == REPLAY_MODE_PLAY) { |
d759c951 | 26 | g_assert(replay_mutex_locked()); |
3d4d16f4 | 27 | replay_account_executed_instructions(); |
3d4d16f4 | 28 | if (replay_next_event_is(EVENT_AUDIO_OUT)) { |
7520462b | 29 | *played = replay_get_qword(); |
3d4d16f4 | 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 | ||
7520462b | 38 | void replay_audio_in(size_t *recorded, void *samples, size_t *wpos, size_t size) |
3d4d16f4 PD |
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 | 45 | replay_put_event(EVENT_AUDIO_IN); |
7520462b KZ |
46 | replay_put_qword(*recorded); |
47 | replay_put_qword(*wpos); | |
3d4d16f4 PD |
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 | 57 | if (replay_next_event_is(EVENT_AUDIO_IN)) { |
7520462b KZ |
58 | *recorded = replay_get_qword(); |
59 | *wpos = replay_get_qword(); | |
3d4d16f4 PD |
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 | } |