hw/sd: Use the QOM BUS() macro to access BusState.qbus
[qemu/ar7.git] / replay / replay-audio.c
blobb113836de497c6edea5f2bc838f4c1b5ec7e9b44
1 /*
2 * replay-audio.c
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();
32 } else {
33 error_report("Missing audio out event in the replay log");
34 abort();
39 void replay_audio_in(int *recorded, void *samples, int *wpos, int size)
41 int pos;
42 uint64_t left, right;
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();
68 } else {
69 error_report("Missing audio in event in the replay log");
70 abort();