4 * Copyright (c) 2010-2017 Institute for System Programming
5 * of the Russian Academy of Sciences.
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.
12 #include "qemu/osdep.h"
13 #include "qemu/error-report.h"
14 #include "sysemu/replay.h"
15 #include "replay-internal.h"
16 #include "sysemu/sysemu.h"
17 #include "audio/audio.h"
19 void replay_audio_out(int *played
)
21 if (replay_mode
== REPLAY_MODE_RECORD
) {
22 g_assert(replay_mutex_locked());
23 replay_save_instructions();
24 replay_put_event(EVENT_AUDIO_OUT
);
25 replay_put_dword(*played
);
26 } else if (replay_mode
== REPLAY_MODE_PLAY
) {
27 g_assert(replay_mutex_locked());
28 replay_account_executed_instructions();
29 if (replay_next_event_is(EVENT_AUDIO_OUT
)) {
30 *played
= replay_get_dword();
31 replay_finish_event();
33 error_report("Missing audio out event in the replay log");
39 void replay_audio_in(int *recorded
, void *samples
, int *wpos
, int size
)
43 if (replay_mode
== REPLAY_MODE_RECORD
) {
44 g_assert(replay_mutex_locked());
45 replay_save_instructions();
46 replay_put_event(EVENT_AUDIO_IN
);
47 replay_put_dword(*recorded
);
48 replay_put_dword(*wpos
);
49 for (pos
= (*wpos
- *recorded
+ size
) % size
; pos
!= *wpos
50 ; pos
= (pos
+ 1) % size
) {
51 audio_sample_to_uint64(samples
, pos
, &left
, &right
);
52 replay_put_qword(left
);
53 replay_put_qword(right
);
55 } else if (replay_mode
== REPLAY_MODE_PLAY
) {
56 g_assert(replay_mutex_locked());
57 replay_account_executed_instructions();
58 if (replay_next_event_is(EVENT_AUDIO_IN
)) {
59 *recorded
= replay_get_dword();
60 *wpos
= replay_get_dword();
61 for (pos
= (*wpos
- *recorded
+ size
) % size
; pos
!= *wpos
62 ; pos
= (pos
+ 1) % size
) {
63 left
= replay_get_qword();
64 right
= replay_get_qword();
65 audio_sample_from_uint64(samples
, pos
, left
, right
);
67 replay_finish_event();
69 error_report("Missing audio in event in the replay log");