int main(int argc, char* argv[])
{
	out_counter=0;
	in_counter=0;
	// load the driver, this will setup all the necessary internal data structures
	if (!loadAsioDriver (ASIO_DRIVER_NAME))
		printf("didn't load\n");
	else
	{
		// initialize the driver
		if (ASIOInit (&asioDriverInfo.driverInfo) == ASE_OK)
		{
			printf ("asioVersion:   %d\n"
					"driverVersion: %d\n"
					"Name:          %s\n"
					"ErrorMessage:  %s\n",
					asioDriverInfo.driverInfo.asioVersion, asioDriverInfo.driverInfo.driverVersion,
					asioDriverInfo.driverInfo.name, asioDriverInfo.driverInfo.errorMessage);
			if (init_asio_static_data (&asioDriverInfo) == 0)
			{
				// ASIOControlPanel(); you might want to check wether the ASIOControlPanel() can open

				// set up the asioCallback structure and create the ASIO data buffer
				asioCallbacks.bufferSwitch = &bufferSwitch;
				asioCallbacks.sampleRateDidChange = &sampleRateChanged;
				asioCallbacks.asioMessage = &asioMessages;
				asioCallbacks.bufferSwitchTimeInfo = &bufferSwitchTimeInfo;
				if (create_asio_buffers (&asioDriverInfo) == ASE_OK)
				{
					if (ASIOStart() == ASE_OK)
					{
						// Now all is up and running
						fprintf (stdout, "\nASIO Driver started succefully.\n\n");
						while (!asioDriverInfo.stopped)
						{
#if WINDOWS
							Sleep(100);	// goto sleep for 100 milliseconds
#elif MAC
							unsigned long dummy;
							Delay (6, &dummy);
#endif
							fprintf (stdout, "%d ms / %d ms / %d samps", asioDriverInfo.sysRefTime, (long)(asioDriverInfo.nanoSeconds / 1000000.0), (long)asioDriverInfo.samples);

							// create a more readable time code format (the quick and dirty way)
							double remainder = asioDriverInfo.tcSamples;
							long hours = (long)(remainder / (asioDriverInfo.sampleRate * 3600));
							remainder -= hours * asioDriverInfo.sampleRate * 3600;
							long minutes = (long)(remainder / (asioDriverInfo.sampleRate * 60));
							remainder -= minutes * asioDriverInfo.sampleRate * 60;
							long seconds = (long)(remainder / asioDriverInfo.sampleRate);
							remainder -= seconds * asioDriverInfo.sampleRate;
							fprintf(stdout,"/%ld/",/*std::sqrt((long double)*/(sum));
							fprintf (stdout, " / TC: %2.2d:%2.2d:%2.2d:%5.5d", (long)hours, (long)minutes, (long)seconds, (long)remainder);

							fprintf (stdout, "     \r");
							#if !MAC
							fflush (stdout);
							#endif
							if ( kbhit() )
								break;
						}
						ASIOStop();
					}
					ASIODisposeBuffers();
				}
			}
			ASIOExit();
		}
		asioDrivers->removeCurrentDriver();
	}
	printf("\n\n\nin = %d out = %d\n",in_counter,out_counter);
	return 0;
}
示例#2
0
void PlayerDlg::CreateAsio()
{
	TCHAR drvname[64];

	ASSERT(asioDrivers == NULL);
	asioDrivers = new AsioDrivers();

	if (asioDrivers->asioGetNumDev() <= 0)
	{
		LogPrint(_T("No ASIO Driver found."));
		return;
	}

	for (int i = 0; i < asioDrivers->asioGetNumDev(); i++)
	{
		asioDrivers->asioGetDriverName(i, drvname, 48);

		SendMessage(m_hOutputDeviceList, CB_ADDSTRING, 0, (LPARAM) drvname);
	}

	SendMessage(m_hOutputDeviceList, CB_SETCURSEL, asioDrivers->asioGetNumDev() -1, 0);

	if (!asioDrivers->loadDriver(drvname))
	{
		LogPrint(_T("ASIO Driver loading failed."));
		return;
	}
	
	m_bAsioDriverLoaded = true;

	// initialize the driver
	if (ASIOInit(&asioDriverInfo.driverInfo) != ASE_OK)
	{
		LogPrint(_T("ASIO Initialization failed."));
		return;
	}

	m_bAsioInitialized = true;

	LogPrint(_T("asioVersion:   %d"), asioDriverInfo.driverInfo.asioVersion);
	LogPrint(_T("driverVersion:   %d"), asioDriverInfo.driverInfo.driverVersion);
	LogPrint(_T("Name:   %S"), asioDriverInfo.driverInfo.name);
	LogPrint(_T("ErrorMessage:   %S"), asioDriverInfo.driverInfo.errorMessage);
	LogPrint(_T("----------------------------------------"));

	if (init_asio_static_data (&asioDriverInfo) == 0)
	{
		// ASIOControlPanel(); you might want to check wether the ASIOControlPanel() can open

		// set up the asioCallback structure and create the ASIO data buffer
		asioCallbacks.bufferSwitch = &bufferSwitch;
		asioCallbacks.sampleRateDidChange = &sampleRateChanged;
		asioCallbacks.asioMessage = &asioMessages;
		asioCallbacks.bufferSwitchTimeInfo = &bufferSwitchTimeInfo;

		if (create_asio_buffers (&asioDriverInfo) == ASE_OK)
		{					
			m_bAsioBufferCreated = true;

			g_playerDlg.LogPrint(_T("Output BitStream sample type: %d"), asioDriverInfo.channelInfos[asioDriverInfo.inputBuffers].type);
		}
		else
		{
			LogPrint(_T("ASIO Buffer creation failed."));
		}
	}
	else
	{
		LogPrint(_T("ASIO Static Data initialization failed."));
	}
}