You are not logged in.

#1 2012-10-01 23:52:26

adam777
Member
Registered: 2012-05-28
Posts: 161

[Solved] ALSA - Play Audio As Is With No Conversion

Hello all,
I have an issue with ALSA I hope you can help me sort out.
For the sake of this post, I'll refer to everything as if played by mplayer2, since the output is much easier this way.

Basically, I want to play everything "as-is", in regards to samplerate and format.
That is, playing music at 16bit/44.1Khz as such, playing movie audio at 16bit/48Khz as such, playing HD audio at 24bit/96Khz as such and so on.

Now, my first attempt was trying to access the HW directly using mplayer's --ao=alsa:device=hw=0.0 and not limiting the format.
Both samples played at correct sample rate but were outputted at 16 bit, since the hardware supposedly do not support floating point, and the output reverted to default.

Selected audio codec: FLAC (Free Lossless Audio Codec) [libavcodec]
AUDIO: 44100 Hz, 2 ch, s16le, 0.0 kbit/0.00% (ratio: 0->176400)
[AO_ALSA] Format floatle is not supported by hardware, trying default.
AO: [alsa] 44100Hz 2ch s16le (2 bytes per sample)

Selected audio codec: Uncompressed PCM [pcm]
AUDIO: 96000 Hz, 2 ch, s24be, 4608.0 kbit/100.00% (ratio: 576000->576000)
[AO_ALSA] Format floatle is not supported by hardware, trying default.
AO: [alsa] 96000Hz 2ch s16le (2 bytes per sample)

Note the Format floatle is not supported by hardware part.

This seemed a bit weird as using alsa without accessing the hardware directly (going through vmix), the output is indeed floating point.
That is, playing with --ao=alsa I get the following (obviously everything is sampled to the default 48Khz):

Selected audio codec: FLAC (Free Lossless Audio Codec) [libavcodec]
AUDIO: 44100 Hz, 2 ch, s16le, 0.0 kbit/0.00% (ratio: 0->176400)
AO: [alsa] 48000Hz 2ch floatle (4 bytes per sample)

Selected audio codec: Uncompressed PCM [pcm]
AUDIO: 96000 Hz, 2 ch, s24be, 4608.0 kbit/100.00% (ratio: 576000->576000)
AO: [alsa] 48000Hz 2ch floatle (4 bytes per sample)

Note that the output format is floatle.

So, I tried specifying --ao=alsa:device=hw=0.0 --format=floatle, only for it to fail as in the first case and reverting to default 16 bit and correct sample rate.

Specifying the required format directly works for the flac sample (s16le, same as the default) but fails for the HD sample (s24be), as expected - I can remember from my Windows days not so long ago I had to output 24 bit audio padded as 32 bit for it to work.

This lead me to my next attempt: --ao=alsa:device=hw=0.0 --format=s32le, which as far as I understand is 32 bit, but not floating point, which isn't exactly what I need.
Anyway, both files played fine with this mode for the few seconds I tried (assuming the remaining bits were padded with zeros), but real-life files (such as movie soundtrack) produced noticeable audio distortions (cracks and pops of all kinds).

So, I'm back to where I began.
Seems like I need to specify the hardware (device=..._) to get correct sample rate, but then I can't get correct format, or let it go via dmix and then the sample rate is wrong.
Now, having giving it a bit more thought, I realized dmix is outputting anything successfully as floating point, so I guess it pads whatever bits needed with zeros, which is just fine.
Assuming the above is correct, is it possible to write something in my .asoundrc file so that input samplerate is preserved?
I'm not very optimistic as it kind of against the whole idea of software mixing, but who knows..
If there's any way of convincing ALSA that my card is perfectly fine when being fed with floating point directly (device=...), that's an option too.

Bottom line, is there a way to make everything sent to card as-is?

That was long... sorry smile
Thanks, Adam.

Last edited by adam777 (2012-10-03 07:45:17)

Offline

#2 2012-10-02 02:10:59

ZekeSulastin
Member
Registered: 2010-09-20
Posts: 266

Re: [Solved] ALSA - Play Audio As Is With No Conversion

Not sure about asoundrc, but as of version 2.0 pulseaudio can automatically change the sample rate of some sound cards based on the incoming data (you never did mention what card you had >.>) while doing application mixing etc. (and resampling if needed).  Maybe give that a shot?

Offline

#3 2012-10-02 03:07:43

GogglesGuy
Member
From: Rocket City
Registered: 2005-03-29
Posts: 610
Website

Re: [Solved] ALSA - Play Audio As Is With No Conversion

adam777 wrote:

Hello all,
I have an issue with ALSA I hope you can help me sort out.
For the sake of this post, I'll refer to everything as if played by mplayer2, since the output is much easier this way.

Basically, I want to play everything "as-is", in regards to samplerate and format.
That is, playing music at 16bit/44.1Khz as such, playing movie audio at 16bit/48Khz as such, playing HD audio at 24bit/96Khz as such and so on.

Sounds reasonable...

adam777 wrote:

Now, my first attempt was trying to access the HW directly using mplayer's --ao=alsa:device=hw=0.0 and not limiting the format.
Both samples played at correct sample rate but were outputted at 16 bit, since the hardware supposedly do not support floating point, and the output reverted to default.

...

Note the Format floatle is not supported by hardware part.

This seemed a bit weird as using alsa without accessing the hardware directly (going through vmix), the output is indeed floating point.

So yes, your hardware doesn't support floating point. Don't compare the hw device to the more higher level interfaces (default,surround,plughw). The higher level interfaces provide additional sample formats which will be converted on the fly to the specific hw device capabilities.

adam777 wrote:

Bottom line, is there a way to make everything sent to card as-is?

That would depend on the input format. Even some 24bit audio files may need some additional padding. If you want to know what your card supports, compile and run the following program: http://www.volkerschatz.com/noise/alsacap.c.

For example, this the output on my machine:

Card 0, ID `Intel', name `HDA Intel'
  Device 0, ID `ALC268 Analog', name `ALC268 Analog', 1 subdevices (1 available)
    2 channels, sampling rate 44100..192000 Hz
    Sample formats: S16_LE, S32_LE
      Subdevice 0, name `subdevice #0'

Last edited by GogglesGuy (2012-10-02 03:09:43)

Offline

#4 2012-10-02 13:09:54

adam777
Member
Registered: 2012-05-28
Posts: 161

Re: [Solved] ALSA - Play Audio As Is With No Conversion

GogglesGuy, thanks for the tip.
My output reads:

Card 0, ID `Intel', name `HDA Intel'
  Device 0, ID `STAC92xx Analog', name `STAC92xx Analog', 1 subdevices (1 available)
    2..4 channels, sampling rate 44100..192000 Hz
    Sample formats: S16_LE, S32_LE
      Subdevice 0, name `subdevice #0'

So I suppose, It indeed does not support floating point.

ZekeSulastin, I may give PulseAudio a spin, though I'm not entirely sold on it.

I'll update if I find something of interest.

Offline

#5 2012-10-02 14:06:54

brebs
Member
Registered: 2007-04-03
Posts: 3,742

Re: [Solved] ALSA - Play Audio As Is With No Conversion

adam777 wrote:

Bottom line, is there a way to make everything sent to card as-is?

You can avoid dmix, but doing so is probably more annoying than it's worth - e.g. *something* will have to convert away from floatle to a format your hardware can use.

I think a good test would be to run your highest-quality audio through dmix, converting it to 48k S16_LE format, then see if you can actually hear any difference wink

For an example ~/.asoundrc to achieve this, see my sig.

Last edited by brebs (2012-10-02 14:08:09)

Offline

#6 2012-10-03 07:45:03

adam777
Member
Registered: 2012-05-28
Posts: 161

Re: [Solved] ALSA - Play Audio As Is With No Conversion

I've already came across your config file, brebs smile
Having tried PuleAudio, it was way too complicated for my taste, so I reverted to ALSA.
That being said, at the moment I'm using a pretty bad sound setup (built-in audio card and notebook speakers), once I setup something more serious (external DAC etc.), hopefully soon, I'll revisit the situation.

Thanks all, marking as solved for the time being.

Offline

Board footer

Powered by FluxBB