Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

No 7.1 sound output #775

Open
Oldes opened this issue Nov 15, 2023 · 8 comments
Open

No 7.1 sound output #775

Oldes opened this issue Nov 15, 2023 · 8 comments

Comments

@Oldes
Copy link
Contributor

Oldes commented Nov 15, 2023

Hi,
I have this 7.1.wav test sound
Found from this page: https://www.reddit.com/r/hometheater/comments/11qqv95/surround_sound_test_files_in_almost_every_format/

And such a code (merged simple-enumeration.c and simple-playback.c examples):

void data_callback(ma_device* pDevice, void* pOutput, const void* pInput, ma_uint32 frameCount)
{
    ma_decoder* pDecoder = (ma_decoder*)pDevice->pUserData;
    if (pDecoder == NULL) {
        return;
    }
    ma_decoder_read_pcm_frames(pDecoder, pOutput, frameCount, NULL);
    (void)pInput;
}

int main(int argc, char** argv)
{
    ma_result result;
    ma_decoder decoder;
    ma_device_config deviceConfig;
    ma_device device;
    ma_context context;
    ma_device_info* pPlaybackDeviceInfos;
    ma_uint32 playbackDeviceCount;
    ma_device_info* pCaptureDeviceInfos;
    ma_uint32 captureDeviceCount;
    ma_uint32 iDevice;

    if (ma_context_init(NULL, 0, NULL, &context) != MA_SUCCESS) {
        printf("Failed to initialize context.\n");
        return -2;
    }

    result = ma_context_get_devices(&context, &pPlaybackDeviceInfos, &playbackDeviceCount, &pCaptureDeviceInfos, &captureDeviceCount);
    if (result != MA_SUCCESS) {
        printf("Failed to retrieve device information.\n");
        return -3;
    }

    printf("Playback Devices\n");
    for (iDevice = 0; iDevice < playbackDeviceCount; ++iDevice) {
        printf("    %u: %s\n", iDevice, pPlaybackDeviceInfos[iDevice].name);
    }

    printf("\n");

    printf("Capture Devices\n");
    for (iDevice = 0; iDevice < captureDeviceCount; ++iDevice) {
        printf("    %u: %s\n", iDevice, pCaptureDeviceInfos[iDevice].name);
    }

    if (argc < 2) {
        printf("No input file.\n");
        return -1;
    }

    result = ma_decoder_init_file(argv[1], NULL, &decoder);
    if (result != MA_SUCCESS) {
        printf("Could not load file: %s\n", argv[1]);
        return -2;
    }

    deviceConfig = ma_device_config_init(ma_device_type_playback);
    deviceConfig.playback.format   = decoder.outputFormat;
    deviceConfig.playback.channels = decoder.outputChannels;
    deviceConfig.sampleRate        = decoder.outputSampleRate;
    deviceConfig.dataCallback      = data_callback;
    deviceConfig.pUserData         = &decoder;

    if (ma_device_init(NULL, &deviceConfig, &device) != MA_SUCCESS) {
        printf("Failed to open playback device.\n");
        ma_decoder_uninit(&decoder);
        return -3;
    }

    if (ma_device_start(&device) != MA_SUCCESS) {
        printf("Failed to start playback device.\n");
        ma_device_uninit(&device);
        ma_decoder_uninit(&decoder);
        return -4;
    }

    printf("Press Enter to quit...");
    getchar();

    ma_device_uninit(&device);
    ma_decoder_uninit(&decoder);

    return 0;
}

I am testing it on Raspberry Pi:

Linux rpi 6.1.0-rpi4-rpi-v8 #1 SMP PREEMPT Debian 1:6.1.54-1+rpt2 (2023-10-05) aarch64 GNU/Linux

With an USB sound card.

My issue is, that when I run the test app with the mentioned sound input, which has 8 channels, I have just merged output from the front jack of the sound card. I was somehow expecting, that the sound would be from all channels, like expected.

Here is the debug output:

oldes@rpi:~/ $ ./test LPCM7.1.wav 
DEBUG: WASAPI backend is disabled.
DEBUG: DirectSound backend is disabled.
DEBUG: WinMM backend is disabled.
DEBUG: Core Audio backend is disabled.
DEBUG: sndio backend is disabled.
DEBUG: audio(4) backend is disabled.
DEBUG: OSS backend is disabled.
DEBUG: PulseAudio backend is disabled.
DEBUG: Attempting to initialize ALSA backend...
DEBUG: Loading library: libasound.so.2
DEBUG: Loading symbol: snd_pcm_open
DEBUG: Loading symbol: snd_pcm_close
DEBUG: Loading symbol: snd_pcm_hw_params_sizeof
...
DEBUG: Loading symbol: snd_config_update_free_global
DEBUG: System Architecture:
DEBUG:   Endian: LE
DEBUG:   SSE2:   NO
DEBUG:   AVX2:   NO
DEBUG:   NEON:   YES
Playback Devices
    0: Discard all samples (playback) or generate zero samples (capture)
    1: Playback/recording through the PulseAudio sound server
    2: Default Audio Device
    3: Rate Converter Plugin Using Libav/FFmpeg Library
    4: Rate Converter Plugin Using Samplerate Library
    5: Rate Converter Plugin Using Speex Resampler
    6: JACK Audio Connection Kit
    7: Open Sound System
    8: PulseAudio Sound Server
    9: Plugin using Speex DSP (resample, agc, denoise, echo, dereverb)
    10: Plugin for channel upmix (4,6,8)
    11: Plugin for channel downmix (stereo) with a simple spacialization
    12: bcm2835 Headphones, bcm2835 Headphones
    13: vc4-hdmi-0, MAI PCM i2s-hifi-0
    14: vc4-hdmi-1, MAI PCM i2s-hifi-0
    15: ICUSBAUDIO7D, USB Audio

Capture Devices
    0: Discard all samples (playback) or generate zero samples (capture)
    1: Playback/recording through the PulseAudio sound server
    2: Default Audio Device
    3: Rate Converter Plugin Using Libav/FFmpeg Library
    4: Rate Converter Plugin Using Samplerate Library
    5: Rate Converter Plugin Using Speex Resampler
    6: JACK Audio Connection Kit
    7: Open Sound System
    8: PulseAudio Sound Server
    9: Plugin using Speex DSP (resample, agc, denoise, echo, dereverb)
    10: Plugin for channel upmix (4,6,8)
    11: Plugin for channel downmix (stereo) with a simple spacialization
    12: ICUSBAUDIO7D, USB Audio
DEBUG: WASAPI backend is disabled.
DEBUG: DirectSound backend is disabled.
DEBUG: WinMM backend is disabled.
DEBUG: Core Audio backend is disabled.
DEBUG: sndio backend is disabled.
DEBUG: audio(4) backend is disabled.
DEBUG: OSS backend is disabled.
DEBUG: PulseAudio backend is disabled.
DEBUG: Attempting to initialize ALSA backend...
DEBUG: Loading library: libasound.so.2
DEBUG: Loading symbol: snd_pcm_open
DEBUG: Loading symbol: snd_pcm_close
DEBUG: Loading symbol: snd_pcm_hw_params_sizeof
...
DEBUG: Loading symbol: snd_config_update_free_global
DEBUG: System Architecture:
DEBUG:   Endian: LE
DEBUG:   SSE2:   NO
DEBUG:   AVX2:   NO
DEBUG:   NEON:   YES
INFO: [ALSA]
INFO:   Playback/recording through the PulseAudio sound server (Playback)
INFO:     Format:      16-bit Signed Integer -> 16-bit Signed Integer
INFO:     Channels:    8 -> 8
INFO:     Sample Rate: 48000 -> 48000
INFO:     Buffer Size: 480*3 (1440)
INFO:     Conversion:
INFO:       Pre Format Conversion:  NO
INFO:       Post Format Conversion: NO
INFO:       Channel Routing:        YES
INFO:       Resampling:             NO
INFO:       Passthrough:            NO
INFO:       Channel Map In:         {CHANNEL_FRONT_LEFT CHANNEL_FRONT_RIGHT CHANNEL_FRONT_CENTER CHANNEL_LFE CHANNEL_BACK_LEFT CHANNEL_BACK_RIGHT CHANNEL_SIDE_LEFT CHANNEL_SIDE_RIGHT}
INFO:       Channel Map Out:        {CHANNEL_FRONT_LEFT CHANNEL_FRONT_RIGHT CHANNEL_BACK_LEFT CHANNEL_BACK_RIGHT CHANNEL_FRONT_CENTER CHANNEL_LFE CHANNEL_SIDE_LEFT CHANNEL_SIDE_RIGHT}
Press Enter to quit...DEBUG: EPIPE (write)

Btw... I had to disable Pulseaudio, because with it I had just these 2 devices:

Playback Devices
    0: CM106 Like Sound Device Analog Stereo
    1: Built-in Audio Analog Stereo

And in the debug output was just a stereo output:

INFO: [PulseAudio] Playback attr: maxlength=57600, tlength=19200, prebuf=-1, minreq=-1, fragsize=19200; periodSizeInFrames=1200
INFO: [PulseAudio] Playback sample spec: format=16-bit Signed Integer, channels=2, rate=44100
INFO: [PulseAudio] Playback actual attr: maxlength=57600, tlength=17632, prebuf=14108, minreq=3528, fragsize=19200; internalPeriodSizeInFrames=4800
INFO: [PulseAudio]
INFO:   CM106 Like Sound Device Analog Stereo (Playback)
INFO:     Format:      16-bit Signed Integer -> 16-bit Signed Integer
INFO:     Channels:    8 -> 2
INFO:     Sample Rate: 48000 -> 44100
INFO:     Buffer Size: 4800*3 (14400)
INFO:     Conversion:
INFO:       Pre Format Conversion:  NO
INFO:       Post Format Conversion: NO
INFO:       Channel Routing:        YES
INFO:       Resampling:             YES
INFO:       Passthrough:            NO
INFO:       Channel Map In:         {CHANNEL_FRONT_LEFT CHANNEL_FRONT_RIGHT CHANNEL_FRONT_CENTER CHANNEL_LFE CHANNEL_BACK_LEFT CHANNEL_BACK_RIGHT CHANNEL_SIDE_LEFT CHANNEL_SIDE_RIGHT}
INFO:       Channel Map Out:        {CHANNEL_FRONT_LEFT CHANNEL_FRONT_RIGHT}

Any idea, what I must do to have the output from all channels? My goal is to have a full surround output from MiniAudio.

Btw.. the sound plays as expected, when I use:

oldes@rpi:~/ $ aplay -D surround71 -t wav ~/LPCM7.1.wav 
Playing WAVE '/home/oldes/LPCM7.1.wav' : Signed 16 bit Little Endian, Rate 48000 Hz, Channels 8
@Oldes
Copy link
Contributor Author

Oldes commented Nov 15, 2023

Hm... when I read the log here... maybe the problem is, that the playback device is:

1: Playback/recording through the PulseAudio sound server

while it probably should be:

15: ICUSBAUDIO7D, USB Audio

@Oldes
Copy link
Contributor Author

Oldes commented Nov 15, 2023

With the device 15 it reports conversion to stereo:

INFO: [ALSA]
INFO:   ICUSBAUDIO7D, USB Audio (Playback)
INFO:     Format:      16-bit Signed Integer -> 16-bit Signed Integer
INFO:     Channels:    8 -> 2
INFO:     Sample Rate: 48000 -> 48000
INFO:     Buffer Size: 1024*3 (3072)
INFO:     Conversion:
INFO:       Pre Format Conversion:  NO
INFO:       Post Format Conversion: NO
INFO:       Channel Routing:        YES
INFO:       Resampling:             NO
INFO:       Passthrough:            NO
INFO:       Channel Map In:         {CHANNEL_FRONT_LEFT CHANNEL_FRONT_RIGHT CHANNEL_FRONT_CENTER CHANNEL_LFE CHANNEL_BACK_LEFT CHANNEL_BACK_RIGHT CHANNEL_SIDE_LEFT CHANNEL_SIDE_RIGHT}
INFO:       Channel Map Out:        {CHANNEL_FRONT_LEFT CHANNEL_FRONT_RIGHT}

@Oldes
Copy link
Contributor Author

Oldes commented Nov 15, 2023

Maybe I should also post here output from aplay -L:

null
    Discard all samples (playback) or generate zero samples (capture)
default
    Playback/recording through the PulseAudio sound server
sysdefault
    Default Audio Device
lavrate
    Rate Converter Plugin Using Libav/FFmpeg Library
samplerate
    Rate Converter Plugin Using Samplerate Library
speexrate
    Rate Converter Plugin Using Speex Resampler
jack
    JACK Audio Connection Kit
oss
    Open Sound System
pulse
    PulseAudio Sound Server
speex
    Plugin using Speex DSP (resample, agc, denoise, echo, dereverb)
upmix
    Plugin for channel upmix (4,6,8)
vdownmix
    Plugin for channel downmix (stereo) with a simple spacialization
hw:CARD=Headphones,DEV=0
    bcm2835 Headphones, bcm2835 Headphones
    Direct hardware device without any conversions
plughw:CARD=Headphones,DEV=0
    bcm2835 Headphones, bcm2835 Headphones
    Hardware device with all software conversions
sysdefault:CARD=Headphones
    bcm2835 Headphones, bcm2835 Headphones
    Default Audio Device
dmix:CARD=Headphones,DEV=0
    bcm2835 Headphones, bcm2835 Headphones
    Direct sample mixing device
usbstream:CARD=Headphones
    bcm2835 Headphones
    USB Stream Output
hw:CARD=vc4hdmi0,DEV=0
    vc4-hdmi-0, MAI PCM i2s-hifi-0
    Direct hardware device without any conversions
plughw:CARD=vc4hdmi0,DEV=0
    vc4-hdmi-0, MAI PCM i2s-hifi-0
    Hardware device with all software conversions
sysdefault:CARD=vc4hdmi0
    vc4-hdmi-0, MAI PCM i2s-hifi-0
    Default Audio Device
hdmi:CARD=vc4hdmi0,DEV=0
    vc4-hdmi-0, MAI PCM i2s-hifi-0
    HDMI Audio Output
dmix:CARD=vc4hdmi0,DEV=0
    vc4-hdmi-0, MAI PCM i2s-hifi-0
    Direct sample mixing device
usbstream:CARD=vc4hdmi0
    vc4-hdmi-0
    USB Stream Output
hw:CARD=vc4hdmi1,DEV=0
    vc4-hdmi-1, MAI PCM i2s-hifi-0
    Direct hardware device without any conversions
plughw:CARD=vc4hdmi1,DEV=0
    vc4-hdmi-1, MAI PCM i2s-hifi-0
    Hardware device with all software conversions
sysdefault:CARD=vc4hdmi1
    vc4-hdmi-1, MAI PCM i2s-hifi-0
    Default Audio Device
hdmi:CARD=vc4hdmi1,DEV=0
    vc4-hdmi-1, MAI PCM i2s-hifi-0
    HDMI Audio Output
dmix:CARD=vc4hdmi1,DEV=0
    vc4-hdmi-1, MAI PCM i2s-hifi-0
    Direct sample mixing device
usbstream:CARD=vc4hdmi1
    vc4-hdmi-1
    USB Stream Output
hw:CARD=ICUSBAUDIO7D,DEV=0
    ICUSBAUDIO7D, USB Audio
    Direct hardware device without any conversions
plughw:CARD=ICUSBAUDIO7D,DEV=0
    ICUSBAUDIO7D, USB Audio
    Hardware device with all software conversions
sysdefault:CARD=ICUSBAUDIO7D
    ICUSBAUDIO7D, USB Audio
    Default Audio Device
front:CARD=ICUSBAUDIO7D,DEV=0
    ICUSBAUDIO7D, USB Audio
    Front output / input
surround21:CARD=ICUSBAUDIO7D,DEV=0
    ICUSBAUDIO7D, USB Audio
    2.1 Surround output to Front and Subwoofer speakers
surround40:CARD=ICUSBAUDIO7D,DEV=0
    ICUSBAUDIO7D, USB Audio
    4.0 Surround output to Front and Rear speakers
surround41:CARD=ICUSBAUDIO7D,DEV=0
    ICUSBAUDIO7D, USB Audio
    4.1 Surround output to Front, Rear and Subwoofer speakers
surround50:CARD=ICUSBAUDIO7D,DEV=0
    ICUSBAUDIO7D, USB Audio
    5.0 Surround output to Front, Center and Rear speakers
surround51:CARD=ICUSBAUDIO7D,DEV=0
    ICUSBAUDIO7D, USB Audio
    5.1 Surround output to Front, Center, Rear and Subwoofer speakers
surround71:CARD=ICUSBAUDIO7D,DEV=0
    ICUSBAUDIO7D, USB Audio
    7.1 Surround output to Front, Center, Side, Rear and Woofer speakers
iec958:CARD=ICUSBAUDIO7D,DEV=0
    ICUSBAUDIO7D, USB Audio
    IEC958 (S/PDIF) Digital Audio Output
dmix:CARD=ICUSBAUDIO7D,DEV=0
    ICUSBAUDIO7D, USB Audio
    Direct sample mixing device
usbstream:CARD=ICUSBAUDIO7D
    ICUSBAUDIO7D
    USB Stream Output

@mackron
Copy link
Owner

mackron commented Nov 15, 2023

In the PulseAudio case it's reporting only 2 channels so that explains why surround output wouldn't be working. Why it's reporting only 2 channels I couldn't tell you.

For the ALSA case it's a different situation. It's detecting the entire 8 channels as expected so it should be outputting correctly. The output channel map (which I'm assuming you've specified in the device config?) is the same, albeit with channels in a different order. In this case miniaudio's channel converter should detect this and do it's channel conversion as a simple shuffle. As a test, what happens if you leave the channel map as it's defaults in the device config? Do you at least get audio out of each speaker, even though they're not in the right order?

@mackron
Copy link
Owner

mackron commented Nov 15, 2023

Nevermind, I just saw in your code that you're indeed not passing in a channel map. For some reason my brain just totally glossed over the code in your comment...

I'm not entirely sure what's going here.

@Oldes
Copy link
Contributor Author

Oldes commented Nov 16, 2023

Right, the above output is without passing a channel map.. I can modify the Channel Map In using channel map as an input, but not the output. I believe it must be some system misconfiguration on my side, just don't know where:/

The sound is ok when I do speaker-test:

oldes@rpi:~ $ speaker-test -t wav -D hw:CARD=ICUSBAUDIO7D,DEV=0 -c 8

speaker-test 1.2.8

Playback device is hw:CARD=ICUSBAUDIO7D,DEV=0
Stream parameters are 48000Hz, S16_LE, 8 channels
WAV file(s)
Rate set to 48000Hz (requested 48000Hz)
Buffer size range from 96 to 96000
Period size range from 48 to 48000
Using max buffer size 96000
Periods = 4
was set period_size = 24000
was set buffer_size = 96000
 0 - Front Left
 2 - Front Center
 1 - Front Right
 5 - Side Right
 7 - Side Right
 4 - Side Left
 6 - Side Left
 3 - LFE

@Oldes
Copy link
Contributor Author

Oldes commented Nov 16, 2023

This is also working:

oldes@rpi:~ $ aplay -D surround71:CARD=ICUSBAUDIO7D,DEV=0 -t wav  ~/LPCM7.1.wav 
Playing WAVE '/home/oldes/LPCM7.1.wav' : Signed 16 bit Little Endian, Rate 48000 Hz, Channels 8

@mackron
Copy link
Owner

mackron commented Feb 28, 2024

I don't know exactly what's causing this. My suspicion is that it's a PulseAudio configuration error somewhere, but I can't know for sure. Does aplay work when you use the default device (Playback/recording through the PulseAudio sound server)? In miniaudio there's actually a back door to use a specific device for ALSA. Maybe that could be worth a try? To do it, you can declare a device ID, and then use strcpy() to specify the name of the device inside the device ID:

ma_device_id id;
strcpy(id.alsa, "surround71:CARD=ICUSBAUDIO7D,DEV=0");
...
deviceConfig.playback.pDeviceID = &id; // <-- Specify the ID via the device config.

That might give you some idea as to whether or not it's a PulseAudio configuration thing, or maybe a miniaudio thing.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants