Ejemplo n.º 1
0
LONG CPlayerView::OnWinAmpPlugWmUserMessage( WPARAM wParam, LPARAM lParam )
{
	int nReturn = 0;

	ENTRY_TRACE( _T( "CPlayerView::OnWinAmpPlugWmUserMessage( %d, %d)" ), wParam, lParam );

	switch ( lParam )
	{
		case 104:
			// Return Playing Status 
			if ( PAUSING == m_nStatus  )
			{
				nReturn = 3;
			} else
			if ( PLAYING == m_nStatus  )
			{
				nReturn = 1;
			}
		break;

		case 105:
			// return playing position in ms
			return m_nCurrentTime;
		break;

		case 106:
			// resume playing at pos wParam
			nReturn = 1;
		break;
	}

	EXIT_TRACE( _T( "CPlayerView::OnWinAmpPlugWmUserMessage, return %d" ), nReturn );

	return nReturn;
}
Ejemplo n.º 2
0
void CPlayerView::OnPause() 
{
	ENTRY_TRACE( _T( "CPlayerView::OnPause()" ) );

	if ( PLAYING == m_nStatus )
	{
		m_nStatus = PAUSING;

		if ( m_pPlayStream )
		{
			m_dwSeekOffset+= m_pPlayStream->GetCurrentTime();

			m_pPlayStream->Pause();
		}

		m_ePaused.ResetEvent();
	}
	else
	{

		if ( m_pPlayStream )
		{
			m_pPlayStream->Resume();
		}

		m_nStatus = PLAYING;

		m_ePaused.SetEvent();

	}
	UpdateData( FALSE );

	EXIT_TRACE( _T( "CPlayerView::OnPause()" ) );

}
Ejemplo n.º 3
0
void CCDPlayDigital::Pause( BOOL bPause )
{
	ENTRY_TRACE( _T( "CCDPlayDigital::Pause( %d )" ), bPause );

	m_bPause = bPause;

	EXIT_TRACE( _T( "CCDPlayDigital::Pause()" ) );
}
Ejemplo n.º 4
0
void CPlayerView::OnNext() 
{
	ENTRY_TRACE( _T( "CPlayerView::OnNext()" ) );

	m_ThreadCommand = THREAD_PLAY_NEXT_TRACK;
	m_bAbortCurrent = TRUE;

	EXIT_TRACE( _T( "CPlayerView::OnNext()" ) );
}
Ejemplo n.º 5
0
// CONSRUCTOR
CTagData::CTagData()
{
	ENTRY_TRACE( _T( "CTagData::CTagData()" ) );

    // Initialize the variables
	Init();

	EXIT_TRACE( _T( "CTagData::CTagData()" ) );
}
Ejemplo n.º 6
0
void CPlayerView::OnDetails() 
{
	ENTRY_TRACE( _T( "CPlayerView::OnDetails()" ) );

	if ( m_pInStream )
	{
		m_pInStream->InfoBox( GetSafeHwnd() );
	}

	EXIT_TRACE( _T( "CPlayerView::OnDetails()" ) );
}
Ejemplo n.º 7
0
void CCDPlayDigital::Stop( )
{
	ENTRY_TRACE( _T( "CCDPlayDigital::Stop()" ) );

	m_bPause = FALSE;
	m_bAbort = TRUE;

	// wait till thread has been finished
	while ( NULL != (volatile void*)m_pThread )
	{
		::Sleep( 10 );
	}

	EXIT_TRACE( _T( "CCDPlayDigital::Stop()" ) );
}
Ejemplo n.º 8
0
void CCDPlayDigital::Play( DWORD dwBeginSector, DWORD dwEndSector )
{
	ENTRY_TRACE( _T( "CCDPlayDigital::Play( %d, %d )" ), dwBeginSector, dwEndSector );

	m_bIsPlaying = TRUE;

	ASSERT( dwBeginSector <= dwEndSector );

	SetBeginSector( dwBeginSector );
	SetEndSector( dwEndSector );

	m_dwTotalBytes = (dwEndSector - dwBeginSector ) * CB_CDDASECTORSIZE;
	m_dwBytesWritten = 0;

	// Fire thread
	m_pThread = AfxBeginThread( RipAndPlay, (void*)this, g_config.GetThreadPriority() );

	EXIT_TRACE( _T( "CCDPlay::Play( )" ) );

}
Ejemplo n.º 9
0
CCDPlayDigital::CCDPlayDigital():
			CObject()
{
	ENTRY_TRACE( _T( "CCDPlayDigital::CCDPlayDigital" ) );

	m_pThread = NULL;
	m_bAbort = FALSE;
	m_dwBeginSector = 0;
	m_dwEndSector = 0;
	m_dwCurrentSector = 0;
	m_bIsPlaying = TRUE;
	m_dwTotalBytes = 0;
	m_dwBytesWritten = 0;
	m_dwCurrentTime = 0;
	m_dwSeekTimeOffset = 0;
	m_bPause = FALSE;

	EXIT_TRACE( _T( "CCDPlayDigital::CCDPlayDigital" ) );

}
Ejemplo n.º 10
0
void CPlayerView::OnStop() 
{
	ENTRY_TRACE( _T( "CPlayerView::OnStop()" ) );

	// stop immediately the output WAV playing
	if ( m_pPlayStream )
	{
		m_pPlayStream->Pause();
		m_pPlayStream->Stop();
	}

	// Now make sure that the thread gets aborted properly
	m_bAbortThread = TRUE;

	// Set status to abort
	m_nStatus = ABORT;

	// Make sure that pause event has been set
	m_ePaused.SetEvent();

	// Wait for thread to finish
	if ( WAIT_OBJECT_0 != WaitForSingleObject( m_eThreadFinished, 13000 ) )
	{
		if ( m_pThread )
		{
			m_pThread->ResumeThread();
			TerminateThread( m_pThread->m_hThread, -2 );
		}
	}

	m_pThread = NULL;

	m_nStatus = IDLE;

	SetControls();

	m_Position.SetPos( 0 );

	EXIT_TRACE( _T( "CPlayerView::OnStop()" ) );

}
Ejemplo n.º 11
0
void CMP3ToWavDlg::OnCancel() 
{
	ENTRY_TRACE( _T( "CMP3ToWavDlg::OnCancel" ) );

	// Beep if we have finished
	MessageBeep( MB_OK );
	MessageBeep( 0xFFFFFFFF );

	// Set abort flag, so don't process any more files
	m_bAbortThread = TRUE;

	// Stop the timer
	KillTimer( TIMERID );

	// Wait for thread to finish
	WaitForSingleObject( m_eThreadFinished, INFINITE );


	// Destroy myself
	DestroyWindow();

	EXIT_TRACE( _T( "CMP3ToWavDlg::OnCancel" ) );
}
Ejemplo n.º 12
0
CDEX_ERR CEncoderFaacDll::InitEncoder( CTaskInfo* pTask )
{
	CDEX_ERR bReturn = CDEX_OK;

	CUString	strLang;

	ENTRY_TRACE( _T( "CEncoderFaacDll::InitEncoder" ) );

	CEncoder::InitEncoder( pTask );

	if ( !LoadDLL(	m_strEncoderPath,
					_W( "\\encoders\\libraries\\libfaac\\Dll" ),
					m_hDLL,
					FALSE,
					FALSE ) )
	{
		bReturn = CDEX_ERROR;
	}

	EXIT_TRACE( _T( "CEncoderFaacDll::InitEncoder, return value %d" ), bReturn );

	return bReturn;
}
Ejemplo n.º 13
0
CDEX_ERR DeInitAspiDll( )
{
	CDEX_ERR bReturn = CDEX_OK;

	ENTRY_TRACE( _T( "DeInitAspiDLL()" ) );

	// release the ASPI library
	if ( hAspiLib )
	{
		FreeLibrary( hAspiLib );
		hAspiLib = NULL;
	}

	// DeInit NT SCSI library
	(void)NtScsiDeInit();



	EXIT_TRACE( _T( "DeInitAspiDLL(), return value: %d" ), bReturn );

	return bReturn;

}
Ejemplo n.º 14
0
// Init CTagData variables
void CTagData::Init()
{
	ENTRY_TRACE( _T( "CTagData::Init()" ) );

	// Initialize all strings and variables
    m_strTitle		= _T( "" );
    m_strArtist		= _T( "" );
    m_strAlbum		= _T( "" );
    m_strYear		= _T( "" );
    m_strComment	= _T( "" );
	m_strEncodedBy  = _T( "" );
    m_strGenre		= _T( "" );
	m_strLengthInMs = _T( "" );
	m_dwCDBID		= 0;
	m_dwVOLID		= 0;
	m_dwCDBID       = 0;
	m_dwVOLID       = 0;
	m_dwTotalTracks = 0;
    m_lTrackOffset  = 0;
	memset( m_btaRawToc, 0, sizeof( m_btaRawToc ) );

    EXIT_TRACE( _T( "CTagData::Init()" ) );
}
Ejemplo n.º 15
0
CDEX_ERR CEncoderFaacDll::OpenStream(CUString strOutFileName,DWORD dwSampleRate,WORD nChannels)
{
	CDEX_ERR	bReturn		= CDEX_OK;
	bool		bStereo		= true;
	CUString		strLang;

    CUStringConvert strCnv;

	ENTRY_TRACE( _T( "CEncoderFaacDll::OpenStream( %s, %d %d" ),
                strCnv.ToT( strOutFileName + _W( "." ) + GetExtension() ),
				dwSampleRate,
				nChannels );


	// setup number of input channels
	m_nInputChannels = nChannels;

	// setup number of output channels
	if ( ( m_nMode & 0xFFFF ) == BE_MP3_MODE_MONO )
	{
		bStereo = false;
	}

	// mixer setup
	if ( ( false == bStereo ) && ( 2 == nChannels ) )
	{
		m_bDownMixToMono  = TRUE;
	}
	else
	{
		m_bDownMixToMono = FALSE;
	}

	if (  ( true == bStereo ) && ( 1 == nChannels ) )
	{
		m_bUpMixToStereo = TRUE;
	}
	else
	{
		m_bUpMixToStereo = FALSE;
	}

		
	// try to get a handle
	m_handle = faacEncOpen( dwSampleRate,
							(bStereo == true )? 2 : 1,
							&m_dwInBufferSize,
							&m_dwOutBufferSize );


	if ( NULL == m_handle )
	{
		CUString strMsg;

		strLang = g_language.GetString( IDS_LOADLIBRARY_FAILED );

		strMsg.Format(	strLang , (LPCWSTR)CUString( ( g_config.GetAppPath() + _W( "\\" ) + m_strEncoderPath ) ) );

		CDexMessageBox( strMsg );
		
		LTRACE( _T( "CEncoderFaacDll::OpenStream Failed to get handle" ) );

		bReturn = CDEX_ERROR;
	}

	if ( CDEX_OK == bReturn )
	{
		// get current config
		m_pConfig = faacEncGetCurrentConfiguration( m_handle );

		// set settings
		if ( GetUserN1() & 0x08 )
		{
			m_pConfig->mpegVersion = FAAC_MPEG4;
		}
		else
		{
			m_pConfig->mpegVersion = FAAC_MPEG2;
		}

		m_pConfig->bitRate = m_nBitrate * 1000;

		m_pConfig->allowMidside = ( GetUserN1() & 0x02 ) ? TRUE : FALSE;

		m_pConfig->useLfe = ( GetUserN1() & 0x04 ) ? TRUE : FALSE;; /* ? */
		m_pConfig->useTns = ( GetUserN1() & 0x01 ) ? TRUE : FALSE;
		m_pConfig->inputFormat = FAAC_INPUT_16BIT;
		m_pConfig->aacObjectType = ( GetUserN2() & 0x07 );
		m_pConfig->shortctl = SHORTCTL_NORMAL;

		switch ( ( GetUserN1() >> 8 ) & 0x0F )
		{
			case 0: m_pConfig->bandWidth = 16000; break;
			case 1: m_pConfig->bandWidth = 18000; break;
			case 2: m_pConfig->bandWidth = 19500; break;
			default: m_pConfig->bandWidth = 19500; break;
		}

		// set new config
		if ( FALSE == faacEncSetConfiguration( m_handle, m_pConfig ) )
		{
			CUString strMsg;

			strLang = g_language.GetString( IDS_LOADLIBRARY_FAILED );

			strMsg.Format(	strLang , (LPCWSTR)CUString( g_config.GetAppPath() + _W( "\\" ) + m_strEncoderPath ) );

			CDexMessageBox( strMsg );
			
			LTRACE( _T( "CEncoderFaacDll::OpenStream Failed to set config" ) );

			bReturn = CDEX_ERROR;
		}

	}
Ejemplo n.º 16
0
CDEX_ERR InitAspiDll( bool& bUseNtScsi )
{
	CDEX_ERR bReturn = CDEX_OK;
	TCHAR lpszPathName[ MAX_PATH + 1 ] = {'\0',};

	ENTRY_TRACE( _T( "InitAspiDLL( %d )" ), bUseNtScsi );

	if ( FALSE == bUseNtScsi ) 
	{
		LTRACE( _T( "Try to use the ASPI libraries" ) );

		// try to load DLL ( no path )
		_tcscpy( lpszPathName, _T( "wnaspi32.dll" ) );

		hAspiLib = LoadLibrary( lpszPathName );

		LTRACE( _T( "Trying to load DLL: \"%s\", results: %d" ), lpszPathName, hAspiLib );

		// check result
		if ( NULL == hAspiLib )
		{
			// try to load DLL from the system directory
			GetSystemDirectory( lpszPathName, MAX_PATH );

			_tcscat( lpszPathName, _T( "\\wnaspi32.dll" ) );
			
			hAspiLib = LoadLibrary( lpszPathName );

			LTRACE( _T( "Trying to load DLL: \"%s\", results: %d" ), lpszPathName, hAspiLib );

			// if failed, try the windows\system directory
			if ( NULL == hAspiLib )
			{
				// try to load DLL from the system directory
				GetWindowsDirectory( lpszPathName, MAX_PATH );

				_tcscat( lpszPathName, _T( "\\wnaspi32.dll" ) );

				hAspiLib = LoadLibrary( lpszPathName );

				LTRACE( _T( "Trying to load DLL: \"%s\", results: %d" ), lpszPathName, hAspiLib );
			}

			// try to use the ASPI library installed by Nero
			if (NULL == hAspiLib)
			{
				HKEY	ahead;

				if (RegOpenKey( HKEY_LOCAL_MACHINE, _T( "Software\\Ahead\\Shared" ), &ahead ) == ERROR_SUCCESS)
				{
					DWORD	size;
					DWORD	type;

					RegQueryValueEx( ahead, _T( "NeroAPI" ), 0, &type, 0, &size );
					RegQueryValueEx( ahead, _T( "NeroAPI" ), 0, &type, (BYTE *) &lpszPathName, &size );

					RegCloseKey( ahead );

					_tcscpy( lpszPathName,  _T( "\\wnaspi32.dll" ) );

					hAspiLib = LoadLibrary( lpszPathName );
				}
			}
		}

		// check ASPI results
		if ( NULL == hAspiLib )
		{
			OSVERSIONINFO	osVersion;

			memset( &osVersion, 0x00, sizeof( osVersion ) );

			osVersion.dwOSVersionInfoSize = sizeof( osVersion );

			GetVersionEx( &osVersion );

			if ( VER_PLATFORM_WIN32_NT == osVersion.dwPlatformId )
			{
				LTRACE( _T( "Native SCSI supported, but not selected" ) );
				bReturn = CDEX_NATIVEEASPISUPPORTEDNOTSELECTED;
			}
			else
			{
				LTRACE( _T( "Native NOT SCSI supported, platform ID = %d" ), osVersion.dwPlatformId );
				bReturn = CDEX_FAILEDTOLOADASPIDRIVERS;
			}

		}
	}
	else
	{
		LTRACE( _T( "Try to use the Native NT SCSI libraries" ) );

		// Use native NT SCSI library
		if ( NtScsiInit() > 0 )
		{
			LTRACE( _T( "Use of Native NT SCSI libraries supported, return OK" ) );
			bReturn = CDEX_OK;
		}
		else
		{
			LTRACE( _T( "Native NOT SCSI supported" ) );
			bReturn = CDEX_NATIVEEASPINOTSUPPORTED;
		}
	}

	if ( CDEX_OK == bReturn )
	{
		if ( FALSE == bUseNtScsi )
		{
			GetASPI32SupportInfo	=(GETASPI32SUPPORTINFO)GetProcAddress(hAspiLib,TEXT_GETASPI32SUPPORTINFO);
			SendASPI32Command		=(SENDASPI32COMMAND)GetProcAddress(hAspiLib,TEXT_SENDASPI32COMMAND);
			//	GetASPI32Buffer			=(GETASPI32BUFFER)GetProcAddress(hAspiLib,TEXT_GETASPI32BUFFER);
			//	FreeASPI32Buffer		=(FREEASPI32BUFFER)GetProcAddress(hAspiLib,TEXT_FREEASPI32BUFFER);
			//	GetASPI32DLLVersion		=(GETASPI32DLLVERSION)GetProcAddress(hAspiLib,TEXT_GETASPI32DLLVERSION);
			//	TranslateASPI32Address	=(TRANSLATEASPI32ADDRESS)GetProcAddress(hAspiLib,TEXT_TRANSLATEASPI32ADDRESS);
		}
		else
		{
			GetASPI32SupportInfo	= NtScsiGetASPI32SupportInfo;
			SendASPI32Command		= NtScsiSendASPI32Command;
		}

		if (	GetASPI32SupportInfo	==NULL	|| 
				SendASPI32Command		==NULL
	//			GetASPI32Buffer			==NULL	||
	//			FreeASPI32Buffer		==NULL	
	//			|| TRUE
	//			GetASPI32DLLVersion		==NULL	|| 
	//			TranslateASPI32Address	==NULL
				)
		{
			LTRACE( _T( "InitAspiDLL::Invalid Pointer: GetASPI32SupportInfo=%p, SendASPI32Command=%p"), GetASPI32SupportInfo, SendASPI32Command );

			FreeLibrary( hAspiLib );
			hAspiLib = NULL;

			GetASPI32SupportInfo = NULL;
			SendASPI32Command = NULL;

			bReturn = CDEX_FAILEDTOLOADASPIDRIVERS;
		}
	}

	EXIT_TRACE( _T( "InitAspiDLL, return value %d" ), bReturn );
	
	return bReturn;
}
Ejemplo n.º 17
0
BOOL CI18n::LoadLanguage(CString strLanguage)
{

	ENTRY_TRACE(_T("CI18n::LoadLanguage(%s)"), strLanguage);

	CString strFilepath;

	strFilepath.Format(_T("%s\\%s.txt"), g_sSettings.GetWorkingDir() + "\\languages", strLanguage);

	CStdioFile fFile;
	CFileException e;
	CString strText	= "";
	sections  sMode = COMMENT;
	
	TRY{

		if(!fFile.Open(strFilepath, CFile::modeRead|CFile::shareDenyWrite|CFile::typeText, &e)){

			LTRACE(_T("Failed to open language file %s"), strFilepath);
			return FALSE;
		}
		fFile.SeekToBegin();
		
		while(fFile.ReadString(strText)){

			strText.TrimLeft();
			strText.TrimRight();
			
			if(strText == _T("START"))      sMode = DIALOG_SEC;
			else if(strText == _T("END"))        sMode = COMMENT;
			else if(strText == _T("INFO_START")) sMode = LANGUAGE_HEADER;
			else if(strText == _T("INFO_END"))   sMode = COMMENT;
			
			if(!strText.IsEmpty() && (strText.Left(1) == _T("#"))){


				switch(sMode){

				case DIALOG_SEC:
					m_viItems.push_back(GetI18nItem(Ascii2Unicode(strText)));
					break;
				case LANGUAGE_HEADER:

					if(strText.Left(10) == _T("#LANGUAGE#")){

						m_strLanguageName = strText.Mid(11, strText.GetLength() - 11);
						m_strLanguageName.TrimLeft();
						m_strLanguageName.TrimRight();
						m_strLanguageName = m_strLanguageName.Mid(1, m_strLanguageName.GetLength() - 2);
					}
					else if(strText.Left(10) == _T("#CODEPAGE#")){

						m_strCodepage = strText.Mid(11, strText.GetLength() - 11);
						m_strCodepage.TrimLeft();
						m_strCodepage.TrimRight();						
						m_strCodepage = m_strCodepage.Mid(1, m_strCodepage.GetLength() - 2);
						m_dwCodePageID = _ttoi(m_strCodepage);
						
					}
					else if(strText.Left(8) == _T("#AUTHOR#")){

						m_strAuthor = strText.Mid(8, strText.GetLength() - 8);
						m_strAuthor.TrimLeft();
						m_strAuthor.TrimRight();						
						m_strAuthor = m_strAuthor.Mid(1, m_strAuthor.GetLength() - 2);
					}
					break;
				}
			}
		}

		fFile.Close();
	}
	CATCH( CFileException, e )
	{

	   #ifdef _DEBUG
		  afxDump << "File could not be opened " << e->m_cause << "\n";
	   #endif

	   m_bLoaded = FALSE;
	   m_strLoadedLang = "";
	}
Ejemplo n.º 18
0
UINT CPlayerView::PlayThreadFunc(PVOID pParams)
{
	BYTE*			pStream		 = NULL;
	CDEX_ERR		bErr		 = CDEX_OK;
	CPlayerView*	pDlg		 = NULL;
	int				nCurrentFile = -1;
	CString			strFileName;

	ENTRY_TRACE( _T( "CPlayerView::PlayFunc" ) );

	nCurrentFile	= 0;

	pDlg=(CPlayerView*)pParams;

	pDlg->m_bAbortThread	= FALSE;
	pDlg->m_nTotalTime = 0;
	pDlg->m_nCurrentTime = 0;

	nCurrentFile = 	pDlg->m_PlayList.GetCurSel( );

	if ( pDlg->GetPlayRandom() )
	{
		srand( (unsigned)time( NULL ) );
		nCurrentFile = rand() % pDlg->m_vFileNames.size();
	}

	if ( nCurrentFile < 0 )
	{
		nCurrentFile = 0;
	}

	while(	( nCurrentFile >= 0 ) &&
			( nCurrentFile < (int)pDlg->m_vFileNames.size() ) && 
			( FALSE == pDlg->m_bAbortThread ) )
	{
		DWORD	dwStreamIndex=0;

		strFileName = pDlg->m_vFileNames[ nCurrentFile ];

#ifdef _DEBUG
//		strFileName = "http://urn.nottingham.ac.uk/urnlive.pls";
//		strFileName = "http://reclib.su.nottingham.ac.uk:8080";
#endif

		pDlg->m_PlayList.SetCurSel( nCurrentFile );

		LTRACE( _T( "Playing track %s (file %d)" ), strFileName, nCurrentFile );

		pDlg->SetThreadCommand( THREAD_PLAY_NEXT_TRACK );

		// Delete the old stream if it does exist
		if ( pDlg->m_pInStream )
		{
			delete pDlg->m_pInStream; pDlg->m_pInStream = NULL;
		}


		// create proper input stream
		pDlg->m_pInStream = ICreateStream( CUString( strFileName ) ); 

		pDlg->m_dwSeekOffset = 0;

		// Open the MPEG stream
		if (pDlg->m_pInStream->OpenStream( CUString( strFileName ) ) )
		{
			DWORD	dwInBufferSize = pDlg->m_pInStream->GetBufferSize();
			int		nMPEGBytes=0;

			// Create a play stream object
			pDlg->m_pPlayStream=new PlayWavStream;

			pDlg->m_pPlayStream->CopyStreamInfo( *pDlg->m_pInStream );

			// Initialize play stream object
			if ( FALSE == pDlg->m_pPlayStream->OpenStream( _W( "" ) ) )
			{
				pDlg->m_bAbortThread = TRUE;
			}

			// Allocate stream input buffer
			auto_ptr<BYTE> pStream( new BYTE[ dwInBufferSize  + STREAMBUFFERSIZE ] );
	
			pDlg->m_bAbortCurrent = FALSE;

			// Set status
			pDlg->m_nStatus = PLAYING;

			while ( ( !pDlg->m_bAbortThread ) && 
					( FALSE == pDlg->m_bAbortCurrent ) )
			{

				if ( PLAYING != pDlg->m_nStatus )
				{
					WaitForSingleObject( pDlg->m_ePaused, INFINITE );
					dwStreamIndex = 0;
					pDlg->m_pInStream->Seek( pDlg->m_dwSeekOffset, SEEK_TIME );

				}

				if ( pDlg->m_bAbortThread )
				{
					break;
				}

				if ( (nMPEGBytes = pDlg->m_pInStream->Read( (BYTE*)( pStream.get() ) + dwStreamIndex,dwInBufferSize ) ) >0 )
				{
					// increase current stream index position
					dwStreamIndex += nMPEGBytes ;

					// play the stuff when there is STREAMBUFFERSIZE samples are present
					while ( ( dwStreamIndex >= STREAMBUFFERSIZE ) && 
							( FALSE == pDlg->m_bAbortThread )  &&
							( FALSE == pDlg->m_bAbortCurrent ) )
					{
						if ( PLAYING != pDlg->m_nStatus )
						{
							break;
						}

						pDlg->m_pPlayStream->Write( pStream.get(), STREAMBUFFERSIZE );
						dwStreamIndex-= STREAMBUFFERSIZE;
						memmove( pStream.get() , (BYTE*)pStream.get() + STREAMBUFFERSIZE, dwStreamIndex );
					}

					pDlg->m_dwBitRate=pDlg->m_pInStream->GetBitRate();
					pDlg->m_nTotalTime=pDlg->m_pInStream->GetTotalTime();
				}
				else
				{
					while ( dwStreamIndex )
					{
						DWORD dwBytes = min( STREAMBUFFERSIZE, dwStreamIndex );

						if ( pDlg->m_bAbortThread )
						{
							break;
						}

						if ( dwBytes < STREAMBUFFERSIZE )
						{
							memset( (BYTE*)pStream.get() + dwBytes, 0, STREAMBUFFERSIZE - dwBytes );
						}

						pDlg->m_pPlayStream->Write( pStream.get(), STREAMBUFFERSIZE );

						dwStreamIndex-= dwBytes;

						if ( dwStreamIndex )
						{
							memmove( pStream.get() , (BYTE*)pStream.get() + dwBytes, dwStreamIndex );
						}
					}

					pDlg->m_bAbortCurrent = TRUE;
				}
			}
		}
		else
		{
			pDlg->MessageBox( _T( "Problem opening the file" ) );
		}

		// Close the mpeg stream
		if (pDlg->m_pInStream)
		{
			pDlg->m_pInStream->CloseStream();

			// Don't delete it, since we want to able to get 
			// the file details
		}

		// Close the play stream
		if (pDlg->m_pPlayStream)
		{
			LTRACE( _T( "Closing the output stream !!!!" ) );
			pDlg->m_pPlayStream->CloseStream();
		}


		delete pDlg->m_pPlayStream; pDlg->m_pPlayStream = NULL;

		switch ( pDlg->GetThreadCommand() )
		{
			case THREAD_PLAY_NEXT_TRACK:
				if ( pDlg->GetPlayRandom() )
				{
					int nNewFile = nCurrentFile;

					// randomize until we got a different track
					while ( pDlg->m_vFileNames.size() > 1 &&
							nCurrentFile == nNewFile )
					{
						srand( (unsigned)time( NULL ) );
						nNewFile = rand() % pDlg->m_vFileNames.size();
					}
					nCurrentFile = nNewFile;
				}
				else
				{
					nCurrentFile++;
				}
			break;
			case THREAD_PLAY_PREV_TRACK:
				if ( nCurrentFile > 0 )
				{
					nCurrentFile--;
				}
			break;
			case THREAD_PLAY_FINISH:
				pDlg->m_bAbortThread = TRUE;
			break;
			case THREAD_PLAY_TRACK:
				nCurrentFile = 	pDlg->m_PlayList.GetCurSel( );
			break;
		}
	}

	pDlg->m_nStatus = IDLE;

	pDlg->m_pThread = NULL;

	pDlg->m_eThreadFinished.SetEvent();

	EXIT_TRACE( _T( "CPlayerView::PlayThreadFunc" ) );

	return 0;
}
Ejemplo n.º 19
0
UINT CMP3ToWavDlg::ConvertFunc(PVOID pParams)
{
	CUString		strLang;
	int			nPeakValue	= 0;
	DWORD		dwIndex		= 0;
	CDEX_ERR	bErr		= CDEX_OK;
	PBYTE		pStream		= NULL;
 	DWORD       dwTotalTime = 0;

	ENTRY_TRACE( _T( "ConvertFunc" ) );

	CMP3ToWavDlg* pDlg = (CMP3ToWavDlg*)pParams;

	pDlg->m_wCurrentTrack = 0;
	pDlg->m_bAbortThread = FALSE;


	CUString strOutDir(g_config.GetCnvOutputDir());

	while(	pDlg->m_wCurrentTrack < pDlg->m_nTotalFiles && 
			!pDlg->m_bAbortThread )
	{
		BOOL bNoToAll = FALSE;

		nPeakValue	= 0;

		POSITION nFileListPos = pDlg->m_Pos;

		pDlg->m_strMP3FileName = pDlg->m_pFileDlg->GetNextPathName( pDlg->m_Pos );
		pDlg->m_strWavFileName = pDlg->m_pFileDlg->GetFileName( nFileListPos );

		CUString strSubPath = pDlg->m_pFileDlg->GetSubPath( nFileListPos );

		int nPos = pDlg->m_strWavFileName.ReverseFind('.');

		if (nPos > 0 )
		{
			pDlg->m_strWavFileName= pDlg->m_strWavFileName.Left( nPos );
		}

		strOutDir = g_config.GetCnvOutputDir() + strSubPath;

		// Prepend output directory
		pDlg->m_strWavFileName= strOutDir + CUString( pDlg->m_strWavFileName );

		// Create Ouput directory
		if ( CDEX_OK != DoesDirExist( strOutDir, FALSE )  )
		{
			LTRACE( _T( "ConvertFunc::Error creating output dir %s" ), strOutDir );

			strLang = g_language.GetString( IDS_CANNOT_CREATE_OUTDIR );
			CDexMessageBox( strLang + strOutDir );
			bErr = CDEX_ERROR;
		}

		// Clear error flag
		bErr = CDEX_OK;

		LTRACE( _T( "Converting track %d" ), pDlg->m_wCurrentTrack );

		// Reset estimate timer
		//pDlg->m_TimeTrack.ReInit();

		pDlg->m_nPercentCompleted=0;

		// create proper input stream
		pDlg->m_pInStream = ICreateStream( CUString( pDlg->m_strMP3FileName ) );

		if ( FALSE == CheckNoFileOverwrite(	pDlg,
										CUString( pDlg->m_strWavFileName ) + _W( ".wav" ), 
										TRUE,
										pDlg->m_bYesToAll,
										bNoToAll ) )
		{
			// Open the input stream if available
			if (	pDlg->m_pInStream && 
					pDlg->m_pInStream->OpenStream( CUString( pDlg->m_strMP3FileName ) ) )
			{
				DWORD	dwBufferSize = pDlg->m_pInStream->GetBufferSize();

				// Reset estimate timer
 				dwTotalTime = pDlg->m_pInStream->GetTotalTime();
 				pDlg->m_TimeTrack.ReInit( dwTotalTime );

				// Create a play stream object
				OSndStreamWAV wavStream;

				wavStream.CopyStreamInfo( *pDlg->m_pInStream );

				// Initialize output WAV stream object
				wavStream.OpenStream( CUString( pDlg->m_strWavFileName ) );

				// Allocate stream input buffer
				pStream = new BYTE[ dwBufferSize ];

				int nMPEGBytes = 0;

				double dSampleRatio = 1.0;

				BOOL bFinished = FALSE;

				while( ( FALSE == bFinished ) && !pDlg->m_bAbortThread )
				{
					nMPEGBytes = pDlg->m_pInStream->Read( pStream, dwBufferSize );
	
					if ( nMPEGBytes > 0 )
					{

						for ( dwIndex=0; dwIndex< (DWORD)nMPEGBytes / 2; dwIndex++ )
						{
							if ( abs( ((SHORT*)pStream)[dwIndex]) > nPeakValue )
								nPeakValue=abs( ((SHORT*)pStream )[ dwIndex ] );
						}

						if ( nMPEGBytes > 0 )
						{
							wavStream.Write( pStream, nMPEGBytes );
						}

						int nTotalTime = pDlg->m_pInStream->GetTotalTime();
						int nCurrentTime = pDlg->m_pInStream->GetCurrentTime();

						if ( nTotalTime )
						{
							pDlg->m_nPercentCompleted = nCurrentTime * 100 / nTotalTime;
						}
						else
						{
							pDlg->m_nPercentCompleted = 0;
						}
					}
					else
					{
						bFinished = TRUE;
					}

				}

				delete [] pStream; pStream= NULL;

				// Close input stream
				pDlg->m_pInStream->CloseStream();

				// Close the WAV stream
				wavStream.CloseStream();

				// close the Input stream

				// Check if we have to normalize the file
				if (	pDlg->m_pFileDlg->m_bNormalize && 
						FALSE == pDlg->m_bAbortThread )
				{
					double dNormFactor=1.0;

					// Reset estimate timer
					pDlg->m_TimeTrack.ReInit(dwTotalTime);

					// Set percentage completed to zero
					pDlg->m_nPercentCompleted=0;

					// Determine normalization factor
					dNormFactor=((nPeakValue-1.0)/327.68);

					// DO we have to normalize this file
					if (dNormFactor<(double)g_config.GetLowNormLevel() || dNormFactor>(double)g_config.GetHighNormLevel())
					{
						if (dNormFactor<(double)g_config.GetLowNormLevel())
						{
							// Normalize to for desired level
							dNormFactor=(double)g_config.GetLNormFactor()/dNormFactor;
						}
						else
						{
							// Normalize to for desired level
							dNormFactor=(double)g_config.GetHNormFactor()/dNormFactor;
						}

						// Little fine tuning to avoid overflows due to round off errors
						dNormFactor*=0.9999;

						LTRACE( _T( "CMP3ToWavDlg::Normalizing Track/File %s with factor %f" ), pDlg->m_strWavFileName, dNormFactor );

						CWAV myWav;

						// Step 1: Open the input WAV file
						if ( myWav.StartNormalizeAudioFile( CUString( pDlg->m_strWavFileName ) )!=0)
						{
							// Step 2: Loop through data and normalize chunk
							while ( myWav.NormalizeAudioFileChunk( dNormFactor, pDlg->m_nPercentCompleted ) == FALSE && 
									!pDlg->m_bAbortThread )
							{
								::Sleep(0);
							}
					
							// Step 3: Close the input WAV file, and replace original
							myWav.CloseNormalizeAudioFile( CUString( pDlg->m_strWavFileName ) , pDlg->m_bAbortThread, TRUE );
						}
					}
				}

				// Check if thread has been aborted, if so, remove original file
				if ( TRUE == pDlg->m_bAbortThread )
				{
					LTRACE( _T( "Deleting file ( due to abort ) %s.wav" ), pDlg->m_strWavFileName );
					DeleteFile( pDlg->m_strWavFileName + _T( ".wav" ) );
				}

				// Check if we have to delete the file
				if ( pDlg->m_pFileDlg->m_bDeleteOriginal && ( FALSE == pDlg->m_bAbortThread )  )
				{
					LTRACE( _T( "Deleting file ( user request ) %s" ), pDlg->m_strMP3FileName );
					DeleteFile( pDlg->m_strMP3FileName );
				}
			}
		}
		else
		{
			if ( TRUE == bNoToAll )
			{
				pDlg->m_bAbortThread = TRUE;
			}
		}

		// delete input stream object
		delete pDlg->m_pInStream;pDlg->m_pInStream=NULL;

		// Jump to the next track
		pDlg->m_wCurrentTrack++;
	}

	pDlg->m_eThreadFinished.SetEvent();

	// OK close the stuff
	pDlg->PostMessage( WM_COMMAND, IDCANCEL,0);

	EXIT_TRACE( _T( "RipFunc" ) );
	return 0;
}
Ejemplo n.º 20
0
CCDPlayDigital::~CCDPlayDigital()
{
	ENTRY_TRACE( _T( "CCDPlayDigital::~CCDPlayDigital" ) );
	EXIT_TRACE( _T( "CCDPlayDigital::~CCDPlayDigital" ) );
}
Ejemplo n.º 21
0
CDEX_ERR CEncoderLameDll::OpenStream(CUString strOutFileName,DWORD dwSampleRate,WORD nChannels)
{
	CDEX_ERR bReturn = CDEX_OK;

	CUString strLang;
    CUStringConvert strCnv;

	ENTRY_TRACE( _T( "CEncoderLameDll::OpenStream( %s, %ld, %d" ),
				strCnv.ToT( strOutFileName + _W( "." ) + GetExtension() ),
				dwSampleRate,
				nChannels );


	DWORD dwInSampleRate = dwSampleRate;

	m_strStreamFileName = strOutFileName;

	// clear all config settings
	memset( &m_beConfig, 0, sizeof(m_beConfig) );

	// set the number of input channels
	m_nInputChannels = nChannels;

	// Divide sample rate by two for MPEG2
	if ( ( GetVersion() >=1 ) && ( dwInSampleRate >= 32000 ) )
	{
		m_dResampleRatio = 2.0;
		dwSampleRate = dwInSampleRate / 2;
	}

	// mask mode, just to be sure (due to an old hack)
	m_nMode &= 0x0F;

	// Do we have to downmix/upmix ?
	if ( BE_MP3_MODE_MONO == m_nMode )
	{
		if ( 2 == nChannels )
		{
			m_bDownMixToMono = TRUE;
		}
		else
		{
			m_bDownMixToMono = FALSE;
		}
	}
	else 
	{
		if ( 1 == nChannels )
		{
			m_bUpMixToStereo = TRUE;
		}
		else
			m_bUpMixToStereo=FALSE;
	}

	int	nCRC		= m_bCRC;
	int nVBR		= (nCRC>>12)&0x0F;
	int nVbrMethod	= (nCRC>>16)&0x0F;

	m_beConfig.dwConfig						= BE_CONFIG_LAME;
	m_beConfig.format.LHV1.dwStructVersion	= 1;
	m_beConfig.format.LHV1.dwStructSize		= sizeof(m_beConfig);
	m_beConfig.format.LHV1.dwSampleRate		= dwSampleRate;
	m_beConfig.format.LHV1.dwReSampleRate	= m_nOutSampleRate;
	m_beConfig.format.LHV1.nMode			= m_nMode; 
	m_beConfig.format.LHV1.dwBitrate		= m_nBitrate;
	m_beConfig.format.LHV1.dwMaxBitrate		= m_nMaxBitrate;
	m_beConfig.format.LHV1.dwMpegVersion	= (dwSampleRate>=32000)?MPEG1:MPEG2;
	m_beConfig.format.LHV1.dwPsyModel		= 0;
	m_beConfig.format.LHV1.dwEmphasis		= 0;
	m_beConfig.format.LHV1.bCRC				= nCRC&0x01;;
	m_beConfig.format.LHV1.bCopyright		= m_bCopyRight;
	m_beConfig.format.LHV1.bPrivate			= m_bPrivate;
	m_beConfig.format.LHV1.bOriginal		= m_bOriginal;

	// allways write the VBR header, even for CBR file
	m_beConfig.format.LHV1.bWriteVBRHeader	= TRUE;

	if ( nVbrMethod > 0 )
	{
		m_beConfig.format.LHV1.bEnableVBR		= TRUE;
		m_beConfig.format.LHV1.nVbrMethod		= (VBRMETHOD)(nVbrMethod-1) ;

		// is this the ABR method ?
		if ( ( VBR_METHOD_ABR + 1 ) == nVbrMethod )
		{
			// get the average bit rate
			m_beConfig.format.LHV1.dwVbrAbr_bps= LOWORD( GetUserN1() )*1000;
			m_beConfig.format.LHV1.nVBRQuality = 0 ;
		}
		else
		{
			// no ABR selected
			m_beConfig.format.LHV1.dwVbrAbr_bps = 0;
			m_beConfig.format.LHV1.nVBRQuality = nVBR ;
		}
	}

	// Get Quality from third nibble
	m_beConfig.format.LHV1.nPreset=( (nCRC >> 8 ) & 0x0F );

	m_fpOut= CID3Tag::SaveInitialV2Tag( strOutFileName + _W( "." ) + GetExtension(), GetId3V2PadSize() );
    //m_fpOut = CDexOpenFile( strOutFileName + _W( "." ) + GetExtension(), _W( "wb+" ) );

	if ( NULL == m_fpOut )
	{
		CUString strErr;

		strLang = g_language.GetString( IDS_ENCODER_ERROR_COULDNOTOPENFILE );

		strErr.Format( strLang, (LPCWSTR)CUString( strOutFileName + _W( "." ) + GetExtension() ) );

        CDexMessageBox( strErr );

		bReturn  = CDEX_FILEOPEN_ERROR;
	}


	if ( CDEX_OK == bReturn )
	{
		int nReturn = m_InitStream(	&m_beConfig,
									&m_dwInBufferSize,
									&m_dwOutBufferSize,
									&m_hbeStream );

		switch ( nReturn )
		{
			case CDEX_OK:
				// do nothing
			break;
			case -1:
				strLang = g_language.GetString( IDS_ENCODER_ERROR_SAMPLERATEBITRATEMISMATCH );
				CDexMessageBox( strLang );
				bReturn = CDEX_ERROR;
			break;
			case -2:
				strLang = g_language.GetString( IDS_ENCODER_ERROR_INVALIDINPUTSTREAM );
				CDexMessageBox( strLang );
				bReturn = CDEX_ERROR;
			break;
			default:
				strLang = g_language.GetString( IDS_ENCODER_ERROR_INVALIDINPUTSTREAM );
				CDexMessageBox( strLang );
				bReturn = CDEX_ERROR;
			break;

		}
	}

	if ( CDEX_OK == bReturn )
	{

		if ( ( GetVersion() >= 1 ) && ( dwInSampleRate >= 32000 ) )
		{
			// Add multiplcation factor for resampling
			m_dwInBufferSize *= 2;
		}

		if ( m_bDownMixToMono )
		{
			m_dwInBufferSize *= 2;
		}


		// Allocate Output Buffer size
		m_pbOutputStream = new BYTE[ m_dwOutBufferSize ];

		// Only expect halve the number of samples
		// in case we have to upsample
		if ( m_bUpMixToStereo )
		{
			// Allocate upsample Buffer size
			m_psInputStream = new SHORT[ m_dwInBufferSize ];

			m_dwInBufferSize /= 2;

		}
	}

	if ( CDEX_OK == bReturn ) 
	{
		// Initialize the input stream
		bReturn = InitInputStream();
	}


	EXIT_TRACE( _T( "CEncoderLameDll::OpenStream, return value %d" ), bReturn );

	return bReturn;
}
Ejemplo n.º 22
0
UINT CCDPlayDigital::RipAndPlay( PVOID pParams )
{
	CDEX_ERR	bReturn = CDEX_OK;
	long		nBufferSize = 0;
	BOOL		bPause = FALSE;

	// tracing info
	ENTRY_TRACE( _T( "CCDPlayDigital::RipAndPlay" ) );
	
	// get pointer to active CCDPlayDigital object
	CCDPlayDigital* pParent= (CCDPlayDigital*)pParams ;

	pParent->m_bAbort = FALSE;

	auto_ptr<PlayWavStream> pPlayStream( new PlayWavStream );

	if ( NULL == pPlayStream.get() )
	{
		bReturn = CDEX_ERROR;
	}
	else
	{
		pPlayStream->SetSampleRate( 44100 );
		pPlayStream->SetChannels( 2 );
		pPlayStream->SetBytesPerSample( sizeof( SHORT ) );
	}

	// Initialize play stream object
	if ( FALSE == pPlayStream->OpenStream( _W("") ) )
	{
		bReturn = CDEX_ERROR;
	}
	else
	{
	}

	DWORD dwSampleBufferSize = pPlayStream->GetBufferSize() / sizeof( SHORT );


	if ( CDEX_OK == bReturn )
	{
		bReturn = CR_OpenRipper(	&nBufferSize,
									pParent->GetBeginSector(),
									pParent->GetEndSector(),
                                    FALSE );
	}

	if ( CDEX_OK == bReturn )
	{
		LONG			nNumBytesRead = 0;
		LONG			nOffset = 0;
		
		// create the stream buffer, allocate on enocder frame additional memory
		auto_ptr<BYTE> pbtBufferStream( new BYTE[ nBufferSize + pPlayStream->GetBufferSize() + 16383 ] );

		// Get a pointer to the buffer
		BYTE* pbtStream = pbtBufferStream.get();

		CDEX_ERR ripErr;

		// Read all chunks
		while (	( CDEX_RIPPING_DONE  != ( ripErr = CR_RipChunk( pbtStream + nOffset, &nNumBytesRead, (BOOL&)pParent->m_bAbort ) ) ) 
				&& !*(volatile BOOL*)&pParent->m_bAbort )
		{
			SHORT*	psEncodeStream=(SHORT*)pbtStream;
			DWORD	dwSamplesToConvert= ( nNumBytesRead + nOffset ) / sizeof( SHORT );

			while ( pParent->m_bPause )
			{
				if ( FALSE == bPause )
				{
					pParent->m_dwCurrentTime = 0;
					pParent->m_dwSeekTimeOffset = pPlayStream->GetCurrentTime();

					bPause = TRUE;
					pPlayStream->Pause();
				}

				::Sleep( 10 );
			}

			if ( bPause )
			{
				pPlayStream->Resume();
				bPause = FALSE;
			}


			// Check for jitter errors
			if ( CDEX_JITTER_ERROR == ripErr )
			{
			}

			// Check if an error did occur
			if ( CDEX_ERROR == ripErr )
			{
				LTRACE( _T( "RipToEncoder::CDEX_ERROR" ) );
				break;
			}

			// Get progress indication
			//nPercent = CR_GetPercentCompleted();

			// Get relative jitter position
			// nJitterPos = CR_GetJitterPosition();

			// Get the number of jitter errors
			// nJitterErrors = CR_GetNumberOfJitterErrors();

			// Get the Peak Value
			// nPeakValue = CR_GetPeakValue();

			// Convert the samples with the encoder
			while ( dwSamplesToConvert >= dwSampleBufferSize )
			{
				if( FALSE == pPlayStream->Write( (BYTE*)psEncodeStream, dwSampleBufferSize * sizeof( SHORT ) ) )
				{
					pParent->m_bAbort = TRUE;
					bReturn = CDEX_ERROR;
				}

				pParent->m_dwCurrentTime = pPlayStream->GetCurrentTime();
				pParent->m_dwBytesWritten += dwSampleBufferSize * sizeof( SHORT );

				// Decrease the number of samples to convert
				dwSamplesToConvert -= dwSampleBufferSize;

				// Increase the sample buffer pointer
				psEncodeStream += dwSampleBufferSize;
			}

			// Copy the remaing bytes up front, if necessary
			if ( dwSamplesToConvert > 0 )
			{
				// Calculate the offset in bytes
				nOffset = dwSamplesToConvert * sizeof( SHORT );

				// Copy up front
				memcpy( pbtStream, psEncodeStream, nOffset );
			}
			else
			{
				nOffset = 0;
			}
		}

		// stop as quickly as possible on when aborting
		if ( pParent->m_bAbort )
		{
			pPlayStream->Pause();
			pPlayStream->Stop();
		}
		else
		{
			if ( nOffset && pParent->m_bAbort )
			{
				if( FALSE == pPlayStream->Write( pbtStream, nOffset ) )
				{
					bReturn = CDEX_ERROR;
				}
				pParent->m_dwBytesWritten += nOffset;
			}

			LTRACE( _T( "Wait for player to Finish" ) );
		}

		// Close the WAV player
		pPlayStream->CloseStream();
	
		LTRACE( _T( "Player finished" ) );

		// Close the Ripper session

		CR_CloseRipper( NULL );

	}
	else
	{
		ASSERT( FALSE );
	}

	pParent->m_pThread = NULL;
	pParent->m_bIsPlaying = FALSE;

	EXIT_TRACE( _T( "RipAndPlay" ) );

	return bReturn;
}