1313680Sngie/*	$NetBSD: h_pad.c,v 1.2 2016/10/15 07:08:06 nat Exp $	*/
2272343Sngie
3272343Sngie/*
4272343Sngie * Copyright (c) 2010 Antti Kantee.  All Rights Reserved.
5272343Sngie *
6272343Sngie * Redistribution and use in source and binary forms, with or without
7272343Sngie * modification, are permitted provided that the following conditions
8272343Sngie * are met:
9272343Sngie * 1. Redistributions of source code must retain the above copyright
10272343Sngie *    notice, this list of conditions and the following disclaimer.
11272343Sngie * 2. Redistributions in binary form must reproduce the above copyright
12272343Sngie *    notice, this list of conditions and the following disclaimer in the
13272343Sngie *    documentation and/or other materials provided with the distribution.
14272343Sngie *
15272343Sngie * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS
16272343Sngie * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
17272343Sngie * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
18272343Sngie * DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
19272343Sngie * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
20272343Sngie * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
21272343Sngie * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
22272343Sngie * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
23272343Sngie * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
24272343Sngie * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
25272343Sngie * SUCH DAMAGE.
26272343Sngie */
27272343Sngie
28272343Sngie#include <sys/types.h>
29272343Sngie
30272343Sngie#include <rump/rump.h>
31272343Sngie#include <rump/rump_syscalls.h>
32272343Sngie
33272343Sngie#include <err.h>
34272343Sngie#include <fcntl.h>
35272343Sngie#include <stdio.h>
36272343Sngie#include <stdlib.h>
37272343Sngie#include <string.h>
38272343Sngie#include <unistd.h>
39272343Sngie
40272343Sngie#include "h_pad_musa.c"
41272343Sngie
42272343Sngie/*
43272343Sngie * Stuff some audio into /dev/audio, read it from /dev/pad.  Use in
44272343Sngie * conjunction with t_pad, which tests that we got sensible output
45272343Sngie * by comparing against a previous audibly good result.
46272343Sngie */
47272343Sngie
48272343Sngie#define BUFSIZE 1024
49272343Sngie
50272343Sngieint
51272343Sngiemain(int argc, char *argv[])
52272343Sngie{
53272343Sngie	char buf[BUFSIZE];
54272343Sngie	char zeros[BUFSIZE];
55272343Sngie	int padfd, audiofd;
56272343Sngie	ssize_t n;
57272343Sngie
58272343Sngie	rump_init();
59313680Sngie	padfd = rump_sys_open("/dev/pad0", O_RDONLY);
60313680Sngie	if (padfd == -1)
61313680Sngie		err(1, "open pad");
62313680Sngie
63272343Sngie	audiofd = rump_sys_open("/dev/audio0", O_RDWR);
64272343Sngie	if (audiofd == -1)
65272343Sngie		err(1, "open audio");
66272343Sngie
67272343Sngie	if ((n = rump_sys_write(audiofd, musa, sizeof(musa))) != sizeof(musa))
68272343Sngie		err(1, "write");
69272343Sngie
70272343Sngie	memset(zeros, 0, sizeof(zeros));
71272343Sngie	while ((n = rump_sys_read(padfd, buf, sizeof(buf))) > 0) {
72272343Sngie		if (memcmp(buf, zeros, sizeof(buf)) == 0)
73272343Sngie			break;
74272343Sngie		write(STDOUT_FILENO, buf, n);
75272343Sngie	}
76272343Sngie}
77