Results 1 to 4 of 4

Thread: how to extract audio format from a sound file

  1. #1
    Join Date
    Jun 2012
    Posts
    2
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default how to extract audio format from a sound file

    Given a sound file (e.g., .wav), is there a way in Qt 4.7 to extract the audio format from it?

    I generate a sound in a way that essentially uses all this example code (from the detailed documentation to the QAudioOutput class).

    This involves hard-coding the audio format with this helper method:

    QAudioFormat audioFormat()
    {
    QAudioFormat format;

    format.setSampleRate(8000);
    format.setChannels(1);
    format.setSampleSize(8);
    format.setCodec("audio/pcm");

    format.setSampleType(QAudioFormat::UnSignedInt);

    return format;
    }


    I give the format to the QAudioOutput instance:

    QAudioFormat format = audioFormat();
    QAudioDeviceInfo info(QAudioDeviceInfo::defaultOutputDevice());

    audioOutput_ = new QAudioOutput(info, format, this); // audioOutput_ is defined already as a QAudioOutput*


    My code works with a .wav file with the right sampling rate.
    I would prefer to extract the format from the .wav file instead - that way, I'm not so constrained with what files I have to use. After getting the format, I could say:

    format = info.nearestFormat(format);

    to get the format to conform to my system. But how do I extract the format from the file?

    Thanks!

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: how to extract audio format from a sound file

    If you generate the sound yourself then how come you don't know what format you generate it in? Or did you mean something else?

    If you just want to play a sound then use QMediaPlayer from QtMultimediaKit module.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  3. #3
    Join Date
    Jun 2012
    Posts
    2
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: how to extract audio format from a sound file

    Quote Originally Posted by wysota View Post
    If you generate the sound yourself then how come you don't know what format you generate it in? Or did you mean something else?

    If you just want to play a sound then use QMediaPlayer from QtMultimediaKit module.
    Thank you for the reply.

    I would like the flexibility to allow the application's user to submit an arbitrary sound file. (I know the format so long as I restrict myself to a limited set of files I have picked out. In either case, I am not generating the sound "from scratch", but merely playing a sound file that either I or the user have supplied.)

    QMediaPlayer seems to be new to Qt 5. I am using Qt 4.7.

  4. #4
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: how to extract audio format from a sound file

    QMediaPlayer is part of Qt4's QtMultimediaKit (QtMobility) set.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


Similar Threads

  1. Extract audio from video
    By pallavi12345 in forum Newbie
    Replies: 1
    Last Post: 17th August 2017, 08:55
  2. QMediaPlayer: MP4 file with AAC audio format
    By ollerei in forum Qt Programming
    Replies: 1
    Last Post: 12th February 2013, 02:51
  3. Replies: 1
    Last Post: 12th December 2012, 09:36
  4. What are the types of video and audio file format Qt simulator supports
    By prajnaranjan.das in forum Qt for Embedded and Mobile
    Replies: 1
    Last Post: 16th May 2011, 10:34
  5. SDL - Audio and QT Creator Sound
    By hakermania in forum Qt Programming
    Replies: 0
    Last Post: 30th August 2010, 22:21

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.