Commit Graph

87 Commits

Author SHA1 Message Date
beeb02025e output/osx: use range-based for 2020-07-01 22:06:36 +02:00
cdf7062597 apple/AudioUnit: wrapper functions for AudioObject properties 2020-07-01 22:05:11 +02:00
346084da1e apple/Throw: new helper library replacing osx_os_status_to_cstring() 2020-07-01 22:05:11 +02:00
bbceb5eb91 output/osx: silently ignore some errors in osx_output_set_device() 2020-07-01 22:05:11 +02:00
90d85319c2 apple/ErrorRef: new library wrapping CFErrorRef 2020-07-01 22:05:10 +02:00
3d03683e7d output: use StringIsEqual() 2020-07-01 22:04:26 +02:00
d8a74802d1 apple/StringRef: new library wrapping CFStringRef 2020-07-01 22:01:53 +02:00
191919d1b1 output/osx: remove trailing newline from exception messages 2020-07-01 22:01:51 +02:00
c4efc37ad8 system/ByteOrder: move to util/ 2020-07-01 17:49:57 +02:00
691b6a236e output/osx: improve sample rate selection
The formula in osx_output_score_sample_rate() to detect multiples of
the source sample rate was broken: when given a 44.1 kHz input file,
it preferred 16 kHz over 48 kHz, because its `frac_portion(16)=0.75`
is smaller than `frac_portion(48)=0.91`.

That formula, introduced by commit 40a1ebee29, looks completely
wrong.  It doesn't do what the code comment pretends it does.

Instead of using that `frac_portion` to calculate a score, this patch
adds to the score only if `frac_portion` is nearly `0` or `1`.  This
means that the factor is nearly integer.

Closes https://github.com/MusicPlayerDaemon/MPD/issues/904
2020-07-01 17:38:08 +02:00
5c7243d3ad output/osx: make several fields const 2020-07-01 17:35:39 +02:00
44cfdff39a output/osx: make variables more local 2020-07-01 17:35:33 +02:00
5eedda691a output/osx: make more AudioObjectPropertyAddress instances static constexpr 2020-07-01 17:35:19 +02:00
a30d5e1b6a output/osx: make AudioObjectPropertyAddress variables static constexpr 2020-07-01 17:34:12 +02:00
8ef09a0a71 output/osx: don't use C99 designated initializers
Fixes `-Wpedantic`.
2020-07-01 17:34:06 +02:00
e8044663b3 output/{alsa,osx}: use ConstBuffer::empty() 2020-07-01 17:32:37 +02:00
8444c33514 output/osx: don't use variable-length arrays 2020-07-01 17:31:46 +02:00
2b7328b434 output/osx: fix coding style 2020-07-01 17:11:02 +02:00
42b22187c8 [OSXOutput] Throw an error when device not found
Currently it falls back to system default device (either internal speaker or headphone) when device not found. 
I believe it is a better to fail in this case, to make it better aligned with platforms (such as alsa).
2019-01-25 19:50:27 -08:00
f5c9071494 *: copyright year 2018 2018-10-31 17:54:59 +01:00
2127a482da Fix various bugs in OS X DSD playback
the most notable bugs are 

1. osx_output_set_device_format should use the target asbd rather than AudioFormat. This is because asbd's sample rate calculation reflects the real dop target rate of the DAC, white AudioFormat's sample rate is the original DSD format rate.

2. the original code value the highest rate that's the multiple of the target rate. This cause DOP always have the wrong rate chosen. This is also not necessary for PCM playback --- MPD's goal is bit perfect, and it's meaningless to raise to two or four times the PCM sample rate.

3.  if sample_rate cannot be synchronized, the test for falling back to PCM is wrong. If the file format is in DSD format such fallback is necessary, whatever the params.dop setting is.
2018-08-07 01:55:06 -07:00
1e88e71b9a [OSXOutputPlugin] Fix a bug that the stream sample rate is missing
the code here tried to guard DSD features behind ENABLE_DSD. However, the sample rate setting should be shared between two scenarios. 

40a1ebee29 (diff-ce7ecec9ea9ca3df90d9c290cb3ef9d4R795)


The code runs fine if the dac supports the sample rate, as Mac OS  will use the device rate if stream rate is 0. 
However, when DAC is uncapable of processing the sample rate, a wrong rate (device rate) will be used for the stream rate.
2018-07-28 00:06:56 -07:00
c58dffa685 Implement Cancel() for OSXOutputPlugin 2018-07-16 09:06:07 -07:00
1d30df9b15 Update OSXOutputPlugin.cxx
some device seems to have issue with setting kAudioDevicePropertyVolumeScalar  with kAudioObjectPropertyElementMaster. Use AudioToolbox 's kAudioHardwareServiceDeviceProperty_VirtualMasterVolume instead. 

Ideally, we should get the steoro channels first, and set the kAudioDevicePropertyVolumeScalar for each channel, which is doable as presented in https://github.com/cmus/cmus/blob/master/op/coreaudio.c. I will do a follow up PR after refactor PR.
2018-07-13 22:27:24 -07:00
ef84e5c8fa further guard dop code by if (dop_enabled) 2018-07-13 16:36:29 -07:00
6d2a30b860 Update OSXOutputPlugin.cxx
1 sec for pause is too long. we wait for the same amount of time as when ring buffer is not available for writing.
2018-07-13 16:14:59 -07:00
9e0fa8e9ec Fix a copy and paste from diff bug. 2018-07-13 15:53:51 -07:00
5e8e038811 Enclose pcm_export into the ENABLE_DSD guard. 2018-07-13 15:31:48 -07:00
e61a804b80 Simplify audio format assignment code 2018-07-13 15:09:11 -07:00
40a1ebee29 Enable OSX output plugin to set hardware sample rate and bit depth at the same time
This PR will fix .

special thanks to @coroner21 who contributed a nice way to score hardware supported format in 

Also, The DSD related code are all guarded with ENABLE_DSD  flag.
2018-07-13 12:48:43 -07:00
680fdb0338 enable macOS to use Hardware Mixer
- Update the mixer to set on device property instead of audio unit property. When user choose "hardware" as mixer type, they will be able to change the hardware device volume instead of the software (AudioUnit) volume. 
- We don't use square root scale in volume calculation as previous code did. This will make the volume level in line with system volume meter --- That is, MPD will have the same percentage volume reading compared to System Setting (Either in "System Preference" or in "Audio Midi Setup" app)
2018-07-10 15:51:32 -07:00
58590b71d1 Fix pause for OSX output plugin (delay one second) 2018-06-02 19:02:37 +02:00
d84cd500bb Fix build with DSD disabled 2018-03-07 22:40:19 +01:00
5b456cadc4 Reset sample rate to initial state on OSX output 2018-03-07 22:38:09 +01:00
4be80982a4 Fix sample rate sync on Mac output for low rates 2018-03-07 21:32:21 +01:00
4d7f1f0c35 Implement Pause() for OSXOutput plugin 2018-03-07 11:59:43 +01:00
d3f097c7f1 Honor 'device "system"' setting for OSX output 2018-03-07 11:59:43 +01:00
e89c421313 Initial support for DSD over PCM on macOS
From: Christian Kröner <ckroener@gmx.net>

This just copies the necessary bits and pieces from the ALSA plugin and applies them to OSXOutput based on dop config setting. It only changes the OSXOutput plugin as needed for DoP (further changes to support additionally e.g. integer mode or setting the physical device mode require rather a complete rewrite of the output plugin).

Fortunately the Core Audio API is by default bit perfect and supports DoP with minimal changes (setting the sampling rate accordingly after ensuring that the physical mode supports at least 24 bits per channel seems to be enough). This was tested on an Amanero Combo384 device hooked up to a ES9018 DAC.

USAGE (try only on DACs that support DoP):
- Add dop "yes" option to mpdconf
- Be sure to set at least 24bits per channel before playing some DSD file (using Audio-MIDI-Setup)
- Based on the dop setting, MPD will change the sample rate as required and output DoP signal to the DAC
- Hog mode is recommended to ensure that no other program will try to mix some output with the DoP stream (resulting in bad noise)
- Alternatively set the default output device to another device (e.g. the built-in output) to avoid having other audio interfere with DSD playback
2018-02-26 14:55:03 +01:00
6246d36fe6 Merge branch 'v0.20.x' 2017-12-16 20:56:06 +01:00
f1ef9f9d31 OSXOutputPlugin: set the buffer time to be 100ms
[mk: the following text was copied from
https://github.com/MusicPlayerDaemon/MPD/pull/167]

For certain format (hi-res files) and normal buffer size hardware, The
hardware may at once consume most of the buffers. However, in Delay()
function, MPD is supposed to wait for 25 ms after the next try. it
will create a hiccup. The negative impact is much major than
increasing the latency.

I understand larger buffers come at a price. That's why in my earlier
commit last year I significantly reduced it. However, the buffer size
in CoreAudio is set according to the hardware, which is super small
latency. For instance, the system audio of 2015 generation of macbook
pro has maximum buffer size of 4096 samples, which is just 0.09s for
44.1k framerate, or 0.04s for 96k frames --- . compare to the 0.5 sec
latency alsa plugin has, even if we quadruple it, it's still super
tiny.
2017-12-12 10:56:42 +01:00
7ba7ce3af7 Correctly set the mixer plugin for osx output 2017-12-02 23:29:23 -08:00
aa9c6062b0 Merge branch 'v0.20.x' into master
contains OSX mixer
2017-08-22 10:36:37 +01:00
5fb39658f1 OSX mixer 2017-08-21 20:05:50 +01:00
31bad5f7af output/Interface: convert to abstract class
Yet another C-style vtable replaced with C++.
2017-08-10 09:01:41 +02:00
bea5681fd8 output/Interface: define a new struct AudioOutput
Hide struct FilteredAudioOutput from the plugins, preparing for hiding
MPD's core internals.
2017-08-08 18:58:40 +02:00
d0157af13e filter/Internal: rename struct AudioOutput to FilteredAudioOutput
Prepare to add an abstract class AudioOutput, to be implemented by
plugins, to get rid of the C-style vtable.
2017-08-07 18:47:39 +02:00
0a3a5a7c65 Merge branch 'v0.20.x' 2017-05-16 10:09:20 +02:00
b3c82f8886 output/{osx,haiku,pulse,sles}: add missing "noexcept"
Fixes build failure on OS X, closes .  With the other plugins,
that's not critical, because those use the AudioOutputWrapper, which
hides this problem.
2017-05-16 07:12:30 +02:00
8fd9d91974 output/Plugin: pass EventLoop& to init()
Eliminate dependency on io_thread_get().
2017-01-25 22:54:41 +01:00
5900253b85 update copyright year 2017-01-03 20:48:59 +01:00