Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

Get BitDepth from an Audio File with QMediaPlayer



  • Hello everyone,

    I think everything is in the title,
    I don't know how to get Bit Depth of an Audio file with QMediaPlayer, I successfully get Audio Time, Sample Rate, Bit Rate or Channels, but I can't get the finger on Sample Size, here is my code :

    float	AudioManager::setTime(QUrl Path, QString Name,
                                  QMap<QString, int> *BitDepth,
                                  QMap<QString, int> *Rate,
                                  QMap<QString, int> *Channels,
                                  QMap<QString, int> *BitRate)
    {
    	static QMediaPlayer	*PlayerAudio = new QMediaPlayer;
    	float				time;
    	int					volume;
    
    	PlayerAudio->setMedia(QUrl::fromLocalFile(Path.toString()));
    	volume = PlayerAudio->volume();
    	PlayerAudio->setVolume(0);
    	PlayerAudio->play();
    	while (PlayerAudio->position() == 0)
    	{
    		QApplication::processEvents();
    		if (PlayerAudio->duration() > 0)
    			break;
    	}
    	PlayerAudio->stop();
    	PlayerAudio->setVolume(volume);
    	time = static_cast<float>(PlayerAudio->duration()) / 1000.0f;
    	(*BitDepth)[Name] = PlayerAudio->metaData("SampleRate").toInt() / 2000; //Absolutly not good but I don't know how to do better ...
    	(*Rate)[Name] = PlayerAudio->metaData("SampleRate").toInt();
    	(*Channels)[Name] = PlayerAudio->metaData("ChannelCount").toInt();
    	(*BitRate)[Name] = PlayerAudio->metaData("AudioBitRate").toInt() * (*Channels)[Name] / 1000;
    	return (time);
    }
    

    I know that isn't perfect but it's working, except for the sample size, I'm searching for an easy, efficient and not too long way (I have 10000 audio files to deals with) to find the sample size value.

    Hopefully someone will be able to help me !?
    Thank's by advance.

    Edit : Is it so easy that no one take time to tell me or is it just so hard that no one know ?



  • This post is deleted!


  • why there is no SampleSize here ??



  • Ok I found it :

    SampleSize = AudioBiteRate / SampleRate;


Log in to reply