Ejemplo n.º 1
0
void MainWindow::onMenuFileOpen()
{
    QFileDialog fd(this);
    fd.setFileMode(fd.DirectoryOnly);
    if(fd.exec() == QDialog::Accepted)
        openDir(fd.directory());
}
Ejemplo n.º 2
0
/**
 * 主对话框过程
 */
INT_PTR CALLBACK mainDlgProc(PROC_PARAMS)
{
	switch(message)
	{
	case WM_CTLCOLORSTATIC:
		return (INT_PTR)((HBRUSH)GetStockObject(WHITE_BRUSH));
	case WM_COMMAND:
		if(HIWORD(wParam) == 0) switch(LOWORD(wParam))
		{
		case IDM_SAVE:
			saveFile();
			break;
		case IDM_LOAD:
			readFile();
			break;
		case IDM_OPENDIR:
			openDir();
			break;
		case IDM_CLEAR:
			clearCourse();
			break;
		} 
		break;
	case WM_NOTIFY:
		if(LOWORD(wParam) == IDC_TABLE && ((LPNMHDR)lParam)->code == NM_DBLCLK)
			onCourseClick((LPNMITEMACTIVATE)lParam);
		break;
	case WM_SYSCOMMAND:
		if(wParam == SC_CLOSE)
			PostQuitMessage(0); //退出
		break;
	}
	return 0;
}
Ejemplo n.º 3
0
void MainWindow::createAction(){

    _open = new QAction(QIcon(":/image/Open.png"), tr("&Open..."), this);
    _open->setShortcuts(QKeySequence::Open);
    _open->setStatusTip(QString::fromUtf8("フォルダを開く"));
    connect(_open, SIGNAL(triggered()), this, SLOT(openDir()));

    _save = new QAction(QIcon(":/image/Save.png"), tr("&Save..."), this);
    _save->setShortcuts(QKeySequence::Save);
    _save->setStatusTip(QString::fromUtf8("フォルダツリーをテキストに保存する"));
    _save->setEnabled(false);
    connect(_save, SIGNAL(triggered()), this, SLOT(saveFileList()));

    _print = new QAction(QIcon(":/image/Print.png"), tr("&Print..."), this);
    _print->setShortcuts(QKeySequence::Print);
    _print->setStatusTip(QString::fromUtf8("フォルダツリーを印刷する"));
    _print->setEnabled(false);
    connect(_print, SIGNAL(triggered()), this, SLOT(printFileList()));

    _settings = new QAction(QIcon(":/image/Settings.png"), tr("&Settings..."), this);
    _settings->setStatusTip(QString::fromUtf8("設定"));
    connect(_settings, SIGNAL(triggered()), this, SLOT(showSettingsDlg()));

    _info = new QAction(QIcon(":/image/Info.png"), tr("&about H.F.D...."), this);
    _info->setStatusTip(QString::fromUtf8("HyperFileDumperについて"));
    connect(_info, SIGNAL(triggered()), this, SLOT(showInfoDlg()));

}
Ejemplo n.º 4
0
Archivo: rfs.c Proyecto: karajrish/OS
//============= TESTING APPLICATION USING THESE FS CALLS ==============
// Menu driven testing application for creation of fs, 
// and all file and directory related operations
int main(int argc, char** argv){
	int fd = openDevice(0);
	init_FS(fd);
	makeDir(fd, "Folder 1", 1, 1, 1);
	makeDir(fd, "Folder 2", 1, 1, 1);
	makeDir(fd, "Folder 3", 1, 1, 1);
	removeDir(fd, "Folder 2");
	int dirhandle = openDir(fd, "Folder 1");
	closeDir(dirhandle);
	shutdownDevice(0);
}
Ejemplo n.º 5
0
QImage *AcquisitionModule::getFrame(int i_numFrame) {

  m_startFrame = i_numFrame;
    
  if (m_parseDirectory)
    openDir();
    
  if (!goToFirstFrame())
    return NULL;
					
  return getNextFrame();
}
Ejemplo n.º 6
0
void KFMJob::openFileOrDir(bool _reload, bool _isFile)
{
    // Can we get a directory listing with the protocol or do we know that it is a file ?
    // Or does KIOServer know that it is a file
    if ( KIOServer::getKIOServer()->supports( url, KIO_List ) && !_isFile &&
         KIOServer::isDir( url ) != 0 ) {

        openDir(_reload);
    }
    else
	openFile(_reload);
    
}
Ejemplo n.º 7
0
bool ofxDiskGrabber::initGrabber(int _width, int _height, std::string _dir)
{
    width = _width;
    height = _height;
    dir = _dir;

    // TODO: dangerous if someone is holding the reference to pixels
    if(pixels)
    {
        free(pixels);
    }
    pixels = new unsigned char[width * height * 3];

    return openDir();
}
Ejemplo n.º 8
0
int train_hmm()
{
	AUD_Int8s  filePath[256] = { 0, };
	AUD_Int32s data;

	setbuf( stdout, NULL );
	setbuf( stdin, NULL );
	AUDLOG( "pls give training wav stream's folder path:\n" );
	filePath[0] = '\0';
	data = scanf( "%s", filePath );
	AUDLOG( "training folder path is: %s\n", filePath );

	entry *pEntry = NULL;
	dir   *pDir   = NULL;

	pDir = openDir( (const char*)filePath );
	while ( ( pEntry = scanDir( pDir ) ) )
	{
		// skip non wav file
		char suffix[256] = { 0, };
		for ( int i = 0; i < (int)strlen( pEntry->name ); i++ )
		{
			suffix[i] = tolower( pEntry->name[i] );
		}
		suffix[strlen( pEntry->name )] = '\0';

		if ( strstr( suffix, ".wav" ) == NULL )
		{
			continue;
		}

		char fileName[256] = { 0, };
		sprintf( fileName, "%s/%s", (const char*)filePath, pEntry->name );

		char hmmName[256] = { 0, };
		sprintf( hmmName, "%s/%s", WOV_KEYWORD_GMMHMMMODEL_DIR, pEntry->name );
		strcpy( hmmName + strlen( hmmName ) - 3, "hmm" );

		train_keyword_hmm( (const AUD_Int8s*)fileName, (AUD_Int8s*)hmmName );
	}
	closeDir( pDir );
	pDir = NULL;

	AUDLOG( "HMM training done\n" );

	return 0;
}
Ejemplo n.º 9
0
MainWindow::MainWindow(QWidget *parent) :
   QMainWindow(parent),
   disableRefreshFilters(false),
   ui(new Ui::MainWindow),
   currentFile(0)
{
   this->ui->setupUi(this);

   connect(this->ui->actOpen, SIGNAL(activated()), this, SLOT(openDir()));
   connect(this->ui->butFilterAll, SIGNAL(clicked()), this, SLOT(checkAll()));
   connect(this->ui->butRefresh, SIGNAL(clicked()), this, SLOT(reloadAll()));

   this->currentDir.setSorting(QDir::Name);
   this->ui->tblLog->setWordWrap(false);
   this->ui->tblLog->setModel(&this->model);
   this->ui->tblLog->setItemDelegate(new TableLogItemDelegate(this));

   this->ui->tblLog->horizontalHeader()->setResizeMode(QHeaderView::Interactive);
   this->ui->tblLog->horizontalHeader()->resizeSection(0, 140);
   this->ui->tblLog->horizontalHeader()->resizeSection(1, 50);
   this->ui->tblLog->horizontalHeader()->resizeSection(2, 140);
   this->ui->tblLog->horizontalHeader()->resizeSection(3, 50);
   this->ui->tblLog->horizontalHeader()->resizeSection(4, 180);
   this->ui->tblLog->horizontalHeader()->resizeSection(5, 1200);
   this->ui->tblLog->verticalHeader()->setResizeMode(QHeaderView::Fixed);
   this->ui->tblLog->verticalHeader()->setDefaultSectionSize(17);
   this->ui->tblLog->setVerticalScrollMode(QAbstractItemView::ScrollPerPixel);

   this->severities = new TooglableList(this);
   this->modules = new TooglableList(this);
   this->threads = new TooglableList(this);
   connect(this->severities, SIGNAL(stateChanged()), this, SLOT(filtersChange()));
   connect(this->modules, SIGNAL(stateChanged()), this, SLOT(filtersChange()));
   connect(this->threads, SIGNAL(stateChanged()), this, SLOT(filtersChange()));

   this->ui->laySeverity->addWidget(this->severities);
   this->ui->layModule->addWidget(this->modules);
   this->ui->layThread->addWidget(this->threads);

   this->lblStatus = new QLabel(this->ui->statusBar);
   this->ui->statusBar->addWidget(this->lblStatus);

   connect(this->ui->butPause, SIGNAL(toggled(bool)), this, SLOT(setWatchingPause(bool)));
   this->setWatchingPause(false);
}
Ejemplo n.º 10
0
MainWindow::MainWindow(QWidget *parent) :
    QMainWindow(parent),
	ui(new Ui::MainWindow),
	m_pModel(NULL),
	m_pPaintArea(NULL)
{
    ui->setupUi(this);
	ui->actionExit->setShortcut( QKeySequence::Quit );
	ui->actionOpenDir->setShortcut( QKeySequence::Open );

	setWindowTitle( tr("OI - zad1 - przeglądarka") );

	m_pModel = new QFileSystemModel();
	m_pModel->setNameFilterDisables ( false );

	QStringList filters;
	filters << "*.png" << "*.jpg" << "*.jpeg" << "*.bmp";

	m_pModel->setNameFilters( filters );

	m_pPaintArea = new PaintArea( ui->scrollArea );
	ui->scrollArea->setWidget( m_pPaintArea );

	connect( ui->actionOpenDir, SIGNAL(triggered()),
			 this, SLOT(openDir()) );
	connect( ui->actionExit, SIGNAL(triggered()),
			 qApp, SLOT(quit()) );

	connect( ui->treeView, SIGNAL(activated(QModelIndex)),
			 this, SLOT(loadImage(QModelIndex)) );

	ui->treeView->installEventFilter( this );
	ui->scrollArea->installEventFilter( this );
	m_pPaintArea->installEventFilter( this );

	ui->treeView->setAcceptDrops( false );
	ui->scrollArea->setAcceptDrops( false );
	m_pPaintArea->setAcceptDrops( false );

	this->setAcceptDrops( true );
}
Ejemplo n.º 11
0
/**
 * Searches in the "name" directory for the "find" file,
 * if file is found and the user wanted to find that filetype
 * the path is added to a list that will be printed at the end.
 * Also puts all directories found in a list for it to be
 * searched.
 */
bool searchForFile(char* name, char *find, int t, struct Node* list) {
	DIR *dir;

	struct dirent *ent;
	struct stat f_info;
	bool foundFile = false;

	if (openDir(&dir, name, &ent)) {
		do {
			if ((lstat(ent->d_name, &f_info)) < 0) {
				fprintf(stderr, "lstat error: ");
				perror(ent->d_name);
			} else {
				if (t == 0 && compareName(ent->d_name, find)) {
					foundFile = true;
				} else if (checkDir(t, f_info, ent->d_name, find)) {
					foundFile = true;
				} else if (checkReg(t, f_info, ent->d_name, find)) {
					foundFile = true;
				} else if (checkLink(t, f_info, ent->d_name, find)) {
					foundFile = true;
				}
				if (checkDirAndRights(f_info) && !isDot(ent->d_name)) {
					int l = strlen(name) + strlen(ent->d_name);
					char *str = calloc(1, sizeof(char[l + 2]));

					strcpy(str, name);
					strcat(str, "/");
					strcat(str, ent->d_name);
					insert(list, str);
				}
			}
		} while ((ent = readdir(dir)));

	}
	closedir(dir);

	return foundFile;
}
Ejemplo n.º 12
0
//Function executed at each frame
bool AcquisitionModule::run() {
    if(firstTime) {
        firstTime = false;
        m_NumFrame = m_startFrame;

        if (m_parseDirectory)
            openDir();

        if (!goToFirstFrame())
            std::cout << "Start frame does not exist in any given directory, or file corrupted" << std::endl;
    }

    QImage *anImage = getNextFrame();

    if (anImage == NULL)
        return false;
  
    if(m_data->currentImage != NULL)
        delete m_data->currentImage;
    m_data->currentImage = anImage;

    return true;
}
Ejemplo n.º 13
0
int8_t RogueSD::exists(const char *path)
{
  // There are a few ways to determine whether path is a file.
  // Determining whether path is a directory is a bit more tricky.
  // If you use FC L path, the contents of the directory are returned.
  // If you use FC LC path, you will get the number of files within the directory, but
  // if there is only 1 file within the directory, it can be misleading (and what happens
  // if there are NO files in the directory?).
  // The current best solution is:
  // 1. Use "FC LS path" to "Open Directory" - if no error, then path is a folder.
  // 2. If an error was returned, use "FC LC path" - if no error, then path is a file.

  if (openDir(path))
  {
    return TYPE_FOLDER;
  }
  else
  {
    if (fileCount(path) == 1)
      return TYPE_FILE;
    else
      return 0;
  }
}
Ejemplo n.º 14
0
Widget::Widget(QWidget *parent)
	: QWidget(parent)
{
	QHBoxLayout *la=new QHBoxLayout;

	output=new QTextEdit;
	output->setAcceptRichText(true);
	output->setReadOnly(true);
	openDirBtn=new QPushButton(tr("Открыть"));
	pathEd=new QLineEdit;
	rescanBtn=new QPushButton(tr("Перезагрузить"));
	la->addWidget(pathEd, 1);
	la->addWidget(openDirBtn, 0);
	la->addWidget(rescanBtn, 0);

	QVBoxLayout *mainLa=new QVBoxLayout;
	mainLa->addLayout(la);
	mainLa->addWidget(output);

	connect(openDirBtn, SIGNAL(clicked()), SLOT(openDir()));
	connect(rescanBtn, SIGNAL(clicked()), SLOT(scan()));

	this->setLayout(mainLa);
}
Ejemplo n.º 15
0
AUD_Int32s wov_adapt_gmm_si()
{
	AUD_Error  error = AUD_ERROR_NONE;
	AUD_Int32s ret   = 0;
	AUD_Int8s  wavPath[256] = { 0, };
	AUD_Int32s data;

	setbuf( stdout, NULL );
	setbuf( stdin, NULL );
	AUDLOG( "pls give adapt wav stream's folder path:\n" );
	wavPath[0] = '\0';
	data = scanf( "%s", wavPath );
	AUDLOG( "adapt wav stream's folder path is: %s\n", wavPath );

	// step 1: read UBM model from file
	void *hUbm = NULL;
	FILE *fpUbm = fopen( WOV_UBM_GMMMODEL_FILE, "rb" );
	if ( fpUbm == NULL )
	{
		AUDLOG( "cannot open ubm model file: [%s]\n", WOV_UBM_GMMMODEL_FILE );
		return AUD_ERROR_IOFAILED;
	}
	error = gmm_import( &hUbm, fpUbm );
	AUD_ASSERT( error == AUD_ERROR_NONE );
	fclose( fpUbm );
	fpUbm = NULL;

	// AUDLOG( "ubm GMM as:\n" );
	// gmm_show( hUbm );

	AUD_Int32s i = 0, j = 0;
	entry      *pEntry = NULL;
	dir        *pDir   = NULL;

	AUD_Int32s totalWinNum = 0;
	pDir = openDir( (const char*)wavPath );
	if ( pDir == NULL )
	{
		AUDLOG( "cannot open folder: %s\n", wavPath );
		return -1;
	}

	while ( ( pEntry = scanDir( pDir ) ) )
	{
		AUD_Int8s   keywordFile[256] = { 0, };
		AUD_Summary fileSummary;
		AUD_Int32s  sampleNum = 0;

		snprintf( (char*)keywordFile, 256, "%s/%s", wavPath, pEntry->name );
		// AUDLOG( "%s\n", keywordFile );

		ret = parseWavFromFile( keywordFile, &fileSummary );
		if ( ret < 0 )
		{
			continue;
		}
		AUD_ASSERT( fileSummary.channelNum == CHANNEL_NUM && fileSummary.bytesPerSample == BYTES_PER_SAMPLE && fileSummary.sampleRate == SAMPLE_RATE );

		// request memeory for template
		sampleNum = fileSummary.dataChunkBytes / fileSummary.bytesPerSample;
		for ( j = 0; j * FRAME_STRIDE + FRAME_LEN <= sampleNum; j++ )
		{
			;
		}
		j = j - MFCC_DELAY;

		totalWinNum += j;
	}
	closeDir( pDir );
	pDir = NULL;

	AUD_Matrix featureMatrix;
	featureMatrix.rows     = totalWinNum;
	featureMatrix.cols     = MFCC_FEATDIM;
	featureMatrix.dataType = AUD_DATATYPE_INT32S;
	ret = createMatrix( &featureMatrix );
	AUD_ASSERT( ret == 0 );

	AUD_Int32s currentRow  = 0;
	pDir = openDir( (const char*)wavPath );
	while ( ( pEntry = scanDir( pDir ) ) )
	{
		AUD_Int8s   keywordFile[256] = { 0, };
		AUD_Summary fileSummary;
		AUD_Int32s  sampleNum        = 0;
		void        *hMfccHandle     = NULL;

		snprintf( (char*)keywordFile, 256, "%s/%s", wavPath, pEntry->name );
		// AUDLOG( "%s\n", keywordFile );

		ret = parseWavFromFile( keywordFile, &fileSummary );
		if ( ret < 0 )
		{
			continue;
		}
		AUD_ASSERT( fileSummary.channelNum == CHANNEL_NUM && fileSummary.bytesPerSample == BYTES_PER_SAMPLE && fileSummary.sampleRate == SAMPLE_RATE );

		AUD_Int32s bufLen = fileSummary.dataChunkBytes;
		AUD_Int16s *pBuf  = (AUD_Int16s*)calloc( bufLen, 1 );
		AUD_ASSERT( pBuf );

		sampleNum = readWavFromFile( (AUD_Int8s*)keywordFile, pBuf, bufLen );
		AUD_ASSERT( sampleNum > 0 );

		// pre-processing

		 // pre-emphasis
		sig_preemphasis( pBuf, pBuf, sampleNum );

		 // calc framing number
		for ( j = 0; j * FRAME_STRIDE + FRAME_LEN <= sampleNum; j++ )
		{
			;
		}

		 // XXX: select salient frames
		AUD_Feature feature;
		feature.featureMatrix.rows     = j - MFCC_DELAY;
		feature.featureMatrix.cols     = MFCC_FEATDIM;
		feature.featureMatrix.dataType = AUD_DATATYPE_INT32S;
		feature.featureMatrix.pInt32s  = featureMatrix.pInt32s + currentRow * feature.featureMatrix.cols;

		feature.featureNorm.len      = j - MFCC_DELAY;
		feature.featureNorm.dataType = AUD_DATATYPE_INT64S;
		ret = createVector( &(feature.featureNorm) );
		AUD_ASSERT( ret == 0 );

		error = mfcc16s32s_init( &hMfccHandle, FRAME_LEN, WINDOW_TYPE, MFCC_ORDER, FRAME_STRIDE, SAMPLE_RATE, COMPRESS_TYPE );
		AUD_ASSERT( error == AUD_ERROR_NONE );

		error = mfcc16s32s_calc( hMfccHandle, pBuf, sampleNum, &feature );
		AUD_ASSERT( error == AUD_ERROR_NONE );

		error = mfcc16s32s_deinit( &hMfccHandle );
		AUD_ASSERT( error == AUD_ERROR_NONE );

		free( pBuf );
		pBuf   = NULL;
		bufLen = 0;

		ret = destroyVector( &(feature.featureNorm) );
		AUD_ASSERT( ret == 0 );

		currentRow += feature.featureMatrix.rows;
	}
	closeDir( pDir );
	pDir = NULL;

	AUD_Matrix llrMatrix;
	llrMatrix.rows     = totalWinNum;
	llrMatrix.cols     = gmm_getmixnum( hUbm );
	llrMatrix.dataType = AUD_DATATYPE_DOUBLE;
	ret = createMatrix( &llrMatrix );
	AUD_ASSERT( ret == 0 );

	AUD_Double llr = 0.;
	for ( j = 0; j < featureMatrix.rows; j++ )
	{
		AUD_Vector componentLLR;
		componentLLR.len      = llrMatrix.cols;
		componentLLR.dataType = AUD_DATATYPE_DOUBLE;
		componentLLR.pDouble  = llrMatrix.pDouble + j * llrMatrix.cols;

		llr = gmm_llr( hUbm, &(featureMatrix), j, &componentLLR );
	}

	AUD_Vector sumLlr;
	sumLlr.len      = llrMatrix.cols;
	sumLlr.dataType = AUD_DATATYPE_DOUBLE;
	ret = createVector( &sumLlr );
	AUD_ASSERT( ret == 0 );

	AUD_Double *pSumLlr = sumLlr.pDouble;
	for ( j = 0; j < llrMatrix.cols; j++ )
	{
		pSumLlr[j] = llrMatrix.pDouble[j];
	}
	for ( i = 1; i < llrMatrix.rows; i++ )
	{
		for ( j = 0; j < llrMatrix.cols; j++ )
		{
			pSumLlr[j] = logadd( pSumLlr[j],  *(llrMatrix.pDouble + i * llrMatrix.cols + j) );
		}
	}

#if 0
	AUD_Vector bestIndex;
	bestIndex.len      = TOP_N;
	bestIndex.dataType = AUD_DATATYPE_INT32S;
	ret = createVector( &bestIndex );
	AUD_ASSERT( ret == 0 );

	// get top TOP_N component
	ret = sortVector( &sumLlr, &bestIndex );
	AUD_ASSERT( ret == 0 );
#else
	llr = pSumLlr[0];
	for ( j = 1; j < sumLlr.len; j++ )
	{
		llr = logadd( llr, pSumLlr[j] );
	}
	// AUDLOG( "llr: %.f\n", llr );

	AUD_Vector sortIndex;
	sortIndex.len      = sumLlr.len;
	sortIndex.dataType = AUD_DATATYPE_INT32S;
	ret = createVector( &sortIndex );
	AUD_ASSERT( ret == 0 );

	ret = sortVector( &sumLlr, &sortIndex );
	AUD_ASSERT( ret == 0 );

	int    num = 0;
	double val = 0.;
	for ( i = 0; i < sortIndex.len; i++ )
	{
		// ln( 0.001 ) ~= -7.
		val =  pSumLlr[sortIndex.pInt32s[i]] - llr + 7.;
		// AUDLOG( "%f, \n", val );
		if ( val < 0 )
		{
			break;
		}
		num++;
	}
	// AUDLOG( "\n" );
	AUD_ASSERT( num > 0 );

	AUDLOG( "computed component num: %d\n", num );

	num = AUD_MAX( num, TOP_N );
	AUDLOG( "normalized component num: %d\n", num );

	AUD_Vector bestIndex;
	bestIndex.len      = num;
	bestIndex.dataType = AUD_DATATYPE_INT32S;
	bestIndex.pInt32s  = sortIndex.pInt32s;
#endif

	int slash = '/';
	char *ptr = strrchr( (char*)wavPath, slash );
	ptr++;

	// select imposter GMM
	void      *hImposterGmm        = NULL;
	AUD_Int8s imposterGmmName[256] = { 0, };
	snprintf( (char*)imposterGmmName, 256, "%s-imposter", ptr );
	error = gmm_select( &hImposterGmm, hUbm, &bestIndex, 0 | GMM_INVERTSELECT_MASK, imposterGmmName );
	AUD_ASSERT( error == AUD_ERROR_NONE );

	gmm_show( hImposterGmm );

	// export gmm
	char imposterFile[256] = { 0 };
	snprintf( imposterFile, 256, "%s/%s-imposter.gmm", WOV_IMPOSTER_GMMMODEL_DIR, ptr );
	AUDLOG( "Export imposter GMM Model to: %s\n", imposterFile );
	FILE *fpImposterGmm = fopen( imposterFile, "wb" );
	AUD_ASSERT( fpImposterGmm );

	error = gmm_export( hImposterGmm, fpImposterGmm );
	AUD_ASSERT( error == AUD_ERROR_NONE );
	AUDLOG( "Export imposter GMM Model File Done\n" );

	fclose( fpImposterGmm );
	fpImposterGmm = NULL;

	error = gmm_free( &hImposterGmm );
	AUD_ASSERT( error == AUD_ERROR_NONE );

	// select keyword GMM
	void      *hAdaptedGmm        = NULL;
	AUD_Int8s adaptedGmmName[256] = { 0, };
	snprintf( (char*)adaptedGmmName, 256, "%s", ptr );
	// AUDLOG( "%s\n", adaptedGmmName );
	error = gmm_select( &hAdaptedGmm, hUbm, &bestIndex, 0, adaptedGmmName );
	AUD_ASSERT( error == AUD_ERROR_NONE );

	ret = destroyVector( &sumLlr );
	AUD_ASSERT( ret == 0 );

	ret = destroyMatrix( &llrMatrix );
	AUD_ASSERT( ret == 0 );

#if 0
	ret = destroyVector( &bestIndex );
	AUD_ASSERT( ret == 0 );
#else
	ret = destroyVector( &sortIndex );
	AUD_ASSERT( ret == 0 );
#endif

#if 1
	// adapt GMM
	error = gmm_adapt( hAdaptedGmm, &featureMatrix );
	AUD_ASSERT( error == AUD_ERROR_NONE );
#endif

	gmm_show( hAdaptedGmm );

	// export gmm
	char modelFile[256] = { 0 };
	snprintf( modelFile, 256, "%s/%s.gmm", WOV_KEYWORD_GMMMODEL_DIR, ptr );
	AUDLOG( "Export GMM Model to: %s\n", modelFile );
	FILE *fpGmm = fopen( modelFile, "wb" );
	AUD_ASSERT( fpGmm );

	error = gmm_export( hAdaptedGmm, fpGmm );
	AUD_ASSERT( error == AUD_ERROR_NONE );
	AUDLOG( "Export GMM Model File Done\n" );

	fclose( fpGmm );
	fpGmm = NULL;

	ret = destroyMatrix( &featureMatrix );
	AUD_ASSERT( ret == 0 );

	error = gmm_free( &hAdaptedGmm );
	AUD_ASSERT( error == AUD_ERROR_NONE );

	error = gmm_free( &hUbm );
	AUD_ASSERT( error == AUD_ERROR_NONE );

	AUDLOG( "keyword model adapt2 done\n" );

	return 0;
}
Ejemplo n.º 16
0
void MainWindow::createMenus()
{
   QAction* action;
   QString  name;
   QMenu*   menu;
   QMenu*   subMenu;

   // ----- File Menu -----
   menu = menuBar()->addMenu("File");

      name = "About";
      action = menu->addAction(name);
      connect(action, SIGNAL(triggered()), this, SLOT(showAbout()));

      name = "New Molecule";
      action = menu->addAction(name);
      connect(action, SIGNAL(triggered()), &m_viewerModel, SLOT(newMoleculeMenu()));
      action->setShortcut(QKeySequence::New);

      name = "New Viewer";
      action = menu->addAction(name);
      connect(action, SIGNAL(triggered()), this, SLOT(newViewer()));

      name = "Open";
      action = menu->addAction(name);
      connect(action, SIGNAL(triggered()), this, SLOT(openFile()));
      action->setShortcut(QKeySequence::Open);

      name = "Open Dir";
      action = menu->addAction(name);
      connect(action, SIGNAL(triggered()), this, SLOT(openDir()));
      action->setShortcut(Qt::SHIFT + Qt::CTRL + Qt::Key_O);

      name = "Open Recent";
      m_recentFilesMenu = menu->addMenu(name);
      updateRecentFilesMenu();

      menu->addSeparator();

      name = "Close Viewer";
      action = menu->addAction(name);
      connect(action, SIGNAL(triggered()), this, SLOT(close()));
      action->setShortcut(QKeySequence::Close);

      name = "Save";
      action = menu->addAction(name);
      connect(action, SIGNAL(triggered()), &m_viewerModel, SLOT(saveAll()));
      action->setShortcut(QKeySequence::Save);

      name = "Save As";
      action = menu->addAction(name);
      connect(action, SIGNAL(triggered()), &m_viewerModel, SLOT(saveAs()));
      action->setShortcut(Qt::SHIFT + Qt::CTRL + Qt::Key_S);

      menu->addSeparator();

      name = "Save Picture";
      action = menu->addAction(name);
      connect(action, SIGNAL(triggered()), m_viewer, SLOT(saveSnapshot()));
      action->setShortcut(Qt::CTRL + Qt::Key_P);

      name = "Record Animation";
      action = menu->addAction(name);
      action->setCheckable(true);
      action->setChecked(false);
      connect(action, SIGNAL(triggered()), this, SLOT(toggleRecordingActive()));
      action->setShortcut(Qt::SHIFT + Qt::CTRL + Qt::Key_P);
      m_recordAnimationAction = action;

      name = "Show Message Log";
      action = menu->addAction(name);
      connect(action, SIGNAL(triggered()), this, SLOT(showLogMessages()));
      action->setShortcut(Qt::CTRL + Qt::Key_L);

      name = "Quit";
      action = menu->addAction(name);
      connect(action, SIGNAL(triggered()), this, SIGNAL(quit()));
      action->setShortcut(Qt::CTRL + Qt::Key_Q);


   // ----- Edit Menu -----
   menu = menuBar()->addMenu("Edit");
  
      name = "Undo";
      action = menu->addAction(name);
      connect(action, SIGNAL(triggered()), &m_undoStack, SLOT(undo()));
      action->setShortcut(QKeySequence::Undo);
      connect(&m_undoStack, SIGNAL(canUndoChanged(bool)), action, SLOT(setEnabled(bool)));

      name = "Redo";
      action = menu->addAction(name);
      connect(action, SIGNAL(triggered()), &m_undoStack, SLOT(redo()));
      action->setShortcut(QKeySequence::Redo);
      connect(&m_undoStack, SIGNAL(canRedoChanged(bool)), action, SLOT(setEnabled(bool)));

      menu->addSeparator();

      name = "Cut";
      action = menu->addAction(name);
      connect(action, SIGNAL(triggered()), &m_viewerModel, SLOT(cutSelection()));
      action->setShortcut(Qt::CTRL + Qt::Key_X);

      name = "Copy";
      action = menu->addAction(name);
      connect(action, SIGNAL(triggered()), &m_viewerModel, SLOT(copySelectionToClipboard()));
      action->setShortcut(Qt::CTRL + Qt::Key_C);

      name = "Paste";
      action = menu->addAction(name);
      connect(action, SIGNAL(triggered()), &m_viewerModel, SLOT(pasteSelectionFromClipboard()));
      action->setShortcut(Qt::CTRL + Qt::Key_V);

      menu->addSeparator();

      name = "Select All";
      action = menu->addAction(name);
      connect(action, SIGNAL(triggered()), &m_viewerModel, SLOT(selectAll()));
      action->setShortcut(Qt::CTRL + Qt::Key_A);

      name = "Select None";
      action = menu->addAction(name);
      connect(action, SIGNAL(triggered()), &m_viewerModel, SIGNAL(clearSelection()));
      action->setShortcut(Qt::SHIFT + Qt::CTRL + Qt::Key_A);

      name = "Invert Selection";
      action = menu->addAction(name);
      connect(action, SIGNAL(triggered()), &m_viewerModel, SLOT(invertSelection()));
      action->setShortcut(Qt::CTRL + Qt::Key_I);

      menu->addSeparator();

      name = "Reindex Atoms";
      action = menu->addAction(name);
      connect(action, SIGNAL(triggered()), this, SLOT(reindexAtoms()));


      menu->addSeparator();

      name = "Preferences";
      action = menu->addAction(name);
      connect(action, SIGNAL(triggered()), this, SLOT(showPreferences()));


   // ----- Display Menu -----
   menu = menuBar()->addMenu("Display");

      name = "Full Screen";
      action = menu->addAction(name);
      action->setCheckable(true);
      action->setChecked(false);
      connect(action, SIGNAL(triggered()), this, SLOT(fullScreen()));
      action->setShortcut(Qt::CTRL + Qt::Key_0);
      m_fullScreenAction = action;

      name = "Reset View";
      action = menu->addAction(name);
      connect(action, SIGNAL(triggered()), m_viewer, SLOT(resetView()));
      action->setShortcut(Qt::CTRL + Qt::Key_R);

      name = "Show Axes";
      action = menu->addAction(name);
      action->setCheckable(true);
      action->setChecked(false);
      connect(action, SIGNAL(triggered()), &m_viewerModel, SLOT(toggleAxes()));
      connect(&m_viewerModel, SIGNAL(axesOn(bool)), action, SLOT(setChecked(bool)));
      action->setShortcut(Qt::Key_A);


      menu->addSeparator();

      name = "Appearance";
      action = menu->addAction(name);
      connect(action, SIGNAL(triggered()), this, SLOT(configureAppearance()));

      menu->addSeparator();

      name = "Atom Labels";
      subMenu = menu->addMenu(name);

         name = "Element";
         action = subMenu->addAction(name);
         connect(action, SIGNAL(triggered()), this, SLOT(setLabel()));
         action->setData(Layer::Atom::Element);
         action->setShortcut(Qt::Key_E);
         action->setCheckable(true);
         m_labelActions << action;

         name = "Index";
         action = subMenu->addAction(name);
         connect(action, SIGNAL(triggered()), this, SLOT(setLabel()));
         action->setData(Layer::Atom::Index);
         action->setShortcut(Qt::Key_I);
         action->setCheckable(true);
         m_labelActions << action;
   
         name = "Mass";
         action = subMenu->addAction(name);
         connect(action, SIGNAL(triggered()), this, SLOT(setLabel()));
         action->setData(Layer::Atom::Mass);
         action->setShortcut(Qt::Key_M);
         action->setCheckable(true);
         m_labelActions << action;

         name = "NMR Shifts";
         action = subMenu->addAction(name);
         connect(action, SIGNAL(triggered()), this, SLOT(setLabel()));
         action->setData(Layer::Atom::NmrShift);
         action->setShortcut(Qt::Key_N);
         action->setCheckable(true);
         m_labelActions << action;

         name = "Partial Charge";
         action = subMenu->addAction(name);
         connect(action, SIGNAL(triggered()), this, SLOT(setLabel()));
         action->setData(Layer::Atom::Charge);
         action->setShortcut(Qt::Key_Q);
         action->setCheckable(true);
         m_labelActions << action;

         name = "Spin Densities";
         action = subMenu->addAction(name);
         connect(action, SIGNAL(triggered()), this, SLOT(setLabel()));
         action->setData(Layer::Atom::Spin);
         action->setShortcut(Qt::Key_S);
         action->setCheckable(true);
         m_labelActions << action;


   // ----- Build Menu -----
   menu = menuBar()->addMenu("Build");

      name = "Fill Valencies With Hydrogens";
      action = menu->addAction(name);
      connect(action, SIGNAL(triggered()), &m_viewerModel, SLOT(addHydrogens()));
      action->setShortcut(Qt::CTRL + Qt::Key_F);

      name = "Reperceive Bonds";
      action = menu->addAction(name);
      connect(action, SIGNAL(triggered()), &m_viewerModel, SLOT(reperceiveBonds()));

      menu->addSeparator();

      name = "Set Geometric Constraint";
      action = menu->addAction(name);
      connect(action, SIGNAL(triggered()), &m_viewerModel, SLOT(setConstraint()));
      action->setShortcut(Qt::CTRL + Qt::Key_K);

      name = "Minimize Structure";
      action = menu->addAction(name);
      connect(action, SIGNAL(triggered()), &m_viewerModel, SLOT(minimizeEnergy()));
      action->setShortcut(Qt::CTRL + Qt::Key_M);

      name = "Select Force Field";

      QActionGroup* forceFieldGroup = new QActionGroup(this);
      subMenu = menu->addMenu(name);

         QString ff("MMFF94");
         action = subMenu->addAction(ff);
         action->setCheckable(true);
         action->setData(ff);
         forceFieldGroup->addAction(action);
         connect(action, SIGNAL(triggered()), this, SLOT(setForceField()));
         if (Preferences::DefaultForceField() == ff) action->setChecked(true);

         ff = "MMFF94s";
         action = subMenu->addAction(ff);
         action->setCheckable(true);
         action->setData(ff);
         forceFieldGroup->addAction(action);
         connect(action, SIGNAL(triggered()), this, SLOT(setForceField()));
         if (Preferences::DefaultForceField() == ff) action->setChecked(true);

         ff = "UFF";
         action = subMenu->addAction(ff);
         action->setCheckable(true);
         action->setData(ff);
         forceFieldGroup->addAction(action);
         connect(action, SIGNAL(triggered()), this, SLOT(setForceField()));
         if (Preferences::DefaultForceField() == ff) action->setChecked(true);

         ff = "Ghemical";
         action = subMenu->addAction(ff);
         action->setCheckable(true);
         action->setData(ff);
         forceFieldGroup->addAction(action);
         connect(action, SIGNAL(triggered()), this, SLOT(setForceField()));
         if (Preferences::DefaultForceField() == ff) action->setChecked(true);

         ff = "Gaff";
         action = subMenu->addAction(ff);
         action->setCheckable(true);
         action->setData(ff);
         forceFieldGroup->addAction(action);
         connect(action, SIGNAL(triggered()), this, SLOT(setForceField()));
         if (Preferences::DefaultForceField() == ff) action->setChecked(true);

      menu->addSeparator();

      name = "Translate To Center";
      action = menu->addAction(name);
      connect(action, SIGNAL(triggered()), &m_viewerModel, SLOT(translateToCenter()));
      action->setShortcut(Qt::CTRL + Qt::Key_T );

      name = "Symmetrize Molecule";
      action = menu->addAction(name);
      connect(action, SIGNAL(triggered()), &m_viewerModel, SLOT(symmetrize()));
      action->setShortcut(Qt::CTRL + Qt::Key_Y );

      name = "Set Symmetry Tolerance";
      action = menu->addAction(name);
      connect(action, SIGNAL(triggered()), &m_viewerModel, SLOT(adjustSymmetryTolerance()));

      name = "Auto-detect Symmetry";
      action = menu->addAction(name);
      action->setCheckable(true);
      action->setChecked(false);
      connect(action, SIGNAL(triggered()), &m_viewerModel, SLOT(toggleAutoDetectSymmetry()));



   // ----- Calculation Menu -----
   menu = menuBar()->addMenu("Calculation");

      name = "Q-Chem Setup";
      action = menu->addAction(name);
      connect(action, SIGNAL(triggered()), this, SLOT(showQChemUI()));
      action->setShortcut(Qt::CTRL + Qt::Key_U );
      m_qchemSetupAction = action;

      name = "Job Monitor";
      action = menu->addAction(name);
      connect(action, SIGNAL(triggered()), this, SLOT(showJobMonitor()));
      action->setShortcut(Qt::CTRL + Qt::Key_J );

      name = "Edit Servers";
      action = menu->addAction(name);
      connect(action, SIGNAL(triggered()), this, SLOT(editNewServers()));

      //name = "Test Internet Connection";
      //action = menu->addAction(name);
      //connect(action, SIGNAL(triggered()), this, SLOT(testInternetConnection()));


   // ----- Help Menu -----
   menu = menuBar()->addMenu("Help");

      name = "Show Help";
      action = menu->addAction(name);
      connect(action, SIGNAL(triggered()), this, SLOT(showHelp()));
}
Ejemplo n.º 17
0
void VolumeIOHelper::showFileSaveDialog(const VolumeBase* volume) {
    tgtAssert(volume, "null pointer passed");

    tgtAssert(volumeSerializerPopulator_, "no volumeserializerpopulator");
    tgtAssert(volumeSerializerPopulator_->getVolumeSerializer(), "no volume serializer");

    //
    // 1. Setup and execute file save dialog
    //

    // open path
    std::string savePath;
    QSettings settings;
    settings.beginGroup("VolumeIOHelper");
    if (settings.contains("lastVolumePath"))
        savePath = settings.value("lastVolumePath").toString().toStdString();
    else
        savePath = VoreenApplication::app()->getUserDataPath("volumes");
    // we want absolute path name to prevent problems when the file dialog perform chdir()
    QDir openDir(QString::fromStdString(savePath));

    // create one filter per volume writer and extension
    QStringList filters;
    std::map<std::string, std::pair<VolumeWriter*, std::string> > filterToWriterMap;
    std::vector<VolumeWriter*> volumeWriters =
        volumeSerializerPopulator_->getVolumeSerializer()->getWriters();
    for (size_t i=0; i<volumeWriters.size(); i++) {
        VolumeWriter* curWriter = volumeWriters.at(i);

        // extensions
        std::vector<std::string> extensionVec = curWriter->getSupportedExtensions();
        for (size_t j=0; j<extensionVec.size(); j++) {
            std::string extension = extensionVec.at(j);
            std::string filterStr = curWriter->getFormatDescription() + " (*." + extension + ")";
            if (extension == "vvd")
                filters.insert(0, QString::fromStdString(filterStr)); //< put VVD format at front
            else
                filters << QString::fromStdString(filterStr);
            filterToWriterMap.insert(
                std::pair<std::string, std::pair<VolumeWriter*, std::string> >(filterStr, std::pair<VolumeWriter*, std::string>(curWriter, extension)));
        }

        // filename
        std::vector<std::string> filenamesVec = curWriter->getSupportedFilenames();
        for (size_t j=0; j<filenamesVec.size(); j++) {
            std::string filename = filenamesVec.at(j);
            std::string filterStr = curWriter->getFormatDescription() + " (" + filename + ")";
            filters << QString::fromStdString(filterStr);
            filterToWriterMap.insert(
                std::pair<std::string, std::pair<VolumeWriter*, std::string> >(filterStr, std::pair<VolumeWriter*, std::string>(curWriter, filename)));
        }

    }

    // sidebar URLs
    QList<QUrl> urls;
    urls << QUrl::fromLocalFile(VoreenApplication::app()->getResourcePath("volumes").c_str());
    urls << QUrl::fromLocalFile(VoreenApplication::app()->getUserDataPath().c_str());
    urls << QUrl::fromLocalFile(VoreenApplication::app()->getBasePath("modules").c_str());
    if (QDir(VoreenApplication::app()->getBasePath("custommodules").c_str()).exists())
        urls << QUrl::fromLocalFile(VoreenApplication::app()->getBasePath("custommodules").c_str());
    if (VoreenApplication::app()->getTestDataPath() != "")
        urls << QUrl::fromLocalFile(VoreenApplication::app()->getTestDataPath().c_str());
    urls << QUrl::fromLocalFile(QDesktopServices::storageLocation(QDesktopServices::DesktopLocation));
    urls << QUrl::fromLocalFile(QDesktopServices::storageLocation(QDesktopServices::HomeLocation));

    // create dialog
    QFileDialog saveAsDialog(parent_, tr("Save Volume..."), openDir.absolutePath(), "");
    saveAsDialog.setNameFilters(filters);
    saveAsDialog.setSidebarUrls(urls);
    saveAsDialog.setViewMode(QFileDialog::Detail);
    saveAsDialog.setAcceptMode(QFileDialog::AcceptSave);
    saveAsDialog.setFileMode(QFileDialog::AnyFile);
    saveAsDialog.setConfirmOverwrite(true);

    // execute dialog
    if (saveAsDialog.exec() != QDialog::Accepted)
        return;

    // retrieve selected filename from dialog
    const QStringList& lst = saveAsDialog.selectedFiles();
    if (lst.empty()) {
        LWARNING("no file selected");
        return;
    }
    else if (lst.size() > 1) {
        LWARNING("more than one file selected");
        return;
    }
    std::string filepath = lst.first().toStdString();

    // retrieve the user selected file filter
    QString selectedFilter = saveAsDialog.selectedFilter();

    // store dialog path
    settings.setValue("lastVolumePath", saveAsDialog.directory().absolutePath());
    settings.endGroup();


    //
    // 2. Save file to specified path (depending on selected filter)
    //
    tgtAssert(volumeSerializerPopulator_, "no volumeserializerpopulator");
    if (filterToWriterMap.find(selectedFilter.toStdString()) == filterToWriterMap.end()) {
        LWARNING("unknown filter selected");
        return;
    }
    VolumeWriter* writer = filterToWriterMap.find(selectedFilter.toStdString())->second.first;

    // if file path does not end with extension, add extension to path
    std::string selectedExtension = filterToWriterMap.find(selectedFilter.toStdString())->second.second;
    std::string filename = tgt::FileSystem::fileName(filepath);
    if (filename != selectedExtension && !QString::fromStdString(filename).endsWith(QString::fromStdString("." + selectedExtension)))
        filepath += "." + selectedExtension;

    LDEBUG("saving volume: " << filepath);
    saveVolumeToPath(volume, writer, filepath);
}
Ejemplo n.º 18
0
MainWindow::MainWindow(QWidget *parent) :
    QMainWindow(parent),
    quitDialog(0), saveChanges(false),
    newJobFileName(""), newJobDestinationDirectory("")
{
    m_has_error_happend = false;
    QMetaObject::invokeMethod(this, "loadSettings", Qt::QueuedConnection);
    setWindowIcon(QIcon(":/ui/icons/motocool.jpg"));

    // Initiallize headers
    QStringList headers;
    headers << tr("Name") << tr("Downloaded/Total") << tr("Progress") << tr("Speed")
            << tr("Status") << tr("Remaining time");

    // Main job list
    jobView = new JobView(this);
    jobView->setHeaderLabels(headers);
    jobView->setSelectionBehavior(QAbstractItemView::SelectRows);
    jobView->setAlternatingRowColors(true);
    jobView->setRootIsDecorated(false);
    setCentralWidget(jobView);

    // Set header resize modes and initial section sizes
    QFontMetrics fm = fontMetrics();
    QHeaderView *header = jobView->header();
    header->resizeSection(0, fm.width("typical-name-length-for-a-download-task"));
    header->resizeSection(1, fm.width(headers.at(1) + "100MB/999MB"));
    header->resizeSection(2, fm.width(headers.at(2) + "100%"));
    header->resizeSection(3, qMax(fm.width(headers.at(3) + "   "), fm.width(" 1023.0 KB/s")));
    header->resizeSection(4, qMax(fm.width(headers.at(4) + "   "), fm.width(tr("Downloading  ") + "   ")));
    header->resizeSection(5, qMax(fm.width(headers.at(5) + "   "), fm.width(tr("--:--") + "   ")));

    // Create common actions
    QAction *newJobAction = new QAction(QIcon(":/ui/icons/bottom.png"), tr("Add &new job"), this);
    pauseJobAction = new QAction(QIcon(":/ui/icons/player_pause.png"), tr("&Pause job"), this);
    removeJobAction = new QAction(QIcon(":/ui/icons/player_stop.png"), tr("&Remove job"), this);
    openDirAction = new QAction(QIcon(":/ui/icons/folder.png"), tr("Open file &directory"), this);

    // File menu
    QMenu *fileMenu = menuBar()->addMenu(tr("&File"));
    fileMenu->addAction(newJobAction);
    fileMenu->addAction(pauseJobAction);
    fileMenu->addAction(removeJobAction);
    fileMenu->addAction(openDirAction);
    fileMenu->addSeparator();
    fileMenu->addAction(QIcon(":/ui/icons/exit.png"), tr("E&xit"), this, SLOT(close()));

    // Help Menu
    QMenu *helpMenu = menuBar()->addMenu(tr("&Help"));
    helpMenu->addAction(tr("&About"), this, SLOT(about()));

    // Top toolbar
    QToolBar *topBar = new QToolBar(tr("Tools"));
    addToolBar(Qt::TopToolBarArea, topBar);
    topBar->setMovable(false);
    topBar->addAction(newJobAction);
    topBar->addAction(pauseJobAction);
    topBar->addAction(removeJobAction);
    topBar->addAction(openDirAction);
    pauseJobAction->setEnabled(false);
    removeJobAction->setEnabled(false);
    openDirAction->setEnabled(false);

    // Set up connections
    connect(jobView, SIGNAL(itemSelectionChanged()),
            this, SLOT(setActionsEnabled()));
    connect(newJobAction, SIGNAL(triggered()),
            this, SLOT(addJob()));
    connect(pauseJobAction, SIGNAL(triggered()),
            this, SLOT(pauseJob()));
    connect(removeJobAction, SIGNAL(triggered()),
            this, SLOT(removeJob()));
    connect(openDirAction, SIGNAL(triggered()),
            this, SLOT(openDir()));
}
Ejemplo n.º 19
0
AUD_Int32s perf_dtw_mfcc_vad()
{
	char            inputPath[256]   = { 0, };
	char            keywordPath[256] = { 0, };
	AUD_Double      threshold, minThreshold, maxThreshold, stepThreshold;
	AUD_Bool        isRecognized     = AUD_FALSE;
	AUD_Int32s      data;

	AUD_Error       error = AUD_ERROR_NONE;

	setbuf( stdin, NULL );
	AUDLOG( "pls give template wav stream's path:\n" );
	keywordPath[0] = '\0';
	data = scanf( "%s", keywordPath );
	AUDLOG( "template path is: %s\n", keywordPath );

	setbuf( stdin, NULL );
	AUDLOG( "pls give test wav stream's path:\n" );
	inputPath[0] = '\0';
	data = scanf( "%s", inputPath );
	AUDLOG( "test stream path is: %s\n", inputPath );

	setbuf( stdin, NULL );
	AUDLOG( "pls give lowest test threshold:\n" );
	data = scanf( "%lf", &minThreshold );
	AUDLOG( "lowest threshold is: %.2f\n", minThreshold );

	setbuf( stdin, NULL );
	AUDLOG( "pls give max test threshold:\n" );
	data = scanf( "%lf", &maxThreshold );
	AUDLOG( "max threshold is: %.2f\n", maxThreshold );

	setbuf( stdin, NULL );
	AUDLOG( "pls give test threshold step:\n" );
	data = scanf( "%lf", &stepThreshold );
	AUDLOG( "threshold step is: %.2f\n", stepThreshold );

	AUDLOG( "\n\n" );

	// file & directory operation, linux dependent
	entry   *pEntry        = NULL;
	dir     *pDir          = NULL;
	entry   *pKeywordEntry = NULL;
	dir     *pKeywordDir   = NULL;

	AUD_Int32s      i, j;

	AUD_Feature     keywordFeature;
	AUD_Int32s      keywordSampleNum = 0;
	AUD_Int32s      keywordWinNum    = 0;
	AUD_Int8s       keywordFile[256] = { 0, };
	AUD_Int8s       keywordName[256] = { 0, };
	AUD_Int32s      keywordID        = 0;

	AUD_DTWSession  dtwSession;
	AUD_Double      score             = 0.;
	AUD_Int32s      sampleNum;

	AUD_Int32s      keywordBufLen = 0;
	AUD_Int16s      *pKeywordBuf  = NULL;
	AUD_Int32s      bufLen        = 0;
	AUD_Int16s      *pBuf         = NULL;

	AUD_Int32s      ret;

	// init performance benchmark
	void *hBenchmark  = NULL;
	char logName[256] = { 0, };
	snprintf( logName, 256, "dtw-mfcc-vad-%d-%d-%d-%d", WOV_DTW_TYPE, WOV_DISTANCE_METRIC, WOV_DTWTRANSITION_STYLE, WOV_DTWSCORING_METHOD );
	ret = benchmark_init( &hBenchmark, (AUD_Int8s*)logName, keywords, sizeof(keywords) / sizeof(keywords[0]) );
	AUD_ASSERT( ret == 0 );

	for ( threshold = minThreshold; threshold < maxThreshold + stepThreshold; threshold += stepThreshold )
	{
		int frameStride = 0;

		ret = benchmark_newthreshold( hBenchmark, threshold );
		AUD_ASSERT( ret == 0 );

		AUDLOG( "***********************************************\n" );
		AUDLOG( "keyword training start...\n" );

		pKeywordDir = openDir( (const char*)keywordPath );
		keywordID  = 0;
		while ( ( pKeywordEntry = scanDir( pKeywordDir ) ) )
		{
			// train keyword
			AUD_Summary fileSummary;

			snprintf( (char*)keywordFile, 256, "%s/%s", (const char*)keywordPath, pKeywordEntry->name );

			ret = parseWavFromFile( keywordFile, &fileSummary );
			if ( ret < 0 )
			{
				continue;
			}
			AUD_ASSERT( fileSummary.channelNum == CHANNEL_NUM && fileSummary.bytesPerSample == BYTES_PER_SAMPLE && fileSummary.sampleRate == SAMPLE_RATE );

			keywordBufLen = fileSummary.dataChunkBytes + 100;
			pKeywordBuf   = (AUD_Int16s*)calloc( keywordBufLen, 1 );
			AUD_ASSERT( pKeywordBuf );

			keywordSampleNum = readWavFromFile( keywordFile, pKeywordBuf, keywordBufLen );
			if ( keywordSampleNum < 0 )
			{
				continue;
			}

			// front end processing
			 // pre-emphasis
			sig_preemphasis( pKeywordBuf, pKeywordBuf, keywordSampleNum );


			for ( j = 0; j * FRAME_STRIDE + FRAME_LEN <= keywordSampleNum; j++ )
			{
				;
			}
			frameStride = FRAME_STRIDE;

			AUDLOG( "pattern[%d: %s] valid frame number[%d]\n", keywordID, keywordFile, j );

			keywordWinNum                         = j;
			keywordFeature.featureMatrix.rows     = keywordWinNum - MFCC_DELAY;
			keywordFeature.featureMatrix.cols     = MFCC_FEATDIM;
			keywordFeature.featureMatrix.dataType = AUD_DATATYPE_INT32S;
			ret = createMatrix( &(keywordFeature.featureMatrix) );
			AUD_ASSERT( ret == 0 );

			keywordFeature.featureNorm.len      = keywordWinNum - MFCC_DELAY;
			keywordFeature.featureNorm.dataType = AUD_DATATYPE_INT64S;
			ret = createVector( &(keywordFeature.featureNorm) );
			AUD_ASSERT( ret == 0 );

			void *hTemplateMfccHandle = NULL;

			// init mfcc handle
			error = mfcc16s32s_init( &hTemplateMfccHandle, FRAME_LEN, WINDOW_TYPE, MFCC_ORDER, frameStride, SAMPLE_RATE, COMPRESS_TYPE );
			AUD_ASSERT( error == AUD_ERROR_NONE );

			// calc MFCC feature
			error = mfcc16s32s_calc( hTemplateMfccHandle, pKeywordBuf, keywordSampleNum, &keywordFeature );
			AUD_ASSERT( error == AUD_ERROR_NONE );

			// deinit mfcc handle
			error = mfcc16s32s_deinit( &hTemplateMfccHandle );
			AUD_ASSERT( error == AUD_ERROR_NONE );

			strncpy( (char*)keywordName, pKeywordEntry->name, 255 );
			ret = benchmark_newtemplate( hBenchmark, keywordName );
			AUD_ASSERT( ret == 0 );

			keywordID++;

			keywordBufLen  = 0;
			free( pKeywordBuf );
			pKeywordBuf = NULL;

			AUDLOG( "keyword training finish...\n" );

			// recognize
			pEntry = NULL;
			pDir   = NULL;
			pDir   = openDir( (const char*)inputPath );
			while ( ( pEntry = scanDir( pDir ) ) )
			{
				AUD_Int8s   inputStream[256] = { 0, };
				void        *hMfccHandle     = NULL;
				AUD_Summary fileSummary;

				snprintf( (char*)inputStream, 256, "%s/%s", (const char*)inputPath, pEntry->name );

				ret = parseWavFromFile( inputStream, &fileSummary );
				if ( ret < 0 )
				{
					continue;
				}
				AUD_ASSERT( fileSummary.channelNum == CHANNEL_NUM && fileSummary.bytesPerSample == BYTES_PER_SAMPLE && fileSummary.sampleRate == SAMPLE_RATE );
				AUDLOG( "input stream: %s\n", inputStream );

				bufLen  = fileSummary.dataChunkBytes;
				pBuf = (AUD_Int16s*)malloc( bufLen + 100 );
				AUD_ASSERT( pBuf );

				sampleNum = readWavFromFile( inputStream, pBuf, bufLen );
				AUD_ASSERT( sampleNum > 0 );

				// VAD
				AUD_Int16s *pValidBuf = (AUD_Int16s*)calloc( bufLen, 1 );
				AUD_ASSERT( pValidBuf );
				AUD_Int16s *pSpeechFlag  = (AUD_Int16s*)calloc( ( sampleNum / VAD_FRAME_LEN ) + 1, sizeof( AUD_Int16s ) );
				AUD_ASSERT( pSpeechFlag );

				void *hVadHandle = NULL;
				ret = sig_vadinit( &hVadHandle, pValidBuf, pSpeechFlag, bufLen, -1, -1 );
				AUD_ASSERT( ret == 0 );

				AUD_Int32s start = -1;
				for ( i = 0; i * VAD_FRAME_LEN + FRAME_LEN <= sampleNum; i++ )
				{
					ret = sig_vadupdate( hVadHandle, pBuf + i * VAD_FRAME_LEN, &start );
					if ( ret == 0 )
					{
						continue;
					}
					else
					{
						break;
					}
				}

				if ( ret == 0 )
				{
					continue;
				}

				AUD_Int32s validSampleNum = ret;
				sig_vaddeinit( &hVadHandle );

#if 1
				char vadFile[256] = { 0, };
				snprintf( vadFile, 255, "./vaded/%s", pEntry->name );
				ret = writeWavToFile( (AUD_Int8s*)vadFile, pValidBuf + start, validSampleNum );
				AUD_ASSERT( ret == 0 );
#endif

				// de-noise
				AUD_Int16s *pCleanBuf = (AUD_Int16s*)calloc( (validSampleNum + start) * BYTES_PER_SAMPLE, 1 );
				AUD_ASSERT( pCleanBuf );

				AUD_Int32s cleanLen = denoise_mmse( pValidBuf, pCleanBuf, (validSampleNum + start) );

#if 1
				char cleanFile[256] = { 0, };
				snprintf( cleanFile, 255, "./clean/%s", pEntry->name );
				ret = writeWavToFile( (AUD_Int8s*)cleanFile, pCleanBuf, cleanLen );
				AUD_ASSERT( ret == 0 );
#endif
				// front end processing
				 // pre-emphasis
				sig_preemphasis( pCleanBuf, pCleanBuf, cleanLen );

				for ( j = 0; j * FRAME_STRIDE + FRAME_LEN <= cleanLen; j++ )
				{
					;
				}
				frameStride = FRAME_LEN;

				bufLen = 0;
				free( pBuf );
				pBuf = NULL;
				free( pValidBuf );
				pValidBuf = NULL;
				free( pSpeechFlag );
				pSpeechFlag = NULL;

				AUD_Feature inFeature;
				inFeature.featureMatrix.rows     = j - MFCC_DELAY;
				inFeature.featureMatrix.cols     = MFCC_FEATDIM;
				inFeature.featureMatrix.dataType = AUD_DATATYPE_INT32S;
				ret = createMatrix( &(inFeature.featureMatrix) );
				AUD_ASSERT( ret == 0 );

				inFeature.featureNorm.len      = j - MFCC_DELAY;
				inFeature.featureNorm.dataType = AUD_DATATYPE_INT64S;
				ret = createVector( &(inFeature.featureNorm) );
				AUD_ASSERT( ret == 0 );

				// init mfcc handle
				error = mfcc16s32s_init( &hMfccHandle, FRAME_LEN, WINDOW_TYPE, MFCC_ORDER, frameStride, SAMPLE_RATE, COMPRESS_TYPE );
				AUD_ASSERT( error == AUD_ERROR_NONE );

				error = mfcc16s32s_calc( hMfccHandle, pCleanBuf, cleanLen, &inFeature );
				AUD_ASSERT( error == AUD_ERROR_NONE );

				// init dtw match
				dtwSession.dtwType        = WOV_DTW_TYPE;
				dtwSession.distType       = WOV_DISTANCE_METRIC;
				dtwSession.transitionType = WOV_DTWTRANSITION_STYLE;
				error = dtw_initsession( &dtwSession, &keywordFeature, inFeature.featureMatrix.rows );
				AUD_ASSERT( error == AUD_ERROR_NONE );

				error = dtw_updatefrmcost( &dtwSession, &inFeature );
				AUD_ASSERT( error == AUD_ERROR_NONE );

				error = dtw_match( &dtwSession, WOV_DTWSCORING_METHOD, &score, NULL );
				AUD_ASSERT( error == AUD_ERROR_NONE );

				error = dtw_deinitsession( &dtwSession );
				AUD_ASSERT( error == AUD_ERROR_NONE );

				// deinit mfcc handle
				error = mfcc16s32s_deinit( &hMfccHandle );
				AUD_ASSERT( error == AUD_ERROR_NONE );

				ret = destroyMatrix( &(inFeature.featureMatrix) );
				AUD_ASSERT( ret == 0 );

				ret = destroyVector( &(inFeature.featureNorm) );
				AUD_ASSERT( ret == 0 );

				AUDLOG( "score: %.2f\n", score );

				isRecognized = AUD_FALSE;
				if ( score <= threshold )
				{
					isRecognized = AUD_TRUE;
				}

				// insert log entry
				ret = benchmark_additem( hBenchmark, (AUD_Int8s*)pEntry->name, score, isRecognized );
				AUD_ASSERT( ret == 0 );

				cleanLen = 0;
				free( pCleanBuf );
				pCleanBuf = NULL;
			}
			closeDir( pDir );
			pDir = NULL;

			ret = benchmark_finalizetemplate( hBenchmark );
			AUD_ASSERT( ret == 0 );

			ret = destroyMatrix( &(keywordFeature.featureMatrix) );
			AUD_ASSERT( ret == 0 );

			ret = destroyVector( &(keywordFeature.featureNorm) );
			AUD_ASSERT( ret == 0 );
		}
		closeDir( pKeywordDir );
		pKeywordDir = NULL;

		ret = benchmark_finalizethreshold( hBenchmark );
		AUD_ASSERT( ret == 0 );
	}

	ret = benchmark_free( &hBenchmark );
	AUD_ASSERT( ret == 0 );

	AUDLOG( "DTW-MFCC VAD Benchmark finished\n" );

	return 0;
}
Ejemplo n.º 20
0
ImageView::ImageView(QWidget *parent) : QMainWindow(parent), ui(new Ui::ImageView)
{
  ui->setupUi(this);

  setWindowTitle("MicroLab ImgP");

  //! \brief connectActionToSlots
  //!
  connectActionToSlots();
  newSonWidgets();

  connect(ui->openDirAction, SIGNAL(triggered()), this, SLOT(openDir()));
  connect(ui->openFileAction, SIGNAL(triggered()), this, SLOT(openFile()));
  connect(ui->actionSave, SIGNAL(triggered()), this, SLOT(save()));
  connect(ui->actionSave_As, SIGNAL(triggered()), this, SLOT(saveAs()));
  connect(ui->actionExit_4, SIGNAL(triggered()), this, SLOT(close()));

  connect(ui->nextButton, SIGNAL(clicked()), this, SLOT(nextImage()));
  connect(ui->previousButton, SIGNAL(clicked()), this, SLOT(previousImage()));
  connect(ui->beginButton, SIGNAL(clicked()), this, SLOT(setBegin()));
  connect(ui->endButton, SIGNAL(clicked()), this, SLOT(setEnd()));
  connect(ui->slideShowButton, SIGNAL(clicked()), this, SLOT(slideShow()));
  connect(ui->slideShowDelaySlider, SIGNAL(valueChanged(int)), this, SLOT(setSlideShowDelay(int)));
  slideshowTimer = new QTimer(this);
  connect(slideshowTimer, SIGNAL(timeout()), this, SLOT(nextImage()));

  ui->imageNameLabel->setText(tr("Select a folder from the <b>file -> openDir</b> or <b>file->openFile</b> menu to view images or image.."));
  ui->openFileAction->setShortcut(tr("Ctrl+O"));
  setImage(":/images/Cover.jpg");

  ui->previousButton->setEnabled(false);
  ui->nextButton->setEnabled(false);
  ui->beginButton->setEnabled(false);
  ui->endButton->setEnabled(false);
  ui->slideShowButton->setEnabled(false);
  ui->slideShowDelaySlider->setEnabled(false);
  ui->slideShowDelayLabel->setEnabled(false);
  ui->slideShowDelaySlider->setValue(15);

  //! NOTICE HERE
  ui->actionOpen_Recent_Files->setEnabled(false);
  ui->actionSave->setEnabled(false);
  ui->actionSave_As->setEnabled(true);
  ui->actionLecel_Set->setEnabled(false); //! @warning  Bug

  setButtonIcon(ui->slideShowButton, ":/images/buttons/play.png", 48, 48);
  setButtonIcon(ui->nextButton, ":/images/buttons/next.png", 48, 48);
  setButtonIcon(ui->previousButton, ":/images/buttons/back.png", 48, 48);
  setButtonIcon(ui->beginButton, ":/images/buttons/rewind.png", 48, 48);
  setButtonIcon(ui->endButton, ":/images/buttons/fastfwd.png", 48, 48);

  setWindowTitle(tr("ImageView"));

  folderName = "";
  imageNumber = 0;
  totalImages = 0;
  slideShowDelay = 2.0;

  QLabel *label = new QLabel("<a href = http://yajunyang.cn>connect me...</a>", this);
  connect(label, SIGNAL(linkActivated(QString)), this, SLOT(openUrl(QString)));
  ui->statusBar->insertWidget(0, label);
}
Ejemplo n.º 21
0
void PaletteEditor::saveGradientAction()
{
	QString saveFile( QFileDialog::getSaveFileName(this,
		tr("Save gradient to a cpt file"),
		QFileInfo(m_lastBrowseDir).absoluteFilePath(),
		tr("CPT Gradient Files (*.cpt)")) );

	if (saveFile.isEmpty())
		return;

	QFileInfo file( saveFile );
	QString openDir( file.absoluteFilePath() );
	logInfo(QString("PaletteEditor::saveGradientAction : saving gradient to %1").arg(saveFile));
	if (openDir != m_lastBrowseDir)
		m_lastBrowseDir = openDir;

	QFile data(file.absoluteFilePath());
	if (!data.open(QFile::ReadWrite))
	{
		QMessageBox msgBox;
		msgBox.setText(tr("Error: Couldn't open file %1").arg(file.filePath()));
		msgBox.setIcon(QMessageBox::Warning);
		msgBox.exec();
		return;
	}

	QTextStream os(&data);
	os << "# COLOR_MODEL = RGB" << endl
		<< scientific << qSetRealNumberPrecision(6) << qSetFieldWidth(4);
	p_stops = m_gradientStops->getStops();
	qStableSort(p_stops.begin(), p_stops.end(), GradientStop::lessThanGradientStopComparison);
	GradientStops::const_iterator i = p_stops.constBegin();
	os << left << (*i).first
		<< right
		<< (*i).second.red()
		<< (*i).second.green()
		<< (*i).second.blue() << ' ';
	++i;
	for ( ; i != p_stops.constEnd(); ++i)
	{
		os << left << (*i).first
		<< right
		<< (*i).second.red()
		<< (*i).second.green()
		<< (*i).second.blue() << endl;

		if (i + 1 != p_stops.constEnd())
			os << left << (*i).first
			<< right
			<< (*i).second.red()
			<< (*i).second.green()
			<< (*i).second.blue() << ' ';
	}
	os << "B   0   0   0" << endl
		<< "F 255 255 255" << endl
		<< "N 255   0   0" << endl;

	data.close();
	if (data.error() != QFile::NoError)
	{
		QMessageBox msgBox;
		msgBox.setText(tr("Error: Couldn't write to file %1").arg(file.filePath()));
		msgBox.setIcon(QMessageBox::Warning);
		msgBox.exec();
	}
}
Ejemplo n.º 22
0
AUD_Int32s test_pitch_tracking()
{
	char            inputPath[256]  = { 0, };
	AUD_Int32s      data;

	setbuf( stdin, NULL );
	AUDLOG( "pls give test wav stream's path:\n" );
	inputPath[0] = '\0';
	data = scanf( "%s", inputPath );
	AUDLOG( "test stream path is: %s\n", inputPath );

	AUDLOG( "\n\n" );

	// file & directory operation, linux dependent
	entry      *pEntry         = NULL;
	dir        *pDir           = NULL;
	AUD_Int8s  fileName[256]   = { 0, };
	AUD_Int32s sampleNum;

	AUD_Int32s bufLen          = 0;
	AUD_Int16s *pBuf           = NULL;


	FILE *fPitch = fopen( "./pitch.log", "wb" );
	AUD_ASSERT( fPitch );

	pDir = openDir( (const char*)inputPath );
	while ( ( pEntry = scanDir( pDir ) ) )
	{
		bufLen = SAMPLE_RATE * BYTES_PER_SAMPLE * 10;
		pBuf   = (AUD_Int16s*)malloc( bufLen );
		AUD_ASSERT( pBuf );

		snprintf( (char*)fileName, 256, "%s/%s", (const char*)inputPath, pEntry->name );

		sampleNum = readWavFromFile( fileName, pBuf, bufLen );
		if ( sampleNum < 0 )
		{
			continue;
		}
		AUDLOG( "stream[%s] sample number[%d]\n", fileName, sampleNum );

		sig_preemphasis( pBuf, pBuf, sampleNum );

		// pitch tracking
		AUD_Int32s pitch;
		pitch_track( pBuf, sampleNum, &pitch );
		fprintf( fPitch, "%d, ", pitch );
		AUDLOG( "%d, \n", pitch );

		free( pBuf );
		pBuf = NULL;
	}

	fclose( fPitch );
	fPitch = NULL;

	AUDLOG( "PITCH-TRACKING finished\n" );

	return 0;
}
Ejemplo n.º 23
0
Wormsign::Wormsign(QWidget *parent, Qt::WFlags flags)
	: QWidget(parent, flags)
{

	appVersion = "2.0";


	//Populate Camera Options
	QMainWindow * mainWin = (QMainWindow *)this->window();
	mainWin->setWindowTitle("Wormsign " + appVersion + " - RealTime Larva Tracking - Questions: Gus Lott x4632");

	expAgent = NULL;

	int height = 1000;
	int width = 1000;
	setGeometry(50,50,width,height);
	setMinimumHeight(height); setMaximumHeight(height);
	setMinimumWidth(width); setMaximumWidth(width);
	//setAutoFillBackground(true);
	//setPalette(QColor(250,250,200));

	//File Menu saves/loads config states.
	

	//Create Preview Canvas for Camera
	camThread = NULL;
	canvas = new CamViewGL;
	canvas->gui = this;
	canvas->show();

	//HARDWARE INTERFACES
	//button to show/hide hardware interfaces
	showHideHW = new QPushButton("<< Hide Config",this);
	showHideHW->setGeometry(530,10,110,20); showHideHW->setCheckable(true);
	showHideHW->setPalette(QColor(200,200,200)); showHideHW->setChecked(true);
	connect(showHideHW,SIGNAL(clicked()),this,SLOT(hideHW()));

	//Create Camera Control Interface
		QStringList camStrList = CoreCamThread::listCams();

		QGroupBox * camControlBox = new QGroupBox("Camera Control",this);
		QFont fnt = camControlBox->font(); fnt.setBold(true); camControlBox->setFont(fnt);
		camControlBox->setGeometry(645,10,350,200);
		
		//pop-up list of available cameras
		camList = new QComboBox(camControlBox);
		camList->addItems(camStrList);
		camList->setGeometry(10,20,200,20);

		//connect toggle button
		camConnect = new QPushButton("Connect",camControlBox);
		camConnect->setGeometry(220,20,100,20);
		camConnect->setCheckable(true); camConnect->setPalette(QPalette(QColor(200,200,200)));
		connect(camConnect,SIGNAL(clicked()),this,SLOT(connectCamera()));

		//ROI, Brightness, Gain, Gamma, Shutter - disabled
		QLabel * roiLabel = new QLabel("ROI (xywh):",camControlBox);
		roiLabel->setFont(fnt);
		roiLabel->setGeometry(10,50,70,20);
		for(int i=0; i<4; i++){
			roiBox[i] = new QSpinBox(camControlBox);
			roiBox[i]->setGeometry(10+80+ 65*i ,50,55,20);
			roiBox[i]->setEnabled(false);
		}
		
		QLabel * tempLabel;
		//Brightness
		tempLabel = new QLabel("Brightness: ",camControlBox); 
		brightBox = new QSpinBox(camControlBox); brightBox->setEnabled(false); 
		brightSlider = new QSlider(Qt::Horizontal,camControlBox); brightSlider->setEnabled(false);
		tempLabel->setGeometry(10,90,120,20); brightBox->setGeometry(110,90,70,20); brightSlider->setGeometry(190,90,150,20);
		//Link slider/box and connect prop update
		connect(brightBox,SIGNAL(valueChanged(int)),brightSlider,SLOT(setValue(int)));
		connect(brightSlider,SIGNAL(valueChanged(int)),brightBox,SLOT(setValue(int)));

		//Gain
		tempLabel = new QLabel("Gain: ",camControlBox); 
		gainBox = new QSpinBox(camControlBox); gainBox->setEnabled(false);
		gainSlider = new QSlider(Qt::Horizontal,camControlBox); gainSlider->setEnabled(false);
		tempLabel->setGeometry(10,110,120,20); gainBox->setGeometry(110,110,70,20); gainSlider->setGeometry(190,110,150,20);
		//Link slider/box and connect prop update
		connect(gainBox,SIGNAL(valueChanged(int)),gainSlider,SLOT(setValue(int)));
		connect(gainSlider,SIGNAL(valueChanged(int)),gainBox,SLOT(setValue(int)));
		
		//Gamma
		tempLabel = new QLabel("Gamma: ",camControlBox); 
		gammaBox = new QSpinBox(camControlBox); gammaBox->setEnabled(false);
		gammaSlider = new QSlider(Qt::Horizontal,camControlBox); gammaSlider->setEnabled(false);
		tempLabel->setGeometry(10,130,120,20); gammaBox->setGeometry(110,130,70,20); gammaSlider->setGeometry(190,130,150,20);
		//Link slider/box and connect prop update
		connect(gammaBox,SIGNAL(valueChanged(int)),gammaSlider,SLOT(setValue(int)));
		connect(gammaSlider,SIGNAL(valueChanged(int)),gammaBox,SLOT(setValue(int)));
				
		//Shutter
		shutLabel = new QLabel("Shutter (x ms): ",camControlBox); 
		shutterBox = new QSpinBox(camControlBox); shutterBox->setEnabled(false);
		shutterSlider = new QSlider(Qt::Horizontal,camControlBox); shutterSlider->setEnabled(false);
		shutLabel->setGeometry(10,150,120,20); shutterBox->setGeometry(110,150,70,20); shutterSlider->setGeometry(190,150,150,20);
		//Link slider/box and connect prop update
		connect(shutterBox,SIGNAL(valueChanged(int)),shutterSlider,SLOT(setValue(int)));
		connect(shutterSlider,SIGNAL(valueChanged(int)),shutterBox,SLOT(setValue(int)));
		
		frameInt = new QLabel("Measured Frame Interval: ",camControlBox);
		frameInt->setGeometry(10,175,200,20);
		QPalette palette = frameInt->palette();
		palette.setColor(frameInt->foregroundRole(), QColor(200,0,0));
		frameInt->setPalette(palette);

			
	//Create Network Connection Control interface, to biorules app
		//Connection to Eric Trautman's Biorules Application
		biorulesConnection = new BiorulesConnect();

		//Panel
		QGroupBox * netPanel = new QGroupBox("BioRules Network Connection",this);
		netPanel->setFont(fnt);
		netPanel->setGeometry(645,230,350,70);

		//IP/Port Controls & Connect Button
		tempLabel = new QLabel("IP:",netPanel);
		tempLabel->setGeometry(10,20,30,20);
		ipText = new QLineEdit(biorulesConnection->ip,netPanel);
		ipText->setGeometry(40,20,150,20);

		tempLabel = new QLabel("Port:",netPanel);
		tempLabel->setGeometry(10,40,40,20);
		portText = new QLineEdit(QString().sprintf("%d",biorulesConnection->port),netPanel);
		portText->setGeometry(40,40,50,20); portText->setEnabled(false);

		netConnect = new QPushButton("Connect",netPanel);
		netConnect->setGeometry(220,20,100,20); netConnect->setFont(fnt);
		netConnect->setCheckable(true); netConnect->setPalette(QColor(200,200,200));
		
		connect(netConnect,SIGNAL(clicked()),this,SLOT(connectBioRules()));
	
		

	//Create Stage Control Serial Connection Interface
		stageThread = new StageThread(this);
		stageThread->biorulesConnection = biorulesConnection;
		connect(stageThread,SIGNAL(posUpdate()),this,SLOT(update()));

		//Panel
		QGroupBox * stagePanel = new QGroupBox("Zaber Stage Serial Interface",this);
		stagePanel->setFont(fnt);
		stagePanel->setGeometry(645,310,350,120);

		tempLabel = new QLabel("Port:",stagePanel);
		tempLabel->setGeometry(10,20,30,20);
		
		stageComList = new QComboBox(stagePanel);
		QStringList comStrList = stageThread->enumeratePorts();  //Scan for available serial ports
		stageComList->insertItems(0,comStrList);
		for(int i=0; i<comStrList.size(); i++)
			if(comStrList[i] == stageThread->comName) stageComList->setCurrentIndex(i);
		stageComList->setGeometry(40,20,100,20);

		stageConnect = new QPushButton("Connect",stagePanel);
		stageConnect->setGeometry(220,20,100,20); stageConnect->setFont(fnt);
		stageConnect->setCheckable(true); stageConnect->setPalette(QColor(200,200,200));
		
		connect(stageConnect,SIGNAL(clicked()),this,SLOT(connectStage()));

		stageX = new QLabel(stagePanel);
		stageX->setGeometry(10,45,150,20);
		stageY = new QLabel(stagePanel);
		stageY->setGeometry(170,45,150,20);

		tempLabel = new QLabel("Velocity (0-4800): ",stagePanel);
		tempLabel->setGeometry(10,70,120,20);
		stageVel = new QSpinBox(stagePanel);
		stageVel->setGeometry(130,70,100,20); stageVel->setEnabled(false); stageVel->setValue(0);
		stageVel->setMinimum(0); stageVel->setMaximum(10000);

		tempLabel = new QLabel("Acceleration: ",stagePanel);
		tempLabel->setGeometry(10,90,120,20);
		stageAccel = new QSpinBox(stagePanel);
		stageAccel->setGeometry(130,90,100,20); stageAccel->setEnabled(false); stageAccel->setValue(0);
		stageAccel->setMinimum(0); stageAccel->setMaximum(10000);

	//Create Stimulus Control Serial Connection Interface, frame rate, intensity, manual stim

		stimThread = new StimThread(this);
		//Panel
		QGroupBox * stimPanel = new QGroupBox("PhotoStim + Trigger System",this);
		stimPanel->setFont(fnt);
		stimPanel->setGeometry(645,440,350,50);

		tempLabel = new QLabel("Port:",stimPanel);
		tempLabel->setGeometry(10,20,30,20);
		
		stimComList = new QComboBox(stimPanel);
		stimComList->insertItems(0,comStrList);
		for(int i=0; i<comStrList.size(); i++)
			if(comStrList[i] == stimThread->comName) stimComList->setCurrentIndex(i);
		stimComList->setGeometry(40,20,100,20);

		stimConnect = new QPushButton("Connect",stimPanel);
		stimConnect->setGeometry(220,20,100,20); stimConnect->setFont(fnt);
		stimConnect->setCheckable(true); stimConnect->setPalette(QColor(200,200,200));
		
		connect(stimConnect,SIGNAL(clicked()),this,SLOT(connectStim()));
		
		

		

	//Experiment Controls, start/stop, log, file names
		QGroupBox * expPanel = new QGroupBox("Experiment Control",this);
		expPanel->setFont(fnt);
		expPanel->setGeometry(645,500,350,160);

		fnt.setBold(false);
		dirSelect = new QPushButton("Browse...",expPanel);
		dirSelect->setGeometry(10,20,70,20); dirSelect->setFont(fnt);

		connect(dirSelect,SIGNAL(clicked()),this,SLOT(selectDir()));

		dirOpen = new QPushButton("Open Dir",expPanel);
		dirOpen->setGeometry(10,45,70,20); dirOpen->setFont(fnt);

		connect(dirOpen,SIGNAL(clicked()),this,SLOT(openDir()));


		expLoc.setFile("C:\\Data\\");
		
		expDirectory = new QLabel(expLoc.path(),expPanel);
		expDirectory->setGeometry(85,20,330,20); 
		expDirectory->setFont(fnt); 
		
		dataLog = new QCheckBox("Log Analysis Results and Stimuli",expPanel);
		dataLog->setGeometry(85,45,200,20); dataLog->setChecked(true);
		vidLog = new QCheckBox("Log Grayscale Video",expPanel);
		vidLog->setGeometry(85,65,200,20); vidLog->setChecked(true);
		markupLog = new QCheckBox("Log Video with Annotation",expPanel);
		markupLog->setGeometry(85,85,200,20); markupLog->setChecked(false);


		//list for available rules (including none) - from biorulesConnection
		tempLabel = new QLabel("BioRule:",expPanel);
		tempLabel->setGeometry(10,110,75,20);
		bioRuleList = new QComboBox(expPanel);
		bioRuleList->setGeometry(85,110,200,20);
		//bioRuleList->insertItem(0,QString("NONE"));
		
		tempLabel = new QLabel("Frame Trigger Interval (ms):",expPanel);
		tempLabel->setGeometry(10,135,180,20);
		frameIntIn = new QSpinBox(expPanel);
		frameIntIn->setGeometry(180,135,50,20); frameIntIn->setValue(33);
		frameIntIn->setRange(10,50);

		fnt.setBold(true);

	//Start/Stop Button and Experiment Ellapsed Time
	fnt.setPointSize(17);
	startStop = new QPushButton("START",this);
	startStop->setGeometry(500,950,120,40); startStop->setCheckable(true); startStop->setEnabled(false);
	startStop->setFont(fnt); startStop->setAutoFillBackground(true); startStop->setPalette(QPalette(QColor(200,0,0)));
	expTime = new QLabel("0:00:00",this);
	expTime->setGeometry(400,950,100,40);
	expTime->setFont(fnt);

	connect(startStop,SIGNAL(clicked()),this,SLOT(startStopExperiment()));


	//DATA PLOTS

	//Algorithm Performance Widget
	perfGraph = new PerformanceGraph(this);
	perfGraph->setGeometry(645,670,350,320);

	//Data Visualization - widget drawing plots of results 
	plots.resize(4);
	for(int i=0; i<4; i++){
		plots[i] = new DataPlot(this);
		plots[i]->setGeometry(10,20+240*i,300,230);
		plots[i]->parameterList->setCurrentIndex(i);
	}

	//Global Arena Trajectory - widget drawing history of animal track - clear history button
	arenaTrack = new ArenaTrack(this);
	arenaTrack->setGeometry(320,40,310,300);
	connect(bioRuleList,SIGNAL(currentIndexChanged(int)),arenaTrack,SLOT(update()));

	//Behavior mode visualization (i.e. stopped, forward, back, casting left, etc)
	behaviorModeView = new BehaviorModeView(this);
	behaviorModeView->setGeometry(320,360,310,300);

	//Manual controls
	manualControls = new ManualControls(this);
	manualControls->setGeometry(320,680,310,250);

	//check for default config in pwd and load it
}
Ejemplo n.º 24
0
void MainWindow::createActions()
{
    openAct = new QAction(tr("&Open"), this);
    openAct->setToolTip(tr("Open an image"));
    actionsManager->addAction(openAct, "_open", this, this, SLOT(open()), QKeySequence::Open);

    saveAct = new QAction(tr("&Save"), this);
    saveAct->setEnabled(false);
    actionsManager->addAction(saveAct, "_save", this, this, SLOT(save()), QKeySequence::Save);

    exitAct = new QAction(tr("&Exit"), this);
    actionsManager->addAction(exitAct, "_exit", this, this, SLOT(close()), QKeySequence::Quit);

    filePropertiesAct = new QAction(tr("Properties"), this);
    filePropertiesAct->setEnabled(false);
    actionsManager->addAction(filePropertiesAct, "_fileProperties", this, this,
                              SLOT(fileProperties()), QKeySequence("Ctrl+."));

    zoomInAct = new QAction(tr("Zoom In"), this);
    zoomInAct->setEnabled(false);
    actionsManager->addAction(zoomInAct, "_zoomIn", this, this, SLOT(zoomIn()), QKeySequence("+"));

    zoomOutAct = new QAction(tr("Zoom Out"), this);
    zoomOutAct->setEnabled(false);
    actionsManager->addAction(zoomOutAct, "_zoomOut", this, this, SLOT(zoomOut()), QKeySequence("-"));

    normalSizeAct = new QAction(tr("Normal Size"), this);
    normalSizeAct->setEnabled(false);
    actionsManager->addAction(normalSizeAct, "_normalSize", this, this, SLOT(normalSize()), QKeySequence("1"));

    adjustSizeAct = new QAction(tr("Best Fit"), this);
    adjustSizeAct->setEnabled(false);
    adjustSizeAct->setCheckable(true);
    actionsManager->addAction(adjustSizeAct, "_adjustSize", this, this, SLOT(adjustSizeSlot()), QKeySequence("0"));

    rotateRightAct = new QAction(tr("Rotate to right"), this);
    rotateRightAct->setToolTip(tr("Rotate image in the clockwise clock"));
    rotateRightAct->setEnabled(false);
    actionsManager->addAction(rotateRightAct, "_rotateRight", this, this, SLOT(rotateRight()));

    rotateLeftAct = new QAction(tr("Rotate to Left"), this);
    rotateLeftAct->setToolTip(tr("Rotate image counter-clockwise to clockwise"));
    rotateLeftAct->setEnabled(false);
    actionsManager->addAction(rotateLeftAct, "_rotateLeft", this, this, SLOT(rotateLeft()));

    flipVerticallyAct = new QAction(tr("Flip vertically"), this);
    flipVerticallyAct->setToolTip(tr("Turns vertically the image"));
    flipVerticallyAct->setEnabled(false);
    actionsManager->addAction(flipVerticallyAct, "_flipVertically", this, this, SLOT(flipVertically()));

    flipHorizontallyAct = new QAction(tr("Flip horizontally"), this);
    flipHorizontallyAct->setToolTip(tr("Reflects the image"));
    flipHorizontallyAct->setEnabled(false);
    actionsManager->addAction(flipHorizontallyAct, "_flipHorizontally", this, this, SLOT(flipHorizontally()));

    aboutAct = new QAction(tr("A&bout"), this);
    actionsManager->addAction(aboutAct, "_about", this, this, SLOT(about()), QKeySequence::HelpContents);

    nextAct = new QAction(tr("Ne&xt"), this);
    nextAct->setStatusTip(tr("Loads next image"));
    nextAct->setEnabled(false);
    actionsManager->addAction(nextAct, "_next", this, this, SLOT(next()), Qt::Key_Right);

    goFirstAct = new QAction(tr("Go to the first"), this);
    goFirstAct->setStatusTip(tr("Loads the first image in the folder"));
    goFirstAct->setEnabled(false);
    actionsManager->addAction(goFirstAct, "_goFirst", this, this, SLOT(goFirst()), Qt::Key_Home);

    prevAct = new QAction(tr("Pre&vious"), this);
    prevAct->setStatusTip(tr("Loads previous image"));
    prevAct->setEnabled(false);
    actionsManager->addAction(prevAct, "_previous", this, this, SLOT(previous()), Qt::Key_Left);

    goLastAct = new QAction(tr("Go to the last"), this);
    goLastAct->setStatusTip(tr("Loads the last image in the folder"));
    goLastAct->setEnabled(false);
    actionsManager->addAction(goLastAct, "_goLast", this, this, SLOT(goLast()), Qt::Key_End);

    openDirAct = new QAction(tr("Open &Folder"), this);
    openDirAct->setStatusTip("Open a folder to explore images inside it");
    actionsManager->addAction(openDirAct, "_openFolder", this, this, SLOT(openDir()), QKeySequence("Ctrl+Shift+O"));

    showMenuBarAct = new QAction(tr("Show Menu Bar"), this);
    showMenuBarAct->setCheckable(true);
    actionsManager->addAction(showMenuBarAct, "_showMenuBar", this, this, SLOT(showMenuBar()), QKeySequence("Ctrl+M"));

    configAct = new QAction(tr("Configuration"), this);
    configAct->setEnabled(true);
    actionsManager->addAction(configAct, "_configuration", this, this, SLOT(configureProgram()), QKeySequence("Ctrl+C"));

    deleteRecentFilesAct = new QAction(tr("Delete list"), this);
    deleteRecentFilesAct->setIcon(QIcon::fromTheme("edit-clear"));
    connect(deleteRecentFilesAct, SIGNAL(triggered()), this, SLOT(deleteRecentFiles()));

    printAct = new QAction(tr("Print"), this);
    printAct->setEnabled(false);
    actionsManager->addAction(printAct, "_print", this, this, SLOT(print()), QKeySequence::Print);

    deleteFileAct = new QAction(tr("Delete"), this);
    deleteFileAct->setEnabled(false);
    deleteFileAct->setToolTip(tr("This deletes completly the file from the disk, doesn't move it to the trash"));
    actionsManager->addAction(deleteFileAct, "_deleteFile", this, this, SLOT(deleteFileSlot()), QKeySequence::Delete);

    moveToAct = new QAction(tr("Move to..."), this);
    moveToAct->setEnabled(false);
    actionsManager->addAction(moveToAct, "_moveTo", this, this, SLOT(moveToSlot()));

    goToAct = new QAction(tr("Go to"), this);
    goToAct->setEnabled(false);
    actionsManager->addAction(goToAct, "_goTo", this, this, SLOT(goToSlot()), QKeySequence("Ctrl+J"));

    configureToolBarAct = new QAction(tr("Configure toolbar"), this);
    actionsManager->addAction(configureToolBarAct, "_configureToolBar", this, this, SLOT(configureToolBarSlot()));

    //set the icons, becouse QIcon::name() was included in Qt4.7
    actionsManager->setActionIcon("_about", "help-about");
    actionsManager->setActionIcon("_adjustSize", "zoom-fit-best");
    actionsManager->setActionIcon("_configuration", "configure");
    actionsManager->setActionIcon("_deleteFile", "edit-delete");
    actionsManager->setActionIcon("_exit", "application-exit");
    actionsManager->setActionIcon("_fileProperties", "document-properties");
    actionsManager->setActionIcon("_flipHorizontally", "object-flip-horizontal");
    actionsManager->setActionIcon("_flipVertically", "object-flip-vertical");
    actionsManager->setActionIcon("_goFirst", "go-first");
    actionsManager->setActionIcon("_goLast", "go-last");
    actionsManager->setActionIcon("_goTo", "go-jump");
    actionsManager->setActionIcon("_moveTo", "none");
    actionsManager->setActionIcon("_next", "go-next");
    actionsManager->setActionIcon("_normalSize", "zoom-original");
    actionsManager->setActionIcon("_open", "document-open");
    actionsManager->setActionIcon("_openFolder", "folder-open");
    actionsManager->setActionIcon("_previous", "go-previous");
    actionsManager->setActionIcon("_print", "document-print");
    actionsManager->setActionIcon("_rotateLeft", "object-rotate-left");
    actionsManager->setActionIcon("_rotateRight", "object-rotate-right");
    actionsManager->setActionIcon("_save", "document-save");
    actionsManager->setActionIcon("_showMenuBar", "show-menu");
    actionsManager->setActionIcon("_showToolBar", "configure-toolbars");
    actionsManager->setActionIcon("_tbMovable", "configure-toolbars");
    actionsManager->setActionIcon("_configureToolBar", "configure-toolbars");
    actionsManager->setActionIcon("_zoomIn", "zoom-in");
    actionsManager->setActionIcon("_zoomOut", "zoom-out");
}
Ejemplo n.º 25
0
void mp3Controls() //Controls
{
	oslReadKeys();	
	
	if (pad.Buttons != oldpad.Buttons) 
	{
		if (osl_keys->pressed.down) 
		{
			mp3Down();
			timer = 0;
		}
		else if (osl_keys->pressed.up) 
		{
			mp3Up();
			timer = 0;
		}
	
		if (osl_keys->pressed.right) 
		{
			mp3Downx5();
			timer = 0;
		}
		else if (osl_keys->pressed.left) 
		{
			mp3Upx5();
			timer = 0;
		}
	
		if (osl_keys->pressed.triangle) 
		{
			curScroll = 1;
			current = 1;
		}
	
		if (osl_keys->pressed.cross) 
		{
			oslPlaySound(KeypressStandard, 1); 
			openDir(folderIcons[current].filePath, folderIcons[current].fileType);
		}
	}
	
	volumeController();
	
	char * ext = strrchr(folderIcons[current].filePath, '.'); 
	
	if (osl_keys->pressed.circle)
	{			
		if((strcmp("ms0:/MUSIC", curDir)==0) || (strcmp("ms0:/PSP/MUSIC", curDir)==0) || (strcmp("ms0:/PSP/GAME/CyanogenPSP/downloads", curDir)==0) || (strcmp("ms0:/", curDir)==0))
		{
			oslDeleteImage(mp3bg);
			oslDeleteImage(mp3_select);
			mp3player();
		}
		else if((strcmp("ms0:/MUSIC", curDir)!=0)) 
		{
			dirBack(3);
		}
		else if((strcmp("ms0:/PSP/MUSIC", curDir)!=0))
		{
			dirBack(4);
		}	
		else if((strcmp("ms0:/PSP/GAME/CyanogenPSP/downloads", curDir)!=0))
		{
			dirBack(5);
		}	
	}
	
	if (((ext) != NULL) && ((strcmp(ext ,".mp3") == 0) || ((strcmp(ext ,".MP3") == 0))) && (osl_keys->pressed.cross))
	{
		if (isPlaying == 1)
		{
			endAudioLib();
			MP3ME_Stop();
			releaseAudio();
			MP3Play(folderIcons[current].filePath);
		}
		else 
		{
			oslPlaySound(KeypressStandard, 1); 
			MP3Play(folderIcons[current].filePath);
		}
	}
	
	if (osl_keys->pressed.square)
	{
		powermenu();
	}
		
	if (osl_keys->pressed.L)
	{
		oslPlaySound(Lock, 1);  
		lockscreen();
    }
	
	captureScreenshot();
	
	timer++;
	if ((timer > 30) && (pad.Buttons & PSP_CTRL_UP))
	{
		mp3Up();
		timer = 25;
	}
	else if ((timer > 30) && (pad.Buttons & PSP_CTRL_DOWN))
	{
		mp3Down();
		timer = 25;
	}

	if (current < 1) 
		current = 1;
	if (current > MAX_FILES) 
		current = MAX_FILES;

}
Ejemplo n.º 26
0
AUD_Int32s perf_dtw_mfcc()
{
	char            inputPath[256]   = { 0, };
	char            keywordPath[256] = { 0, };
	AUD_Double      threshold, minThreshold, maxThreshold, stepThreshold;
	AUD_Bool        isRecognized     = AUD_FALSE;
	AUD_Int32s      data;

	AUD_Error       error = AUD_ERROR_NONE;

	setbuf( stdin, NULL );
	AUDLOG( "pls give keyword wav stream's path:\n" );
	keywordPath[0] = '\0';
	data = scanf( "%s", keywordPath );
	AUDLOG( "keyword path is: %s\n", keywordPath );

	setbuf( stdin, NULL );
	AUDLOG( "pls give test wav stream's path:\n" );
	inputPath[0] = '\0';
	data = scanf( "%s", inputPath );
	AUDLOG( "test stream path is: %s\n", inputPath );

	setbuf( stdin, NULL );
	AUDLOG( "pls give min test threshold:\n" );
	data = scanf( "%lf", &minThreshold );
	AUDLOG( "min threshold is: %.2f\n", minThreshold );

	setbuf( stdin, NULL );
	AUDLOG( "pls give max test threshold:\n" );
	data = scanf( "%lf", &maxThreshold );
	AUDLOG( "max threshold is: %.2f\n", maxThreshold );

	setbuf( stdin, NULL );
	AUDLOG( "pls give test threshold step:\n" );
	data = scanf( "%lf", &stepThreshold );
	AUDLOG( "threshold step is: %.2f\n", stepThreshold );

	AUDLOG( "\n\n" );

	// file & directory operation, linux dependent
	entry   *pEntry        = NULL;
	dir     *pDir          = NULL;
	entry   *pKeywordEntry = NULL;
	dir     *pKeywordDir   = NULL;

	AUD_Feature     keywordFeature;
	AUD_Int32s      keywordSampleNum = 0;
	AUD_Int32s      keywordWinNum    = 0;
	AUD_Int8s       keywordFile[256] = { 0, };
	AUD_Int8s       keywordName[256] = { 0, };
	AUD_Int32s      keywordID        = 0;

	AUD_DTWSession  dtwSession;
	AUD_Double      score            = 0.;
	AUD_Int32s      sampleNum;

	AUD_Int32s      keywordBufLen = 0;
	AUD_Int16s      *pKeywordBuf  = NULL;
	AUD_Int32s      bufLen        = 0;
	AUD_Int16s      *pBuf         = NULL;

	AUD_Int32s      frameStride   = FRAME_STRIDE;

	AUD_Int32s      j;
	AUD_Int32s      ret;

	// init performance benchmark
	void *hBenchmark  = NULL;
	char logName[256] = { 0, };
	snprintf( logName, 256, "dtw-mfcc-%d-%d-%d-%d", WOV_DTW_TYPE, WOV_DISTANCE_METRIC, WOV_DTWTRANSITION_STYLE, WOV_DTWSCORING_METHOD );
	ret = benchmark_init( &hBenchmark, (AUD_Int8s*)logName, keywords, sizeof(keywords) / sizeof(keywords[0]) );
	AUD_ASSERT( ret == 0 );


	for ( threshold = minThreshold; threshold < maxThreshold + stepThreshold; threshold += stepThreshold )
	{
		ret = benchmark_newthreshold( hBenchmark, threshold );
		AUD_ASSERT( ret == 0 );

		AUDLOG( "***********************************************\n" );
		AUDLOG( "keyword training start...\n" );

		pKeywordDir = openDir( (const char*)keywordPath );
		keywordID  = 0;
		while ( ( pKeywordEntry = scanDir( pKeywordDir ) ) )
		{
			// train keyword
			keywordBufLen  = SAMPLE_RATE * BYTES_PER_SAMPLE * 10;
			pKeywordBuf = (AUD_Int16s*)calloc( keywordBufLen, 1 );
			AUD_ASSERT( pKeywordBuf );

			snprintf( (char*)keywordFile, 256, "%s/%s", (const char*)keywordPath, pKeywordEntry->name );

			keywordSampleNum = readWavFromFile( keywordFile, pKeywordBuf, keywordBufLen );
			if ( keywordSampleNum < 0 )
			{
				continue;
			}

			// front end processing
			 // pre-emphasis
			sig_preemphasis( pKeywordBuf, pKeywordBuf, keywordSampleNum );

			for ( j = 0; j * frameStride + FRAME_LEN <= keywordSampleNum; j++ )
			{
				;
			}
			AUDLOG( "pattern[%d: %s] valid frame number[%d]\n", keywordID, keywordFile, j );

			keywordWinNum                         = j;
			keywordFeature.featureMatrix.rows     = keywordWinNum - MFCC_DELAY;
			keywordFeature.featureMatrix.cols     = MFCC_FEATDIM;
			keywordFeature.featureMatrix.dataType = AUD_DATATYPE_INT32S;
			ret = createMatrix( &(keywordFeature.featureMatrix) );
			AUD_ASSERT( ret == 0 );

			keywordFeature.featureNorm.len      = keywordWinNum - MFCC_DELAY;
			keywordFeature.featureNorm.dataType = AUD_DATATYPE_INT64S;
			ret = createVector( &(keywordFeature.featureNorm) );
			AUD_ASSERT( ret == 0 );

			void *hKeywordMfccHandle = NULL;

			// init mfcc handle
			error = mfcc16s32s_init( &hKeywordMfccHandle, FRAME_LEN, WINDOW_TYPE, MFCC_ORDER, frameStride, SAMPLE_RATE, COMPRESS_TYPE );
			AUD_ASSERT( error == AUD_ERROR_NONE );

			// calc MFCC feature
			error = mfcc16s32s_calc( hKeywordMfccHandle, pKeywordBuf, keywordSampleNum, &keywordFeature );
			AUD_ASSERT( error == AUD_ERROR_NONE );

			// deinit mfcc handle
			error = mfcc16s32s_deinit( &hKeywordMfccHandle );
			AUD_ASSERT( error == AUD_ERROR_NONE );

			strncpy( (char*)keywordName, pKeywordEntry->name, 255 );
			ret = benchmark_newtemplate( hBenchmark, keywordName );
			AUD_ASSERT( ret == 0 );

			keywordID++;

			keywordBufLen  = 0;
			free( pKeywordBuf );
			pKeywordBuf    = NULL;

			AUDLOG( "keyword training finish...\n" );

			// recognize
			pEntry = NULL;
			pDir   = NULL;
			pDir   = openDir( (const char*)inputPath );
			
#if PERF_PROFILE
			AUD_Tick t;
#endif
			while ( ( pEntry = scanDir( pDir ) ) )
			{
				AUD_Int8s   inputStream[256] = { 0, };
				void        *hMfccHandle     = NULL;
				AUD_Summary fileSummary;

				snprintf( (char*)inputStream, 256, "%s/%s", (const char*)inputPath, pEntry->name );

				ret = parseWavFromFile( inputStream, &fileSummary );
				if ( ret < 0 )
				{
					continue;
				}

				AUD_ASSERT( fileSummary.channelNum == CHANNEL_NUM && fileSummary.bytesPerSample == BYTES_PER_SAMPLE && fileSummary.sampleRate == SAMPLE_RATE );
				AUDLOG( "input stream: %s\n", inputStream );

				bufLen = fileSummary.dataChunkBytes;
				pBuf   = (AUD_Int16s*)calloc( bufLen + 100, 1 );
				AUD_ASSERT( pBuf );

#if PERF_PROFILE
				t = -time_gettick();
#endif
				sampleNum = readWavFromFile( inputStream, pBuf, bufLen );
				AUD_ASSERT( sampleNum > 0 );
#if PERF_PROFILE
				t += time_gettick();
				AUDLOG( "PERF: read wav files takes %.2f ms\n", t / 1000. );
#endif

				// front end processing
				 // pre-emphasis
#if PERF_PROFILE
				t = -time_gettick();
#endif
				sig_preemphasis( pBuf, pBuf, sampleNum );
#if PERF_PROFILE
				t += time_gettick();
				AUDLOG( "PERF: pre-emphasis takes %.2f ms\n", t / 1000. );
#endif

				for ( j = 0; j * frameStride + FRAME_LEN <= sampleNum; j++ )
				{
					;
				}

#if PERF_PROFILE
				t = -time_gettick();
#endif
				AUD_Feature inFeature;
				inFeature.featureMatrix.rows     = j - MFCC_DELAY;
				inFeature.featureMatrix.cols     = MFCC_FEATDIM;
				inFeature.featureMatrix.dataType = AUD_DATATYPE_INT32S;
				ret = createMatrix( &(inFeature.featureMatrix) );
				AUD_ASSERT( ret == 0 );
#if PERF_PROFILE
				t += time_gettick();
				AUDLOG( "PERF: create feature matrix takes %.2f ms\n", t / 1000. );
#endif


#if PERF_PROFILE
				t = -time_gettick();
#endif
				inFeature.featureNorm.len      = j - MFCC_DELAY;
				inFeature.featureNorm.dataType = AUD_DATATYPE_INT64S;
				ret = createVector( &(inFeature.featureNorm) );
				AUD_ASSERT( ret == 0 );
#if PERF_PROFILE
				t += time_gettick();
				AUDLOG( "PERF: create feature norm takes %.2f ms\n", t / 1000. );
#endif


				// init mfcc handle
#if PERF_PROFILE
				t = -time_gettick();
#endif
				error = mfcc16s32s_init( &hMfccHandle, FRAME_LEN, WINDOW_TYPE, MFCC_ORDER, frameStride, SAMPLE_RATE, COMPRESS_TYPE );
				AUD_ASSERT( error == AUD_ERROR_NONE );
#if PERF_PROFILE
				t += time_gettick();
				AUDLOG( "PERF: mfcc init takes %.2f ms\n", t / 1000. );
#endif

#if PERF_PROFILE
				t = -time_gettick();
#endif
				error = mfcc16s32s_calc( hMfccHandle, pBuf, sampleNum, &inFeature );
				AUD_ASSERT( error == AUD_ERROR_NONE );
#if PERF_PROFILE
				t += time_gettick();
				AUDLOG( "PERF: mfcc calc takes %.2f ms\n", t / 1000. );
#endif

				// init dtw match
				dtwSession.dtwType        = WOV_DTW_TYPE;
				dtwSession.distType       = WOV_DISTANCE_METRIC;
				dtwSession.transitionType = WOV_DTWTRANSITION_STYLE;
				error = dtw_initsession( &dtwSession, &keywordFeature, inFeature.featureMatrix.rows );
				AUD_ASSERT( error == AUD_ERROR_NONE );

#if PERF_PROFILE
				t = -time_gettick();
#endif
				error = dtw_updatefrmcost( &dtwSession, &inFeature );
				AUD_ASSERT( error == AUD_ERROR_NONE );
#if PERF_PROFILE
				t += time_gettick();
				AUDLOG( "PERF: dtw update frame cost takes %.2f ms\n", t / 1000. );
#endif


#if PERF_PROFILE
				t = -time_gettick();
#endif
				error = dtw_match( &dtwSession, WOV_DTWSCORING_METHOD, &score, NULL );
				AUD_ASSERT( error == AUD_ERROR_NONE );
#if PERF_PROFILE
				t += time_gettick();
				AUDLOG( "PERF: dtw match takes %.2f ms\n", t / 1000. );
#endif

				error = dtw_deinitsession( &dtwSession );
				AUD_ASSERT( error == AUD_ERROR_NONE );

				// deinit mfcc handle
				error = mfcc16s32s_deinit( &hMfccHandle );
				AUD_ASSERT( error == AUD_ERROR_NONE );

				ret = destroyMatrix( &(inFeature.featureMatrix) );
				AUD_ASSERT( ret == 0 );

				ret = destroyVector( &(inFeature.featureNorm) );
				AUD_ASSERT( ret == 0 );

				isRecognized = AUD_FALSE;
				if ( score <= threshold )
				{
					isRecognized = AUD_TRUE;
				}

				AUDLOG( "score: %.2f\n", score );

				// insert log entry
				ret = benchmark_additem( hBenchmark, (AUD_Int8s*)pEntry->name, score, isRecognized );
				AUD_ASSERT( ret == 0 );

				bufLen  = 0;
				free( pBuf );
				pBuf = NULL;
			}
			closeDir( pDir );
			pDir = NULL;

			ret = benchmark_finalizetemplate( hBenchmark );
			AUD_ASSERT( ret == 0 );

			ret = destroyMatrix( &(keywordFeature.featureMatrix) );
			AUD_ASSERT( ret == 0 );

			ret = destroyVector( &(keywordFeature.featureNorm) );
			AUD_ASSERT( ret == 0 );
		}
		closeDir( pKeywordDir );
		pKeywordDir = NULL;

		ret = benchmark_finalizethreshold( hBenchmark );
		AUD_ASSERT( ret == 0 );
	}

	ret = benchmark_free( &hBenchmark );
	AUD_ASSERT( ret == 0 );

	AUDLOG( "DTW-MFCC Benchmark finished\n" );

	return 0;
}
Ejemplo n.º 27
0
void TestB()
{
	char tty_name[] = "/dev_tty1";

	int fd_stdin  = open(tty_name, O_RDWR);
	assert(fd_stdin  == 0);
	int fd_stdout = open(tty_name, O_RDWR);
	assert(fd_stdout == 1);

	char rdbuf[128];
	char cmd[8];
	char filename[120];
	char buf[1024];
	int m,n;

	initFSTree();


	printf("                        ==================================\n");
	printf("                                    File Manager           \n");
	printf("                                 Kernel on Orange's \n\n");
	printf("                        ==================================\n");
	while (1) {
		printPath();
		printf("$ :");
		int r = read(fd_stdin, rdbuf, 70);
		rdbuf[r] = 0;

		if (strcmp(rdbuf, "i") == 0)
		{
			char treeInfo[2048] = {0};
			getTreeInfo(treeInfo);
			printf("%s\n", treeInfo);
		}
		else if(strcmp(rdbuf, "s") == 0)
		{
			showTree();
		}
		else if(strcmp(rdbuf, "p") == 0)
		{
			printPath();
			printf("\n");
		}
		else if (strcmp(rdbuf, "help") == 0)
		{
			printf("=============================================================================\n");
			printf("Command List     :\n");
			printf("1. create [filename]       : Create a new file \n");
			printf("2. read [filename]         : Read the file\n");
			printf("3. write [filename]        : Write at the end of the file\n");
			printf("4. delete [filename]       : Delete the file\n");
			printf("5. help                    : Display the help message\n");
			printf("==============================================================================\n");		
		}
		else if (strcmp(rdbuf, "dir") == 0)
		{
			printCurrFile();
			continue;
		}
		else
		{
			int fd;
			int i = 0;
			int j = 0;
			char temp = -1;
			while(rdbuf[i]!=' ' && rdbuf[i] != 0)
			{
				cmd[i] = rdbuf[i];
				i++;
			}
			cmd[i++] = 0;
			while(rdbuf[i] != 0)
			{
				filename[j] = rdbuf[i];
				i++;
				j++;
			}
			filename[j] = 0;

			if(strcmp(cmd, "mkdir") == 0)
			{
				createDir(filename);

				saveTreeToDsik();
				// //write TreeRecord
				// char treeInfo[2048]={0};
				// getTreeInfo(treeInfo);
				// printf("%s\n", treeInfo);

				// fd = open("TreeRecord", O_RDWR);
				// if (fd == -1)
				// {
				// 	printf("Failed to open 'TreeRecord'!\n");
				// 	continue ;
				// }
				// strcpy(buf,treeInfo);
				// printf("buf :%s\n", buf);

				// n = write(fd, buf, 1024);
				// close(fd);

			}
			else if(strcmp(cmd, "cd") == 0)
			{
				//open dir
				if(strcmp(filename, "..") == 0)
				{
					backDir();
				}
				else
				{
					openDir(filename);
				}
			}
			else if(strcmp(cmd,"rmdir") == 0)
			{
				//delete dir
				if(isThereFile(filename) == 0)
				{
					printf("fail to remove dir, not here!\n");
					continue;
				}
				deleteDirRecord(filename);

				saveTreeToDsik();
				// //write TreeRecord
				// char treeInfo[2048]={0};
				// getTreeInfo(treeInfo);
				// printf("%s\n", treeInfo);

				// fd = open("TreeRecord", O_RDWR);
				// if (fd == -1)
				// {
				// 	printf("Failed to open 'TreeRecord'!\n");
				// 	continue ;
				// }
				// strcpy(buf,treeInfo);
				// printf("buf :%s\n", buf);

				// n = write(fd, buf, 1024);
				// close(fd);
			}
			else if (strcmp(cmd, "create") == 0)
			{
				fd = open(filename, O_CREAT | O_RDWR);
				if (fd == -1)
				{
					printf("Failed to create file! Please check the fileaname!\n");
					continue ;
				}
				buf[0] = 0;
				write(fd, buf, 1);
				printf("File created: %s (fd %d)\n", filename, fd);
				close(fd);

				//add to tree currFatherDir
				fTreeArray[treeCurrSize].currDir = treeCurrSize;
				fTreeArray[treeCurrSize].fatherDir = currFatherDir;
				fTreeArray[treeCurrSize].isDir = 0;  //not a dir
				strcpy(fTreeArray[treeCurrSize].fileName, filename);
				treeCurrSize++;
				treeCount++;

				// showTree();

				// char* treeInfo;
				// treeInfo = getTreeInfo();
				// printf("%d\n", treeCurrSize);

				saveTreeToDsik();
				// //write TreeRecord
				// char treeInfo[2048]={0};
				// getTreeInfo(treeInfo);
				// printf("%s\n", treeInfo);

				// fd = open("TreeRecord", O_RDWR);
				// if (fd == -1)
				// {
				// 	printf("Failed to open 'TreeRecord'!\n");
				// 	continue ;
				// }
				// strcpy(buf,treeInfo);
				// printf("buf :%s\n", buf);

				// n = write(fd, buf, 1024);
				// close(fd);

			}
			else if (strcmp(cmd, "read") == 0)
			{
				if(isThereFile(filename) == 0)
				{
					printf("fail to read file, not here!\n");
					continue;
				}
				fd = open(filename, O_RDWR);
				if (fd == -1)
				{
					printf("Failed to open file! Please check the fileaname!\n");
					continue ;
				}
				
				n = read(fd, buf, 1024);
				
				printf("%s\n", buf);
				close(fd);

			}
			else if (strcmp(cmd, "write") == 0)
			{
				// if(isThereFile(filename) == 0)
				// {
				// 	printf("fail to write file, not here!\n");
				// 	continue;
				// }
				fd = open(filename, O_RDWR);
				if (fd == -1)
				{
					printf("Failed to open file! Please check the fileaname!\n");
					continue ;
				}

				m = read(fd_stdin, rdbuf,80);
				rdbuf[m] = 0;
				
				n = write(fd, rdbuf, m+1);
				close(fd);


			}
			else if (strcmp(cmd, "delete") == 0)
			{
				if(isThereFile(filename) == 0)
				{
					printf("fail to delete file, not here!\n");
					continue;
				}

				m=unlink(filename);
				if (m == 0)
				{
					printf("File deleted!\n");

					//delete file from tree records, not a dir
					int i = 0;
					for (; i < treeCurrSize; ++i)
					{
						if(strcmp(fTreeArray[i].fileName,filename) == 0)
						{
							fTreeArray[i].currDir = -1;
							continue;
						}
					}
					treeCount--;
					// showTree();

					saveTreeToDsik();
					// //write TreeRecord
					// char treeInfo[2048]={0};
					// getTreeInfo(treeInfo);
					// printf("%s\n", treeInfo);

					// fd = open("TreeRecord", O_RDWR);
					// if (fd == -1)
					// {
					// 	printf("Failed to open 'TreeRecord'!\n");
					// 	continue ;
					// }
					// strcpy(buf,treeInfo);
					// printf("buf :%s\n", buf);

					// n = write(fd, buf, 1024);
					// close(fd);

					continue;
				}
				else
				{
					printf("Failed to delete file! Please check the fileaname!\n");
					continue;
				}

			}
			else 
			{
				printf("Command not found, Please check!\n");
				continue;
			}

			
			
		}
		
			
	}

	assert(0); /* never arrive here */
}
Ejemplo n.º 28
0
Window::Window(int argc, char *argv[]) :
    QMainWindow(NULL),
    ui(new Ui::Window)
{
    ui->setupUi(this);

	// Cache size
	cacheSize = 50;
	cachePos  = 0;

	prefs = new Preferences(this);
    about = new AboutDialog(this);

    connect(prefs, SIGNAL(finished(int)), this, SLOT(updatePrefs()));

    initSlider(ui->xSlider);
    initSlider(ui->ySlider);
    initSlider(ui->zSlider);
    initSpanSlider(ui->xSpanSlider);
    initSpanSlider(ui->ySpanSlider);
    initSpanSlider(ui->zSpanSlider);

	// Rotation
    connect(ui->xSlider,  SIGNAL(valueChanged(int)),     ui->viewport, SLOT(setXRotation(int)));
    connect(ui->viewport, SIGNAL(xRotationChanged(int)), ui->xSlider, SLOT(setValue(int)));
    connect(ui->ySlider,  SIGNAL(valueChanged(int)),     ui->viewport, SLOT(setYRotation(int)));
    connect(ui->viewport, SIGNAL(yRotationChanged(int)), ui->ySlider, SLOT(setValue(int)));
    connect(ui->zSlider,  SIGNAL(valueChanged(int)),     ui->viewport, SLOT(setZRotation(int)));
    connect(ui->viewport, SIGNAL(zRotationChanged(int)), ui->zSlider, SLOT(setValue(int)));

	// Slicing
    connect(ui->xSpanSlider, SIGNAL(lowerValueChanged(int)), ui->viewport, SLOT(setXSliceLow(int)));
    connect(ui->xSpanSlider, SIGNAL(upperValueChanged(int)), ui->viewport, SLOT(setXSliceHigh(int)));
    connect(ui->ySpanSlider, SIGNAL(lowerValueChanged(int)), ui->viewport, SLOT(setYSliceLow(int)));
    connect(ui->ySpanSlider, SIGNAL(upperValueChanged(int)), ui->viewport, SLOT(setYSliceHigh(int)));
    connect(ui->zSpanSlider, SIGNAL(lowerValueChanged(int)), ui->viewport, SLOT(setZSliceLow(int)));
    connect(ui->zSpanSlider, SIGNAL(upperValueChanged(int)), ui->viewport, SLOT(setZSliceHigh(int)));

    ui->animSlider->setRange(0, 10);
    ui->animSlider->setSingleStep(1);
    ui->animSlider->setPageStep(10);
    ui->animSlider->setTickInterval(2);
    ui->animSlider->setTickPosition(QSlider::TicksRight);
    ui->animSlider->setEnabled(false);

    // Actions
    connect(ui->actionAbout, SIGNAL(triggered()), this, SLOT(openAbout()));
    connect(ui->actionPreferences, SIGNAL(triggered()), this, SLOT(openSettings()));
    connect(ui->actionFiles, SIGNAL(triggered()), this, SLOT(openFiles()));
    connect(ui->actionDir, SIGNAL(triggered()), this, SLOT(openDir()));

    connect(ui->actionCubes,   SIGNAL(triggered()), this, SLOT(toggleDisplay()));
    connect(ui->actionCones,   SIGNAL(triggered()), this, SLOT(toggleDisplay()));
    connect(ui->actionVectors, SIGNAL(triggered()), this, SLOT(toggleDisplay()));

    displayType = new QActionGroup(this);
    displayType->addAction(ui->actionCubes);
    displayType->addAction(ui->actionCones);
    displayType->addAction(ui->actionVectors);
    ui->actionCubes->setChecked(true);

    signalMapper = new QSignalMapper(this);
    signalMapper->setMapping (ui->actionFollow, "") ;
    connect (signalMapper, SIGNAL(mapped(QString)), this, SLOT(watchDir(QString))) ;
    connect(ui->actionFollow, SIGNAL(triggered()), signalMapper, SLOT(map()));

    ui->xSlider->setValue(15 * 16);
    ui->ySlider->setValue(345 * 16);
    ui->zSlider->setValue(0 * 16);
	setWindowTitle(tr("MuView 0.9"));

	// Data, don't connect until we are ready (probably still not ready here)...
    connect(ui->animSlider, SIGNAL(valueChanged(int)), this, SLOT(updateDisplayData(int)));
	
	// Load files from command line if supplied
	if (argc > 1) {
		QStringList rawList;
		for (int i=1; i<argc; i++) {
			rawList << argv[i];
		}

		if (rawList.contains(QString("-w"))) {
			if (rawList.indexOf("-w") < (rawList.length() - 1))  {
				watchDir(rawList[rawList.indexOf("-w")+1]);
			}
		} else {
			QStringList allLoadedFiles;
			foreach (QString item, rawList)
			{
				QFileInfo info(item);
				if (!info.exists()) {
					std::cout << "File " << item.toStdString() << " does not exist" << std::endl;
				} else {
								// Push our new content...
					if (info.isDir()) {
						QDir chosenDir(item);
						dirString = chosenDir.path()+"/";
						QStringList filters;
						filters << "*.omf" << "*.ovf";
						chosenDir.setNameFilters(filters);
						QStringList files = chosenDir.entryList();

						foreach (QString file, files)
						{
							filenames << (dirString+file);
							displayNames << (dirString+item);
							//omfCache.push_back(readOMF((dirString+file).toStdString(), tempHeader));
						}

					} else {