2017-02-02 13:50:54 +08:00
|
|
|
/*
|
|
|
|
* replay-audio.c
|
|
|
|
*
|
|
|
|
* Copyright (c) 2010-2017 Institute for System Programming
|
|
|
|
* of the Russian Academy of Sciences.
|
|
|
|
*
|
|
|
|
* This work is licensed under the terms of the GNU GPL, version 2 or later.
|
|
|
|
* See the COPYING file in the top-level directory.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "qemu/osdep.h"
|
|
|
|
#include "qemu/error-report.h"
|
|
|
|
#include "sysemu/replay.h"
|
|
|
|
#include "replay-internal.h"
|
|
|
|
#include "audio/audio.h"
|
|
|
|
|
2019-08-19 07:06:58 +08:00
|
|
|
void replay_audio_out(size_t *played)
|
2017-02-02 13:50:54 +08:00
|
|
|
{
|
|
|
|
if (replay_mode == REPLAY_MODE_RECORD) {
|
2018-02-27 17:52:48 +08:00
|
|
|
g_assert(replay_mutex_locked());
|
2017-02-02 13:50:54 +08:00
|
|
|
replay_save_instructions();
|
|
|
|
replay_put_event(EVENT_AUDIO_OUT);
|
2019-08-19 07:06:58 +08:00
|
|
|
replay_put_qword(*played);
|
2017-02-02 13:50:54 +08:00
|
|
|
} else if (replay_mode == REPLAY_MODE_PLAY) {
|
2018-02-27 17:52:48 +08:00
|
|
|
g_assert(replay_mutex_locked());
|
2017-02-02 13:50:54 +08:00
|
|
|
replay_account_executed_instructions();
|
|
|
|
if (replay_next_event_is(EVENT_AUDIO_OUT)) {
|
2019-08-19 07:06:58 +08:00
|
|
|
*played = replay_get_qword();
|
2017-02-02 13:50:54 +08:00
|
|
|
replay_finish_event();
|
|
|
|
} else {
|
|
|
|
error_report("Missing audio out event in the replay log");
|
|
|
|
abort();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-08-19 07:06:58 +08:00
|
|
|
void replay_audio_in(size_t *recorded, void *samples, size_t *wpos, size_t size)
|
2017-02-02 13:50:54 +08:00
|
|
|
{
|
|
|
|
int pos;
|
|
|
|
uint64_t left, right;
|
|
|
|
if (replay_mode == REPLAY_MODE_RECORD) {
|
2018-02-27 17:52:48 +08:00
|
|
|
g_assert(replay_mutex_locked());
|
2017-02-02 13:50:54 +08:00
|
|
|
replay_save_instructions();
|
|
|
|
replay_put_event(EVENT_AUDIO_IN);
|
2019-08-19 07:06:58 +08:00
|
|
|
replay_put_qword(*recorded);
|
|
|
|
replay_put_qword(*wpos);
|
2017-02-02 13:50:54 +08:00
|
|
|
for (pos = (*wpos - *recorded + size) % size ; pos != *wpos
|
|
|
|
; pos = (pos + 1) % size) {
|
|
|
|
audio_sample_to_uint64(samples, pos, &left, &right);
|
|
|
|
replay_put_qword(left);
|
|
|
|
replay_put_qword(right);
|
|
|
|
}
|
|
|
|
} else if (replay_mode == REPLAY_MODE_PLAY) {
|
2018-02-27 17:52:48 +08:00
|
|
|
g_assert(replay_mutex_locked());
|
2017-02-02 13:50:54 +08:00
|
|
|
replay_account_executed_instructions();
|
|
|
|
if (replay_next_event_is(EVENT_AUDIO_IN)) {
|
2019-08-19 07:06:58 +08:00
|
|
|
*recorded = replay_get_qword();
|
|
|
|
*wpos = replay_get_qword();
|
2017-02-02 13:50:54 +08:00
|
|
|
for (pos = (*wpos - *recorded + size) % size ; pos != *wpos
|
|
|
|
; pos = (pos + 1) % size) {
|
|
|
|
left = replay_get_qword();
|
|
|
|
right = replay_get_qword();
|
|
|
|
audio_sample_from_uint64(samples, pos, left, right);
|
|
|
|
}
|
|
|
|
replay_finish_event();
|
|
|
|
} else {
|
|
|
|
error_report("Missing audio in event in the replay log");
|
|
|
|
abort();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|