Commit Graph

458 Commits

Author SHA1 Message Date
riastradh
d1579b2d70 Rename min/max -> uimin/uimax for better honesty.
These functions are defined on unsigned int.  The generic name
min/max should not silently truncate to 32 bits on 64-bit systems.
This is purely a name change -- no functional change intended.

HOWEVER!  Some subsystems have

	#define min(a, b)	((a) < (b) ? (a) : (b))
	#define max(a, b)	((a) > (b) ? (a) : (b))

even though our standard name for that is MIN/MAX.  Although these
may invite multiple evaluation bugs, these do _not_ cause integer
truncation.

To avoid `fixing' these cases, I first changed the name in libkern,
and then compile-tested every file where min/max occurred in order to
confirm that it failed -- and thus confirm that nothing shadowed
min/max -- before changing it.

I have left a handful of bootloaders that are too annoying to
compile-test, and some dead code:

cobalt ews4800mips hp300 hppa ia64 luna68k vax
acorn32/if_ie.c (not included in any kernels)
macppc/if_gm.c (superseded by gem(4))

It should be easy to fix the fallout once identified -- this way of
doing things fails safe, and the goal here, after all, is to _avoid_
silent integer truncations, not introduce them.

Maybe one day we can reintroduce min/max as type-generic things that
never silently truncate.  But we should avoid doing that for a while,
so that existing code has a chance to be detected by the compiler for
conversion to uimin/uimax without changing the semantics until we can
properly audit it all.  (Who knows, maybe in some cases integer
truncation is actually intended!)
2018-09-03 16:29:22 +00:00
nat
e01c875899 Using audioctl without the -p switch defaults to the mix ring. This allows
setting the hardware gain etc.

Update the audio spec in audio.7 to reflect these changes.

Addresses PR kern/52781.
2018-05-22 01:35:49 +00:00
nat
c9be6b645f Fix a typo with sc_out/inports when setting the hardware recording gain on the
mix ring.  Found by mrg@

XXX pullup-8
2018-05-17 11:35:31 +00:00
nat
82b545a2e8 Fix over cautious compiler error - setmode may not be initialized. 2018-05-15 10:23:03 +00:00
nat
eae209c66d Expose the audio_info structure of vchan zero(0) the mix ring to allow
setting the hardware gain and balance via audioctl(1) using the -p 0
switch.

It is not possible to influence the hardware gain/blance from the
audio_info structure of vchans 1 onwards.  It is now possible to return
the audio mixers audio format from the audio_info structure of vchan 0 to
ease applications configuring for mmapped play back.

This is conformant to the audio specification posted on tech-kern see:
	"NetBSD Audio Specification 2018"
or audio.7 manual page to be added in a follow up commit.
2018-05-15 00:28:00 +00:00
nat
a9838f2e53 Fix numbering of vchan mixer controls to correspond to the vchan number in
use.
This makes the numbering of vchans consistient for audioctl and mixerctl.
2018-05-15 00:19:08 +00:00
isaki
ad9a56d912 Revert my wrong r1.380 and add a comment instead. 2018-02-06 04:39:18 +00:00
christos
7b2f7dc634 CID-1427745: kill possible buffer overflows. 2018-01-21 17:34:33 +00:00
nat
91843a6b25 Allow open of audioctl devices whilst audio is open with the mixer
disabled.

XXX pullup -8
2018-01-12 04:10:10 +00:00
nat
433e65b8f1 Forcefully detach children of audio instances.
This addresses part of PR kern/52889 as children of pad(4) were not
detaching.
2018-01-09 04:14:21 +00:00
nat
df76725601 Rework of play/rec threads to ensure effective use of locks.
Addresses part of PR kern/52889 where the mixing thread would not exit on
audio detach.
2018-01-09 04:10:27 +00:00
nat
ba7d7fa18b Only signal a pause change on a transition of a pause change.
This addresses a problem found in audio/sox causing high cpu usage.

Path and analysis by Onno van der Linden.
2018-01-06 23:15:36 +00:00
nat
29ac8c3c0c Whitespace. 2018-01-06 21:16:36 +00:00
nat
1da05ac732 Convert double block size of data though the play back filters. This is
primarily for when audio mixing is disabled to stop inserting silence when
there is data available.

This change should have no effect when mixing is enabled as there is only
1 block of data in the mix ring.
2017-12-16 16:04:20 +00:00
nat
a6bee1591c Allow the hwvc block size to be set to any amount with audio mixing
disabled.
2017-12-16 15:58:56 +00:00
nat
6e2d3f1a74 Only init the mix ring if sc_usemixer is enabled as with mixing set to
false the mix ring is not used.
2017-12-16 15:56:00 +00:00
christos
ea05286d92 add fo_name so we can identify the fileops in a simple way. 2017-11-30 20:25:54 +00:00
nat
8bdda647e8 Speed up improvements for MIX_FUNC.
As suggested by jmcneill@.
2017-11-28 07:35:27 +00:00
nat
fc80c6117c Use correct combination of mix ring block size and vc playring used low
for signalling the writer or fetching data from the vc play ring filters.

When dealing with the ring buffer sc_mpr.s it is necessary to use the hwvc
or mixring block sizes as they represent the final size of the data to be
played back from the stream vc.

When dealing with sc_pustream when there is play back filters or not one
should use the vc->sc_mpr.blocksize, as this represents the amount of data
before going through play back filters.

This should address PR kern/52685.
2017-11-16 23:43:48 +00:00
nat
6359585b28 Add vc to debug messages in audio_mix.
Also add debug message when available data in the vc is less than the mix
ring blocksize.  NFC.
2017-11-16 23:32:11 +00:00
nat
96100f6b39 For the virtual stream it is required to insert silence. As these streams
are not harware streams audio_pint_silence is ineffective.

As audio_mix() was the only consumer of audio_pint_silence it has been
removed along with sc_sil_count - which was only used by this function.
2017-11-15 04:28:45 +00:00
nat
d6a97917e6 The harware vc is rounded to a power of two then round_blocksize is called.
This improves playback and makes it possibile to use mmapped audio on usb.
2017-11-15 02:13:33 +00:00
nat
cf588ee07b audio_pint improvements for when audio mixing is disabled.
When audio mixing is disabled there is only the hardware vc the mix ring
is not used.
2017-11-15 02:02:55 +00:00
nat
2f436ba4cf Improved audiostartp for when audio mixing is disabled. 2017-11-15 01:58:48 +00:00
nat
c5a8bbef5a Improved draining function for when the mixer is and is not enabled.
One block of silence is also played in audio drivers using start_output
when draining the hardware, this helps playback of short (less than
blocksize) samples.
2017-11-15 01:55:45 +00:00
nat
e99a9d9318 Plug memory leak as the mixer state does not grow or shrink when audio
mixing is disabled.  This avoids triggering a panic also.
2017-11-15 01:49:59 +00:00
nat
380d4173c3 Don't return EIO falsely when dealing with the hardware vc.
Draining of the hardware vc on close is now possible.
2017-11-15 01:45:57 +00:00
nat
b4c5258702 Use mixring blocksizes in the right places when mixer is enabled.
This means that x68k's vs audio works once again with sysctl usemixer=1.

Tested with xm6i.
2017-11-07 09:26:55 +00:00
nat
739a40f15c A sysctl is now available to disable the in kernel mixer.
sysctl -w hw.hdafg0.usemixer=0

There currently is a problem draining the last block with the mixer
disabled.  I will fix this in a follow up commit.

AFAIK there will be a problem wiht vs(4) on x68k with the mixer disabled
as the filters for mulaw, alaw and unsigned linear have been removed post
audio mixing changes.

Documentation for this sysctl variable will be made to audio.4 in a follow
up commit.

Ok christos@.
2017-11-07 01:13:19 +00:00
nat
f9c961740c AU_RING_SIZE -> s.bufsize in audio_initbufs. 2017-11-04 01:50:48 +00:00
nat
96fab80f5b Blocksizes sould be rounded to a power of 2 as OSS applications need this.
Tested by martin@.
2017-11-03 21:15:18 +00:00
nat
007778ea57 Revert to previous. It is necessary to use the calculated blocksize if
none supplied.

Tested by martin@.
2017-11-03 21:12:44 +00:00
nat
e13e341b58 No need to ratify block size twice as this is done in audio_initbufs.
This is a rework of rev 1.421.
2017-11-03 05:31:38 +00:00
nat
5ef468cb75 Calc latency when altering precision, frequency and channels sysctls. 2017-11-03 05:09:49 +00:00
nat
bc03d86400 Allow for block sizes less than hw block size. This allows for the lowest
possible latency for all precision, sample rate and frequencies.

This is a rework of rev 1.419.
2017-11-03 05:07:37 +00:00
nat
4a6596f95c Use mix ring block size in audio write, startp, and audio drain. 2017-11-03 05:04:17 +00:00
nat
69a2b841f3 Revert commit rev 1.419 to audio.c. This should address PR kern/52685.
This also means that drivers that have a static block size will have more
latency at lower sample rates/precision/channels.  Also audio drivers that
do more than supply rounded blocksizes in their round_blocksize functions
will have to be changed.
2017-11-02 02:08:02 +00:00
nat
caf77590f5 Only allow blocksizes greater or equal to the calculated one.
This should help applications as the blocksize obtained (AUDIO_SET/GETINFO)
will work without stutter.

Ok christos@.
2017-10-31 21:18:02 +00:00
nat
3cd3e8f101 Move calculation of sc_latency into a function.
The latency of the audio device is updated on attach in the audio auto
config and shown on screen.

Ok christos@.
2017-10-31 21:13:24 +00:00
nat
a7a2f28741 round_blocksize is only used for the hardware ring buffer. All other
buffers (mix ring, streams) are set to be a power of 2.

This allows for consistent latency where a static blocksize is enforced by
the underlying audio device driver.

Ok christos@.
2017-10-31 21:09:26 +00:00
riastradh
f89317cae1 No externs in .c files! Include ioconf.h for struct cfdriver xyz_cd. 2017-10-28 03:34:26 +00:00
nat
a896b4ad4b Independent blocksizes for virtual channels where a static blocksize is
not stipulated by the underlying hw driver.

This improves latency in games esp. when the stream format differs from
the harware format.

OK christos@.
2017-10-27 01:34:32 +00:00
nat
0d21d703c2 Ensure that the low/high water marks are at least PREFILL_BLOCKS. 2017-10-26 22:45:00 +00:00
nat
49ed8a423f Add latency sysctl to adjust hw blocksize and hence latency of the mixer.
usage: sysctl -w hw.hdafg0.lantency="value in milliseconds"

It is possible to set the latency of the mixer unless a static blocksize
is configured by the underlying hardware driver (pad, vcaudio on RPI).

Documentation updates to audio.4 will occur in a follow up commit.

OK christos@.  XXX pullup-8.
2017-10-26 22:38:27 +00:00
maya
18b796d442 Use C99 initializer for filterops
Mostly done with spatch with touchups for indentation

@@
expression a;
identifier b,c,d;
identifier p;
@@
const struct filterops p =
- 	{ a, b, c, d
+ 	{
+ 	.f_isfd = a,
+ 	.f_attach = b,
+ 	.f_detach = c,
+ 	.f_event = d,
};
2017-10-25 08:12:37 +00:00
isaki
05c8278c15 Fix return value. fo_kqfilter is expected to return errno on error.
This is the rest of 1.226 (10 years ago).
2017-10-21 09:58:56 +00:00
isaki
3e40697aa0 Fix return value. fo_poll is expected to return revents on error. 2017-10-21 09:12:40 +00:00
isaki
d9c230b0b3 Fix return value. fo_mmap is expected to return errno on error. 2017-10-21 09:02:23 +00:00
nat
15c69bdde5 Ensure proper use of sc_opens (play back) and sc_recopens (recording).
Fix logic for /dev/sound so audiosetinfo is only called once.

These changes are to ensure that init_output/input is only called once for
the respective function play back or recording.  For multiple recording or
plack back streams init_input/output is only called once fot the first
play/rec stream.

This addresses PR kern/52580, PR kern/52581 and PR kern/52582 analyzed and
reported by isaki@.
2017-10-01 21:49:20 +00:00
isaki
fdac6d12b2 Improve logic in audio_initbufs(). No functional changes intended. 2017-09-30 05:37:55 +00:00