• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: Cannot change device stream format
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Cannot change device stream format


  • Subject: Re: Cannot change device stream format
  • From: Yue Wang <email@hidden>
  • Date: Sun, 03 Jan 2016 23:18:16 -0800

Thanks Brian! This sounds very reasonable to me. What about volume setting? Will that affect the result (since multiply a floating point number may narrowing dynamic range)? There're also rumors that adjusting iTunes' (or Foobar2000's) volume to max will give bit perfect result.  I have no idea if that's the case.

I have another curious question, though. Can I trust AudioOutputUnit automatically do that for me (i.e, set the AudioDevice's physical format to match the file format, and hog device and disable mixing, and set the stream format of AudioOutputUnit as the file format,  and send raw PCM file data to the AudioOutputUnit, and expect AudioOutputUnit automatically translate 16bit integer to 32bit float and translate back to 16 bit int without loss of precision and send to device). If that path is "bit perfect", then no extra work is needed. Unlike Android's audio stack, AudioOutputUnit is a black box to me, so I have no knowledge of its behavior.




On Sun, Jan 3, 2016 at 6:05 PM, Brian Willoughby <email@hidden> wrote:
Hello Yue,

I think you may be trying too hard to achieve "bit perfect." It's entirely possible to do bit perfect audio up to 24-bit, including 16-bit, within the 32-bit float format that CoreAudio defaults to using at the system level. Even though the device format does not literally match the format you're sending you can still have a lossless conversion.

For 16-bit audio, all you need to do is divide the signed 16-bit sample by 32768 (2^15) and send the 32-bit floating point result. For 24-bit audio, the constant is 2^23, or 8,388,608. You could also support 20-bit audio with the appropriate conversion factor.

I have confirmed this using iTunes, the Metric Halo Labs MobileIO interfaces, and loopback of the audio stream to a bit viewer such as TobyBear BitViewer or my own AudioUnit. Those interfaces have a custom FireWire CoreAudio driver with a 32-bit transport, but it's perfectly feasible to send and receive 32-bit float without altering the original 16-bit or 24-bit sample data.

You may need to devise some sort of loopback test to confirm that the translations to 32-bit float and back to 24-bit fixed point format are indeed lossless and bit perfect for your driver code.

Note that it's often good to allow the option for dithering the samples if the input file exceeds the DAC, such as 32-bit files to 24-bit DAC or 20-bit files to 16-bit DAC. If you support an option for dither, then you should allow it to be turned off for "bit perfect" operations.

Brian Willoughby
Sound Consulting


On Jan 3, 2016, at 12:27 AM, Yue Wang <email@hidden> wrote:
> I am a contributor to the cmus music player project (https://cmus.github.io/) who implemented the coreaudio output plugin. My original implementation is based on AudioOutputUnit, which works perfectly fine. Latest code is hosted at https://github.com/Wang-Yue/cmus/blob/master/coreaudio.c.
>
> I'm currently doing an experiment to provide "bit perfect" support (similar what BitPerfect on App Store is doing), that sends the unmodified linear PCM data directly to an output device (such as a DAC), if the device supports such data format.
>
> I ran into problem that I cannot change the device stream format from 32 bit float (system default) to 16 bit int (CD format). My hardware does support the 16 bit integer format as an available physical format, and I can set it as kAudioStreamPropertyPhysicalFormat. In Audio Midi Setup I can see it's correctly updated.
>
> Then I try to set the kAudioDevicePropertyStreamFormat with 16bit integer AudioStreamBasicDescription. It returns without any error. However, when getting the description from the device again, it seems unchanged (still 32 bit float).
>
> My code is listed in
> https://github.com/Wang-Yue/cmus/blob/exclusive/coreaudio.c#L821
>
> If I force to call AudioDeviceStart, I will get very noisy audio (which is also 2x faster than normal speed).
>
> Could someone help and take a look?


 _______________________________________________
Do not post admin requests to the list. They will be ignored.
Coreaudio-api mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:

This email sent to email@hidden

  • Follow-Ups:
    • Re: Cannot change device stream format
      • From: Brian Willoughby <email@hidden>
References: 
 >Cannot change device stream format (From: Yue Wang <email@hidden>)
 >Re: Cannot change device stream format (From: Brian Willoughby <email@hidden>)

  • Prev by Date: Re: Cannot change device stream format
  • Next by Date: Re: Cannot change device stream format
  • Previous by thread: Re: Cannot change device stream format
  • Next by thread: Re: Cannot change device stream format
  • Index(es):
    • Date
    • Thread