Exemplo n.º 1
0
 void testBasic()
 {
   WavPack::File f("data/no_length.wv");
   WavPack::Properties *props = f.audioProperties();
   CPPUNIT_ASSERT_EQUAL(44100, props->sampleRate());
   CPPUNIT_ASSERT_EQUAL(2, props->channels());
   CPPUNIT_ASSERT_EQUAL(1, props->bitrate());
   CPPUNIT_ASSERT_EQUAL(0x407, props->version());
 }
Exemplo n.º 2
0
 void testLengthScan()
 {
   WavPack::File f("data/no_length.wv");
   WavPack::Properties *props = f.audioProperties();
   CPPUNIT_ASSERT_EQUAL(4, props->length());
 }
Exemplo n.º 3
0
bool cMediaInfo::readFromFile(const QString& szFileName)
{
	clear();

	QFileInfo	fileInfo(szFileName);
	if(!fileInfo.exists())
		return(false);

	if(!fileInfo.suffix().compare("APE", Qt::CaseInsensitive))
		m_fileType	= MEDIA_TYPE_APE;
	else if(!fileInfo.suffix().compare("WMA", Qt::CaseInsensitive))
		m_fileType	= MEDIA_TYPE_ASF;
	else if(!fileInfo.suffix().compare("FLAC", Qt::CaseInsensitive))
		m_fileType	= MEDIA_TYPE_FLAC;
	else if(!fileInfo.suffix().compare("AAC", Qt::CaseInsensitive))
		m_fileType	= MEDIA_TYPE_MP4;
	else if(!fileInfo.suffix().compare("MP4", Qt::CaseInsensitive))
		m_fileType	= MEDIA_TYPE_MP4;
	else if(!fileInfo.suffix().compare("M4A", Qt::CaseInsensitive))
		m_fileType	= MEDIA_TYPE_MP4;
	else if(!fileInfo.suffix().compare("MPC", Qt::CaseInsensitive))
		m_fileType	= MEDIA_TYPE_MPC;
	else if(!fileInfo.suffix().compare("MP1", Qt::CaseInsensitive))
		m_fileType	= MEDIA_TYPE_MPEG;
	else if(!fileInfo.suffix().compare("MP2", Qt::CaseInsensitive))
		m_fileType	= MEDIA_TYPE_MPEG;
	else if(!fileInfo.suffix().compare("MP3", Qt::CaseInsensitive))
		m_fileType	= MEDIA_TYPE_MPEG;
	else if(!fileInfo.suffix().compare("TTA", Qt::CaseInsensitive))
		m_fileType	= MEDIA_TYPE_TRUEAUDIO;
	else if(!fileInfo.suffix().compare("WV", Qt::CaseInsensitive))
		m_fileType	= MEDIA_TYPE_WAVPACK;
	else if(!fileInfo.suffix().compare("WAV", Qt::CaseInsensitive))
		m_fileType	= MEDIA_TYPE_WAV;

	if(m_fileType	== MEDIA_TYPE_UNKNOWN)
		return(false);

	m_szFileName					= szFileName;

	ID3v1::Tag*			lpTagV1		= 0;
	ID3v2::Tag*			lpTagV2		= 0;
	APE::Tag*			lpTagAPE	= 0;
	APE::File*			lpApe		= 0;
	ASF::File*			lpASF		= 0;
	FLAC::File*			lpFlac		= 0;
	MP4::File*			lpMP4		= 0;
	MPC::File*			lpMPC		= 0;
	MPEG::File*			lpMPEG		= 0;
	TrueAudio::File*	lpTrueAudio	= 0;
	WavPack::File*		lpWavPack	= 0;
	RIFF::WAV::File*	lpWav		= 0;

	TagLib::PropertyMap	tags;

	QString				szTmp;

	switch(m_fileType)
	{
	case MEDIA_TYPE_APE:
	{
		lpApe	= new APE::File(m_szFileName.toLocal8Bit().data());

		lpTagV1										= lpApe->ID3v1Tag();
		lpTagAPE									= lpApe->APETag();
		tags										= lpApe->properties();

		APE::Properties* lpAudioProperties			= lpApe->audioProperties();

		if(lpAudioProperties)
		{
			m_iLength								= lpAudioProperties->length();
			m_iBitrate								= lpAudioProperties->bitrate();
			m_iSampleRate							= lpAudioProperties->sampleRate();
			m_iChannels								= lpAudioProperties->channels();
			m_iBitsPerSample						= lpAudioProperties->bitsPerSample();
			m_iVersion								= lpAudioProperties->version();
		}
		break;
	}
	case MEDIA_TYPE_ASF:
	{
		lpASF	= new ASF::File(m_szFileName.toLocal8Bit().data());
		TagLib::ASF::Tag*	lpTag					= lpASF->tag();
		m_szTitle									= QString::fromStdWString(lpTag->title().toWString());
		szTmp										= QString::fromStdWString(lpTag->artist().toWString());
		if(!szTmp.isEmpty() && m_bID3V1)
			m_szArtistList							= szTmp.split("\n");
		m_szAlbum									= QString::fromStdWString(lpTag->album().toWString());
		m_szComment									= QString::fromStdWString(lpTag->comment().toWString());
		szTmp										= QString::fromStdWString(lpTag->genre().toWString());
		if(!szTmp.isEmpty() && m_bID3V1)
			m_szGenreList							= szTmp.split("\n");
		m_szRating									= QString::fromStdWString(lpTag->genre().toWString());
		m_szCopyright								= QString::fromStdWString(lpTag->copyright().toWString());
		m_iYear										= lpTag->year();
		m_szTrackNumber								= QString("%1").arg(lpTag->track());

		tags										= lpASF->properties();

		ASF::Properties* lpAudioProperties			= lpASF->audioProperties();

		if(lpAudioProperties)
		{
			m_iLength								= lpAudioProperties->length();
			m_iBitrate								= lpAudioProperties->bitrate();
			m_iSampleRate							= lpAudioProperties->sampleRate();
			m_iChannels								= lpAudioProperties->channels();
			m_bIsEncrypted							= lpAudioProperties->isEncrypted();
		}
		break;
	}
	case MEDIA_TYPE_FLAC:
	{
		lpFlac	= new FLAC::File(m_szFileName.toLocal8Bit().data());
		lpTagV1										= lpFlac->ID3v1Tag();
		lpTagV2										= lpFlac->ID3v2Tag();
		tags										= lpFlac->properties();

		FLAC::Properties* lpAudioProperties			= lpFlac->audioProperties();

		if(lpAudioProperties)
		{
			m_iLength								= lpAudioProperties->length();
			m_iBitrate								= lpAudioProperties->bitrate();
			m_iSampleRate							= lpAudioProperties->sampleRate();
			m_iChannels								= lpAudioProperties->channels();
			m_iSampleWidth							= lpAudioProperties->sampleWidth();
			m_ullSampleFrames						= lpAudioProperties->sampleFrames();
		}
		break;
	}
	case MEDIA_TYPE_MP4:
	{
		lpMP4	= new MP4::File(m_szFileName.toLocal8Bit().data());
		TagLib::MP4::Tag*	lpTag					= lpMP4->tag();
		m_szTitle									= QString::fromStdWString(lpTag->title().toWString());
		szTmp										= QString::fromStdWString(lpTag->artist().toWString());
		if(!szTmp.isEmpty() && m_bID3V1)
			m_szArtistList							= szTmp.split("\n");
		m_szAlbum									= QString::fromStdWString(lpTag->album().toWString());
		m_szComment									= QString::fromStdWString(lpTag->comment().toWString());
		szTmp										= QString::fromStdWString(lpTag->genre().toWString());
		if(!szTmp.isEmpty() && m_bID3V1)
			m_szGenreList							= szTmp.split("\n");
		m_iYear										= lpTag->year();
		m_szTrackNumber								= QString("%1").arg(lpTag->track());

		tags										= lpMP4->properties();

		MP4::Properties* lpAudioProperties			= lpMP4->audioProperties();

		if(lpAudioProperties)
		{
			m_iLength								= lpAudioProperties->length();
			m_iBitrate								= lpAudioProperties->bitrate();
			m_iSampleRate							= lpAudioProperties->sampleRate();
			m_iChannels								= lpAudioProperties->channels();
			m_iBitsPerSample						= lpAudioProperties->bitsPerSample();
			m_bIsEncrypted							= lpAudioProperties->isEncrypted();
		}
		break;
	}
	case MEDIA_TYPE_MPC:
	{
		lpMPC	= new MPC::File(m_szFileName.toLocal8Bit().data());
		lpTagV1										= lpMPC->ID3v1Tag();
		lpTagAPE									= lpMPC->APETag();
		tags										= lpMPC->properties();

		MPC::Properties* lpAudioProperties			= lpMPC->audioProperties();

		if(lpAudioProperties)
		{
			m_iLength								= lpAudioProperties->length();
			m_iBitrate								= lpAudioProperties->bitrate();
			m_iSampleRate							= lpAudioProperties->sampleRate();
			m_iChannels								= lpAudioProperties->channels();
			m_iVersion								= lpAudioProperties->mpcVersion();
			m_ullSampleFrames						= lpAudioProperties->sampleFrames();
			m_iTrackGain							= lpAudioProperties->trackGain();
			m_iAlbumGain							= lpAudioProperties->albumGain();
			m_iTrackPeak							= lpAudioProperties->trackPeak();
			m_iAlbumPeak							= lpAudioProperties->albumPeak();
		}
		break;
	}
	case MEDIA_TYPE_MPEG:
	{
		lpMPEG	= new MPEG::File(m_szFileName.toLocal8Bit().data());

		lpTagV1										= lpMPEG->ID3v1Tag();
		lpTagV2										= lpMPEG->ID3v2Tag();
		lpTagAPE									= lpMPEG->APETag();
		tags										= lpMPEG->properties();

		MPEG::Properties*	lpAudioProperties		= lpMPEG->audioProperties();

		if(lpAudioProperties)
		{
			m_iLength								= lpAudioProperties->length();
			m_iBitrate								= lpAudioProperties->bitrate();
			m_iSampleRate							= lpAudioProperties->sampleRate();
			m_iChannels								= lpAudioProperties->channels();
			m_iLayer								= lpAudioProperties->layer();
			switch(lpAudioProperties->version())
			{
			case MPEG::Header::Version1:
				m_iVersion	= 10;
				break;
			case MPEG::Header::Version2:
				m_iVersion	= 20;
				break;
			case MPEG::Header::Version2_5:
				m_iVersion	= 25;
				break;
			}
			m_bProtectionEnabled					= lpAudioProperties->protectionEnabled();
			switch(lpAudioProperties->channelMode())
			{
			case MPEG::Header::Stereo:
				m_channelMode						= CHANNEL_MODE_STEREO;
				break;
			case MPEG::Header::JointStereo:
				m_channelMode						= CHANNEL_MODE_JOINTSTEREO;
				break;
			case MPEG::Header::DualChannel:
				m_channelMode						= CHANNEL_MODE_DUALMONO;
				break;
			case MPEG::Header::SingleChannel:
				m_channelMode						= CHANNEL_MODE_MONO;
				break;
			}
			m_bIsCopyrighted						= lpAudioProperties->isCopyrighted();
			m_bIsOriginal							= lpAudioProperties->isOriginal();
		}
		break;
	}
	case MEDIA_TYPE_TRUEAUDIO:
	{
		lpTrueAudio	= new TrueAudio::File(m_szFileName.toLocal8Bit().data());
		lpTagV1										= lpTrueAudio->ID3v1Tag();
		lpTagV2										= lpTrueAudio->ID3v2Tag();
		tags										= lpTrueAudio->properties();

		TrueAudio::Properties* lpAudioProperties	= lpTrueAudio->audioProperties();

		if(lpAudioProperties)
		{
			m_iLength								= lpAudioProperties->length();
			m_iBitrate								= lpAudioProperties->bitrate();
			m_iSampleRate							= lpAudioProperties->sampleRate();
			m_iChannels								= lpAudioProperties->channels();
			m_iBitsPerSample						= lpAudioProperties->bitsPerSample();
			m_iVersion								= lpAudioProperties->ttaVersion();
		}
		break;
	}
	case MEDIA_TYPE_WAVPACK:
	{
		lpWavPack	= new WavPack::File(m_szFileName.toLocal8Bit().data());
		lpTagV1										= lpWavPack->ID3v1Tag();
		lpTagAPE									= lpWavPack->APETag();
		tags										= lpWavPack->properties();

		WavPack::Properties* lpAudioProperties		= lpWavPack->audioProperties();

		if(lpAudioProperties)
		{
			m_iLength								= lpAudioProperties->length();
			m_iBitrate								= lpAudioProperties->bitrate();
			m_iSampleRate							= lpAudioProperties->sampleRate();
			m_iChannels								= lpAudioProperties->channels();
			m_iBitsPerSample						= lpAudioProperties->bitsPerSample();
			m_ullSampleFrames						= lpAudioProperties->sampleFrames();
			m_iVersion								= lpAudioProperties->version();
		}
		break;
	}
	case MEDIA_TYPE_WAV:
	{
		lpWav	= new RIFF::WAV::File(m_szFileName.toLocal8Bit().data());
		lpTagV2										= lpWav->tag();
		tags										= lpWav->properties();

		RIFF::WAV::Properties* lpAudioProperties	= lpWav->audioProperties();

		if(lpAudioProperties)
		{
			m_iLength								= lpAudioProperties->length();
			m_iBitrate								= lpAudioProperties->bitrate();
			m_iSampleRate							= lpAudioProperties->sampleRate();
			m_iChannels								= lpAudioProperties->channels();
			m_iSampleWidth							= lpAudioProperties->sampleWidth();
			m_ullSampleFrames						= lpAudioProperties->sampleFrames();
		}
		break;
	}
	default:
		break;
	}

	if(lpTagV2 && m_bID3V2)
		readTagV2(lpTagV2);
	if(lpTagV1 && m_bID3V1)
		readTagV1(lpTagV1);
	if(lpTagAPE && m_bAPE)
		readTagAPE(lpTagAPE);
	if(m_bProperties)
		readTagProperties(tags);

	if(lpApe)
		delete lpApe;
	if(lpASF)
		delete lpASF;
	if(lpFlac)
		delete lpFlac;
	if(lpMP4)
		delete lpMP4;
	if(lpMPC)
		delete lpMPC;
	if(lpMPEG)
		delete lpMPEG;
	if(lpTrueAudio)
		delete lpTrueAudio;
	if(lpWavPack)
		delete lpWavPack;
	if(lpWav)
		delete lpWav;

	m_bIsValid	= true;
	return(true);
}