From nobody Mon Aug 26 13:54:52 2024 X-Original-To: dev-commits-src-all@mlmmj.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mlmmj.nyi.freebsd.org (Postfix) with ESMTP id 4WsscY4wtwz5SyFC; Mon, 26 Aug 2024 13:54:53 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256 client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "mxrelay.nyi.freebsd.org", Issuer "R11" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4WsscY3ZX8z4fbD; Mon, 26 Aug 2024 13:54:53 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1724680493; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=0Od9ExCjs5KW0uJt++jfW/RWazoPsArEuH7PLs4jfwg=; b=rVs0WCUeBH1jH/83RVqS+i+qFTQZy6SpwrGk26VAl4/6TrrdwhEm5VUPJxh8QNZ7rLC1sx gNn5bWC4i4QStOu9VK8HDXXW87/z2pW1YfLQda8WvZa6FD5xI84iQcDQ7W3O3iZkg2rtIH dobwFqKIaVDsPAgKHWUi2aZgdjkwQJaoK/gnLmUH8tPJ/84rsfs1yN+mmy34BOOw2Jarhb 6VUImx+MEqiV7rF+isBo8vb5bYPRYe+gpPpUXZp00xEr3j41DrfE8O0NwxA9hYopMzkpOR HckkwYmCVtqgL46bk6Kb1nYcMfGf/Y1FCjeQZZZV8LnQcvxl9/rPb8+SHVd08w== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1724680493; a=rsa-sha256; cv=none; b=k58GF1UQdTTUhXdJdLbMIFbH+niWxzYDeqTcwH6uLnDosPWjiYCW5Nw0h/xG3K0Fid8sqL 8wIbaVh0YEI9CoY922PxCT2J+q0IjR5i4J+94cspvnaVi8KgyX48BfqW+UOqBnaelU6UNN ZH4a2UDLSk/5Vdj/MWYiBmXjfJCyMPyRFyphPNb/yZMo4mtkgyB7Ie9ym9RblT21u1pJOp P1Wt8gvNOG9KlriOUFPWZwopJ8q8Pj2Hu1dc8bOK6mPQyreTTRBP+lu7ZbvpnWmJ1c+q0i XUK+bwLWMGt00a9KS4Dr3+J3ubV2M9KMCFvDalUwzOnAU7vCy87jC3nUis6nNA== ARC-Authentication-Results: i=1; mx1.freebsd.org; none ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1724680493; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=0Od9ExCjs5KW0uJt++jfW/RWazoPsArEuH7PLs4jfwg=; b=ee8pXR53JacXhXdqyhKmJx0seEtc0UC4YOCmHJK2aAPm0rmtem2mwCChgS+51sOvgzbKJ2 yeXRpaUZNQtqezLxIObRWHrrLoOqHTuzq7KewPcEV+3OyrbUjR1SYfQTdRruOCDOy3yJUc inDCq4q8M5Ko0VEyrfhDk5ZzL24z5BlMoAAB1ZNm1Kix9XGVH4RcnwByr4LFhJ/nPwf2YK AtofYDhAEUjFWKwCqYrNhzZPf1s+RSsgp3p+a5xBwoUIHt1LXah6Yh6B2ZWWLD/ia7q8tC VFJcUahoE+y9nKdC9roS8C1kiOI67Kmv/ls+tR4Iqn8plLpIPph4G6jnAsgpfw== Received: from gitrepo.freebsd.org (gitrepo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:5]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id 4WsscY0ksDz17wf; Mon, 26 Aug 2024 13:54:53 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org ([127.0.1.44]) by gitrepo.freebsd.org (8.18.1/8.18.1) with ESMTP id 47QDsrfZ017603; Mon, 26 Aug 2024 13:54:53 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.18.1/8.18.1/Submit) id 47QDsq3I017600; Mon, 26 Aug 2024 13:54:52 GMT (envelope-from git) Date: Mon, 26 Aug 2024 13:54:52 GMT Message-Id: <202408261354.47QDsq3I017600@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-branches@FreeBSD.org From: Christos Margiolis Subject: git: 91b1e2a4a84b - stable/14 - sound examples: Delete stale ossinit.h file List-Id: Commit messages for all branches of the src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-all List-Help: List-Post: List-Subscribe: List-Unsubscribe: X-BeenThere: dev-commits-src-all@freebsd.org Sender: owner-dev-commits-src-all@FreeBSD.org MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: christos X-Git-Repository: src X-Git-Refname: refs/heads/stable/14 X-Git-Reftype: branch X-Git-Commit: 91b1e2a4a84ba90c40eed9378a5be4cfbd623037 Auto-Submitted: auto-generated The branch stable/14 has been updated by christos: URL: https://cgit.FreeBSD.org/src/commit/?id=91b1e2a4a84ba90c40eed9378a5be4cfbd623037 commit 91b1e2a4a84ba90c40eed9378a5be4cfbd623037 Author: Christos Margiolis AuthorDate: 2024-08-24 12:16:21 +0000 Commit: Christos Margiolis CommitDate: 2024-08-26 13:54:00 +0000 sound examples: Delete stale ossinit.h file Fixes: 3decd659a788("sound examples: Simplify audio example") Sponsored by: The FreeBSD Foundation MFC after: 2 days (cherry picked from commit 7ae4868a9a1ad255e03529f5872c78f14f215f25) --- share/examples/sound/oss/ossinit.h | 262 ------------------------------------- 1 file changed, 262 deletions(-) diff --git a/share/examples/sound/oss/ossinit.h b/share/examples/sound/oss/ossinit.h deleted file mode 100644 index 5fd614ecb4fb..000000000000 --- a/share/examples/sound/oss/ossinit.h +++ /dev/null @@ -1,262 +0,0 @@ -/* - * SPDX-License-Identifier: BSD-2-Clause - * - * Copyright (c) 2021 Goran Mekić - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - */ - -#include -#include -#include -#include -#include -#include -#include - - -#ifndef SAMPLE_SIZE -#define SAMPLE_SIZE 16 -#endif - -/* Format can be unsigned, in which case replace S with U */ -#if SAMPLE_SIZE == 32 -typedef int32_t sample_t; -int format = AFMT_S32_NE; /* Signed 32bit native endian format */ -#elif SAMPLE_SIZE == 16 -typedef int16_t sample_t; -int format = AFMT_S16_NE; /* Signed 16bit native endian format */ -#elif SAMPLE_SIZE == 8 -typedef int8_t sample_t; -int format = AFMT_S8_NE; /* Signed 8bit native endian format */ -#else -#error Unsupported sample format! -typedef int32_t sample_t; -int format = AFMT_S32_NE; /* Not a real value, just silencing - * compiler errors */ -#endif - - - -/* - * Minimal configuration for OSS - * For real world applications, this structure will probably contain many - * more fields - */ -typedef struct config { - char *device; - int channels; - int fd; - int format; - int frag; - int sample_count; - int sample_rate; - int sample_size; - int chsamples; - int mmap; - oss_audioinfo audio_info; - audio_buf_info buffer_info; -} config_t; - - -/* - * Error state is indicated by value=-1 in which case application exits - * with error - */ -static inline void -check_error(const int value, const char *message) -{ - if (value == -1) { - fprintf(stderr, "OSS error: %s %s\n", message, strerror(errno)); - exit(1); - } -} - - - -/* Calculate frag by giving it minimal size of buffer */ -static inline int -size2frag(int x) -{ - int frag = 0; - - while ((1 << frag) < x) { - ++frag; - } - return frag; -} - - -/* - * Split input buffer into channels. Input buffer is in interleaved format - * which means if we have 2 channels (L and R), this is what the buffer of - * 8 samples would contain: L,R,L,R,L,R,L,R. The result are two channels - * containing: L,L,L,L and R,R,R,R. - */ -void -oss_split(config_t *config, sample_t *input, sample_t *output) -{ - int channel; - int index; - - for (int i = 0; i < config->sample_count; ++i) { - channel = i % config->channels; - index = i / config->channels; - output[channel * index] = input[i]; - } -} - - -/* - * Convert channels into interleaved format and place it in output - * buffer - */ -void -oss_merge(config_t *config, sample_t *input, sample_t *output) -{ - for (int channel = 0; channel < config->channels; ++channel) { - for (int index = 0; index < config->chsamples; ++index) { - output[index * config->channels + channel] = input[channel * index]; - } - } -} - -void -oss_init(config_t *config) -{ - int error; - int tmp; - - /* Open the device for read and write */ - config->fd = open(config->device, O_RDWR); - check_error(config->fd, "open"); - - /* Get device information */ - config->audio_info.dev = -1; - error = ioctl(config->fd, SNDCTL_ENGINEINFO, &(config->audio_info)); - check_error(error, "SNDCTL_ENGINEINFO"); - printf("min_channels: %d\n", config->audio_info.min_channels); - printf("max_channels: %d\n", config->audio_info.max_channels); - printf("latency: %d\n", config->audio_info.latency); - printf("handle: %s\n", config->audio_info.handle); - if (config->audio_info.min_rate > config->sample_rate || config->sample_rate > config->audio_info.max_rate) { - fprintf(stderr, "%s doesn't support chosen ", config->device); - fprintf(stderr, "samplerate of %dHz!\n", config->sample_rate); - exit(1); - } - if (config->channels < 1) { - config->channels = config->audio_info.max_channels; - } - - /* - * If device is going to be used in mmap mode, disable all format - * conversions. Official OSS documentation states error code should not be - * checked. http://manuals.opensound.com/developer/mmap_test.c.html#LOC10 - */ - if (config->mmap) { - tmp = 0; - ioctl(config->fd, SNDCTL_DSP_COOKEDMODE, &tmp); - } - - /* - * Set number of channels. If number of channels is chosen to the value - * near the one wanted, save it in config - */ - tmp = config->channels; - error = ioctl(config->fd, SNDCTL_DSP_CHANNELS, &tmp); - check_error(error, "SNDCTL_DSP_CHANNELS"); - if (tmp != config->channels) { /* or check if tmp is close enough? */ - fprintf(stderr, "%s doesn't support chosen ", config->device); - fprintf(stderr, "channel count of %d", config->channels); - fprintf(stderr, ", set to %d!\n", tmp); - } - config->channels = tmp; - - /* Set format, or bit size: 8, 16, 24 or 32 bit sample */ - tmp = config->format; - error = ioctl(config->fd, SNDCTL_DSP_SETFMT, &tmp); - check_error(error, "SNDCTL_DSP_SETFMT"); - if (tmp != config->format) { - fprintf(stderr, "%s doesn't support chosen sample format!\n", config->device); - exit(1); - } - - /* Most common values for samplerate (in kHz): 44.1, 48, 88.2, 96 */ - tmp = config->sample_rate; - error = ioctl(config->fd, SNDCTL_DSP_SPEED, &tmp); - check_error(error, "SNDCTL_DSP_SPEED"); - - /* Get and check device capabilities */ - error = ioctl(config->fd, SNDCTL_DSP_GETCAPS, &(config->audio_info.caps)); - check_error(error, "SNDCTL_DSP_GETCAPS"); - if (!(config->audio_info.caps & PCM_CAP_DUPLEX)) { - fprintf(stderr, "Device doesn't support full duplex!\n"); - exit(1); - } - if (config->mmap) { - if (!(config->audio_info.caps & PCM_CAP_TRIGGER)) { - fprintf(stderr, "Device doesn't support triggering!\n"); - exit(1); - } - if (!(config->audio_info.caps & PCM_CAP_MMAP)) { - fprintf(stderr, "Device doesn't support mmap mode!\n"); - exit(1); - } - } - - /* - * If desired frag is smaller than minimum, based on number of channels - * and format (size in bits: 8, 16, 24, 32), set that as frag. Buffer size - * is 2^frag, but the real size of the buffer will be read when the - * configuration of the device is successfull - */ - int min_frag = size2frag(config->sample_size * config->channels); - - if (config->frag < min_frag) { - config->frag = min_frag; - } - - /* - * Allocate buffer in fragments. Total buffer will be split in number - * of fragments (2 by default) - */ - if (config->buffer_info.fragments < 0) { - config->buffer_info.fragments = 2; - } - tmp = ((config->buffer_info.fragments) << 16) | config->frag; - error = ioctl(config->fd, SNDCTL_DSP_SETFRAGMENT, &tmp); - check_error(error, "SNDCTL_DSP_SETFRAGMENT"); - - /* When all is set and ready to go, get the size of buffer */ - error = ioctl(config->fd, SNDCTL_DSP_GETOSPACE, &(config->buffer_info)); - check_error(error, "SNDCTL_DSP_GETOSPACE"); - if (config->buffer_info.bytes < 1) { - fprintf( - stderr, - "OSS buffer error: buffer size can not be %d\n", - config->buffer_info.bytes - ); - exit(1); - } - config->sample_count = config->buffer_info.bytes / config->sample_size; - config->chsamples = config->sample_count / config->channels; -}