5.1 Surround over HDMI: Solve one problem, another rises up.

UPDATE 1:  After a good night's sleep, and after doing a bit more reading on alsa-project.org (big props to this page), I managed to get a much better ~/.asoundrc together.  It solves all my problems, and I can do everything I need.  I've preserved the post below in case anyone else runs into these issues, and I'll post my solution as a response to this post.
UPDATE 2:  Looks like I celebrated too early.  Got more strange problems.  Screw it, I'm going back to PulseAudio.  I just wrote a wrapper script to kill and restart Pulse for applications that really, really need ALSA.
Okay.  I've almost completely worn out my fingers trying to get this working.  I feel like I'm playing Whack-a-Mole.  This is a bit of a lengthy post, but I'll try my best to describe every problem I've encountered in as much detail as I can, followed by the solutions I found, followed by the problems each solution brought with it.  By going through everything this way, mole by mole, hopefully it'll be easy to follow along and help me come to a universally working solution.
Summarized Version of Problems:
5.1 surround works only on specific applications which are robust enough to allow me to manually specify audio output options, and only if ALSA isn't configured at all
once I've configured ALSA, sound works on every application, but it's all downmixed to 2.0 stereo from this point on
installing PulseAudio lets me choose 5.1 surround as a default, but brings with it its own problems and drawbacks, namely the lack of passthrough support for encoded streams
Long-Winded Version:
I have my computer connected over HDMI to an AVR with a 5.1 surround speaker system.  At first, I didn't have anything configured in ~/.asoundrc (or its global equivalent, /etc/asound.conf).  Neither file existed, so everything was running off defaults.  I got the name and device number of my card from aplay, ran speaker-test and played a six-channel test file in mplayer.
$ aplay -l
**** List of PLAYBACK Hardware Devices ****
card 0: HDMI [HDA Intel HDMI], device 3: HDMI 0 [HDMI 0]
Subdevices: 1/1
Subdevice #0: subdevice #0
$ aplay -L
null
Discard all samples (playback) or generate zero samples (capture)
pulse
PulseAudio Sound Server
hdmi:CARD=HDMI,DEV=0
HDA Intel HDMI, HDMI 0
HDMI Audio Output
$ speaker-test -Dhdmi -c6
speaker-test 1.0.28
Playback device is hdmi
Stream parameters are 48000Hz, S16_LE, 6 channels
Using 16 octaves of pink noise
Rate set to 48000Hz (requested 48000Hz)
Buffer size range from 64 to 349504
Period size range from 32 to 174752
Using max buffer size 349504
Periods = 4
was set period_size = 174752
was set buffer_size = 349504
0 - Front Left
4 - Front Center
1 - Front Right
3 - Rear Right
2 - Rear Left
5 - LFE
Time per period = 21.868405
$ mplayer -ao alsa:device=hdmi -channels 6 Nums_5dot1_24_48000.wav
MPlayer SVN-r37224 (C) 2000-2014 MPlayer Team
210 audio & 441 video codecs
mplayer: could not connect to socket
mplayer: No such file or directory
Failed to open LIRC support. You will not be able to use your remote control.
Playing Nums_5dot1_24_48000.wav.
libavformat version 55.33.100 (internal)
Audio only file format detected.
Load subtitles in ./
==========================================================================
Opening audio decoder: [pcm] Uncompressed PCM audio decoder
AUDIO: 48000 Hz, 6 ch, s24le, 6912.0 kbit/100.00% (ratio: 864000->864000)
Selected audio codec: [pcm] afm: pcm (Uncompressed PCM)
==========================================================================
[AO_ALSA] Format s24le is not supported by hardware, trying default.
AO: [alsa] 48000Hz 6ch s16le (2 bytes per sample)
Video: no video
Starting playback...
A: 8.6 (08.5) of 9.0 (09.0) 0.3%
Exiting... (End of file)
Everything seemed well, all six channels played from the correct location on both tests, but I did realize that the device number of the card was 3, not 0.  A lot of applications that aren't as configurable expect the default card/device to be set properly, and audio won't work in those applications without specifying that in ALSA's configuration.  Knowing this, I set the following in my ~/.asoundrc:
pcm.!default {
type hw
card HDMI
device 3
ctl.!default {
type hw
card HDMI
device 3
This, however, ended up causing more problems.  Oh, it made sound work on everything by default after that, but only for one application at a time!  That surpised me, as I thought ALSA's big advantage over OSS is that it can multitask.  Running the speaker-test the way I did earlier turned out fine, but when I tried playing that test file in mplayer, things got weird again. Here's the output from mplayer:
$ mplayer -ao alsa -channels 6 Nums_5dot1_24_48000.wav
MPlayer SVN-r37224 (C) 2000-2014 MPlayer Team
210 audio & 441 video codecs
mplayer: could not connect to socket
mplayer: No such file or directory
Failed to open LIRC support. You will not be able to use your remote control.
Playing Nums_5dot1_24_48000.wav.
libavformat version 55.33.100 (internal)
Audio only file format detected.
Load subtitles in ./
==========================================================================
Opening audio decoder: [pcm] Uncompressed PCM audio decoder
AUDIO: 48000 Hz, 6 ch, s24le, 6912.0 kbit/100.00% (ratio: 864000->864000)
Selected audio codec: [pcm] afm: pcm (Uncompressed PCM)
==========================================================================
[AO_ALSA] alsa-lib: pcm_hw.c:1557:(snd_pcm_hw_open) open '/dev/snd/pcmC0D0p' failed (-2): No such file or directory
[AO_ALSA] Playback open error: No such file or directory
Failed to initialize audio driver 'alsa'
Could not open/initialize audio device -> no sound.
Audio: no sound
Video: no video
Exiting... (End of file)
Why the hell is it looking for pcmC0D0p?  It should be looking at pcmC0D3p.  Did it not get the memo from ~/.asoundrc?  Urgh.
I've also tried '-af channels=6' in place of '-channels 6' but the same result happened.  It does the same thing without the '-ao alsa' option, I just specified it to trim down the output, so that I wouldn't be copying and pasting all kinds of other errors about not finding OSS or JACK or other things I don't have installed.
If I symlink /dev/snd/pcmC0D0p to /dev/snd/pcmC0D3p, it'll fix the problem, but that feels like one ugly kludge.  I'd have to do it again over and over every time I reboot, too.
Not sure if this would help matters or not, but if anyone knows how to change my card's device number from 3 to 0, I'd like to try that as well, but I'm not sure how to do that sort of thing.  I'm just guessing it might be worth trying, since everything looks for card0/device0 by default, and that kludge I tried earlier did have an effect, so maybe if we can just switch those device numbers with each other, everything would work smoothly without having to force anything through ALSA's configuration at all.  I believe card0/device0 belongs to the Host Bridge... is there a way to have them trade their device numbers for one another's in a safe manner?
I can also get it to play if I specify the device like I did in my first test, using '-ao alsa:device=hdmi', but that defeats the purpose of getting good defaults set if I still have to set everything by hand before I play something.  If I try playing the test file without any options, like so:
$ mplayer Nums_5dot1_24_48000.wav
... it will play, but only in two-channel stereo, and the parts that should happen in the center, rear and LFE channels get downmixed into the left and right channels.
I can get it to work in aplay, though!  All six channels!  Not that I plan on using this as my primary multimedia software.
$ aplay -c6 Nums_5dot1_24_48000.wav
The only solution I found so far that allows me to have 5.1 audio by default is to install the PulseAudio server, which is able to find a sink/source named 'alsa_output.pci-0000_00_03.0.hdmi-surround' and lets me choose that as my default.  Only problem with this is that PulseAudio has its own problems.
Aside from the crackling sound issues in some Wine games, Pulse also has a much bigger drawback -- a complete lack of passthrough support, meaning I can't use encoded streams such as Dolby DTS and TrueHD with PulseAudio.  I have a Harman/Kardon AVR and I'd like to get my money's worth out of it, so I'd really like to figure out a solution in ALSA without using Pulse at all.
Does anyone know how I can have my cake and eat it, too?  I just need 5.1 surround, by default, in ALSA without PulseAudio.
HUGE thanks to anyone who tries to help here.  This is really making me sad and frustrated, I've been using Arch for quite a while now and this is the first real big stumper I've come across that forced me to post a thread.  Otherwise I've been having a wonderful time.
Edited because I tried something different that removed *some* issues, but the above problems still remain.
Last edited by Rybelda (2014-10-27 22:10:24)

Well, I thought I fixed it doing this...
pcm.!default {
type plug
slave.pcm "dmixer"
pcm.dmixer {
type dmix
ipc_key 1138
ipc_key_add_uid true
slave {
pcm "hw:0,3"
format S32_LE
channels 8
rate 192000
period_size 9600
buffer_size 38400
... but then realized it strangely makes applications that run at 640x480 have no sound at all.  No idea why the video resolution is screwing up the sound, but that's what's happening, because if I set the resolution any higher, the sound comes back.
I'm going back to PulseAudio, I feel like ALSA is mocking me.  I wrote a wrapper script for the few times where pure, Pulse-less ALSA will be necessary for me.  Here it is, in case it helps anyone else.  I've tested it with XBMC, it turns off Pulse and allows ALSA to pass through encoded streams unhindered.  It also works with some Wine applications that have scratchy audio glitches in Pulse.
#!/bin/bash
echo "autospawn = no" > $HOME/.config/pulse/client.conf
pulseaudio --kill &> /dev/null
"$*"
rm -f $HOME/.config/pulse/client.conf
pulseaudio --start &> /dev/null
I'm removing the SOLVED tag because technically I didn't resolve any of my original issues, I more or less gave up on what I wanted to do and found another way to satisfy my needs, but it still isn't as elegant as I had hoped for.  In any case, I'm done with this issue for now and the forseeable near-future, but if anyone has anything further to add, feel free.
Last edited by Rybelda (2014-10-27 22:32:55)

Similar Messages

  • I have a Compaq Presario CQ62-213AX but i can't get 5.1 surround over HDMI. How can i get this?

    My Compaq Presario CQ62-213AX should be able to output 5.1 surround over HDMI but in 'supported formats' only stereo is listed.
    This computer has a ATI Mobility Radeon™ HD 5430 and according to the specs,
    http://www.amd.com/us/products/notebook/graphics/a​ti-mobility-hd-5400/Pages/hd-5430-specs.aspx
    and here...
    "A special feature of the HD 5000 series is its ability to transmit HD audio formats (like Dolby True HD or DTS HD Master Audio) with up to 8 channels and 192 KHz / 24 Bit over HDMI 1.3a."
    http://www.notebookcheck.net/ATI-Mobility-Radeon-H​D-5430.23702.0.html
    it should work.
    My other HP laptop (DV7) is doing this fine so my system setup is OK.
    I have tried a full factory reset and have fully updated my system but it still doesn't work.
    Please tell me what i need to do to get it to work.
    Thanks,
    Tina.

    I can try-dunno how much help I'll be, though
    go here for Realtek drivers for surround sound
    http://www.realtek.com.tw/products/productsView.aspx?Langid=1&PFid=37&Level=5&Co nn=4&ProdID=144
    try this: go to Windows Sound, then playback devices, then click on speakers icon (should have realtek as default). Click on that, and click configure
    if realtek has a sound manager, try clicking on that, and a config dialog might appear
    sorry can't be much more help than that
    JB

  • After getting an update from 10.6.8 many of my programs were no longer able to open. How can I undo the update or solve this problem another way?

    After getting an update from 10.6.8 many of my programs were no longer able to open. How can I undo the update or solve this problem another way?

    Do you have a bootable clone from prior to the update? If so, roll back with that.
    Are your apps that won't open PPC and do they need Rosetta? Do you need to activate Rosetta?
    Have you considered reinstalling 10.6 from your install disc and then coming forward with the 10.6.8 Combo Updater, then doing software update and not including whatever it was you installed that caused this propblem?
    By the way - what update was it that caused this problem?

  • NVIDIA display over HDMI and ATI sound over HDMI using one mainboard

    Hello everyone,
    I was curious to know if it is possible to use a setup where I use an NVIDIA card to send display over HDMI to my receiver and at the same time I use an internal ATI chip to send audio over HDMI to the same receiver.
    In my setup it is a GA-MA78GM-S2H mainboard with a built in ATI HD3200 IGP and an NVIDIA 9500GT GPU and I'll be using XBMC as media centre.
    The problem is there is no hardware acceleration support for the display of full-hd (1080p 24) for the ATI chip, whereas NVIDIA using  VDPAU is.
    On the other hand the 9500GT doen not support audio over HDMI (unlike the newer models like GT210 or GT220), I can connect SPDIF to the NVIDIA card to allow some sort of audio over HDMI, but in that case I'll still have the bandwidth limitation associated with SPDIF.
    I tried to set up a box with both NVIDIA and catalyst drivers to use the above functions, but when I try to install catalyst drivers I get a hardware conflict notice that NVIDIA and Catalyst drivers cannot be installed at the same time on the same system.
    AFAIK I need the catalyst drivers (or hd-radeon) in order for also to recognize the device (?)
    Anyone any information if installing both drivers is required and possible? Or are there any other methods to achieve such set up?
    TIA,
    daf art

    Hello everyone,
    I was curious to know if it is possible to use a setup where I use an NVIDIA card to send display over HDMI to my receiver and at the same time I use an internal ATI chip to send audio over HDMI to the same receiver.
    In my setup it is a GA-MA78GM-S2H mainboard with a built in ATI HD3200 IGP and an NVIDIA 9500GT GPU and I'll be using XBMC as media centre.
    The problem is there is no hardware acceleration support for the display of full-hd (1080p 24) for the ATI chip, whereas NVIDIA using  VDPAU is.
    On the other hand the 9500GT doen not support audio over HDMI (unlike the newer models like GT210 or GT220), I can connect SPDIF to the NVIDIA card to allow some sort of audio over HDMI, but in that case I'll still have the bandwidth limitation associated with SPDIF.
    I tried to set up a box with both NVIDIA and catalyst drivers to use the above functions, but when I try to install catalyst drivers I get a hardware conflict notice that NVIDIA and Catalyst drivers cannot be installed at the same time on the same system.
    AFAIK I need the catalyst drivers (or hd-radeon) in order for also to recognize the device (?)
    Anyone any information if installing both drivers is required and possible? Or are there any other methods to achieve such set up?
    TIA,
    daf art

  • Problems with FLAC 5.1 audio over HDMI and mpv

    The last mpv update (0.7) seems to have changed the way it gets info about the audio playback device.
    Last week, I could play videos with FLAC 5.1 audio over HDMI without any problem. My .asoundrc was just:
    pcm.!default {
    type hw
    card 0
    device 3
    But after the last update, if I try to play a video while the default pcm device is set to HDMI, I get this error:
    mpv: ../audio/chmap_sel.c:89: mp_chmap_sel_add_map: Assertion `s->num_chmaps < (sizeof(s->chmaps) / sizeof((s->chmaps)[0]))' failed.
    Aborted (core dumped)
    I tried downmixing, since the problem seems the number of channels.
    I added this to my .asoundrc:
    pcm.!surround51 {
    type vdownmix
    slave.pcm "default"
    pcm.!surround40 {
    type vdownmix
    slave.pcm "default" {
    Now mpv starts without errors but I hear no sound.
    Everything is fine in mplayer, even without the downmixing in .asoundrc
    What should I add to my .asoundrc so that mpv recognises the playback device correctly?
    Last edited by x_nik2468 (2014-11-29 12:10:40)

    andreyv wrote:It will be fixed in mpv 0.7.1.
    So this is merely a mpv problem.
    Good to know, I'll just wait for the update

  • Sound over HDMI works halfway.[SOLVED]

    //After looking around, HDMI only sends the signals to turn down the HDMI connected device. I guess it's as good as it gets...//
    Using nVidia GT218 [ION] on Zotac Hd-id11.
    NVIDIA Driver Version: 260.19.44
    2.6.37-ARCH
    //pianobar uses libao. My config, ~/.libao, looks like this and fixed pianobar over hdmi//
    default_driver=alsa
    dev=hw:1,3
    Sound works over HDMI for most of my applications(Flash, Gnome player, Skype) but I have no volume leveler under alsamixer nor does pianobar output to HDMI unless I launch it twice. The error that allows pianobar to work over HDMI is
    ao_alsa WARNING: Unable to open surround playback. Trying default device...
    I'm wondering, is there something I'm missing?
    //this will have 4 outputs if you don't use sound.conf instead of just one//
    What alsamixer looks like on card 1
    //if you don't use a sound.conf file(see next section) the defaults will probably be hw1,7)//
    This plays "Front Center" over HDMI.
    $ aplay -D plughw:1,3 /usr/share/sounds/alsa/Front_Center.wav
    Playing WAVE '/usr/share/sounds/alsa/Front_Center.wav' : Signed 16 bit Little Endian, Rate 48000 Hz, Mono
    $ cat /etc/asound.conf
    pcm.!default {
    type plug
    slave.pcm {
    type hw
    card 1
    device 3
    //Turns out I didn't have to even make a sound.conf//
    $ cat /etc/modprobe.d/sound.conf
    options snd-hda-intel enable_msi=0 probe_mask=0xffff,0xfff2
    //snd_hda_codec_realtek is the codec used to replace snd_hda_codec_nvhdmi, make sure it's loaded//
    $ lsmod|grep '^snd' | column -t
    snd_hda_codec_hdmi 20024 1
    snd_hda_codec_realtek 224540 1
    snd_seq_dummy 1119 0
    snd_seq_oss 25232 0
    snd_seq_midi_event 4568 1 snd_seq_oss
    snd_seq 41912 5 snd_seq_dummy,snd_seq_oss,snd_seq_midi_event
    snd_pcm_oss 33950 0
    snd_mixer_oss 15366 1 snd_pcm_oss
    snd_usb_audio 70888 0
    snd_hda_intel 18988 3
    snd_usbmidi_lib 15361 1 snd_usb_audio
    snd_hda_codec 64796 3 snd_hda_codec_hdmi,snd_hda_codec_realtek,snd_hda_intel
    snd_hwdep 4804 2 snd_usb_audio,snd_hda_codec
    snd_pcm 59496 6 snd_hda_codec_hdmi,snd_pcm_oss,snd_usb_audio,snd_hda_intel,snd_hda_codec
    snd_timer 15687 2 snd_seq,snd_pcm
    snd_rawmidi 15512 1 snd_usbmidi_lib
    snd_page_alloc 6021 2 snd_hda_intel,snd_pcm
    snd_seq_device 4409 4 snd_seq_dummy,snd_seq_oss,snd_seq,snd_rawmidi
    snd 43987 20 snd_hda_codec_hdmi,snd_hda_codec_realtek,snd_seq_oss,snd_seq,snd_pcm_oss,snd_mixer_oss,snd_usb_audio,snd_hda_intel,snd_usbmidi_lib,snd_hda_codec,snd_hwdep,snd_pcm,snd_timer,snd_rawmidi,snd_seq_device
    $ ls -l /dev/snd
    total 0
    drwxr-xr-x 2 root root 80 Mar 13 10:22 by-path
    crw-rw----+ 1 root audio 116, 8 Mar 13 10:22 controlC0
    crw-rw----+ 1 root audio 116, 11 Mar 13 10:22 controlC1
    crw-rw----+ 1 root audio 116, 7 Mar 13 10:22 hwC0D2
    crw-rw----+ 1 root audio 116, 10 Mar 13 10:22 hwC1D1
    crw-rw----+ 1 root audio 116, 6 Mar 13 10:22 pcmC0D0c
    crw-rw----+ 1 root audio 116, 5 Mar 13 19:40 pcmC0D0p
    crw-rw----+ 1 root audio 116, 4 Mar 13 10:22 pcmC0D1p
    crw-rw----+ 1 root audio 116, 9 Mar 13 19:38 pcmC1D3p
    crw-rw----+ 1 root audio 116, 3 Mar 13 10:22 seq
    crw-rw----+ 1 root audio 116, 2 Mar 13 10:22 timer
    Last edited by seca (2011-03-22 03:43:43)

    I am also having this problem... I get this error when I play certain songs in pianobar:
    ao_alsa WARNING: Unable to open surround playback. Trying default device...
    I am not sure how to fix this

  • 10.7.1 Audio over HDMI Problem

    Hi All,
    Here is a breif history of my problems with audio over HDMI. From 10.6.3 to 10.6.7 everything was working great. I have a mid 2010 i7 iMac hooked up via HDMI to a Marantz receiver which is in turn hooked up to a Panny TV. Everything worked as it should, audio went out to the receiver and video to the TV. Then the upgrade to 10.6.8 began the trouble. On the Marantz, I have a visual representation of the audio input. The unit showed that the audio was intermittently "flashing out". That was confirmed while listening to the output of the iMac via the Marantz. The image to the Panny was solid. I tried a variety of fixes (grabbing system files from 10.6.7, PRAM reset, etc.) all to no avail. So I reverted back to 10.6.7. Recently I tried again. Upgraded to 10.6.8 and applied the supplimental update that was supposed to fix the audio over HDMI issue. No good there either. I got the same audio dropping out problem. So I figured I'd go all out and try to upgrade to Lion. The upgrade went smoothly but the problem has morphed a bit. Now when the Marantz is on the iMac input, the iMac doesn't output audio or video ver HDMI. The moment I switch to another input on the Marantz (DVD for example) the iMac senses a switch and outputs audio and video. (At least that is what Display and Sound preferences indicate, as I'm not on the correct input on the receiver, I have no way to verify that anything is actually happening). So I'm back to square one. Do I downgrade back to 10.6.7? Any opinions or similar experiences out there? TIA!!

    If anyone's curious, I seemed to have solved the problem the other night. I simply switched the HDMI input on the receiver. Previously it was going into the "game" HDMI input, and I switched it to the "DVD" HDMI input. I'm not really sure why that made a difference. As I mentioned before, all was fine under 10.6.7. Perhaps under 10.6.8 and later, Apple changed the HDCP and the Marantz can only make sense out of it on a "traditional video input" (ie DVD). That's the only explanation I can come up with. Oh well, all's well that end's well I guess.
    Thanks.

  • THE ONE WHO SOLVES THIS PROBLEM IS GREAT!

    I'm serious. I am so fed up I am with this problem. Ground rules: you must NOT just give me code. I need to be able to know why my problem is happening, and how to fix it myself. I'm a grad student and am bound by a code of conduct. I don't have any more time to spend investigating this. It could be something simple or complex...I am at a loss.
    Here is the situation: I'm developing this console java application on my Windows PC. When I run it on my pc, it runs in under a minute. However, when I transfer my program to the servers at my school (sun unix workstations) it takes a ridiculous amount of time to run the same program. I am told that 80% of the students in my class have their programs running in less than 5 minutes. Almost all of them didn't have to do any kind of optimizations. They just wrote it, and it worked. My program is averaging 10-15 min, but my prof runs it locally at school, and says it takes 40 min!
    The entire program is posted below. Please forgive me for not commenting so great. They were better at first, but when I started moving things around and changing everything, I threw comments out the window. Still, the existing comments should be helpful in understanding what I'm doing. NOTE: Below the code is the DTD that all the .xml files I'm parsing conforms to. Here are a few links to .xml files that represent part of the dataset. The actual dataset consists of 40 files totaling 30MB.
    http://www.geocities.com/c_t_r_11/items-1.xml
    http://www.geocities.com/c_t_r_11/items-10.xml
    http://www.geocities.com/c_t_r_11/items-20.xml
    the dtd is at:
    http://www.geocities.com/c_t_r_11/itemsdtd.txt
    And here is the code:
    /* Instructions:
    This program processes all files passed on the command line (to parse
    an entire diectory, type "java MyParser myFiles/*.xml" at the shell).
    At the point noted below, an individual XML file has been parsed into a
    DOM Document node. You should fill in code to process the node. Java's
    interface for the Document Object Model (DOM) is in package
    org.w3c.dom. The documentation is available online at
    http://java.sun.com/j2se/1.4/docs/api/index.html
    A tutorial of DOM can be found at:
    http://java.sun.com/webservices/docs/ea2/tutorial/doc/JAXPDOM.html#67581
    Some auxiliary methods have been written for you. You may find them
    useful.
    Modified by:
    Will
    import java.io.*;
    import java.text.*;
    import java.util.*;
    import javax.xml.parsers.DocumentBuilder;
    import javax.xml.parsers.DocumentBuilderFactory;
    import javax.xml.parsers.FactoryConfigurationError;
    import javax.xml.parsers.ParserConfigurationException;
    import org.w3c.dom.*;
    import org.xml.sax.SAXException;
    import org.xml.sax.SAXParseException;
    import org.xml.sax.ErrorHandler;
    class MyParser{
        static DocumentBuilder builder;
        static final String[] typeName = {
            "none",
            "Element",
            "Attr",
            "Text",
            "CDATA",
            "EntityRef",
            "Entity",
            "ProcInstr",
            "Comment",
            "Document",
            "DocType",
            "DocFragment",
            "Notation",
        static final String[] itemTags = {
            "Number_of_Bids",
            "Started",
            "Ends"
        static class MyErrorHandler implements ErrorHandler {
            public void warning(SAXParseException exception)
                    throws SAXException {
                fatalError(exception);
            public void error(SAXParseException exception)
                    throws SAXException {
                fatalError(exception);
            public void fatalError(SAXParseException exception)
                    throws SAXException {
                exception.printStackTrace();
                System.out.println("There should be no errors " +
                        "in the supplied XML files.");
                System.exit(3);
        /* Non-recursive (NR) version of Node.getElementsByTagName(...) */
        static Element[] getElementsByTagNameNR(Element e, String tagName) {
            Vector elements = new Vector();
            Node child = e.getFirstChild();
            while (child != null) {
                if (child instanceof Element && child.getNodeName().equals(tagName))
                    elements.add(child);
                child = child.getNextSibling();
            Element[] result = new Element[elements.size()];
            elements.copyInto(result);
            return result;
        /* Returns the first subelement of e matching the given tagName, or
        * null if one does not exist. */
        static Element getElementByTagNameNR(Element e, String tagName) {
            Node child = e.getFirstChild();
            while (child != null) {
                if (child instanceof Element && child.getNodeName().equals(tagName))
                    return (Element) child;
                child = child.getNextSibling();
            return null;
        /* Returns the text associated with the given element (which must have
        * type #PCDATA) as child, or "" if it contains no text. */
        static String getElementText(Element e) {
            if (e.getChildNodes().getLength() == 1) {
                Text elementText = (Text) e.getFirstChild();
                return elementText.getNodeValue();
            else
                return "";
        /* Returns the text (#PCDATA) associated with the first subelement X
        * of e with the given tagName. If no such X exists or X contains no
        * text, "" is returned. */
        static String getElementTextByTagNameNR(Element e, String tagName) {
            Element elem = getElementByTagNameNR(e, tagName);
            if (elem != null)
                return getElementText(elem);
            else
                return "";
        /* Returns the amount (in XXXXX.xx format) denoted by a money-string
        * like $3,453.23. Returns the input if the input is an empty string. */
        static String strip(String money) {
            if (money.equals(""))
                return money;
            else {
                double am = 0.0;
                NumberFormat nf = NumberFormat.getCurrencyInstance(Locale.US);
                try { am = nf.parse(money).doubleValue(); }
                catch (ParseException e) {
                    System.out.println("This method should work for all " +
                            "money values you find in our data.");
                    System.exit(20);
                nf.setGroupingUsed(false);
                return nf.format(am).substring(1);
        /* Process one items-???.xml file. */
        static void processFile(File xmlFile) {
            Document doc = null;
            try {
                doc = builder.parse(xmlFile);
            catch (IOException e) {
                e.printStackTrace();
                System.exit(3);
            catch (SAXException e) {
                System.out.println("Parsing error on file " + xmlFile);
                System.out.println("  (not supposed to happen with supplied XML files)");
                e.printStackTrace();
                System.exit(3);
            /* At this point 'doc' contains a DOM representation of an 'Items' XML
            * file. Use doc.getDocumentElement() to get the root Element. */
            System.out.println("Successfully parsed - " + xmlFile);
            /*Open the output files for each relation****************************/
            PrintWriter itemsFile = null, usersFile = null,
                    bidsFile = null, categoriesFile = null;
            /*Open files for writing each of the txt files******************/
            try{
                itemsFile = new PrintWriter(new BufferedOutputStream(new FileOutputStream("Items.dat", true)), true);
                usersFile = new PrintWriter(new BufferedOutputStream(new FileOutputStream("Users.dat", true)), true);
                bidsFile = new PrintWriter(new BufferedOutputStream(new FileOutputStream("Bids.dat", true)), true);
                categoriesFile = new PrintWriter(new BufferedOutputStream(new FileOutputStream("Categories.dat", true)), true);
            }catch(FileNotFoundException e){
                System.out.println("Error trying to open an output file: " + e.getMessage());
                System.exit(0);
            /*Parse content for each relation in turn********************/
            //Write to the Items.txt file
            NodeList itemNodes = doc.getDocumentElement().getElementsByTagName("Item");
            final String colSep = "|#|";
            String itemID = null;
            Element[] categories = null;
            NodeList bids = null;
            NodeList eBid = null;
            NodeList bidders = null;
            Element tempElement = null;
            Element itemElement = null;
            Element thisBid = null;
            String description = new String();
            for(int i=0; i<itemNodes.getLength(); i++){
                //Get the item Element for this iteration
                itemElement = (Element)itemNodes.item(i);
                /*Write out ItemID**************************************/
                itemID = itemElement.getAttribute("ItemID");
                itemsFile.print(itemID);
                itemsFile.print(colSep);
                /*Write out Name****************************************/
                itemsFile.print(getElementTextByTagNameNR(itemElement, "Name"));
                itemsFile.print(colSep);
                /*Write out the Currently element***********************/
                itemsFile.print(strip(getElementTextByTagNameNR(itemElement, "Currently")));
                itemsFile.print(colSep);
                /*Write out the Buy_Price element, if it exists*********/
                Element checkNode = null;
                if( (checkNode = getElementByTagNameNR(itemElement, "Buy_Price")) != null){
                    itemsFile.print(strip(checkNode.getFirstChild().getNodeValue()));
                itemsFile.print(colSep);
                /*Add the First_Bid element*****************************/
                itemsFile.print(strip(getElementTextByTagNameNR(itemElement, "First_Bid")));
                itemsFile.print(colSep);
                /*Now iterate over the next three elements, adding them in turn*/
                for(int j=0; j<itemTags.length;j++){
                    itemsFile.print(getElementTextByTagNameNR(itemElement, itemTags[j]));
                    itemsFile.print(colSep);
                /*Add the SellerID**************************************/
                itemsFile.print(getElementByTagNameNR(itemElement, "Seller").getAttribute("UserID")
                        + colSep);
                /*Finally, add the description.  Truncate, if necessary*/
                description = getElementTextByTagNameNR(itemElement, "Description");
                itemsFile.print(description.substring(0, Math.min(4000, description.length())));
                itemsFile.print(colSep);
                itemsFile.println();
                /*Locate all of the Categories******************************/
                categories = getElementsByTagNameNR(itemElement, "Category");
                /*For every category in this item, write a ItemID-Category pair*/
                for(int j=0; j<categories.length; j++){
                    categoriesFile.print(itemID + colSep);
                    categoriesFile.print(categories[j].getFirstChild().getNodeValue());
                    categoriesFile.println(colSep);
                if( (bids = itemElement.getElementsByTagName("Bid")) != null){
                    /*Go through the bids, writing the info***********/
                    for(int j=0; j<bids.getLength(); j++){
                        thisBid = (Element)bids.item(j);
                        bidsFile.print(getElementByTagNameNR(thisBid, "Bidder").getAttribute("UserID"));
                        bidsFile.print(colSep);
                        bidsFile.print(itemID);
                        bidsFile.print(colSep);
                        bidsFile.print(getElementTextByTagNameNR(thisBid, "Time"));
                        bidsFile.print(colSep);
                        bidsFile.print(strip(getElementTextByTagNameNR(thisBid, "Amount")));
                        bidsFile.println(colSep);
                /*write out userid and rating from any and all bidder nodes*/
                if( (bidders = itemElement.getElementsByTagName("Bidder")) != null){
                    for(int j=0; j<bidders.getLength(); j++){
                        usersFile.print(bidders.item(j).getAttributes().getNamedItem("UserID").getNodeValue());
                        usersFile.print(colSep);
                        usersFile.print(bidders.item(j).getAttributes().getNamedItem("Rating").getNodeValue());
                        usersFile.print(colSep);
                        //If there's a location node, write it
                        if( getElementByTagNameNR((Element)bidders.item(j), "Location") != null){
                            usersFile.print(getElementTextByTagNameNR((Element)bidders.item(j), "Location"));
                        usersFile.print(colSep);
                        //If there's a country node, write it
                        if( getElementByTagNameNR((Element)bidders.item(j), "Country") != null){
                            usersFile.print(getElementTextByTagNameNR((Element)bidders.item(j), "Country"));
                        usersFile.println(colSep);
                /*Now write out the Seller information*******************/
                usersFile.print(getElementByTagNameNR(itemElement, "Seller").getAttribute("UserID"));
                usersFile.print(colSep);
                usersFile.print(getElementByTagNameNR(itemElement, "Seller").getAttribute("Rating"));
                usersFile.print(colSep);
                usersFile.print(getElementTextByTagNameNR(itemElement, "Location"));
                usersFile.print(colSep);
                usersFile.print(getElementTextByTagNameNR(itemElement, "Country"));
                usersFile.println(colSep);
            itemsFile.close();
            usersFile.close();
            bidsFile.close();
            categoriesFile.close();
        public static void main (String[] args) {
            if (args.length == 0) {
                System.out.println("Usage: java MyParser [file] [file] ...");
                System.exit(1);
    /* Initialize parser. */
            try {
                DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
                factory.setValidating(true);
                factory.setIgnoringElementContentWhitespace(true);
                builder = factory.newDocumentBuilder();
                builder.setErrorHandler(new MyErrorHandler());
            catch (FactoryConfigurationError e) {
                System.out.println("unable to get a document builder factory");
                System.exit(2);
            catch (ParserConfigurationException e) {
                System.out.println("parser was unable to be configured");
                System.exit(2);
    /* Process all files listed on command line. */
            for (int i = 0; i < args.length; i++) {
                File currentFile = new File(args);
    processFile(currentFile);
    REMEMBER: Please do not just post the correct code. This will violate my code of conduct. I need tutoring--consultation.

    If I was trying to get someone else to do my work,
    I wouldn't be posting this saying what I have said
    would I? I'm not unwilling to do the work myself.From what was stated in your OP, it seemed that you
    were.I'm sorry if it seemed that way. I don't want something for nothing. I've spent MANY hours, which I don't have, trying to work this out. I have hit a point where I don't think my expertise is going to solve the problem. That's why I've turned to some experts who might say something along the lines of, "Hey, I know what that is...you're compiling against... and on the Unix box, it's compiling against..." I was NOT looking for something like, "See the code below that fixes your problem."
    The only problem is that I don't have direct access
    to the sun unix machines I'm running the app on,
    so I can't run a profiler on it. Ah, okay. So the only knowledge you have of how it
    performs on those machines is from your instructor
    running it and then telling you how long it took?No. I can SSH into the servers and run the program from a command line. But I wouldn't be able to install any profiler programs.
    You could ask your prof to run it with -Xprof or
    -Xhprof or whatever. Or you could put in a bunch of
    timing statements to get a rough idea of which parts
    are making it take that extra 39 minute or whatever.is -Xprof a java command line option? If so, I will look into doing that. Maybe it's available on the machines at school. Thanks for that input.

  • One of the usb devices attached to this computer has malfunctioned, and Windows does not recognize it. For assistance in solving this problem, click this message.

    I connected my sons Ipod Touch to my pc and it worked fine. Now, when I try to connect my iPad the following message comes up: One of the usb devices attached to this computer has malfunctioned, and Windows does not recognize it. For assistance in solving this problem, click this message.
    I checked the cable. It surely is not the cable. If I connect the iPod again it works fine. If I use the same cable with my pc and ipad at work or my other son’s laptop, it is working perfectly. It is only on my laptop where the iPod was connected. Something tells me it got something to do with the drivers that went corrupt or something when I connected the iPod.
    I searched the internet and I see a lot of people gets this message. Still no solved answers yet. Is there a place where I can download the drivers again or any other suggestions?
    Windows 7 and iPad 2
    Kind regards,

    I was hoping it would be something like a USB device conflict, but now the shuffle is the only thing connected...
    This article was one of the ones you linked to above in your initial post
    http://support.apple.com/kb/TS1369
    Under Part 9. Verify that USB drivers are installed, did you try the steps in If only "Unknown Device" appears?  That appears to be your situation.
    Also, you said that the shuffle initially worked well enough to do a sync, then it had the same problem again.  If you can get it to work again initially, before doing anything else, try the following.  Select the shuffle in the iTunes sidebar, under DEVICES.  Over to the right, go to the Summary tab.  By default, the checkbox for Enable disk use should be unchecked.  If so, check it and Apply the change.  See if that makes any difference. 
    (If Enable disk use was already checked, try unchecking it and Apply the change.  Basically, set it the "other way" and see if there is any improvement.)
    NOTE:  When disk use is enabled, you have to eject the iPod in iTunes before disconnecting it physically.
    If the disk use change makes a difference, that may provide a clue about the actual cause.

  • Using iPod shuffle 4th generation for first time and receiving the error : one of the USB devices attached to this computer has malfunctioned, and windows does not recognize it. For assistance in solving this problem, click this message

    Using iPod shuffle 4th generation for first time and receiving the error : one of the USB devices attached to this computer has malfunctioned, and windows does not recognize it. For assistance in solving this problem, click this message.
    Using win 7 and latest iTunes [10.6.3]. Have already gone through below links and did not find any solution.
    http://support.apple.com/kb/HT2292
    http://support.apple.com/kb/TS1369
    http://support.apple.com/kb/HT1923
    http://en.kioskea.net/forum/affich-17997-ipod-not-detected

    I was hoping it would be something like a USB device conflict, but now the shuffle is the only thing connected...
    This article was one of the ones you linked to above in your initial post
    http://support.apple.com/kb/TS1369
    Under Part 9. Verify that USB drivers are installed, did you try the steps in If only "Unknown Device" appears?  That appears to be your situation.
    Also, you said that the shuffle initially worked well enough to do a sync, then it had the same problem again.  If you can get it to work again initially, before doing anything else, try the following.  Select the shuffle in the iTunes sidebar, under DEVICES.  Over to the right, go to the Summary tab.  By default, the checkbox for Enable disk use should be unchecked.  If so, check it and Apply the change.  See if that makes any difference. 
    (If Enable disk use was already checked, try unchecking it and Apply the change.  Basically, set it the "other way" and see if there is any improvement.)
    NOTE:  When disk use is enabled, you have to eject the iPod in iTunes before disconnecting it physically.
    If the disk use change makes a difference, that may provide a clue about the actual cause.

  • OS X Delay over HDMI rougted through Xbox One (no delay using Windows)

    I have my Mac Mini (late 2012, OS X 10.8.5) connected via HDMI to my Xbox One, which is connected to my tv via HDMI. I have been experience a very annoying lag, especially noticeable when using my trackpad. There is a noticeable delay between my trackpad input and the movement of the cursor on my tv. At first, I thought this was due to the signal being routed through the Xbox, considering the fact that I never experienced any delay prior to routing through the Xbox One. I just assumed the Xbox was causing the slight delay. However, I have a Windows partition which I hardly ever use. Today, I booted into Windows for the first time since I've been routing through the Xbox. To my surprise, there was no delay whatsoever. My cursor moved perfectly in time with my trackpad input. Now that I've booted back into OS X, I'm experiencing the delay again. The Xbox does seem to be introducing the problem, as the delay is gone when I connect my Mac Mini directly to my tv, bypassing the Xbox. Why would there be a delay introduced to OS X when there is absolutely no delay on Windows 7? Is there something I can do to fix this? Is there some sort of preference that I can change in OS X to reduce this delay? I know the Xbox is introducing the problem, but it doesn't really seem to be the cause, and I can't help but think that it can be fixed since the Xbox isn't causing the problem with Windows running on the same computer.
    I know that I could just bypass the Xbox, but I don't want to do that. I'm aware that this would fix the probem, but it would be very inconvenient. Also, that doesn't really solve the problem, it just ignores it. Whatever the cause of the delay, it appears to be unique to OS X, not caused solely by the Xbox.

    try another smtp relay service...
    in either case, you may want to setup an SPF record for your domain which specifies the relay service is authorized to send mail for your domain.
    Jeff

  • I'm having problems with iPhoto and the facebook set-up.  Every time I attempt to do so it says an error has occured and try again later.  I have not seen a solution posted.  Therefore, how does one contact Apple to solve the problem?  I'm new to the worl

    I'm having problems with iPhoto and the facebook set-up.  Every time I attempt to do so it says an error has occured and try again later.  I have not seen a solution posted.  Therefore, how does one contact Apple to solve the problem?  I'm new to the world of iMac but I find it a bit frustrating trying to solve basic issues/problems:(

    For what it's worth, you posted this in 2011, and here in 2014 I am still having this same issue. Over the last two days, I have had to unlock my apple account 8 times. I didn't get any new devices. I haven't initiated a password reset. I didn't forget my password. I set up two factor authentication and have been able to do the unlocking with the key and using a code sent to one of my devices. 
    That all works.
    It's this having to unlock my account every time I go to use any of my devices. And I have many: iMac, iPad, iPad2, iPad mini, iPhone 5s, iPod touch (daughter), and my old iPhone 4 being used as an ipod touch now.  They are all synced, and all was working just fine.
    I have initiated an incident with Apple (again) but I know they are just going to suggest I change my Apple ID. It's a simple one, and one that I am sure others think is theirs. I don't want to change it. I shouldn't have to. Apple should be able to tell me who is trying to use it, or at least from where.
    Thanks for listening,
    Melissa

  • Recently, after cancelling the tick of a song, which is the next song after the one I am listening, in the song list, the canceled song will still run for the next song. I remember that it used not to happen like this. How can I solve this problem?

    Recently, after cancelling the tick of a song, which is the next song after the one I am listening, in the song list, the canceled song will still run for the next song. I remember that it used not to happen like this. How can I solve this problem?

    This looks like a change of behaviour in iTunes 12. Once songs are queued up to the Up Next list then they play whether ticked or not. If you want to skip certain songs already queued click the Up Next tool, then click the small X to the left of the song that appears when you hover over it.
    tt2

  • I recieve SMS and i hear established melody and I do't hear the person on all over SMS. How to solve this problem?

    Problem with an incoming message. For example, during my conversation the second line receives a call, I hear the sound in dynamics such as "piiiip piiiip," but when in this situation I recieve SMS and i hear established melody and I do't hear the person on all over SMS. How to solve this problem? Perhaps someone tell me? save in advance

    Not Charge
    - See:     
    iPod touch: Hardware troubleshooting
    iPhone and iPod touch: Charging the battery
    - Try another cable. The cable for 5G iPod (lightning connector) seems to be more prone to failure than the older cable.
    - Try another charging source
    - Inspect the dock connector on the iPod for bent or missing contacts, foreign material, corroded contacts, broken, missing or cracked plastic.
    - Make an appointment at the Genius Bar of an Apple store.
      Apple Retail Store - Genius Bar

  • I bought my iphone 5s a week before and now its volume "up" button is not working when pressed.Does anybody know what to do to make it work?I have a one year warranty.Should i give it to apple retail shop or is there any way to solve this problem?

    I bought my iphone 5s a week before and now its volume "up" button is not working when pressed.Does anybody know what to do to make it work?I have a one year warranty.Should i give it to apple retail shop or is there any way to solve this problem?

    IF it is a manufacturing defect and you bought the device from Apple or an authorized Apple retailer, then take it into Apple.

Maybe you are looking for

  • What is the best, most efficient way to read a .xls File and create a pipe-delimited .csv File?

    What is the best and most efficient way to read a .xls File and create a pipe-delimited .csv File? Thanks in advance for your review and am hopeful for a reply. ITBobbyP85

  • Reset Page Items

    I have page with multiple buttons.After any button is pressed I am branching to the same page. For Example If I enter data in the fields and press create button row is being inserted and branches to same page.But I need to reset the items after every

  • Material cost

    Hi All, Can somebody help me to calculate raw material cost of material on weekly basis. & with steps how the  system will calculate the matl. cost. Thanks in advance Vaibhav

  • Slow address lookup when writing emails

    When I begin a new email, and begin to type in the name or email address of the person I'm writing to, the lookup/auto-populate is painfully slow. Its so slow in fact, that I can usually type out the entire address before it returns the suggestion li

  • Acquiring a measure every x seconds from a Keithley 2000 multimeter

    Hi everybody, I'm working on a program on labview which should acquire a measure every x seconds from a Keithley2000 multimeter. I managed to acquire a single reading using the "Single Read VI" from Keithley 2000 Instrument Drivers. To acquire a read