DSD and supporting codec-requested sample rate change
Hi, Direct Stream Digital (DSD) is the name given to the 1-bit delta sigma encoding system found in audiophile equipment. It is an alternative to PCM. A DSD decoder was added recently that transforms an input DSD bitstream into floating point PCM. While this is sufficient to listen to content on a computer, it doesn't permit direct manipulation of the DSD samples. Nor does it let FFmpeg feed DSD samples into an external DAC. I have started modifying FFmpeg to better support DSD, but have hit problems with sample rate changes. Potentially some API changes to libswresample is required. Ideas or comments welcome. EFFORT SO FAR: 1. add AV_SAMPLE_FMT_DSD (and the planar variant). 2. incorporate DSD->PCM conversion into libswresample. 3. rework the dsd_msbf, dsd_lsbf, etc decoders to output AV_SAMPLE_FMT_DSD. (very similar in function to the libavcodec/pcm.c decoders) 4. DSD-over-PCM (DoP) encoder DoP is a method of storing DSD bits into a 24-bit PCM stream. The high 8-bits of each PCM sample is marked with a pattern, and the lower 16-bits are DSD samples. External DACs are able to detect the pattern and process the raw DSD samples. http://dsd-guide.com/sites/default/files/white-papers/DoP_openStandard_1v1.p... 5. DST (Direct Stream Transfer) decoder Lossless compression for DSD samples. Described in MPEG-4 Part 3, Subpart 10. http://itscj.ipsj.or.jp/sc29/open/29view/29n6213t.doc PROBLEMS: 1. DSD->PCM conversion results in a change to the sample rate. For example, 2.8224 MHz 1-bit DSD samples => 352.8 kHz PCM samples; and 5.6448 MHz 1-bit DSD samples => 705.6 kHz PCM samples. a) Should libswresample return the new sample rate? b) Should the user of libswresample be expected to know the change between DSD->PCM and populate the 'in_sample_rate' and 'out_sample_rate' accordingly? 2. DoP encoding takes DSD 1-bit samples @ 2.8224 MHz and smushes them into 24-bit PCM @ 176.4 kHz. How can the DoP codec inform avcodec that the output packets have a different sample rate? Editing 'avctx->sample_rate' doesnt work because other modules expect this information to remain static. Cheers, -- Peter (A907 E02F A6E5 0CD2 34CD 20D2 6760 79C5 AC40 DD6B)
On Mon, Apr 21, 2014 at 04:15:09PM +1000, Peter Ross wrote:
Hi,
Direct Stream Digital (DSD) is the name given to the 1-bit delta sigma encoding system found in audiophile equipment. It is an alternative to PCM.
A DSD decoder was added recently that transforms an input DSD bitstream into floating point PCM. While this is sufficient to listen to content on a computer, it doesn't permit direct manipulation of the DSD samples. Nor does it let FFmpeg feed DSD samples into an external DAC.
I have started modifying FFmpeg to better support DSD, but have hit problems with sample rate changes. Potentially some API changes to libswresample is required. Ideas or comments welcome.
EFFORT SO FAR:
1. add AV_SAMPLE_FMT_DSD (and the planar variant).
2. incorporate DSD->PCM conversion into libswresample.
3. rework the dsd_msbf, dsd_lsbf, etc decoders to output AV_SAMPLE_FMT_DSD. (very similar in function to the libavcodec/pcm.c decoders)
4. DSD-over-PCM (DoP) encoder DoP is a method of storing DSD bits into a 24-bit PCM stream. The high 8-bits of each PCM sample is marked with a pattern, and the lower 16-bits are DSD samples. External DACs are able to detect the pattern and process the raw DSD samples. http://dsd-guide.com/sites/default/files/white-papers/DoP_openStandard_1v1.p...
5. DST (Direct Stream Transfer) decoder Lossless compression for DSD samples. Described in MPEG-4 Part 3, Subpart 10. http://itscj.ipsj.or.jp/sc29/open/29view/29n6213t.doc
PROBLEMS:
1. DSD->PCM conversion results in a change to the sample rate. For example, 2.8224 MHz 1-bit DSD samples => 352.8 kHz PCM samples; and 5.6448 MHz 1-bit DSD samples => 705.6 kHz PCM samples.
a) Should libswresample return the new sample rate?
id tend to suggest that the sample rates should represent the true (in a mathematical sense) samplerates of the signals. And i realize that this definition is a bit fuzzy without a definition of what a sample is.
b) Should the user of libswresample be expected to know the change between DSD->PCM and populate the 'in_sample_rate' and 'out_sample_rate' accordingly?
id suggest that it should be handled like any other sample format but iam not working on this, you do, so there may be better options that iam not recognizing ...
2. DoP encoding takes DSD 1-bit samples @ 2.8224 MHz and smushes them into 24-bit PCM @ 176.4 kHz. How can the DoP codec inform avcodec that the output packets have a different sample rate? Editing 'avctx->sample_rate' doesnt work because other modules expect this information to remain static.
iam not sure i understand the problem where does mhz DSD -> khz PCM differ from mhz PCM -> khz PCM ? [...] -- Michael GnuPG fingerprint: 9FF2128B147EF6730BADF133611EC787040B0FAB If you think the mosad wants you dead since a long time then you are either wrong or dead since a long time.
Quoting Michael Niedermayer <michaelni@gmx.at>:
On Mon, Apr 21, 2014 at 04:15:09PM +1000, Peter Ross wrote:
Hi,
Direct Stream Digital (DSD) is the name given to the 1-bit delta sigma encoding system found in audiophile equipment. It is an alternative to PCM.
[..]
1. DSD->PCM conversion results in a change to the sample rate. For example, 2.8224 MHz 1-bit DSD samples => 352.8 kHz PCM samples; and 5.6448 MHz 1-bit DSD samples => 705.6 kHz PCM samples.
a) Should libswresample return the new sample rate?
id tend to suggest that the sample rates should represent the true (in a mathematical sense) samplerates of the signals. And i realize that this definition is a bit fuzzy without a definition of what a sample is.
Right. Each DSD sample is 1-bit.
b) Should the user of libswresample be expected to know the change between DSD->PCM and populate the 'in_sample_rate' and 'out_sample_rate' accordingly?
id suggest that it should be handled like any other sample format but iam not working on this, you do, so there may be better options that iam not recognizing ...
Okay.
2. DoP encoding takes DSD 1-bit samples @ 2.8224 MHz and smushes them into 24-bit PCM @ 176.4 kHz. How can the DoP codec inform avcodec that the output packets have a different sample rate? Editing 'avctx->sample_rate' doesnt work because other modules expect this information to remain static.
iam not sure i understand the problem
where does mhz DSD -> khz PCM differ from mhz PCM -> khz PCM ?
DoP is an industry standard that uses PCM to deliver DSD samples to external DAC equipment. The encoding stores 16 x 1-bit DSD samples into each 24-bit PCM sample. The high 8 bits of each PCM sample indicate an alternating magic number, so that capable DACs can detect the marker and process the DSD samples. This is known as bit-perfect DSD. Therefore a source stream of DSD samples @ 2.8224 Mhz is "encoded" into a 176.4kHz PCM stream (2.8224 x 10^6 / 16). The challenge for FFmpeg is that libavcodec/dopenc.c needs to change the sample rate (from 2.8224 MHz to 176.4kHz). Our codecs have not traditionally done this; there is no concept of input and output sample rate. A solution I have considered is adding AVCodecContext.dsd_sample_rate that would only apply to SAMPLE_FMT_DSD. The dopenc_init() function would read dsd_sample_rate and then set sample_rate. -- Peter (Roaming)
On Sat, Apr 26, 2014 at 04:42:27AM +0200, Peter Ross wrote:
Quoting Michael Niedermayer <michaelni@gmx.at>:
On Mon, Apr 21, 2014 at 04:15:09PM +1000, Peter Ross wrote:
Hi,
Direct Stream Digital (DSD) is the name given to the 1-bit delta sigma encoding system found in audiophile equipment. It is an alternative to PCM.
[..]
1. DSD->PCM conversion results in a change to the sample rate. For example, 2.8224 MHz 1-bit DSD samples => 352.8 kHz PCM samples; and 5.6448 MHz 1-bit DSD samples => 705.6 kHz PCM samples.
a) Should libswresample return the new sample rate?
id tend to suggest that the sample rates should represent the true (in a mathematical sense) samplerates of the signals. And i realize that this definition is a bit fuzzy without a definition of what a sample is.
Right. Each DSD sample is 1-bit.
b) Should the user of libswresample be expected to know the change between DSD->PCM and populate the 'in_sample_rate' and 'out_sample_rate' accordingly?
id suggest that it should be handled like any other sample format but iam not working on this, you do, so there may be better options that iam not recognizing ...
Okay.
2. DoP encoding takes DSD 1-bit samples @ 2.8224 MHz and smushes them into 24-bit PCM @ 176.4 kHz. How can the DoP codec inform avcodec that the output packets have a different sample rate? Editing 'avctx->sample_rate' doesnt work because other modules expect this information to remain static.
iam not sure i understand the problem
where does mhz DSD -> khz PCM differ from mhz PCM -> khz PCM ?
DoP is an industry standard that uses PCM to deliver DSD samples to external DAC equipment.
The encoding stores 16 x 1-bit DSD samples into each 24-bit PCM sample. The high 8 bits of each PCM sample indicate an alternating magic number, so that capable DACs can detect the marker and process the DSD samples. This is known as bit-perfect DSD. Therefore a source stream of DSD samples @ 2.8224 Mhz is "encoded" into a 176.4kHz PCM stream (2.8224 x 10^6 / 16).
The challenge for FFmpeg is that libavcodec/dopenc.c needs to change the sample rate (from 2.8224 MHz to 176.4kHz). Our codecs have not traditionally done this; there is no concept of input and output sample rate.
A solution I have considered is adding AVCodecContext.dsd_sample_rate that would only apply to SAMPLE_FMT_DSD. The dopenc_init() function would read dsd_sample_rate and then set sample_rate.
there is some similar mess with AAC-SBR where a incorrect sample rate is stored about the 24bit 176.4kHz, can this be played by normal PCM decoders? that is, do the 8 or less high bits represent a downsampled version? also what about simply considering that 24bit encoding to be a opaque encoding like any other encoder produces ? there would be no sample rate on the output just a packet/frame rate [...] -- Michael GnuPG fingerprint: 9FF2128B147EF6730BADF133611EC787040B0FAB Many that live deserve death. And some that die deserve life. Can you give it to them? Then do not be too eager to deal out death in judgement. For even the very wise cannot see all ends. -- Gandalf
On Mon, Apr 28, 2014 at 10:21:48PM +0200, Michael Niedermayer wrote:
On Sat, Apr 26, 2014 at 04:42:27AM +0200, Peter Ross wrote:
Quoting Michael Niedermayer <michaelni@gmx.at>:
On Mon, Apr 21, 2014 at 04:15:09PM +1000, Peter Ross wrote:
Hi,
Direct Stream Digital (DSD) is the name given to the 1-bit delta sigma encoding system found in audiophile equipment. It is an alternative to PCM.
[..]
there is some similar mess with AAC-SBR where a incorrect sample rate is stored
thanks for that example.
about the 24bit 176.4kHz, can this be played by normal PCM decoders? that is, do the 8 or less high bits represent a downsampled version?
no. the marker alternates between 0x05 and 0xFA. "This has been chosen to minimize the click that might be experienced when the receiving hardware misinterpretes the data as PCM when it really is DSD. If this should happen it would create a tone around 88kHz and roughly -34db, nothing harmful and something that most D/A converters would suppress to some degree before it even reaches the loudspeaker." -- specification
also what about simply considering that 24bit encoding to be a opaque encoding like any other encoder produces ? there would be no sample rate on the output just a packet/frame rate
surely libavdevice will want to know the playback sample_rate. -- Peter (A907 E02F A6E5 0CD2 34CD 20D2 6760 79C5 AC40 DD6B)
On Sat, May 03, 2014 at 11:15:41PM +1000, Peter Ross wrote:
On Mon, Apr 28, 2014 at 10:21:48PM +0200, Michael Niedermayer wrote:
On Sat, Apr 26, 2014 at 04:42:27AM +0200, Peter Ross wrote:
Quoting Michael Niedermayer <michaelni@gmx.at>:
On Mon, Apr 21, 2014 at 04:15:09PM +1000, Peter Ross wrote:
Hi,
Direct Stream Digital (DSD) is the name given to the 1-bit delta sigma encoding system found in audiophile equipment. It is an alternative to PCM.
[..]
there is some similar mess with AAC-SBR where a incorrect sample rate is stored
thanks for that example.
about the 24bit 176.4kHz, can this be played by normal PCM decoders? that is, do the 8 or less high bits represent a downsampled version?
no. the marker alternates between 0x05 and 0xFA. "This has been chosen to minimize the click that might be experienced when the receiving hardware misinterpretes the data as PCM when it really is DSD. If this should happen it would create a tone around 88kHz and roughly -34db, nothing harmful and something that most D/A converters would suppress to some degree before it even reaches the loudspeaker." -- specification
also what about simply considering that 24bit encoding to be a opaque encoding like any other encoder produces ? there would be no sample rate on the output just a packet/frame rate
surely libavdevice will want to know the playback sample_rate.
yes, some downsample to sample rate, this could also be usefull for other formats in theory, 96khz aac decoded into 48khz pcm by skiping the higher frequency components or by skiping SBR [...] -- Michael GnuPG fingerprint: 9FF2128B147EF6730BADF133611EC787040B0FAB No great genius has ever existed without some touch of madness. -- Aristotle
participants (2)
-
Michael Niedermayer -
Peter Ross