Commit Graph

113 Commits

Author SHA1 Message Date
nia
c1f0400234 ossaudio(3): Do not reuse results from AUDIO_GETBUFINFO in SETINFO
Should help PR 55876.
2020-12-19 12:55:28 +00:00
nia
aab2f38b54 Add some missing channel order related ioctl defines.
These are no-ops (unimplemented) on both FreeBSD and Solaris
and the one piece of code I've found that uses it seems to assume the
call will fail so it should be safe to leave this returning EINVAL.

However, it does need the definitions to compile...
2020-12-03 22:10:21 +00:00
nia
f7f198978e ossaudio(3): Clone some useful behaviour from the Solaris kernel
Both SNDCTL_DSP_SPEED and SNDCTL_DSP_CHANNELS support a special value
0 to "query the configured value without changing it". In our case,
this actually means setting and querying the hardware rate.

I don't know if OSSv3 or FreeBSD or other implementations also do this.
But it seems safe and sensible to support.
2020-11-13 09:02:39 +00:00
nia
8a0fd92fc8 ossaudio(3): Set errno and return -1 rather than returning errno. 2020-11-04 22:59:24 +00:00
nia
a9d493a299 ossaudio(3): Reduce code duplication for querying capabilities 2020-11-03 09:46:00 +00:00
nia
f0eecf651f ossaudio(3): Return device playback and capture capabilities in GETCAPS 2020-11-03 09:36:12 +00:00
nia
54df53aac3 ossaudio(3): More capability defines from OSSv4 2020-11-03 09:33:53 +00:00
nia
7a66cf0ffc ossaudio(3): return correctly initialized return value in unlikely
error case. pointed out by tnn.
2020-11-03 08:24:33 +00:00
nia
2ea12967a0 ossaudio(3): Simplify setting rate (try to supply the nearest one possible) 2020-10-30 21:44:49 +00:00
roy
07a43c5149 libossaudio: return newfd here as we return retval elsewhere 2020-10-24 14:43:53 +00:00
wiz
80fb34196c Fix typo in comment. 2020-10-23 12:13:04 +00:00
nia
2cd43b36c6 ossaudio(3): Add an implementation of SNDCTL_CARDINFO
Correct some of the counts returned by SNDCTL_SYSINFO so this works.
2020-10-23 09:05:20 +00:00
nia
054aefec7a ossaudio(3): This is not compat_linux 2020-10-22 19:39:48 +00:00
nia
41a2db1f31 ossaudio(3): Add SNDCTL_AUDIOINFO_EX as an alias of SNDCTL_AUDIOINFO 2020-10-20 08:57:45 +00:00
wiz
0e2cbe842f Remove trailing whitespace. 2020-10-20 07:52:04 +00:00
nia
d1d954926b ossaudio(3): Plug a fd leak in the new mixer API 2020-10-20 06:53:37 +00:00
nia
bbfc3fa4fd ossaudio.3: Bump date 2020-10-20 06:43:55 +00:00
nia
6abc2e7583 ossaudio(3): Turn BUGS section into a list of potential compat issues 2020-10-20 06:43:34 +00:00
nia
988ec12f1c ossaudio(3): Add some endian-specific U16 formats
for compatibility with FreeBSD
2020-10-20 06:33:52 +00:00
nia
8bdeed361e ossaudio(3): add some no-op defines for ossv4 compat. 2020-10-19 10:28:47 +00:00
nia
028d2f4db2 ossaudio(3): these ioctls need to return samples, not bytes 2020-10-19 09:07:29 +00:00
nia
27ca241ed7 ossaudio(3): Add SNDCTL_DSP_CURRENT_(I|O)PTR
In OSSv4 these are supposed to avoid the wrapping problems with the
older GET(I|O)PTR ioctls but we don't quite get the same benefit here.

XXX: We could probably fake it by maintaining some state in-between calls.
2020-10-19 09:01:24 +00:00
nia
1f7ebca62c ossaudio(3): Add initial support for the OSSv4.1 Mixer API
One or two calls from this API were supported previously and have been
moved to the correct place.

Mapping the controls correctly is a difficult task. There is a define
hidden in the OSS headers that would allow an AUDIO_MIXER_SET control
to be represented perfectly, but it seems to _only_ exist there, and
no software supports it. So for now only one member of a set can be
set at a time - unfortunate. I've hidden code that should unlock
doing this the proper way under #notyet.

I'm not too happy with the way this code is managing file descriptors.
Currently it has to open a new fd for each ioctl due to OSSv4 deciding
to specify the device number in a structure rather than in the filename.
In the future, we could reuse the file descriptor if the correct one is
detected open.

This allows the mixer programs provided with the OSSv4 sources to compile
and work cleanly. I've observed problems with it failing to work on
secondary devices, and should investigate this later. There may be
a fd leak somewhere.
2020-10-17 23:23:06 +00:00
wiz
e3d011e985 Use Fx and Nx. End Rs block. Remove trailing whitespace.
Remove unnecessary Pp.
2020-10-17 09:04:59 +00:00
nia
b32d7310bd ossaudio.3: note this is most/all of ossv3 and some of ossv4 2020-10-16 20:51:54 +00:00
nia
d53a6cbc32 ossaudio(3): Add SNDCTL_DSP_COOKEDMODE, SNDCTL_DSP_GETERROR
SNDCTL_DSP_COOKEDMODE simply always returns 1.
"Cooked mode" is a silly way the OSSv4 authors chose to refer to allowing
for reprocessed streams. The NetBSD kernel always performs format
conversion and it can't be turned off.

SNDCTL_DSP_GETERROR provides access to the read/write over/underrun
counters. There are other things it might return, but they don't make
sense for our implementation.
2020-10-16 20:24:35 +00:00
nia
ad3ea96832 ossaudio.3: Sort sections. 2020-10-16 16:48:07 +00:00
nia
381a0b036e ossaudio.3: More information about the history and status of this API 2020-10-16 16:30:53 +00:00
nia
9613c80501 ossaudio: Bump copyright date and improve description. 2020-10-16 15:40:16 +00:00
nia
d9a5cdad2e ossaudio: Add comments for the more obscure parts of SNDCTL_AUDIOINFO 2020-10-16 12:36:01 +00:00
nia
2874e967ea ossaudio: Various OSSv4 fixes for SNDCTL_AUDIOINFO
- Per OSSv4, make this ioctl work on the main mixer device.
  Since the native NetBSD API uses queries on individual audio devices,
  we have to reopen the correct audio device specified in the input to the
  ioctl and fetch information from that.
- Correctly return whether the device is for playback, capture, or both.
- Return the full name of the device in the name field.
- The "handle" has to be a globally unique identifier. The closest thing
  we have to that is device numbers, so use device numbers.
- Return reasonable values in min_rate/max_rate and min_channels/max_channels.

This should allow Mumble's device enumeration to work with a lot less
patching.
2020-10-16 12:23:34 +00:00
nia
ab8a3679da ossaudio: removed outdated comment 2020-04-20 12:01:44 +00:00
nia
8e9e149d7d ossaudio: Implement SNDCTL_DSP_(SET|GET)TRIGGER. 2020-04-19 13:44:50 +00:00
nia
d4490f2a9c ossaudio: Make SNDCTL_DSP_[GET|SET][PLAY|RECORD]VOL closer to OSSv4
Problems in the previous code include returning values in the 0-255
range NetBSD uses instead of the 0-100 range OSSv4 expects, using
AUDIO_GETBUFINFO (which doesn't even return the mixer bits), and
not encoding channels as specified: "level=(left)|(right << 8)".

In reality, setting the gain in this way (through /dev/audio rather
than /dev/mixer) doesn't seem to work properly, and the mixer-set
value seems to be retained.

However, these changes at least ensure that the return values are
correct and the balance is set correctly.

I've only found one application using this API (audio/audacious), and
OSSv4 support in it is currently disabled precisely because it breaks
when it attempts to set the track volume using it.
2020-04-19 11:27:40 +00:00
nia
87706eec7d ossaudio: If the user's channel count is rejected, use the hardware count 2020-04-15 16:39:06 +00:00
nia
0eb796bf71 ossaudio: Make SNDCTL_DSP_SETFMT conform with OSSv4.
The OSSv4 spec says we shouldn't really error if an invalid format is
chosen by an application. Things are especially likely to be confused
if we return MULAW, since in OSSv4 terms that means that's the native
hardware format. Instead, set and return the current hardware format
if an invalid format is chosen.

For the 24-bit sample formats, note that the NetBSD kernel currently
can't handle them in its default configuration, and will return an error
code if you attempt to use them. So, if an applicaton requests 24-bit PCM,
promote it to 32-bit PCM. According to the spec, this is valid and
applications should be checking the return value anyway.

In the Linux compat layer, we just use S16LE as a fallback. The OSSv3
headers that are still being shipped with Linux don't contain definitions
for fancier formats and we can reasonably expect all applications to
support S16LE.
2020-04-15 15:25:33 +00:00
nia
6476938d92 ossaudio: Make SNDCTL_DSP_SPEED more robust when using invalid rates.
From the perspective of reading the OSSv4 specification, NetBSD's
behaviour when an invalid sample rate is set makes no sense at all:
AUDIO_SETINFO simply returns an error code, and then we immediately
fall through to getting the sample rate, which is still set to the
legacy default of 8000 Hz.

Instead, what OSS applications generally expect is that they will be
able to receive the actual hardware sample rate. This is very, very
unlikely to be 8000 Hz on a modern machine.

No functional change when setting a sample rate between the supported
rates of 1000 and 192000 Hz. When a rate outside this range is requested,
the hardware rate is returned (on modern hardware, generally always 48000
Hz or a multiple of 48000 Hz).
2020-04-15 14:54:34 +00:00
isaki
5b3dd8b1b9 Use record field for recording even on
SNDCTL_DSP_STEREO, SNDCTL_DSP_SETFMT, and SNDCTL_DSP_CHANNELS.
2019-11-03 11:13:45 +00:00
isaki
d97643b742 Use record.sample_rate for recording on SNDCTL_DSP_SPEED.
Fix PR lib/54667.
2019-11-02 11:48:23 +00:00
isaki
8b1980912d Fix minor bugs of SNDCTL_DSP_GETISPACE.
- hiwat is playback-only parameter.
- 'bytes' should not be rounded down.
2019-02-02 04:52:16 +00:00
isaki
6b4163e9ca Revert a wrong SNDCTL_DSP_GETOSPACE part of rev1.33.
- 'fragments' is the number of full free blocks and should not be
  negative value.
- 'bytes' should not be rounded down.
It makes mpv work correctly (fixes a second half of kern/53028).
Reviewed by mlelstv@
2019-01-29 11:54:02 +00:00
mrg
bfe7e5d8b3 memset to zero the entire array, not just 8 bytes of it.
picked up by gcc7's checker that the array size has not
been multipled by the member size.

here, we had 8 but should have had 8 * sizeof(int).

XXX: real bug - pullup-7, pullup-8
2019-01-23 00:08:06 +00:00
nat
e5d1b604d5 ABI of libossaudio did not change, so there was no need to bump the version
number.

Pointed out by mrg@
2017-03-24 11:46:52 +00:00
nat
dab5456581 Calculate GETISPACE/GETOSPACE properly.
Bump version.

Addresses PR kern/51999.
2017-03-23 15:50:48 +00:00
maya
39d6057df2 speed limit is 80 (missed this one) 2017-02-10 08:52:04 +00:00
maya
6ac4e27787 strncpy->strlcpy. use sizeof instead of numbers. 2017-02-10 08:50:27 +00:00
nat
141dc004bd Add missing defines for 16, 24 and 32 bit NE and OE formats.
Add the ability to set 24 and 32 bit precision.

This commit was approved by wiz@
2014-09-09 10:45:18 +00:00
nat
dc2ecd830b libossaudio minor version bump to signify new ioctls. 2014-05-18 10:36:34 +00:00
nat
a8ba8ad76b Adds ioctls and defines for OSSv4 compatibility.
The ioctl definitions and accompanying structures were
taken from FreeBSD's soundcard.h, hopefully providing
some binary compatibility.

The ioctls are as follows:
	SNDCTL_SYSINFO: Returns a structure containing
		details about the audio device.
	SNDCTL_ENGINEINFO - SNDCTL_AUDIOINFO: Returns a
		structure with playback/recording
		characteristics.
	SNDCTL_DSP_GETPLAYVOL, SNDCTL_DSP_SETPLAYVOL,
	SNDCTL_DSP_GETRECVOL, SNDCTL_DSP_SETRECVOL:
		Retrieves/Sets Playback/Recording volume.
	SNDCTL_DSP_SKIP - SNDCTL_DSP_SILENCE: These ioctls
		were intended to manipulate the underlying
		audio buffer skip or insert silence.  These
		return EINVAL.

SOUND_VERSION is unchanged, but is definable,  It will be
changed when the mixer OSSv4 ioctls are written.

Addresses PR 46611
This commit was approved by wiz@.
2014-05-17 12:38:42 +00:00
christos
a4deae0de5 fix typo, WARNS=5 2012-05-05 15:57:45 +00:00