コード例 #1
0
bool CMyAPEInfo::GetFieldAsUtf8(wchar_t *pFieldName,CAPETag &tag, CSongMetaData::StringData &s)
{
	CAPETagField * pAPETagField = tag.GetTagField(pFieldName);
	if (pAPETagField == NULL)
	{
		return false;
	}
	else if (pAPETagField->GetIsUTF8Text() || (tag.GetAPETagVersion() < 2000))
	{
		if (tag.GetAPETagVersion() >= 2000)
			s = pAPETagField->GetFieldValue();
		else
			s = ConvFromISO8859_1ToUTF8(pAPETagField->GetFieldValue());

	}
	else
	{
		wxASSERT(false);
		return false;
	}
	return true;
}
コード例 #2
0
ファイル: Sample1.cpp プロジェクト: cristiklein/monkeys-audio
int main(int argc, char* argv[]) 
{
	///////////////////////////////////////////////////////////////////////////////
	// error check the command line parameters
	///////////////////////////////////////////////////////////////////////////////
	if (argc != 2) 
	{
		printf("~~~Improper Usage~~~\r\n\r\n");
		printf("Usage Example: Sample 1.exe 'c:\\1.ape'\r\n\r\n");
		return 0;
	}

	///////////////////////////////////////////////////////////////////////////////
	// variable declares
	///////////////////////////////////////////////////////////////////////////////
	int					nRetVal = 0;										// generic holder for return values
	char				cTempBuffer[256]; ZeroMemory(&cTempBuffer[0], 256);	// generic buffer for string stuff
	char *				pFilename = argv[1];								// the file to open
	IAPEDecompress *	pAPEDecompress = NULL;								// APE interface
	CSmartPtr<wchar_t> spInput;

	spInput.Assign(GetUTF16FromANSI(argv[1]), TRUE);
	
//*
	///////////////////////////////////////////////////////////////////////////////
	// open the file and error check
	///////////////////////////////////////////////////////////////////////////////
	pAPEDecompress = CreateIAPEDecompress(spInput, &nRetVal);
	if (pAPEDecompress == NULL) 
	{
		printf("Error opening APE file. (error code %d)\r\n\r\n", nRetVal);
		return 0;
	}


	///////////////////////////////////////////////////////////////////////////////
	// display some information about the file
	///////////////////////////////////////////////////////////////////////////////
	printf("Displaying information about '%s':\r\n\r\n", pFilename);

	// file format information
	printf("File Format:\r\n");
	printf("\tVersion: %.2f\r\n", float(pAPEDecompress->GetInfo(APE_INFO_FILE_VERSION)) / float(1000));
	switch (pAPEDecompress->GetInfo(APE_INFO_COMPRESSION_LEVEL))
	{
		case COMPRESSION_LEVEL_FAST: printf("\tCompression level: Fast\r\n\r\n"); break;
		case COMPRESSION_LEVEL_NORMAL: printf("\tCompression level: Normal\r\n\r\n"); break;
		case COMPRESSION_LEVEL_HIGH: printf("\tCompression level: High\r\n\r\n"); break;
		case COMPRESSION_LEVEL_EXTRA_HIGH: printf("\tCompression level: Extra High\r\n\r\n"); break;
	}

	// audio format information
	printf("Audio Format:\r\n");
	printf("\tSamples per second: %" PRIiPTR "\r\n", pAPEDecompress->GetInfo(APE_INFO_SAMPLE_RATE));
	printf("\tBits per sample: %" PRIiPTR "\r\n", pAPEDecompress->GetInfo(APE_INFO_BITS_PER_SAMPLE));
	printf("\tNumber of channels: %" PRIiPTR "\r\n", pAPEDecompress->GetInfo(APE_INFO_CHANNELS));
	printf("\tPeak level: %" PRIiPTR "\r\n\r\n", pAPEDecompress->GetInfo(APE_INFO_PEAK_LEVEL));

	// size and duration information
	printf("Size and Duration:\r\n");
	printf("\tLength of file (s): %" PRIiPTR "\r\n", pAPEDecompress->GetInfo(APE_INFO_LENGTH_MS) / 1000);
	printf("\tFile Size (kb): %" PRIiPTR "\r\n\r\n", pAPEDecompress->GetInfo(APE_INFO_APE_TOTAL_BYTES) / 1024);
	
	// tag information
	printf("Tag Information:\r\n");
	
	CAPETag * pAPETag = (CAPETag *) pAPEDecompress->GetInfo(APE_INFO_TAG);
	BOOL bHasID3Tag = pAPETag->GetHasID3Tag();
	BOOL bHasAPETag = pAPETag->GetHasAPETag();

	
	if (bHasID3Tag || bHasAPETag)
	{
	    printf("\tID3 Tag: %s, APE Tag: %s", bHasID3Tag ? "Yes" : "No", bHasAPETag ? "" : "No");
	    if (bHasAPETag)
	    {
		printf("%d", pAPETag->GetAPETagVersion() / 1000);
	    }
	    printf("\n\n");
		// iterate through all the tag fields
		//BOOL bFirst = TRUE;
		CAPETagField * pTagField;
//		while (pAPETag->GetNextTagField(bFirst, &pTagField))
		int index = 0;
		while ((pTagField = pAPETag->GetTagField(index)) != NULL)
		{
			//bFirst = FALSE;
			index ++;
			
			// output the tag field properties (don't output huge fields like images, etc.)
			if (pTagField->GetFieldValueSize() > 128)
			{
				printf("\t%s: --- too much data to display ---\r\n", GetANSIFromUTF16(pTagField->GetFieldName()));
			}
			else
			{
/*
			    const wchar_t *fieldName;
			    char *name;
			    wchar_t fieldValue[255];
			    char *value;

			    fieldName = pTagField->GetFieldName();
			    name = GetANSIFromUTF16(fieldName);

			    memset(fieldValue, 0, 255 * sizeof(wchar_t));
			    int len;
			    pAPETag->GetFieldString(fieldName, fieldValue, &len);
			    
			    value = GetANSIFromUTF16(fieldValue);
*/
			    const wchar_t *fieldName;
			    char *name;
			    const char *fieldValue;
			    char *value;

			    fieldName = pTagField->GetFieldName();
			    name = GetANSIFromUTF16(fieldName);

			    fieldValue = pTagField->GetFieldValue();
			    if (pAPETag->GetAPETagVersion() == CURRENT_APE_TAG_VERSION)
			    {
				value = GetANSIFromUTF8((unsigned char *)fieldValue);
			    }
			    else
			    {
				value = (char *)fieldValue;
			    }
			    printf("\t%s : %s\n", name, value);
			}
		}
	}
	else 
	{
		printf("\tNot tagged\r\n\r\n");
	}
	
	///////////////////////////////////////////////////////////////////////////////
	// cleanup (just delete the object
	///////////////////////////////////////////////////////////////////////////////
	delete pAPEDecompress;

	///////////////////////////////////////////////////////////////////////////////
	// quit
	///////////////////////////////////////////////////////////////////////////////
	return 0;
}
コード例 #3
0
HRESULT CWavPackSplitterFilterInputPin::CompleteConnect(IPin *pReceivePin)
{
	HRESULT hr = CBaseInputPin::CompleteConnect(pReceivePin);
	if (FAILED(hr)) {
		return hr;
	}

	if (m_pWavPackParser) {
		wavpack_parser_free(m_pWavPackParser);
		m_pWavPackParser = NULL;
	}

	m_pWavPackParser = wavpack_parser_new((stream_reader*)m_pIACBW, FALSE);
	if (!m_pWavPackParser) {
		return E_FAIL;
	}

	// Compute total duration
	REFERENCE_TIME rtDuration;
	rtDuration = m_pWavPackParser->first_wphdr.total_samples;
	rtDuration = (rtDuration * 10000000) / m_pWavPackParser->sample_rate;
	m_pParentFilter->SetDuration(rtDuration);

	// parse APE Tag Header
	stream_reader* io = m_pWavPackParser->io;
	char buf[APE_TAG_FOOTER_BYTES];
	memset(buf, 0, sizeof(buf));
	uint32_t cur_pos = io->get_pos(io);
	DWORD file_size = io->get_length(io);
	if (cur_pos + APE_TAG_FOOTER_BYTES <= file_size) {
		io->set_pos_rel(io, -APE_TAG_FOOTER_BYTES, SEEK_END);
		if (io->read_bytes(io, buf, APE_TAG_FOOTER_BYTES) == APE_TAG_FOOTER_BYTES) {
			CAPETag* APETag = DNew CAPETag;
			if (APETag->ReadFooter((BYTE*)buf, APE_TAG_FOOTER_BYTES) && APETag->GetTagSize()) {
				size_t tag_size = APETag->GetTagSize();
				io->set_pos_rel(io, file_size - tag_size, SEEK_SET);
				BYTE *p = DNew BYTE[tag_size];
				if (io->read_bytes(io, p, tag_size) == tag_size) {
					if (APETag->ReadTags(p, tag_size)) {
						POSITION pos = APETag->TagItems.GetHeadPosition();
						while (pos) {
							CApeTagItem* item = APETag->TagItems.GetAt(pos);
							CString TagKey = item->GetKey();
							TagKey.MakeLower();

							if (item->GetType() == CApeTagItem::APE_TYPE_BINARY) {
								m_CoverMime = _T("");
								if (!TagKey.IsEmpty()) {
									CString ext = TagKey.Mid(TagKey.ReverseFind('.')+1);
									if (ext == _T("jpeg") || ext == _T("jpg")) {
										m_CoverMime = _T("image/jpeg");
									} else if (ext == _T("png")) {
										m_CoverMime = _T("image/png");
									}
								}

								if (!m_Cover.GetCount() && !m_CoverMime.IsEmpty()) {
									m_CoverFileName = TagKey;
									m_Cover.SetCount(tag_size);
									memcpy(m_Cover.GetData(), item->GetData(), item->GetDataLen());
								}
							} else {
								CString TagValue = item->GetValue();
								if (TagKey == _T("cuesheet")) {
									CAtlList<Chapters> ChaptersList;
									if (ParseCUESheet(TagValue, ChaptersList)) {
										m_pParentFilter->ChapRemoveAll();
										while (ChaptersList.GetCount()) {
											Chapters cp = ChaptersList.RemoveHead();
											m_pParentFilter->ChapAppend(cp.rt, cp.name);
										}
									}
								}

								if (TagKey == _T("artist")) {
									m_pParentFilter->SetProperty(L"AUTH", TagValue);
								} else if (TagKey == _T("comment")) {
									m_pParentFilter->SetProperty(L"DESC", TagValue);
								} else if (TagKey == _T("title")) {
									m_pParentFilter->SetProperty(L"TITL", TagValue);
								} else if (TagKey == _T("year")) {
									m_pParentFilter->SetProperty(L"YEAR", TagValue);
								} else if (TagKey == _T("album")) {
									m_pParentFilter->SetProperty(L"ALBUM", TagValue);
								}
							}

							APETag->TagItems.GetNext(pos);
						}
					}
				}

				delete [] p;
			}

			delete APETag;
		}

		io->set_pos_rel(io, cur_pos, SEEK_SET);
	}

	return S_OK;
}
コード例 #4
0
ファイル: ApeDecoder.cpp プロジェクト: zhaojunlucky/Audio
HRESULT ApeDecoder::Open( LPWSTR strFileName, WAVEFORMATEX* pwfx, DWORD dwFlags )
{
	//char ex[2048] = "ape";
	//if(!isFile_ex(strFileName,ex))
	//{
	//	return M_FILE_EXTENSION_NOT_EXPECTED;//E_FAIL;
	//}
	if(WAVEFILE_READ != dwFlags)
	{
		return M_INVALID_PARAMETERS;//E_FAIL;
	}
	int nRetVal = 0;
	m_pAPEDecompress = CreateIAPEDecompress(strFileName,&nRetVal);
	if(NULL == m_pAPEDecompress)
	{
		return M_APE_FAIL_CREATE_DECODER;//E_FAIL;
	}
	m_block_algin = m_pAPEDecompress->GetInfo(APE_INFO_BLOCK_ALIGN);
	m_nWaveDataAllocSize = APE_BLOCKS_NUM * m_block_algin;
	m_pWaveDataAlloc = (BYTE*) malloc(m_nWaveDataAllocSize);
	m_pWaveDataBuffer = m_pWaveDataAlloc;
	m_total_blocks = m_pAPEDecompress->GetInfo(APE_DECOMPRESS_TOTAL_BLOCKS);
	m_id3.bitrate = m_pAPEDecompress->GetInfo(APE_DECOMPRESS_AVERAGE_BITRATE);
	// get and set wave header
	nRetVal = m_pAPEDecompress->GetInfo(APE_INFO_WAVEFORMATEX,(int) m_pwfx,0);
	if(0 != nRetVal)
	{
		return M_APE_FAIL_GET_WAVE_INFO;//E_FAIL;
	}
	m_dwSize = m_pAPEDecompress->GetInfo(APE_INFO_WAV_DATA_BYTES);
	if(m_dwSize <= 0)
	{
		return M_APE_FAIL_GET_INFO;//E_FAIL;
	}
	m_id3.duration_times = (float)m_dwSize / (float)m_pwfx->nAvgBytesPerSec; 

	m_id3.EmptyTags();
	CAPETag * pAPETag = (CAPETag *) m_pAPEDecompress->GetInfo(APE_INFO_TAG);
	BOOL bHasID3Tag = pAPETag->GetHasID3Tag();
	BOOL bHasAPETag = pAPETag->GetHasAPETag();

	if (bHasID3Tag || bHasAPETag)
	{
		// iterate through all the tag fields
		
		CAPETagField * pTagField = pAPETag->GetTagField(APE_TAG_FIELD_TITLE);
		if(pTagField)
		{
			/*printf("%X\n",pTagField->GetFieldValue()[0]);
			printf("%X\n",pTagField->GetFieldValue()[1]);
			printf("%X\n",pTagField->GetFieldValue()[2]);*/
			if(pTagField->GetIsUTF8Text())
			{
				CCharWCharHelper cwh;
				cwh.ZMultiByteToWideChar(pTagField->GetFieldValue(),ZUTF8);
				m_id3.title.SetData(cwh.GetWideChar(),cwh.GetWideCharLength());
			}
			else
				m_id3.title.SetData(pTagField->GetFieldValue(),strlen(pTagField->GetFieldValue()));
		}


		pTagField = pAPETag->GetTagField(APE_TAG_FIELD_ARTIST);
		if(pTagField)
		{
			if(pTagField->GetIsUTF8Text())
			{
				CCharWCharHelper cwh;
				cwh.ZMultiByteToWideChar(pTagField->GetFieldValue(),ZUTF8);
				m_id3.artist.SetData(cwh.GetWideChar(),cwh.GetWideCharLength());
			}
			else
				m_id3.artist.SetData(pTagField->GetFieldValue(),strlen(pTagField->GetFieldValue()));
		}


		pTagField = pAPETag->GetTagField(APE_TAG_FIELD_ALBUM);
		if(pTagField)
		{
			if(pTagField->GetIsUTF8Text())
			{
				CCharWCharHelper cwh;
				cwh.ZMultiByteToWideChar(pTagField->GetFieldValue(),ZUTF8);
				m_id3.album.SetData(cwh.GetWideChar(),cwh.GetWideCharLength());
			}
			else
				m_id3.album.SetData(pTagField->GetFieldValue(),strlen(pTagField->GetFieldValue()));
		}


		pTagField = pAPETag->GetTagField(APE_TAG_FIELD_YEAR);
		if(pTagField)
		{
			if(pTagField->GetIsUTF8Text())
			{
				CCharWCharHelper cwh;
				cwh.ZMultiByteToWideChar(pTagField->GetFieldValue(),ZUTF8);
				m_id3.year.SetData(cwh.GetWideChar(),cwh.GetWideCharLength());
			}
			else
				m_id3.year.SetData(pTagField->GetFieldValue(),strlen(pTagField->GetFieldValue()));
		}


		pTagField = pAPETag->GetTagField(APE_TAG_FIELD_COMMENT);
		if(pTagField)
		{
			if(pTagField->GetIsUTF8Text())
			{
				CCharWCharHelper cwh;
				cwh.ZMultiByteToWideChar(pTagField->GetFieldValue(),ZUTF8);
				m_id3.comment.SetData(cwh.GetWideChar(),cwh.GetWideCharLength());
			}
			else
				m_id3.comment.SetData(pTagField->GetFieldValue(),strlen(pTagField->GetFieldValue()));
		}


		pTagField = pAPETag->GetTagField(APE_TAG_FIELD_GENRE);
		if(pTagField)
		{
			if(pTagField->GetIsUTF8Text())
			{
				CCharWCharHelper cwh;
				cwh.ZMultiByteToWideChar(pTagField->GetFieldValue(),ZUTF8);
				m_id3.genre.SetData(cwh.GetWideChar(),cwh.GetWideCharLength());
			}
			else
				m_id3.genre.SetData(pTagField->GetFieldValue(),strlen(pTagField->GetFieldValue()));
		}

		
	}
	return S_OK;
}
コード例 #5
0
ファイル: Sample 1.cpp プロジェクト: Kr0nZ/boxee
int main(int argc, char* argv[]) 
{
	///////////////////////////////////////////////////////////////////////////////
	// error check the command line parameters
	///////////////////////////////////////////////////////////////////////////////
	if (argc != 2) 
	{
		printf("~~~Improper Usage~~~\r\n\r\n");
		printf("Usage Example: Sample 1.exe 'c:\\1.ape'\r\n\r\n");
		return 0;
	}

	///////////////////////////////////////////////////////////////////////////////
	// variable declares
	///////////////////////////////////////////////////////////////////////////////
	int					nRetVal = 0;										// generic holder for return values
	char				cTempBuffer[256]; ZeroMemory(&cTempBuffer[0], 256);	// generic buffer for string stuff
	char *				pFilename = argv[1];								// the file to open
	IAPEDecompress *	pAPEDecompress = NULL;								// APE interface
		
	///////////////////////////////////////////////////////////////////////////////
	// open the file and error check
	///////////////////////////////////////////////////////////////////////////////
	pAPEDecompress = CreateIAPEDecompress(pFilename, &nRetVal);
	if (pAPEDecompress == NULL) 
	{
		printf("Error opening APE file. (error code %d)\r\n\r\n", nRetVal);
		return 0;
	}

	///////////////////////////////////////////////////////////////////////////////
	// display some information about the file
	///////////////////////////////////////////////////////////////////////////////
	printf("Displaying information about '%s':\r\n\r\n", pFilename);

	// file format information
	printf("File Format:\r\n");
	printf("\tVersion: %.2f\r\n", float(pAPEDecompress->GetInfo(APE_INFO_FILE_VERSION)) / float(1000));
	switch (pAPEDecompress->GetInfo(APE_INFO_COMPRESSION_LEVEL))
	{
		case COMPRESSION_LEVEL_FAST: printf("\tCompression level: Fast\r\n\r\n"); break;
		case COMPRESSION_LEVEL_NORMAL: printf("\tCompression level: Normal\r\n\r\n"); break;
		case COMPRESSION_LEVEL_HIGH: printf("\tCompression level: High\r\n\r\n"); break;
		case COMPRESSION_LEVEL_EXTRA_HIGH: printf("\tCompression level: Extra High\r\n\r\n"); break;
	}

	// audio format information
	printf("Audio Format:\r\n");
	printf("\tSamples per second: %d\r\n", pAPEDecompress->GetInfo(APE_INFO_SAMPLE_RATE));
	printf("\tBits per sample: %d\r\n", pAPEDecompress->GetInfo(APE_INFO_BITS_PER_SAMPLE));
	printf("\tNumber of channels: %d\r\n", pAPEDecompress->GetInfo(APE_INFO_CHANNELS));
	printf("\tPeak level: %d\r\n\r\n", pAPEDecompress->GetInfo(APE_INFO_PEAK_LEVEL));

	// size and duration information
	printf("Size and Duration:\r\n");
	printf("\tLength of file (s): %d\r\n", pAPEDecompress->GetInfo(APE_INFO_LENGTH_MS) / 1000);
	printf("\tFile Size (kb): %d\r\n\r\n", pAPEDecompress->GetInfo(APE_INFO_APE_TOTAL_BYTES) / 1024);
	
	// tag information
	printf("Tag Information:\r\n");
	
	CAPETag * pAPETag = (CAPETag *) pAPEDecompress->GetInfo(APE_INFO_TAG);
	BOOL bHasID3Tag = pAPETag->GetHasID3Tag();
	BOOL bHasAPETag = pAPETag->GetHasAPETag();
	
	if (bHasID3Tag || bHasAPETag)
	{
		// iterate through all the tag fields
		BOOL bFirst = TRUE;
		CAPETagField * pTagField;
		while (pAPETag->GetNextTagField(bFirst, &pTagField))
		{
			bFirst = FALSE;
			
			// output the tag field properties (don't output huge fields like images, etc.)
			if (pTagField->GetFieldValueSize() > 128)
			{
				printf("\t%s: --- too much data to display ---\r\n", pTagField->GetFieldName());
			}
			else
			{
				printf("\t%s: %s\r\n", pTagField->GetFieldName(), pTagField->GetFieldValue());
			}
		}
	}
	else 
	{
		printf("\tNot tagged\r\n\r\n");
	}
	
	///////////////////////////////////////////////////////////////////////////////
	// cleanup (just delete the object
	///////////////////////////////////////////////////////////////////////////////
	delete pAPEDecompress;

	///////////////////////////////////////////////////////////////////////////////
	// quit
	///////////////////////////////////////////////////////////////////////////////
	return 0;
}