Menu

how to add audio to DxTuner

ronhud
2006-07-21
2012-10-29
  • ronhud

    ronhud - 2006-07-21

    First, thanks to all of the regulars here whose posts have been a tremendous help in getting me going on my Directshow TV Tuner Card project.

    I'm using ATI HDTV Wonder and the video works fine in DxTuner. I've tried a lot of things to get the audio to work, but I'm having a hard time. I've been a database and .NET developer for many years, but this project is the most-challenging ever.

    I would appreciate if someone could give me some direction as to how you would go about adding audio to DxTuner. The relevant area of the code is posted below to show how DxTuner works. I'm able to use Graphedit and see everything. Thanks a lot for any help anyone can offer:

            // Attach the filter graph to the capture graph
            int hr = captureGraphBuilder.SetFiltergraph(this.graphBuilder);
            DsError.ThrowExceptionForHR(hr);
    
            //Add the Video input device to the graph
            hr = graphBuilder.AddFilter(theDevice, "source filter");
            DsError.ThrowExceptionForHR(hr);
    
            //Render any preview pin of the device
            hr = captureGraphBuilder.RenderStream(PinCategory.Preview, MediaType.Video, theDevice, null, null);
            DsError.ThrowExceptionForHR(hr);
    
     
    • bowljoman

      bowljoman - 2007-02-03

      I find if you insert the ati BDA reciever component and BDA tuner Component. INsert the Microsoft ATSC network provider filter and render the 'antenna out' pin and the entire BDA graph constructs itself. In Graph edit anyway.

       
    • snarfle

      snarfle - 2006-07-21

      So, how far have you gotten? Have you added the audio device to the graph? Or is your capture device outputting mpeg2 streams or some such?

       
      • ronhud

        ronhud - 2006-09-04

        Sorry if I'm posting this in too many places, but I get the impression that many threads are about this same problem. Apologies to the Admin if I'm posting it too much. This is based on the code in DxTuner:

                hr = captureGraphBuilder.FindInterface(null, null, theDevice, typeof(IAMTVTuner).GUID, out o);
                if (hr >= 0)
                {
                    tuner = (IAMTVTuner)o;
                    o = null;
        
                    hr = captureGraphBuilder.FindInterface(null, null, theDevice, typeof(IAMCrossbar).GUID, out o);
                    if (hr >= 0)
                    {
                        crossbar = (IBaseFilter)o;
                        o = null;
                    }
        
                    // 9/5/06 Ron Hudson  Add this code to make ATI HDTV Audio work
        
                    // Constants from top of file:
                    //private string mAUDIO_IN = "4: Audio Tuner In";
                    //private string mAUDIO_OUT = "1: Audio Decoder Out";
        
                    IPin sourcePin, destPin, xPin;
                    sourcePin = DsFindPin.ByName(crossbar, mAUDIO_IN);
                    destPin = DsFindPin.ByName(crossbar, mAUDIO_OUT);
                    hr = sourcePin.Disconnect();
                    hr = sourcePin.Connect(destPin, null);
        
                }
        
         
        • Nergiz

          Nergiz - 2007-02-01

          Hi I copied the code and inserted it below the first set of code in your answer.
          Unfortunely the sourcePin.Connect function returns an error. -2147220943
          I've tried to find what the error means, but the DShow docs on MSDN dont say.

          ( msdn documentation. Connect return values )
          S_OK Success.
          VFW_E_ALREADY_CONNECTED The pin is already connected.
          VFW_E_NO_ACCEPTABLE_TYPES Cannot find an acceptable media type.
          VFW_E_NO_TRANSPORT Pins cannot agree on a transport, or there is no allocator for the connection.
          VFW_E_NOT_STOPPED The filter is active and the pin does not support dynamic reconnection.
          VFW_E_TYPE_NOT_ACCEPTED The specified media type is not acceptable.

          I have no idea which of the errors -2147220943 is...

          Do you have any ideas why the code wouldn't work?
          Everything else in the program works fine.
          sourcePin and destPin also look fine when stepping through the code.

          Any help is appreciated.

          ( code I used )

          // 9/5/06 Ron Hudson Add this code to make ATI HDTV Audio work

          // Constants from top of file:
          //private string mAUDIO_IN = "4: Audio Tuner In";
          //private string mAUDIO_OUT = "1: Audio Decoder Out";

          IPin sourcePin, destPin, xPin;
          sourcePin = DsFindPin.ByName(crossbar, mAUDIO_IN);
          destPin = DsFindPin.ByName(crossbar, mAUDIO_OUT);
          hr = sourcePin.Disconnect();
          hr = sourcePin.Connect(destPin, null);

           
          • snarfle

            snarfle - 2007-02-01

            From DsUtils.cs:

                public const int E_CircularGraph = unchecked((int)0x80040231)
            
             
            • Nergiz

              Nergiz - 2007-02-02

              Hello Snarfle!
              I thank you for your reply

              "From DsUtils.cs:
              public const int E_CircularGraph = unchecked((int)
              0x80040231)".

              It doesn´t help me because I´m beginer and I don´t
              understand this code so much. Please Snarfle, this project
              is very important for me and I need your help. If I
              succeed I will give you some donation.

              I use a Hauppauge analog/digital TV-Card DVBT (WinTV HVR-
              900). I succeed to see the Swedish analog channels without
              audio but not the digital terrestrial channels. I don´t
              know why!!! Because my TV-Card works correctly with the
              original manifacture drivers. Another problem is the
              settings from the "tuner" and the "crossbar" don´t saves.

              How I can see digital channels and how to get audio?

              I´m grateful for your help.
              Nergiz /Stockholm

               
              • snarfle

                snarfle - 2007-02-02

                A circular graph means that you have

                FilterA->FilterB->FilterC

                Then you try to connect FilterC to FilterA. That would make a circle, which makes no sense.

                Try connecting to your graph using GraphEdt (discussed in our docs). Being able to visualize can help solve problems.

                 
    • ronhud

      ronhud - 2006-07-22

      Thanks for your help snarfle. I tried to send you an email message at your sourceforge
      address offering to pay for your help, but it was returned. If anyone is interested in
      getting paid to help me with this project, please email me as 2006a@ronhudson.com or two-thousand six at ronhudson dot-you-know-what. I will pay a bonus to the first person who can help me get the audio working on the platform I'm using now, or to the first person who can prove that my current machine/tuner card won't work with ds.net.

      I will write about my project here so that others might benefit if they have a similar issue. It would be nice if we could work-out this problem together here on the forum.

      Platform:

      XP Pro SP2
      Pentium 4 2.8 GHz
      512 MB Memory
      NVIDIA GeForce FX 5200
      Dual Outputs - 128 MB Memory each

      TV Tuner Card: new ATI HDTV All-In-Wonder

      This link shows the GraphEdit shot alog with a screen shot of DxTuner displaying the video correctly:

      http://www.ronhudson.com/dsdemos/ge1.htm

      As you can see, the audio hardware appears to have been added to the graph, but it doesn't render. The audio works fine if I use the Multimedia player application that came with the card.

      I'll post some more information in a separate message. Would appreciate any thoughts or comments anyone might have, even if you just want to congratulate me for getting GraphEdit to work (since this is my first DirectShow project).

      Thanks again to snarfle for all of the contributions he makes here. Did someone mention another newsgroup where I could post this problem? I'll check the ms newsgroups and post this there too.

       
      • snarfle

        snarfle - 2006-07-22

        Does the audio play when you build the graph in graphedit? A neat trick is to attach to the graph in graphedt, then save it. This allows you to play with your graphs without having to build them manually from scratch.

        Does the audio play from the avi file? Some devices won't output signal on two pins at the same time.

        Have you tried playing with the crossbar? Sometimes the audio doesn't get correctly cross-connected. You can attach graphedit and play with the settings using property pages to see if this is the problem.

         
    • almere109

      almere109 - 2006-07-22

      In most cases, I had problems with the audio crossbar (and audio source selection). How do you retrieve the audio device driver? You use theDevice for it?

      //Render any preview pin of the device
      hr = captureGraphBuilder.RenderStream(PinCategory.Preview, MediaType.Audio, theDevice, null, null);
      DsError.ThrowExceptionForHR(hr);

      Did you try to use PCM Audio? Did you try to connect the audio renderer directly (without Smart tee)? Sometime ago somebody had to connect the filters explicit.

       
      • ronhud

        ronhud - 2006-07-22

        I'm going to try all of the things you guys are suggesting and I'll report back what happens. I've tried using various combinations of RenderStream arguments as you have suggested, but it might be helpful if I could run some of those combinations and again and report back to the group. This will be good documentation if anyone else tries to do this after me.

        Thanks again for your help.

        Ron Hudson
        2006 at ronhudson dotyouknow

         
        • snarfle

          snarfle - 2006-07-22

          You might also take a look at CaptureTest from http://www.LimeGreenSocks.com/DShow. It is based on Brian Low's work from CodeProject, but with a few updates, and modified to work with DS.net.

           
      • snarfle

        snarfle - 2006-07-22

        I don't believe all sound cards set the Preview category for their pins. You might be better off with

        RenderStream(null, MediaType.Audio, theDevice, null, null);

         
    • ronhud

      ronhud - 2006-07-22

      Thanks to all of you for the help. Be sure to email me if you're interested in bidding on the digital tuning part of this project.

      I have tried connecting the graph in GraphEdit and playing it, generally with no success. However, I agree that it's one of the fastest ways to "prototype" graphs. Based on your encouragement, I'll put together some different combinations in GraphEdit. We'll see if we can get something working there first. I'll post screen shots on my web site and show them to the group.

      Thanks again for helping me beat on this thing. It can be a lonely and daunting task!

       
    • ronhud

      ronhud - 2006-07-22

      I just tried playing the AVI file and it doesn't seem to work. The video comes through fine and the file gets created, but who knows why it doesn't seem to play in Windows Media Player. I intend to disable the record function anyway, so this is not a major problem in and of itself. However, it could be an indication of what's wrong with my audio. All I care about is real-time TV and audio for now.

      I have some more ideas and I'll post back here with my progress. Thanks again for the help.

       
    • ronhud

      ronhud - 2006-07-22

      okay, here goes some test reports:

      First, I run the ATI Multimedia TV application to verify that audio works in the TV Tuner card.

      RESULT ** SUCCESS, I CAN HEAR AUDIO AND SEE VIDEO...JUST LIKE ON A TV. IT'S EVEN COMING THROUGH IN STEREO...SOUNDS GREAT

      THROUGH MY SOUNDMAX SOUND CARD.

      starting with the ORIGINAL baseline code from DxTuner.InitGraph() THAT SHOWS VIDEO CORRECTLY, BUT WITH NO AUDIO:

              //Create the media control for controlling the graph
              mediaControl = (IMediaControl) this.graphBuilder;
      
              // Attach the filter graph to the capture graph
              int hr = captureGraphBuilder.SetFiltergraph(this.graphBuilder);
              DsError.ThrowExceptionForHR(hr);
      
              //Add the Video input device to the graph
              hr = graphBuilder.AddFilter(theDevice, "source filter");
              DsError.ThrowExceptionForHR(hr);
      
              // Original DxTuner code
              hr = captureGraphBuilder.RenderStream(PinCategory.Preview, MediaType.Video, theDevice, null, null);
              DsError.ThrowExceptionForHR(hr);
      
              //Snarfle suggestion  
              //hr = captureGraphBuilder.RenderStream(null, MediaType.Audio, theDevice, null, null);
              //DsError.ThrowExceptionForHR(hr);
      
              //Alemere109 suggestion  
              //hr = captureGraphBuilder.RenderStream(PinCategory.Preview, MediaType.Audio, theDevice, null, null);
              //DsError.ThrowExceptionForHR(hr);
      

      RESULT ** VIDEO WORKS. NO AUDIO.
      GraphEdit Screen Shot: http://www.ronhudson.com/dsdemos/orig.jpg

      Now I uncomment Snarfle's first suggested fix, WITH the original DxTuner RenderStream call for video.

              // Original DxTuner code
              hr = captureGraphBuilder.RenderStream(PinCategory.Preview, MediaType.Video, theDevice, null, null);
              DsError.ThrowExceptionForHR(hr);
      
              //Snarfle suggestion  
              hr = captureGraphBuilder.RenderStream(null, MediaType.Audio, theDevice, null, null);
              DsError.ThrowExceptionForHR(hr);
      
              //Alemere109 suggestion  
              //hr = captureGraphBuilder.RenderStream(PinCategory.Preview, MediaType.Audio, theDevice, null, null);
              //DsError.ThrowExceptionForHR(hr);
      

      RESULT ** NO AUDIO:
      GraphEdit Screen Shot: http://www.ronhudson.com/dsdemos/snarfleOrig.jpg

      Now I test Snarfle's first suggested fix WITHOUT the original DxTuner RenderStream call, attempting to add audio ONLY.

              // Original DxTuner code
              //hr = captureGraphBuilder.RenderStream(PinCategory.Preview, MediaType.Video, theDevice, null, null);
              //DsError.ThrowExceptionForHR(hr);
      
              //Snarfle suggestion  
              hr = captureGraphBuilder.RenderStream(null, MediaType.Audio, theDevice, null, null);
              DsError.ThrowExceptionForHR(hr);
      
              //Alemere109 suggestion  
              //hr = captureGraphBuilder.RenderStream(PinCategory.Preview, MediaType.Audio, theDevice, null, null);
              //DsError.ThrowExceptionForHR(hr);
      

      RESULT ** NO VIDEO OR AUDIO:
      GraphEdit Screen Shot: http://www.ronhudson.com/dsdemos/snarfleAudioOnly.jpg

      I try alemere109's suggestion WITH the original DxTuner RenderStream call for video:

              // Original DxTuner code
              hr = captureGraphBuilder.RenderStream(PinCategory.Preview, MediaType.Video, theDevice, null, null);
              DsError.ThrowExceptionForHR(hr);
      
              //Snarfle suggestion  
              //hr = captureGraphBuilder.RenderStream(null, MediaType.Audio, theDevice, null, null);
              //DsError.ThrowExceptionForHR(hr);
      
              //Alemere109 suggestion  
              hr = captureGraphBuilder.RenderStream(PinCategory.Preview, MediaType.Audio, theDevice, null, null);
              DsError.ThrowExceptionForHR(hr);
      

      RESULT ** NO AUDIO
      GraphEdit Screen Shot: http://www.ronhudson.com/dsdemos/alemereOrig.jpg

      I try alemere109's suggestion WITHOUT the original DxTuner RenderStream call, attempting to add audio ONLY.:

              // Original DxTuner code
              //hr = captureGraphBuilder.RenderStream(PinCategory.Preview, MediaType.Video, theDevice, null, null);
              //DsError.ThrowExceptionForHR(hr);
      
              //Snarfle suggestion  
              //hr = captureGraphBuilder.RenderStream(null, MediaType.Audio, theDevice, null, null);
              //DsError.ThrowExceptionForHR(hr);
      
              //Alemere109 suggestion  
              hr = captureGraphBuilder.RenderStream(PinCategory.Preview, MediaType.Audio, theDevice, null, null);
              DsError.ThrowExceptionForHR(hr);
      

      RESULT ** NO AUDIO
      GraphEdit Screen Shot: http://www.ronhudson.com/dsdemos/alemereAudioOnly.jpg

      Return to original DxTuner code to verify that video still appears:
      RESULT ** VIDEO STILL OKAY, NO AUDIO

      Run ATI Multimedia TV app to verify that audio still works>
      RESULT ** AUDIO AND VIDEO GOOD

      More testing later. Thanks again for your help.

       
    • almere109

      almere109 - 2006-07-23

      That the Avi video does not play in Media player is probably due to the missing video compressor (I usually use DV Video Encoder).
      Do you have a graphedt version, you can test one. What you should try is to right click on the AV Crossbar. Then select in the right box audio decoder out (normally you see video decoder out). THen you go the left box and select the appropriate input line Video Tuner in. Then press okay. If this is done, the crossbar setting should be okay. If this would be the problem, the the LimeShow version, and also my version on the codeproject site will probably work because the crossbar will be set properly. In two codeproject articles (audio file saving, video file saving) some background information can be found on this.
      THere could be more reasons why there is no sound, but I can hardly imaging that that is bothering you. But okay, I can at least mention it. Sometimes the TV tuner has the wrong video standard setting (e.g. NTSC instead of PAL). In such scenario there will be no sound (this is a little bit hardware dependent). Video will usually look a little bit strange. ANother thing is that the tuner frequency range goes up to 800MHz instead of 863MHz.

       
    • ronhud

      ronhud - 2006-07-23

      That looks like it might work Alemere. Will try it and let you know what happens. Thanks again for taking time to help me. If it works then I'll mail you a gift.

       
    • ronhud

      ronhud - 2006-07-23

      Sorry, posted this to the wrong thread before:

      Using Alemere's suggestion to tweak the crossbar, I accessed the Crossbar dialog box and changed it to point to the audio tuner in and audio decoder out pins. However, it had no effect and all I still got was video.

      With the video still running, I accessed the Crossbar dialog box again to see if it still showed audio pins instead of video pins, BUT IT DID NOT. It may be that setting options in the Crossbar dialog box is not "getting saved" to the ATI interface.

      I'm going to try setting the crossbar in code, and try some things to get the crossbar settings to "save" when using the Crossbar dialog box. I'll report my progress back to the group.

       
    • ronhud

      ronhud - 2006-07-23

      IT WORKS!!!

      THE KEY WAS IN THE CROSSBAR JUST AS SNARFLE AND ALEMERE SAID IT MIGHT BE.

      It was actually Alemere's suggestion to play with the crossbar dialog that did it. The first time I tried, it didn't appear to "save" the audio routing I configured from the crossbar. But I continued to mess around with it and it eventually worked. I'm optimistic now that I can get it to work in code.

      I will post the code when I get it all working so that others may benefit.

      Alemere and Snarfle: It's not 100% clear which of you deserves my thanks more, so I will make this offer: Send me your mailing addresses using my email address posted previously in this thread. If both of you send me your addresses within 5 days, then I'll split the reward and mail you each a check. If only one of you sends me your mailing address, then I'll send the entire reward to that person. If neither of you sends me your address, then I'll just keep my money and be eternally grateful to both of you.

      Thanks again from the bottom of my heart. I can now get paid for this job and get something for all of the time and effort I've put into it.

      THIS FORUM HELPS PEOPLE SOLVE PROBLEMS, AND I CAN ATTEST TO THAT. THANK YOU SOURCEFORGE, AND THANK YOU TO THOSE WHO DEVELOPED DXTUNER AND DIRECTSHOW.NET.

       
      • snarfle

        snarfle - 2006-07-23

        I'll pass, thanks.

        However, if you wanted to create a DxCrossBar showing CrossBar usage to make life easier for the next fellow...

         
    • almere109

      almere109 - 2007-02-01

      The pin numbering is capture card dependent. It might be possible that Audio Tuner In is not 4 and/or Audio Decoder is not 1. The added code is a little bit simple, usually some more checks would be better. E.g. do not use a hard coded mapping, instead of that use a software check on media type and/or pin name. You could make it a initialization option and just look for a matching pin.
      This week an article of my has been publiced on the codeproject. That article adds code for using the TV tuner with the IksPropertySet in C# (might be interesting for this project also). There are also some remarks on using Audio (and loosing it).

      The example uses DShowNet instead of DirectShowLib, but that should not be a big problem. I marked already the parts that were missing in DShowNet (so are included in DirectShowLib). Maybe it gives you a clue: http://www.codeproject.com/cs/media/tvfinetune.asp
      If you have more questions on this, do not hesitate to ask (Here or on that site ... on that site I will receive an email automatic).

       

Log in to post a comment.

MongoDB Logo MongoDB