Results 1 to 9 of 9

Thread: Receiving audio through USB frame grabber and playing it

  1. #1
    Join Date
    Apr 2011
    Posts
    231
    Thanks
    141
    Thanked 6 Times in 5 Posts

    Default Receiving audio through USB frame grabber and playing it

    Following is what I have tried.

    Qt Code:
    1. #include "audiooutput.h"
    2.  
    3. Output::Output()
    4. {
    5. foreach (const QAudioDeviceInfo &deviceInfo, QAudioDeviceInfo::availableDevices(QAudio::AudioInput))
    6. qDebug() << "Device name in: " << deviceInfo.deviceName();
    7.  
    8. foreach (const QAudioDeviceInfo &deviceInfo, QAudioDeviceInfo::availableDevices(QAudio::AudioOutput))
    9. qDebug() << "Device name out: " << deviceInfo.deviceName();
    10.  
    11.  
    12. QAudioDeviceInfo d;
    13. QList<QAudioDeviceInfo> l = d.availableDevices(QAudio::AudioInput);
    14.  
    15. d = l[0];
    16.  
    17. QAudioFormat format;
    18. QAudioDeviceInfo info(QAudioDeviceInfo::defaultInputDevice());
    19. if (!info.isFormatSupported(format)) {
    20. format = info.nearestFormat(format);
    21. }
    22.  
    23. audioInpu = new QAudioInput(d, format, this);
    24. audioInpu->setVolume(100);
    25. //QIODevice *p = audioInpu->start();
    26.  
    27. QAudioFormat format1;
    28. QAudioDeviceInfo info1(QAudioDeviceInfo::defaultOutputDevice());
    29. if (!info1.isFormatSupported(format1)) {
    30. format1 = info.nearestFormat(format1);
    31. }
    32.  
    33. audioOutpu = new QAudioOutput(format1, this);
    34. connect(audioOutpu, SIGNAL(stateChanged(QAudio::State)), this, SLOT(handleStateChanged(QAudio::State)));
    35. audioOutpu->setVolume(100);
    36. audioOutpu->start( audioInpu->start());
    37. }
    38.  
    39. Output::handleStateChanged(QAudio::State newState)
    40. {
    41. switch (newState) {
    42. case QAudio::IdleState:
    43. qDebug() <<"jjjjjj";
    44. break;
    45.  
    46. case QAudio::StoppedState:
    47. if (audioInpu->error() != QAudio::NoError)
    48. {
    49. qDebug() << "\naudio stopped: " <<audioInpu->error();
    50. }
    51. break;
    52.  
    53. default:
    54. // ... other cases as appropriate
    55. break;
    56. }
    57. }
    To copy to clipboard, switch view to plain text mode 

    Following is the output of the program
    Qt Code:
    1. Device name in: "Line (2- USB Audio Device)"
    2. Device name out: "Speakers (Realtek High Definiti"
    3. jjjjjj
    To copy to clipboard, switch view to plain text mode 

    The input and output devices are being detected as you can see in the output, but "jjjjjj" being printed means "idle state".

    Problem is that I don't know how to pass the audio input to the speakers. I cannot hear anything other than a buzzing sound.

    Please guide.

  2. #2
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,416
    Thanks
    37
    Thanked 1,544 Times in 1,494 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: Receiving audio through USB frame grabber and playing it

    Quote Originally Posted by TheIndependentAquarius View Post
    The input and output devices are being detected as you can see in the output, but "jjjjjj" being printed means "idle state".
    Which is logical given that your code does not attempt to play anything.

    Quote Originally Posted by TheIndependentAquarius View Post
    Problem is that I don't know how to pass the audio input to the speakers. I cannot hear anything other than a buzzing sound.
    My guess you be that you create a QAudioInput and pass the QIODevice you get from its start() method to the start(QIODevice*) of the QAudioOutput or vice versa.

    Cheers,
    _

  3. The following user says thank you to anda_skoa for this useful post:

    TheIndependentAquarius (10th August 2016)

  4. #3
    Join Date
    Apr 2011
    Posts
    231
    Thanks
    141
    Thanked 6 Times in 5 Posts

    Default Re: Receiving audio through USB frame grabber and playing it

    Thanks for the response.

    Why did you say that I am not attempting to play anything? I have called that start function of QAudioOutput. What else is the way?

  5. #4
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,416
    Thanks
    37
    Thanked 1,544 Times in 1,494 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: Receiving audio through USB frame grabber and playing it

    Right, sorry!

    I must have overlooked that you are already passing the input's device to the output's start as suggested.

    Hmm, have you checked the state transitions of the audio input object?

    Are the two formats equal?

    Cheers,
    _

  6. #5
    Join Date
    Apr 2011
    Posts
    231
    Thanks
    141
    Thanked 6 Times in 5 Posts

    Default Re: Receiving audio through USB frame grabber and playing it

    I request you to explain me what do you mean by state transitions?

    Also, you mean I should check whether input and output formats are same? But, I have used their default states.

    I have also checked the input device through vlc player. It does work properly.

  7. #6
    Join Date
    Apr 2011
    Posts
    231
    Thanks
    141
    Thanked 6 Times in 5 Posts

    Default Re: Receiving audio through USB frame grabber and playing it

    Well, now I am explicitly setting the formats:

    For audio input:
    Qt Code:
    1. QAudioFormat desiredFormat;
    2. desiredFormat.setChannelCount(5);
    3. desiredFormat.setCodec("audio/pcm");
    4. desiredFormat.setSampleType(QAudioFormat::SignedInt);
    5. desiredFormat.setSampleRate(44100);
    6. desiredFormat.setSampleSize(16);
    To copy to clipboard, switch view to plain text mode 

    For audio output:
    Qt Code:
    1. desiredFormat1.setChannelCount(5);
    2. desiredFormat1.setCodec("audio/pcm");
    3. desiredFormat1.setSampleType(QAudioFormat::SignedInt);
    4. desiredFormat1.setSampleRate(44100);
    5. desiredFormat1.setSampleSize(24);
    To copy to clipboard, switch view to plain text mode 

    As you can see that sample size for output is 24 and input is 16. The problem is that if I keep both these values same, no sound is produced.
    I have tried with different variations of sample sizes, but input works only with 16 and output only with 24.

    Works means buzzing sound, real audio is not being heard in any case.

    Audio Input is being shown idle now.

    Can you help?
    Last edited by TheIndependentAquarius; 11th August 2016 at 10:23.

  8. #7
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,416
    Thanks
    37
    Thanked 1,544 Times in 1,494 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: Receiving audio through USB frame grabber and playing it

    My guess is that the formats need to be the same for the simple "hand over device" approach to work.

    Different formats will likely need to be made compatible by converting the input data to fit the output's needs.

    Cheers,
    _

  9. #8
    Join Date
    Apr 2011
    Posts
    231
    Thanks
    141
    Thanked 6 Times in 5 Posts

    Default Re: Receiving audio through USB frame grabber and playing it

    Quote Originally Posted by anda_skoa View Post
    Different formats will likely need to be made compatible by converting the input data to fit the output's needs.
    what would be the way to do that here?

  10. #9
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,416
    Thanks
    37
    Thanked 1,544 Times in 1,494 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: Receiving audio through USB frame grabber and playing it

    No idea, never used that before.

    Cheers,
    _

Similar Threads

  1. Frame grabber video/still capture
    By Mookie in forum Qt Programming
    Replies: 1
    Last Post: 14th August 2013, 03:39
  2. Playing an audio file with phonon
    By epaduel in forum Newbie
    Replies: 5
    Last Post: 31st January 2012, 01:48
  3. can I use Phonon with frame grabber
    By gkhrapunovich in forum Qt Programming
    Replies: 2
    Last Post: 25th March 2011, 21:29
  4. Playing multiple audio files with Phonon
    By MartinWalter in forum Qt Programming
    Replies: 0
    Last Post: 23rd December 2010, 11:19
  5. Qsound Error while playing Audio
    By augusbas in forum Qt for Embedded and Mobile
    Replies: 3
    Last Post: 1st February 2010, 11:20

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.