Gentoo Forums
Gentoo Forums
Gentoo Forums
Quick Search: in
ac3dec and S/PDIF input, real-time playback [SOLVED]
View unanswered posts
View posts from last 24 hours

 
Reply to topic    Gentoo Forums Forum Index Multimedia
View previous topic :: View next topic  
Author Message
jimyx17
n00b
n00b


Joined: 20 May 2005
Posts: 6

PostPosted: Mon Nov 05, 2007 11:26 pm    Post subject: ac3dec and S/PDIF input, real-time playback [SOLVED] Reply with quote

Hi!!

sorry if my english is not as good as should.... but i'm trying for get dolby digital (ac3) sound from my xbox360 to the sound card of my computer. I wanted to use my pc as a a/v receiver and decode ac3 sound and play it through the analog output. So at last I wanted to have xbox-->spidf-->ac3dec-->speakers 5.1

I have a Terratec Aureon 5.1 mkII sound card, and i can see this devices:

Code:
controlC0  controlC1  midiC1D0  pcmC0D0c  pcmC0D0p  seq  timer


and the amixer command says this:

Code:

Simple mixer control 'Master',0
  Capabilities: pvolume pvolume-joined pswitch pswitch-joined
  Playback channels: Mono
  Limits: Playback 0 - 255
  Mono: Playback 73 [29%] [-34.73dB] [on]
Simple mixer control 'Line',0
  Capabilities: pvolume cvolume pswitch pswitch-joined cswitch cswitch-joined
  Playback channels: Front Left - Front Right
  Capture channels: Front Left - Front Right
  Limits: Playback 0 - 255 Capture 0 - 128
  Front Left: Playback 191 [75%] [34.38dB] [on] Capture 1 [1%] [0.00dB] [on]
  Front Right: Playback 191 [75%] [34.38dB] [on] Capture 1 [1%] [0.00dB] [on]
Simple mixer control 'Mic',0
  Capabilities: pvolume pvolume-joined cvolume pswitch pswitch-joined cswitch cswitch-joined cswitch-exclusive
  Capture exclusive group: 0
  Playback channels: Mono
  Capture channels: Mono
  Limits: Playback 0 - 255 Capture 0 - 128
  Mono: Playback 191 [75%] [34.38dB] [on] Capture 1 [1%] [0.00dB] [off]
Simple mixer control 'Mic Capture',0
  Capabilities: pswitch pswitch-joined
  Playback channels: Mono
  Mono: Playback [off]
Simple mixer control 'IEC958 In',0
  Capabilities: cswitch cswitch-joined
  Capture channels: Mono
  Mono: Capture [on]
Simple mixer control 'Input 1',0
  Capabilities: cswitch cswitch-joined cswitch-exclusive
  Capture exclusive group: 0
  Capture channels: Mono
  Mono: Capture [on]
Simple mixer control 'Input 2',0
  Capabilities: cswitch cswitch-joined cswitch-exclusive
  Capture exclusive group: 0
  Capture channels: Mono
  Mono: Capture [off]


and I configured asound.conf with this:

Code:

#pcm.!default {
#type hw
#  slave.pcm "upmix_20to51"
#  slave.pcm "upmix_to51"
#  slave.pcm "my51"
#  slave.pcm "front:CARD=V8235"
#}


pcm.upmix_10to51 {
    type plug
    slave.pcm lowpass_21to21
    slave.channels 3
    ttable {
        0.0     1       # left channel
        0.1     1       # copy left to right channel
        0.2     1       # and copy left to subwoofer
    }
}

pcm.upmix_20to51 {
    type plug
    slave.pcm lowpass_21to21
    slave.channels 3
    ttable {
        0.0     1       # left channel
        1.1     1       # right channel
        0.2     0.5     # mix left and right ...
        1.2     0.5     # ... channel for subwoofer
    }
}

pcm.lowpass_21to21 {
    type ladspa
    slave.pcm upmix_21to51
    path "/usr/lib/ladspa"
    channels 3
    plugins {
        0 {
            #The identity plugin (id 1098) just copies all channels from the input to the output without changes.
            id 1098 # Identity (Audio) (1098/identity_audio)
            policy duplicate
            input.bindings.0 "Input";
            output.bindings.0 "Output";
        }
        1 {
            #The second plugin, the low-pass plugin (id 1672) takes only the third channel, the subwoofer channel, and applies the low-pass filter to it.
            id 1672 # 4 Pole Low-Pass Filter with Resonance (FCRCIA) (1672/lp4pole_fcrcia_oa)
            policy none
            input.bindings.2 "Input";
            output.bindings.2 "Output";
            input {
                #The first control value is the cutoff frequency in Hz and the second is the resonance (0.0 to 4.0).
                controls [ 300 0 ]
            }
        }
    }
    #The unchanged channels 0 and 1 together with the filtered channel 2 are given to the next PCM.
}

pcm.upmix_21to51 {
    type plug
    slave.pcm "dmix51"
    slave.channels 6
    ttable {
        0.0     1       # front left
        1.1     1       # front right
        0.5     1       # rear left       (look at: -1-)
        1.4     1       # rear right     (look at: -1-)
        0.2     0.5    # center         (look at: -1-)
        1.2     0.5    # center         (look at: -1-)
        2.3     1       # subwoofer   (look at: -1-)
    }
}

pcm.upmix_allto51 {
  type plug
  slave.pcm "my51"
  slave.channels 6
  route_policy duplicate
}

pcm.!default {
  type plug
  slave.pcm "dmix51"
  slave.channels 6
  ttable {
        0.0   1       # front left
        1.1   1       # front right
        2.5   1       # rear left       (look at: -1-)
        3.4   1       # rear right     (look at: -1-)
        4.2   1       # center          (look at: -1-)
        5.3   1       # subwoofer   (look at: -1-)
  }
}

pcm.dmix51 {
  type dmix
  ipc_key 1024
  ipc_key_add_uid false
  ipc_perm 0666
  slave {
     pcm "hw:Audio"
     channels 6
     period_time 0
     period_size 1024
     buffer_size 8192
     rate 48000
  }
}

ctl.dmix51 {
  type hw
  card Audio
}

#### -1- ####
# ttable.INTERN.EXTERN VERH

# normally:
# 0 --> front left
# 1 --> front right
# 2 --> rear left
# 3 --> rear right
# 4 --> center
# 5 --> lfe

# Bei meiner Terratec Aureon 5.1 USB sind die Kanäle etwas vertauscht:
# 0 = vorne links
# 1 = vorne rechts
# 5 = hinten links
# 4 = hinten rechts
# 2 = center
# 3 = lfe
#### -1- ####



I tryed with mplayer, ac3dec, ac3jack and almost all stuff that I found without any result... Please I'm a newbie in sound stuff... somebody can help me... please!

Thanks a lot for your time if you read/ansewr this post and sorry if I'm making lost your time!


Last edited by jimyx17 on Wed Nov 07, 2007 10:53 pm; edited 1 time in total
Back to top
View user's profile Send private message
jimyx17
n00b
n00b


Joined: 20 May 2005
Posts: 6

PostPosted: Wed Nov 07, 2007 12:36 am    Post subject: Reply with quote

I've just read another post asking the same, and I find the answer doesn't work to me, and I think the problem is the syn word, because the miniapp never find this word in the spdif input.

Can Somebody probe it and tell if work or doesnt work?

This is the:

http://www.mail-archive.com/alsa-user@lists.sourceforge.net/msg13742.html

thanks a lot
Back to top
View user's profile Send private message
jimyx17
n00b
n00b


Joined: 20 May 2005
Posts: 6

PostPosted: Wed Nov 07, 2007 10:52 pm    Post subject: Reply with quote

Ok I've just see the problem. The miniapp is working fine, but need a modification. The problem is the length of the variable "byte". This is a 16 bits variable, but when the stream pass through the aplication move 24 bits to the left, so we lost information. The problem is solved if you change the variable type to uint32_t leaving the aplication as shows:
Code:

#include <stdio.h>

typedef unsigned char uint8_t;
typedef unsigned short uint16_t;
typedef unsigned long uint32_t;

#define SPDIF_SYNC      0x4e1ff872

struct spdif_head_t {
        uint32_t        sync;
        uint8_t         type;
        uint8_t         bsmod;
        uint16_t        databits;       
};

int spdif_sync(FILE *in, struct spdif_head_t *header)
{
        uint32_t byte;
        uint32_t dword = 0xffffffff;

        while ((byte = fgetc(in)) != EOF) {
      
                dword = dword >> 8 | (byte << 24);
                if (dword == SPDIF_SYNC) {
                        header->sync = dword;
                        if ((byte = fgetc(in)) == EOF)
                                return -1;
                        header->type = byte;
                        if ((byte = fgetc(in)) == EOF)
                                return -1;
                        header->bsmod = byte;
                        if ((byte = fgetc(in)) == EOF)
                                return -1;
                        header->databits = byte;
                        if ((byte = fgetc(in)) == EOF)
                                return -1;
                        header->databits |= byte << 8;
                        return 0;
                }
        }
       
        return -1;
}

int main(int argc, char **argv)
{
        char *stream_name = "stdin";
        FILE *in = stdin, *out = stdout;
        fpos_t fpos;
        int i, byte0, byte1, pos, last_pos;
        struct spdif_head_t header;

        last_pos = 0;
        while (spdif_sync(in, &header) == 0) {
        /*      fgetpos(in, &fpos);
                pos = *((int *) &fpos);
                printf("Found SPDIF sync at %010lx: %5x, len %5x\n", pos,
                                                        pos - last_pos,
                                                        header.databits / 8);
                last_pos = pos;
        */
                for (i = 0; i < header.databits / 8 / 2; i++) {
                        if ((byte1 = fgetc(in)) == EOF)
                                break;
                        if ((byte0 = fgetc(in)) == EOF)
                                break;
                        fputc(byte0, out);
                        fputc(byte1, out);
                }
        }

        return 0;
}


With this, you only must exec this command, and you'll have a realtime spdif/ac3 sound from your PC:

Code:
arecord -D spdif -f dat -t raw | spdifextract | ac3dec -6


Remember you must specify a 5.1 dev as default if you dont do it, you must specify the output dev with -D option of ac3dec
Back to top
View user's profile Send private message
cmd_
n00b
n00b


Joined: 27 Apr 2004
Posts: 11

PostPosted: Wed Sep 10, 2008 10:11 am    Post subject: Reply with quote

Hi jimyx17 I'm trying to reproduce your success with my computer but I have no luck.
My soundcard is a 1st generation Audigy Platinum (and 5.25" LiveDrive, with spdif in/out). I tried to get 5.1 dolby digital from xbox360 and a dvd player trough the spdif input.

Here is my .asoundrc
Code:
pcm.doom {   #To remap the swaped sub/center with rear channels for ET:QuakeWars
   slave.pcm surround51
   slave.channels 6
   type route
   ttable.0.0 1
   ttable.1.1 1
   ttable.2.4 1
   ttable.3.5 1
   ttable.4.2 1
   ttable.5.3 1
}


Here is the arecord --list-devices
Code:
# arecord -l
**** List of PLAYBACK Hardware Devices ****
card 0: Audigy [Audigy 1 [SB0090]], device 0: emu10k1 [ADC Capture/Standard PCM Playback]
  Subdevices: 32/32
  Subdevice #0: subdevice #0
  Subdevice #1: subdevice #1
  Subdevice #2: subdevice #2
  Subdevice #3: subdevice #3
  Subdevice #4: subdevice #4
  Subdevice #5: subdevice #5
  Subdevice #6: subdevice #6
  Subdevice #7: subdevice #7
  Subdevice #8: subdevice #8
  Subdevice #9: subdevice #9
  Subdevice #10: subdevice #10
  Subdevice #11: subdevice #11
  Subdevice #12: subdevice #12
  Subdevice #13: subdevice #13
  Subdevice #14: subdevice #14
  Subdevice #15: subdevice #15
  Subdevice #16: subdevice #16
  Subdevice #17: subdevice #17
  Subdevice #18: subdevice #18
  Subdevice #19: subdevice #19
  Subdevice #20: subdevice #20
  Subdevice #21: subdevice #21
  Subdevice #22: subdevice #22
  Subdevice #23: subdevice #23
  Subdevice #24: subdevice #24
  Subdevice #25: subdevice #25
  Subdevice #26: subdevice #26
  Subdevice #27: subdevice #27
  Subdevice #28: subdevice #28
  Subdevice #29: subdevice #29
  Subdevice #30: subdevice #30
  Subdevice #31: subdevice #31
card 0: Audigy [Audigy 1 [SB0090]], device 2: emu10k1 efx [Multichannel Capture/PT Playback]
  Subdevices: 8/8
  Subdevice #0: subdevice #0
  Subdevice #1: subdevice #1
  Subdevice #2: subdevice #2
  Subdevice #3: subdevice #3
  Subdevice #4: subdevice #4
  Subdevice #5: subdevice #5
  Subdevice #6: subdevice #6
  Subdevice #7: subdevice #7
card 0: Audigy [Audigy 1 [SB0090]], device 3: emu10k1 [Multichannel Playback]
  Subdevices: 1/1
  Subdevice #0: subdevice #0


And arecord --list-pcms
Code:
# arecord -L
default:CARD=Audigy
    Audigy 1 [SB0090], ADC Capture/Standard PCM Playback
    Default Audio Device
front:CARD=Audigy,DEV=0
    Audigy 1 [SB0090], ADC Capture/Standard PCM Playback
    Front speakers
rear:CARD=Audigy,DEV=0
    Audigy 1 [SB0090], ADC Capture/Standard PCM Playback
    Rear speakers
center_lfe:CARD=Audigy,DEV=0
    Audigy 1 [SB0090], ADC Capture/Standard PCM Playback
    Center and Subwoofer speakers
surround40:CARD=Audigy,DEV=0
    Audigy 1 [SB0090], ADC Capture/Standard PCM Playback
    4.0 Surround output to Front and Rear speakers
surround41:CARD=Audigy,DEV=0
    Audigy 1 [SB0090], ADC Capture/Standard PCM Playback
    4.1 Surround output to Front, Rear and Subwoofer speakers
surround50:CARD=Audigy,DEV=0
    Audigy 1 [SB0090], ADC Capture/Standard PCM Playback
    5.0 Surround output to Front, Center and Rear speakers
surround51:CARD=Audigy,DEV=0
    Audigy 1 [SB0090], ADC Capture/Standard PCM Playback
    5.1 Surround output to Front, Center, Rear and Subwoofer speakers
iec958:CARD=Audigy,DEV=0
    Audigy 1 [SB0090], ADC Capture/Standard PCM Playback
    IEC958 (S/PDIF) Digital Audio Output
null
    Discard all samples (playback) or generate zero samples (capture)


Spdif info from /proc/asound/card0/spdif-in when PCM signal is sent:
Code:
# cat /proc/asound/card0/spdif-in

CD-ROM S/PDIF In
No signal detected.

Optical or Coax S/PDIF In
Professional Mode     : no
Not Audio Data        : no
Copyright             : yes
Emphasis              : none
Mode                  : 0
Category Code         : 0x4
Generation Status     : copy
Source Mask           : 0
Channel Number        : unspec
Sample Rate           : 48000Hz
Clock Accuracy        : 1000ppm
S/PDIF Valid          : on
S/PDIF Locked         : on
Rate Locked           : on
Estimated Sample Rate : 47998


Spdif info from /proc/asound/card0/spdif-in when Dolby Digital 5.1 signal is sent:
Code:
# cat /proc/asound/card0/spdif-in

CD-ROM S/PDIF In
No signal detected.

Optical or Coax S/PDIF In
Professional Mode     : no
Not Audio Data        : yes
Copyright             : yes
Emphasis              : none
Mode                  : 0
Category Code         : 0x4
Generation Status     : copy
Source Mask           : 0
Channel Number        : unspec
Sample Rate           : 48000Hz
Clock Accuracy        : 1000ppm
S/PDIF Valid          : off
S/PDIF Locked         : on
Rate Locked           : on
Estimated Sample Rate : 47998


List from /proc/asound/card0/
Code:
# ls /proc/asound/card0/
codec97#0  emu10k1  fx8010_acode  fx8010_code  fx8010_gpr  fx8010_tram_addr  fx8010_tram_data  id  midi0  midi1  midi2  midi3  oss_mixer  pcm0c  pcm0p  pcm1c  pcm2c  pcm2p  pcm3p  spdif-in  voices  wavetableD1


I tried things like the commented in this post (in spanish but with some code): https://forums.gentoo.org/viewtopic.php?p=5209244

Thanks for all.
Back to top
View user's profile Send private message
Chewi
Developer
Developer


Joined: 01 Sep 2003
Posts: 886
Location: Edinburgh, Scotland

PostPosted: Mon Oct 25, 2010 2:32 pm    Post subject: Reply with quote

I tried this with my ASUS Xonar D2X but jitter resulted in horrible bursts of noise. I spoke to the original author of that code and he said very few cards, if any, have a PLL for dealing with the jitter. jimyx17 was using what is now a fairly inexpensive card though so I'd really like to know for sure whether he actually got it working. Are you out there, jimyx17?
Back to top
View user's profile Send private message
Display posts from previous:   
Reply to topic    Gentoo Forums Forum Index Multimedia All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum