From patchwork Thu Jan 14 13:45:49 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?UTF-8?B?Wm9sdMOhbiBLxZF2w6Fnw7M=?= X-Patchwork-Id: 567476 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [IPv6:2001:4830:134:3::11]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 6CFA514031E for ; Fri, 15 Jan 2016 01:09:43 +1100 (AEDT) Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b=tKKIH/V4; dkim-atps=neutral Received: from localhost ([::1]:42750 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1aJiar-0005as-Av for incoming@patchwork.ozlabs.org; Thu, 14 Jan 2016 09:09:41 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:35789) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1aJiEZ-0001eR-NS for qemu-devel@nongnu.org; Thu, 14 Jan 2016 08:46:40 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1aJiEY-0003Xo-PT for qemu-devel@nongnu.org; Thu, 14 Jan 2016 08:46:39 -0500 Received: from mail-wm0-x241.google.com ([2a00:1450:400c:c09::241]:36634) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1aJiEY-0003Xb-Gg for qemu-devel@nongnu.org; Thu, 14 Jan 2016 08:46:38 -0500 Received: by mail-wm0-x241.google.com with SMTP id l65so43662766wmf.3 for ; Thu, 14 Jan 2016 05:46:38 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-type:content-transfer-encoding; bh=v/huo09OzcY6yoKJ+GGYGZG0BvlYdEb1yeK+AylXCM0=; b=tKKIH/V4ZD3Nee9emTbcHQ4PgJIyTN6uaKSjELXKwVszNS2+abLfWjYsd8RdoIjUDW zvRBs+xN3aWPU4CnTWO8JNZHEMKy1ob/lkto0vhJ+Dj/wPd9Vvn/N1PenbaMRpmUTtRG DyvEi7RStUc3JPhxI/yGG8C3IBf0flGxma8y0wzXS4NbmbYFt+x7dJp3Y48XPRJxyU8v IhoXDwcuY0mztnBEfGHpNNi4CMABVCwEncvgKTve5hGX67um9TC2e4XtgVYdKuyYU0rh 03QPqZSpNr2ab+a9ftMZ3E3B0GofvZ+O3Is+1g5cXkEWVTwuBHmQ9lhL5XmOzuQ1DQFT ttJg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-type:content-transfer-encoding; bh=v/huo09OzcY6yoKJ+GGYGZG0BvlYdEb1yeK+AylXCM0=; b=R+rJ+TcA+DXvV0TLst5SYvnCaiIed2G+ay8hbTmvtCZzXH+7g/Kpy6FordqyLN48iH +zGScQkTOM5iNhfRkgWT2TK6OjG8qu9zL7VjrSE6rPnq8MfKWXVv9CAFsyNcWVRsQSug CRk1r8ISbDGOT8qTJj7J93xihJyt1F2hYrYIkWGH7pH7MMjzw2BdWr5+Sn/+I1RstxEv al/JehYGVOglamzhdVXR4FWnRIJ82XLfLAz3VnekomXkL+0ccGXLpHkebUtcwmo6S3fr tGTuEzTg7JCd8+c9Tlbd2TJTGzZbTUXrBj30JrA57/rPm1uWf0ff6L1u6DC7vMvkC3CS vVqw== X-Gm-Message-State: ALoCoQmKtqTN5I8tBAf9X2seBQ6Xr6qhjiAs8EY+7Lsf4zutZmdsVhnMHFXxmeTUoGwb/n+fuHqXHi52viCiDiSp8pJLDtW4Kg== X-Received: by 10.194.220.233 with SMTP id pz9mr4811924wjc.95.1452779197988; Thu, 14 Jan 2016 05:46:37 -0800 (PST) Received: from nullptr.home.dirty-ice.org (188-143-126-18.pool.digikabel.hu. [188.143.126.18]) by smtp.gmail.com with ESMTPSA id 79sm7398061wmo.7.2016.01.14.05.46.37 (version=TLSv1/SSLv3 cipher=OTHER); Thu, 14 Jan 2016 05:46:37 -0800 (PST) From: "=?UTF-8?q?K=C5=91v=C3=A1g=C3=B3=2C=20Zolt=C3=A1n?=" X-Google-Original-From: =?UTF-8?q?K=C5=91v=C3=A1g=C3=B3=2C=20Zolt=C3=A1n?= To: qemu-devel@nongnu.org Date: Thu, 14 Jan 2016 14:45:49 +0100 Message-Id: <5a321cc0595c497c51950bd6b332008304061606.1452776884.git.DirtY.iCE.hu@gmail.com> X-Mailer: git-send-email 2.7.0 In-Reply-To: References: MIME-Version: 1.0 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 2a00:1450:400c:c09::241 Cc: Gerd Hoffmann Subject: [Qemu-devel] [PATCH 36/51] wavaudio: port to the new audio backend api X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Signed-off-by: Kővágó, Zoltán --- audio/wavaudio.c | 55 +++++++++---------------------------------------------- 1 file changed, 9 insertions(+), 46 deletions(-) diff --git a/audio/wavaudio.c b/audio/wavaudio.c index d49a118..b289689 100644 --- a/audio/wavaudio.c +++ b/audio/wavaudio.c @@ -33,52 +33,27 @@ typedef struct WAVVoiceOut { HWVoiceOut hw; FILE *f; int64_t old_ticks; - void *pcm_buf; int total_samples; } WAVVoiceOut; -static int wav_run_out (HWVoiceOut *hw, int live) +static size_t wav_write_out(HWVoiceOut *hw, void *buf, size_t len) { WAVVoiceOut *wav = (WAVVoiceOut *) hw; - int rpos, decr, samples; - uint8_t *dst; - struct st_sample *src; int64_t now = qemu_clock_get_ns(QEMU_CLOCK_VIRTUAL); int64_t ticks = now - wav->old_ticks; int64_t bytes = muldiv64 (ticks, hw->info.bytes_per_second, get_ticks_per_sec ()); - - if (bytes > INT_MAX) { - samples = INT_MAX >> hw->info.shift; - } - else { - samples = bytes >> hw->info.shift; - } - + bytes = MIN(bytes, len); + bytes = bytes >> hw->info.shift << hw->info.shift; wav->old_ticks = now; - decr = MIN (live, samples); - samples = decr; - rpos = hw->rpos; - while (samples) { - int left_till_end_samples = hw->samples - rpos; - int convert_samples = MIN (samples, left_till_end_samples); - src = hw->mix_buf + rpos; - dst = advance (wav->pcm_buf, rpos << hw->info.shift); - - hw->clip (dst, src, convert_samples); - if (fwrite (dst, convert_samples << hw->info.shift, 1, wav->f) != 1) { - dolog ("wav_run_out: fwrite of %d bytes failed\nReaons: %s\n", - convert_samples << hw->info.shift, strerror (errno)); - } - - rpos = (rpos + convert_samples) % hw->samples; - samples -= convert_samples; - wav->total_samples += convert_samples; + if (bytes && fwrite(buf, bytes, 1, wav->f) != 1) { + dolog("wav_write_out: fwrite of %zu bytes failed\nReaons: %s\n", + bytes, strerror(errno)); } - hw->rpos = rpos; - return decr; + wav->total_samples += bytes >> hw->info.shift; + return bytes; } /* VICE code: Store number as little endian. */ @@ -134,13 +109,6 @@ static int wav_init_out(HWVoiceOut *hw, struct audsettings *as, audio_pcm_init_info (&hw->info, &wav_as); hw->samples = 1024; - wav->pcm_buf = audio_calloc (AUDIO_FUNC, hw->samples, 1 << hw->info.shift); - if (!wav->pcm_buf) { - dolog("Could not allocate buffer (%zu bytes)\n", - hw->samples << hw->info.shift); - return -1; - } - le_store (hdr + 22, hw->info.nchannels, 2); le_store (hdr + 24, hw->info.freq, 4); le_store (hdr + 28, hw->info.freq << (bits16 + stereo), 4); @@ -150,8 +118,6 @@ static int wav_init_out(HWVoiceOut *hw, struct audsettings *as, if (!wav->f) { dolog ("Failed to open wave file `%s'\nReason: %s\n", wav_path, strerror(errno)); - g_free (wav->pcm_buf); - wav->pcm_buf = NULL; return -1; } @@ -205,9 +171,6 @@ static void wav_fini_out (HWVoiceOut *hw) wav->f, strerror (errno)); } wav->f = NULL; - - g_free (wav->pcm_buf); - wav->pcm_buf = NULL; } static int wav_ctl_out (HWVoiceOut *hw, int cmd, ...) @@ -231,7 +194,7 @@ static void wav_audio_fini (void *opaque) static struct audio_pcm_ops wav_pcm_ops = { .init_out = wav_init_out, .fini_out = wav_fini_out, - .run_out = wav_run_out, + .write = wav_write_out, .ctl_out = wav_ctl_out, };