Example #1
0
void Alsa9Buf::SetChunksize( snd_pcm_sframes_t frames )
{
	preferred_chunksize = frames;

	SetHWParams();
	SetSWParams();
}
Example #2
0
void Alsa9Buf::SetSampleRate(int hz)
{
	samplerate = hz;
	samplerate_set_explicitly = true;

	if( !SetHWParams() )
	{
		/*
		 * If this fails, we're no longer set up; if we call SW param calls,
		 * ALSA will assert out on us (instead of gracefully returning an error).
		 *
		 * If we fail here, it means we set up the initial stream, but can't
		 * configure it to the sample rate we want.  This happened on a CS46xx
		 * with an old ALSA version, at least: snd_pcm_hw_params failed
		 * with ENOMEM.  It set up only 10 44.1khz streams; it may have been
		 * trying to increase one to 48khz and, for some reason, that needed
		 * more card memory.  (I've tried to work around that by setting up
		 * streams as 48khz to begin with, so we set it up as the maximum
		 * to begin with.)
		 */
		FAIL_M( ssprintf("SetHWParams(%i) failed", hz) );
	}

	SetSWParams();
}
Example #3
0
Alsa9Buf::Alsa9Buf( hw hardware, int channels_ )
{
	GetSoundCardDebugInfo();
		
	InitializeErrorHandler();
	
	channels = channels_;
	samplerate = 44100;
	samplebits = 16;
	last_cursor_pos = 0;
	samplerate_set_explicitly = false;
	preferred_writeahead = 8192;
	preferred_chunksize = 1024;

	/* Open the device. */
	int err;
	err = dsnd_pcm_open( &pcm, DeviceName(), SND_PCM_STREAM_PLAYBACK, SND_PCM_NONBLOCK );
	if (err < 0)
		RageException::ThrowNonfatal("dsnd_pcm_open(%s): %s", DeviceName().c_str(), dsnd_strerror(err));

	if( !SetHWParams() )
	{
		CHECKPOINT;
		dsnd_pcm_close(pcm);
		CHECKPOINT;
		RageException::ThrowNonfatal( "SetHWParams failed" );
	}

	SetSWParams();
}
Example #4
0
//-----------------------------------------------------------------------------
bool DAQShutdown(void) {

	ChangeHWParam(PUMP1, OFF);
	ChangeHWParam(PUMP2, OFF);
	ChangeHWParam(CAMERA, OFF);
	//ChangeHWParam(FANS, OFF);
	ChangeHWParam(LASER, OFF);
	ChangeHWParam(STIRRER, OFF);
	SetHWParams();

	CloseHandle(hSerialDaq);								// close serial port

	return true;
}
Example #5
0
RString Alsa9Buf::Init( int channels_,
		int iWriteahead,
		int iChunkSize,
		int iSampleRate )
{
	channels = channels_;
	preferred_writeahead = iWriteahead;
	preferred_chunksize = iChunkSize;
	if( iSampleRate == 0 )
		samplerate = 44100;
	else
		samplerate = iSampleRate;
	
	GetSoundCardDebugInfo();
		
	InitializeErrorHandler();
	
	/* Open the device. */
	int err;
	err = dsnd_pcm_open( &pcm, DeviceName(), SND_PCM_STREAM_PLAYBACK, SND_PCM_NONBLOCK );
	if( err < 0 )
		return ssprintf( "dsnd_pcm_open(%s): %s", DeviceName().c_str(), dsnd_strerror(err) );

	if( !SetHWParams() )
	{
		CHECKPOINT;
		return "SetHWParams failed";
	}

	SetSWParams();

	LOG->Info( "ALSA: Mixing at %ihz", samplerate );

	if( preferred_writeahead != writeahead )
		LOG->Info( "ALSA: writeahead adjusted from %u to %u", (unsigned) preferred_writeahead, (unsigned) writeahead );
	if( preferred_chunksize != chunksize )
		LOG->Info( "ALSA: chunksize adjusted from %u to %u", (unsigned) preferred_chunksize, (unsigned) chunksize );

	return "";
}
Example #6
0
//-----------------------------------------------------------------------------
void ChangeHWParam(int param, double val) {

	hardware[param].value.d = val;
	hardware[param].changed = true;
	SetHWParams();
}
Example #7
0
//-----------------------------------------------------------------------------
void ChangeHWParam(int param, int val) {

	hardware[param].value.i = (uint16)val;
	hardware[param].changed = true;
	SetHWParams();
}
Example #8
0
//-----------------------------------------------------------------------------
void CIfcbDlg::OnTimer(UINT_PTR nIDEvent) {

	static UINT32 prevCount = 0;
	CString fpsText;
	unsigned int fps;
	CString str;
	//int stepCount;
	char cval[20];
	CString valstr;
	CStringToChar(cval, &valstr);
	CString args;		
	CString args2;	

	switch (nIDEvent) {
		case SYRINGE_TIMER_ID:
			DEBUG_MESSAGE(_T("Syringe timeout fired\r\n"));
			AcqComplete(END_AUTO);						// finish this run
			if (++syringesDone < nSyringes) {			// start a new run if required
				if (!AcqInit())
					Stop();
			} else {									// release the start button
				RunButton.SetCheck(BST_UNCHECKED);
				grabbing = false;						// this stops the data files being written twice
				OnBnClickedRun();
				if (autoShutdown)
					ShutdownWindows();
			}
			break;

		case TRIGGER_TIMER_ID:
			GenerateTrigger();
			break;

		case AUTOSTART_TIMER_ID:
			KillTimer(AUTOSTART_TIMER_ID);
			if (nSyringes) {							// start a run if required
				RunButton.SetCheck(BST_CHECKED);
				OnBnClickedRun();
			}
			break;

		case ACQ_START_TIMEOUT_ID:
			DEBUG_MESSAGE(_T("Trigger timeout fired\r\n"));
			AcqComplete(END_RETRY);						// finish this run
			if (!AcqInit())								// start a new run
				Stop();
			break;

		case FRAMERATE_TIMER_ID:
			if (!grabbing)
				break;
			UINT32_TYPE thisCount;
			thisCount = TabContainer.tabPages[cameraTab]->GetFrameCount();
//			TabContainer.tabPages[cameraTab]->SetDlgItemInt(IDC_FRAMEDROPPEDCOUNT, (thisCount - prevCount) * 2, FALSE);
			fps = (thisCount - prevCount) * 2;
			prevCount = thisCount;
			fpsText.Format(_T("%d.%d"), fps / 10, fps % 10);
			TabContainer.tabPages[cameraTab]->SetDlgItemText(IDC_FRAMEDROPPEDCOUNT, fpsText);
			break;

		case FRAMECOUNT_TIMER_ID:
			if (!grabbing)
				break;
			TabContainer.tabPages[cameraTab]->SetDlgItemInt(IDC_FRAMECOUNT, TabContainer.tabPages[cameraTab]->GetFrameCount(), FALSE);
			break;

		case TCP_TIMER_ID:
			HandleTcp();
			break;

		case PZT_TIMER_ID:							// synchronise the PZT command to only happen directly after a capture
			rqPZT = true;
			//PZTcommand(PZTmode RUN);
			break;

		case PZT_SCAN_TIMER_ID:
			rqPZT = true; // at 492, add this here to see if it fixes eventual-crashing problem with scanning
			str.Format(_T("in scan timer; stepCount = %d\r\n"), stepCount);
				DEBUG_MESSAGE_EXT(str); 
				//To DoFreqScan,
				//we want a loop using a counter for FreqStep (e.g.,StepCounter), 
				//so that at each StepCounter, FreqStep is added to NewFreq. 
				//This loop needs to extend over multiple syringes (i.e., using 
				//freqstepsPerSyr = minPerSyr / minPerStep (from Fileio.cpp) 
				//to keep track of when to go back to StartFreq.
				//We want the loop to continue indefinitely so that multiple scans
				//can be made as instrument temperature is varied (for calibration).

				if (stepCount == 1) {
					PZTfrequency = (int)(StartFreq + FreqStep);
				}
				else if(stepCount % freqstepsPerCycle == 0) {
					PZTfrequency = (int)StartFreq;
				}
				else {
					PZTfrequency = PZTfrequency + (int)FreqStep;
				}
				WriteFreqFile();
					/*args.Format(_T(" --nogui --on --noinit --hz %d --volts %d"), PZTfrequency, PZTvolts);
					DEBUG_MESSAGE_EXT(args); 
					DEBUG_MESSAGE_EXT(_T("\r\n"));
					str = sigGenPath; // note -- this includes the file name as well as path (e.g., "C:\AcousticFocusingWHOI\sig_gen\sig-gen-v1.0.4_64bit\sig-gen-v1.0.4\sig-gen")
					//DEBUG_MESSAGE_EXT(str); 
					DEBUG_MESSAGE_EXT(_T("\r\n"));
					//args2.Format(_T("floor(freqstepsPerSyr) = %f"), floor(freqstepsPerSyr)); 
					args2.Format(_T("freqstepsPerCycle = %d"), int(floor(freqstepsPerCycle))); 
					DEBUG_MESSAGE_EXT(args2); 
					DEBUG_MESSAGE_EXT(_T("\r\n"));
					//args.Format(_T(""));
					//str = "%windir\\system32\\notepad.exe";
					//str += (args);
					//DEBUG_MESSAGE_EXT(str);
					//DEBUG_MESSAGE_EXT(_T("\r\n")); 
					ShellExecute(NULL, _T("open"), str, args, NULL, SW_HIDE);	
					//ShellExecute(NULL, _T("open"), str, args, NULL, SW_NORMAL);	
					*/
					stepCount = stepCount + 1;
					//return;
			rqPZT =  true;
			//}
			break;
			

		case CAPTURE_TIMER_ID:						// used when hasCamera == false
			if (rqStop) {
				Stop();
				break;
			}

			if (!grabbing)
				break;
			
			if (!CheckForCapture()) {
				if (rqStop)
					Stop();
				break;
			}

			KillTimer(ACQ_START_TIMEOUT_ID);
			triggerTickCount = GetTickCount();
			ProcessTrigger(0);
			SetHWParams();							// change any parameters that need it

			// alignment graph plot - takes about 0.5 ms
			if (GraphData.GraphType != GraphData.GRAPH_NONE) {
				TabContainer.tabPages[graphTab]->UpdateGraph();
				TabContainer.tabPages[graphTab]->PostMessage(WM_PAINT, 0, 0);
			}

			DaqArmTrigger();
			if (rqStop)
				Stop();
			break;

		default:
			break;
	}
}
Example #9
0
void Alsa9Buf::SetWriteahead( snd_pcm_sframes_t frames )
{
	preferred_writeahead = frames;
	SetHWParams();
	SetSWParams();
}