예제 #1
0
int main(void)
{
   /*建立audio矩陣來存放要用的檔案*/
   Audio audio[5];
   
   /* 讀入5個音效檔 */ 
   openAudioFile("DR220A_CH.wav", &audio[0]);
   openAudioFile("DR220A_SD.wav", &audio[1]);
   openAudioFile("DR220A_HT.wav", &audio[2]);
   openAudioFile("DR220A_CCY.wav", &audio[3]);
   openAudioFile("DR220A_BD.wav", &audio[4]);

                  /* 播放對應的音效 */ 
                  playAudio(&audio[0]);
                  Sleep(1000);            
                  /* 播放對應的音效 */ 
                  playAudio(&audio[1]);
                  Sleep(1000);
                  /* 播放對應的音效 */ 
                  playAudio(&audio[2]);
                  Sleep(1000);
                  /* 播放對應的音效 */ 
                  playAudio(&audio[3]);
                  Sleep(1000);
                  /* 播放對應的音效 */ 
                  playAudio(&audio[4]);
                  Sleep(1000);
      
}
예제 #2
0
void AudioLoader::reset() {
    Algorithm::reset();

    if (!parameter("filename").isConfigured()) return;

    string filename = parameter("filename").toString();

    closeAudioFile();
    openAudioFile(filename);

    pushChannelsSampleRateInfo(_audioCtx->channels, _audioCtx->sample_rate);
}
void ofApp::beginRenderMode(){
    cout<<"render mode"<<endl;

    setResolution(render_width, render_height);

    //set minimal lag of audio behind video
    vwt->setAudioDelay(1./frame_rate_limit + 1./audio_sample_rate);

    //open a new wav file and write header
    stringstream file_name;
    cur_save_dir = ofDirectory(ofGetTimestampString());
    cur_save_dir.create();
    file_name << cur_save_dir.path()<<ofToDataPath("/audio.wav");

    openAudioFile(file_name.str());
}
예제 #4
0
void Transcribe::restoreHistory(int index) {
  saveHistory(); // Save the history to remember the audio position befor we
                 // load a new file

  QModelIndex model_index = m_history.index(index, 0);
  m_restore_pos = model_index.data(HistoryModel::AudioPostionRole).toUInt();
  QString audio_file_path = model_index.data(HistoryModel::AudioFileRole).toString();
  QString text_file_path  = model_index.data(HistoryModel::TextFileRole).toString();
  openAudioFile(audio_file_path);
  openTextFile(text_file_path);

  // Same as with pickFiles():
  // saveHistory() is called when the audio file has finished loading, but we
  // need do it here as well because openTextFile() might return after the audio
  // file has finished loading. The joys of concurrency ...
  saveHistory();
}
예제 #5
0
void Transcribe::pickFiles() {
  QFileDialog dlg;

  // Unfortunately, Android doesn't really work with the concept of files,
  // they are abstracted away. Since it would require a major effort to make
  // this work in the Android way, we'll just try to make the best of it.
#ifdef Q_OS_ANDROID
    // First see if we have storage permissions. We fail here if we don't have
    // them and let the callback to the request popup call this method again.
    if (!StoragePerm::instance()->tryPermission(std::bind(&Transcribe::pickFiles, this))) return;

    // Make the QFileDialog a bit better by maximizing it.
    dlg.setWindowState(Qt::WindowMaximized);
    dlg.setViewMode(QFileDialog::List);

    // Add the root and the internal memory location to the paths to choose
    // from. There are no real standard paths for this, let's hope Qt knows
    // what to do.
    QUrl home_url = QUrl::fromLocalFile(QStandardPaths::standardLocations(QStandardPaths::GenericDataLocation).first());
    dlg.setDirectoryUrl(home_url);
    QList<QUrl> urls;
    urls << QUrl::fromLocalFile("/");
    urls << home_url;
    dlg.setSidebarUrls(urls);
#endif

  // Let the user pick an audio file
  dlg.setWindowTitle(tr("Open an audio file"));
  dlg.setNameFilter(tr("Audio files (*.wav *.mp3 *.aac *.amr *.aiff *.flac *.ogg *.wma, *.opus)"));
  dlg.setFileMode(QFileDialog::ExistingFile);
  dlg.setAcceptMode(QFileDialog::AcceptOpen);
  if (dlg.exec() == QDialog::Rejected || dlg.selectedFiles().count() != 1) {
    return;
  }

  m_restore_pos = 0;
  openAudioFile(dlg.selectedFiles().at(0));

#ifdef Q_OS_ANDROID
  QString audio_path = dlg.selectedFiles().at(0);
  QString text_path;

  // Check if the audio file is in our history
  if (!m_history.textFileForAudio(audio_path, text_path)) {
    // If not, create a new file in the app private folder based on the audio
    // file name. If a text file with the name already exists, append a number
    // to it.
    QString base_name = QFileInfo(audio_path).baseName();
    QDir home = QDir(QStandardPaths::writableLocation((QStandardPaths::AppDataLocation)));
    text_path = home.filePath(base_name + ".txt");
    short counter = 1;
    while (QFile::exists(text_path)) {
      text_path = home.filePath(QString("%1_%2.txt").arg(base_name).arg(counter, 2, 10, QChar('0')));
      counter++;
    }
  }

  openTextFile(text_path);
#else
  // Recycle the file dialog to let the user pick a text file for the
  // transcript. As a file suggestion, we base a txt file on the current audio
  // file.
  dlg.setWindowTitle(tr("Pick a text file for the transcript"));
  dlg.setNameFilter(tr("Text files (*.txt)"));
  dlg.setFileMode(QFileDialog::AnyFile);
  dlg.setAcceptMode(QFileDialog::AcceptSave);
  dlg.setOption(QFileDialog::DontConfirmOverwrite, true);
  dlg.setLabelText(QFileDialog::Accept, tr("Open/Create"));
  QFileInfo info(dlg.selectedFiles().at(0));
  dlg.setDirectory(info.absolutePath());
  dlg.selectFile(info.baseName() + ".txt");
  if (dlg.exec() == QDialog::Rejected || dlg.selectedFiles().count() != 1) {
    return;
  }

  openTextFile(dlg.selectedFiles().at(0));
#endif

  // saveHistory() is called when the audio file has finished loading, but we
  // need do it here as well because openTextFile() might return after the audio
  // file has finished loading. The joys of concurrency ...
  saveHistory();
}
예제 #6
0
파일: rmp3.c 프로젝트: rojekabc/okienkoc
int doAction(unsigned int action, const void *param)
{
	GOC_BDEBUG("Call action %d", action);
	int old;
	switch ( action )
	{
		case ACTION_AUMIX_PLUS: // Increase volume
			mixerChangeVolume(mixer, 1, NULL);
			break;
		case ACTION_AUMIX_MINUS: // Decrease volume
			mixerChangeVolume(mixer, -1, NULL);
			break;
		case ACTION_AUMIX_NEXTDEV:
			next_aumix_port();
			break;
		case ACTION_AUMIX_PREVDEV:
			break;
		case ACTION_AUMIX_CURRDEV: {
			MixerElement* active = NULL;
			mixerGetSelectedElement(mixer, &active);
			*(int*)param = (int)active->volume;
			break;
		}
		case ACTION_AUMIX_CURRNAME: {
			MixerElement* active = NULL;
			mixerGetSelectedElement(mixer, &active);
			*(char**)param = active->name;
			break;
		}
		case ACTION_NEXT:
			old = mode;
			// zatrzymaj granie
			if ( mode == MODE_PLAY )
			{
				mode = MODE_STOP;
				pthread_mutex_lock(&mutexPlay);
			}
			// zmieñ piosenkê
			TRY_OPEN( playlistNext );
			mode = old;
			if ( filename )
			{
				// pu¶æ granie dalej
				if ( mode == MODE_PLAY )
					pthread_mutex_unlock(&mutexPlay);
			}
			else
				mode = MODE_STOP;
			return 0;
		case ACTION_PREV:
			old = mode;
			// zatrzymaj granie
			if ( mode == MODE_PLAY )
			{
				mode = MODE_NEXT;
				pthread_mutex_lock(&mutexPlay);
			}
			// zmieñ piosenkê
			TRY_OPEN( playlistPrev );
			mode = old;
			if ( filename )
			{
				// pu¶æ granie dalej
				if ( mode == MODE_PLAY )
					pthread_mutex_unlock(&mutexPlay);
			}
			else
				mode = MODE_STOP;
			return 0;
		case ACTION_PAUSE:
			if ( mode == MODE_PLAY )
			{
				// zatrzymaj granie
				mode = MODE_PAUSE;
				pthread_mutex_lock(&mutexPlay);
			}
			else
			{
				// je¶li wcze¶niej nie wybrano piosenki, wybierz
				if ( filename == NULL )
					TRY_OPEN( playlistNext );
				if ( filename )
				{
					// pu¶æ granie dalej
					mode = MODE_PLAY;
					pthread_mutex_unlock(&mutexPlay);
				}
			}
			return 0;
		case ACTION_PLAY:
			if ( mode == MODE_PLAY )
			{
				// zatrzymaj granie
				mode = MODE_STOP;
				pthread_mutex_lock(&mutexPlay);
			}
			// zmieñ piosenkê
			if ( param != NULL ) {
				openAudioFile((const char*)param); //TODO: -1
			} else {
				openAudioFile(filename); //TODO: -1
			}
			if ( filename )
			{
				mode = MODE_PLAY;
				// pu¶æ granie dalej
				pthread_mutex_unlock(&mutexPlay);
			}
			else
			{
				mode = MODE_STOP;
			}
			return 0;
		case ACTION_START:
			pthread_mutex_init(&threadMutex, NULL);
			pthread_mutex_init(&mutexPlay, NULL);
			pthread_mutex_lock(&mutexPlay);
			TRY_OPEN( playlistNext );
			if ( filename )
			{
				mode = MODE_PLAY;
				pthread_mutex_unlock(&mutexPlay);
			}
			else
			{
				mode = MODE_STOP;
			}
			pthread_create(&threadPlay, NULL, &playFile, NULL);
			return 0;
		case ACTION_QUIT:
			printf("Quit and clean thread.\n");
			fflush( stdout );
			// zatrzymaj granie
			if ( mode != MODE_STOP )
			{
				mode = MODE_STOP;
				pthread_mutex_lock(&mutexPlay);
				mode = MODE_QUIT;
				pthread_mutex_unlock(&mutexPlay);
			}
			else
			{
				mode = MODE_QUIT;
				pthread_mutex_unlock(&mutexPlay);
			}
			pthread_mutex_destroy(&threadMutex);
			pthread_mutex_destroy(&mutexPlay);
			pthread_join( threadPlay, NULL );
			return 0;
		case ACTION_STOP:
			if ( mode == MODE_PLAY )
			{
				// zatrzymaj granie
				mode = MODE_STOP;
				pthread_mutex_lock(&mutexPlay);
			}
			else
			{
				if ( filename )
					// odtwórz od pocz±tku
					openAudioFile(filename); // TODO: -1
				else
					// znajd¼ plik do otworzenia
					TRY_OPEN(playlistNext);
				if ( filename )
				{
					// pu¶æ granie dalej
					mode = MODE_PLAY;
					pthread_mutex_unlock(&mutexPlay);
				}
				else
				{
					mode = MODE_STOP;
				}
			}
			return 0;
		case ACTION_INFO:
		{
			FileInfo* fileInfo = (FileInfo*)param;
			fileInfo->filename = goc_stringCopy(fileInfo->filename, filename);
			finfoInfo(filename, fileInfo);
			return 0;
		}
		default:
			return ERR_UNKNOWN_ACTION;
	}
	return 0;
}
예제 #7
0
int single_game(){
    Audio RRR;
    openAudioFile(".\\wav\\RRR.wav", &RRR);
	initializeKeyInput();
	Character yg = characterMaking1(".\\pic\\yg.pixel",".\\pic\\yg.color");
	int key_val[NUM_KEYS]={VK_A,VK_D,VK_ESCAPE};
	int stand=0,score=0,standBrick,pDown1,pDown2;
	double drop=0,scoreCount=0;
	Brick bricks[15];
	int i,j,k;
    char scoreStr[4]={'0'};
	for(i=0;i<10;i++){
		bricks[i].y=-1;
		bricks[i].w=40;
		bricks[i].h=2;
		if(i%2==0)bricks[i].color=15;
		else if(i<=5)bricks[i].color=8;
		else if(i>5)bricks[i].color=12;
		else bricks[i].color=10;
	}
	bricks[0].x=0;
	bricks[0].y=100;
	Font *large_font=read_font("font.txt");
	float lastbrick=0;
	int hp = 10,second=0;
	float rate=0.15;
	while(1){
		clearScreen();
		srand(clock());
        for(i=0;i<10;i++){
            if(bricks[i].y>0)bricks[i].y--;
            else if(bricks[i].y==0)bricks[i].y=-100;
            for(k=0;k<2;k++){
                for(j=0;j<bricks[k].w;j++){
                    putString(bricks[i].x+j,bricks[i].y+k,"=",bricks[i].color,0);
                }
            }
        }
        if(score>50){
            rate = 0.2;
        }
        else if(score>75){
            rate = 0.25;
        }
        else if(score>100){
            rate = 0.3;
        }
		if((float)clock()/(float)CLOCKS_PER_SEC-(float)lastbrick>rate&&rand()%10==1){
			for(i=0;i<10;i++){
				if(bricks[i].y<0){
					bricks[i].y=170;
					bricks[i].x=rand()%185;
					lastbrick=(float)clock()/(float)CLOCKS_PER_SEC;
					for(k=0;k<2;k++){
                        for(j=0;j<bricks[i].w;j++){
                            putString(bricks[i].x+j,bricks[i].y+k,"=",bricks[i].color,0);
                        }
                    }
					break;
				}
			}
		}

        for(k=0;k<10;k++){
        	if(abs(yg.y+yg.h-bricks[k].y)<=2&&(
            (yg.x+yg.w>bricks[k].x&&yg.x+yg.w<bricks[k].x+bricks[k].w)||
            (yg.x>bricks[k].x&&yg.x<bricks[k].x+bricks[k].w))){
        		stand=1;
        		standBrick=k;
        		yg.y=bricks[k].y-yg.h;
                break;
			}
			else if(k==9){
                stand=0;
                standBrick=-1;
			}
		}

        if(stand==1){
            drop=0;
            second++;
            if(bricks[standBrick].color==15&&second==15){
                second=0;
                if(hp<10)hp++;
            }
            else if(bricks[standBrick].color==12){
                second++;
                if(second==20){
                    second=0;
                    hp--;
                    playAudio(&RRR);
                }
            }
            else if(bricks[standBrick].color==8){
                if(second==10){
                    second=0;
                    bricks[standBrick].y=-100;
                }
            }
		}
		else{
            if(drop<2)drop+=0.5;
            yg.y+=(int)drop;
            second=0;
		}

		if(yg.y<0){
            yg.y+=10;
            drop=3;
            hp-=4;
            playAudio(&RRR);
		}
		for (k = 0 ; k < NUM_KEYS ; k++){
            if(KEY_DOWN(key_val[k])){
                switch (key_val[k]){
	                case VK_A:
	                	if(yg.x>=0)yg.x-=5;
	                	break;
	                case VK_D:
	                	if(yg.x+yg.w<225)yg.x+=5;
	                	break;
                    case VK_ESCAPE:
                        return 3;
                        break;
          	  	}
            }
        }
        show_image(yg.pic,yg.x,yg.y);
        for(i=0;i<225;i++){
            for(j=151;j<=170;j++){
                putString(i,j," ",0,0);
            }
        }
		putStringLarge(large_font,159,158,"HP ",15);
		putStringLarge(large_font,159,152,"STAGE ",15);
		scoreCount++;
		score = (pow(scoreCount/300,1.5));
		scoreStr[0]=score/100+'0';
		scoreStr[1]=score/10%10+'0';
		scoreStr[2]=score%10+'0';
		putStringLarge(large_font,201,152,scoreStr,15);
		for(i=0;i<hp;i++){
            for(j=1;j<5;j++){
                for(k=0;k<=4;k++)putString(180+i*4+j,158+k,"|",12,0);
            }
		}
		for(i=0;i<225;i++)putString(i,0,"V",12,0);
        for(i=0;i<225;i++){
            putString(i,149,"=",12,0);
        }
        for(i=0;i<150;i++){
            putString(0,i,"|",0,12);
            putString(224,i,"|",0,12);
        }
        drawCmdWindow();
        if(yg.y>150||hp<=0){
            break;
		};
        if(KEY_UP(VK_P)&&pDown1)pDown1=0;
        if(KEY_UP(VK_P)&&pDown2)pDown2=0;
        if(KEY_DOWN(VK_P)&&!pDown1){
            pDown1=1;
            putStringLarge(large_font,45,70,"Press P to continue",12);
            drawCmdWindow();
            Sleep(500);
            while(1){
                if(KEY_DOWN(VK_P)&&!pDown2){
                    pDown2=1;
                    break;
                }
            }
        }
		Sleep(20);
	}
	pauseAudio(&RRR);
	Image * jh =read_image(".\\pic\\jh.pixel",".\\pic\\jh.color");
	show_image(jh,15,30);
    putStringLarge(large_font,75,80,"SCORE ",15);
    putStringLarge(large_font,120,80,scoreStr,15);
    drawCmdWindow();
	Audio *barbar;
	openAudioFile(".\\wav\\88wav.wav",&barbar);
	playAudio(&barbar);
	Sleep(3500);
	int flagg = 1;
    putStringLarge(large_font, 45, 90, "Press esc to exit", 15);
    drawCmdWindow();
    while(flagg){
        if(KEY_DOWN(VK_ESCAPE))return 3;
    }
	clearScreen();
}
예제 #8
0
파일: menu.c 프로젝트: lin826/Slapjack
void initAudioNUM()
{

    openAudioFile("1.wav", &audioNUM[0][0]);
    openAudioFile("1_2.wav", &audioNUM[0][1]);

    openAudioFile("2.wav", &audioNUM[1][0]);
    openAudioFile("2_1.wav", &audioNUM[1][1]);

    openAudioFile("3.wav", &audioNUM[2][0]);
    openAudioFile("3.wav", &audioNUM[2][1]);

    openAudioFile("4.wav", &audioNUM[3][0]);
    openAudioFile("4_1.wav", &audioNUM[3][1]);

    openAudioFile("5.wav", &audioNUM[4][0]);
    openAudioFile("5_1.wav", &audioNUM[4][1]);

    openAudioFile("6.wav", &audioNUM[5][0]);
    openAudioFile("6.wav", &audioNUM[5][1]);

    openAudioFile("7.wav", &audioNUM[6][0]);
    openAudioFile("7.wav", &audioNUM[6][1]);

    openAudioFile("8.wav", &audioNUM[7][0]);
    openAudioFile("8_1.wav", &audioNUM[7][1]);

    openAudioFile("9.wav", &audioNUM[8][0]);
    openAudioFile("9_1.wav", &audioNUM[8][1]);

    openAudioFile("10.wav", &audioNUM[9][0]);
    openAudioFile("10_1.wav", &audioNUM[9][1]);

    openAudioFile("11.wav", &audioNUM[10][0]);
    openAudioFile("11.wav", &audioNUM[10][1]);

    openAudioFile("12.wav", &audioNUM[11][0]);
    openAudioFile("12_1.wav", &audioNUM[11][1]);

    openAudioFile("13.wav", &audioNUM[12][0]);
    openAudioFile("13.wav", &audioNUM[12][1]);
}
예제 #9
0
파일: menu.c 프로젝트: lin826/Slapjack
void initAudio()
{
    //win
    openAudioFile("applaus.wav", &audioWin[0]);
    openAudioFile("ccheer.wav", &audioWin[1]);

    //lose
    openAudioFile("fart.wav", &audioLose[0]);
    openAudioFile("fart2.wav", &audioLose[1]);

    //game over
    openAudioFile("falling.wav", &audioOver[0]);
    openAudioFile("Hahaha.wav", &audioOver[1]);
    openAudioFile("laughcartoon.wav", &audioOver[2]);
    openAudioFile("manha.wav", &audioOver[3]);
    openAudioFile("scream.wav", &audioOver[4]);
    openAudioFile("tarzan.wav", &audioOver[5]);

    //start heart
    openAudioFile("heart.wav", &audio[0]);
}
예제 #10
0
/* LoadBuffer loads the named audio file into an OpenAL buffer object, and
 * returns the new buffer ID. */
static ALuint LoadSound(const char *filename)
{
    ALenum err, format, type, channels;
    ALuint rate, buffer;
    size_t datalen;
    void *data;
    FilePtr sound;

    /* Open the audio file */
    sound = openAudioFile(filename, 1000);
    if(!sound)
    {
        fprintf(stderr, "Could not open audio in %s\n", filename);
        closeAudioFile(sound);
        return 0;
    }

    /* Get the sound format, and figure out the OpenAL format */
    if(getAudioInfo(sound, &rate, &channels, &type) != 0)
    {
        fprintf(stderr, "Error getting audio info for %s\n", filename);
        closeAudioFile(sound);
        return 0;
    }

    format = GetFormat(channels, type, NULL);
    if(format == AL_NONE)
    {
        fprintf(stderr, "Unsupported format (%s, %s) for %s\n",
                ChannelsName(channels), TypeName(type), filename);
        closeAudioFile(sound);
        return 0;
    }

    /* Decode the whole audio stream to a buffer. */
    data = decodeAudioStream(sound, &datalen);
    if(!data)
    {
        fprintf(stderr, "Failed to read audio from %s\n", filename);
        closeAudioFile(sound);
        return 0;
    }

    /* Buffer the audio data into a new buffer object, then free the data and
     * close the file. */
    buffer = 0;
    alGenBuffers(1, &buffer);
    alBufferData(buffer, format, data, datalen, rate);
    free(data);
    closeAudioFile(sound);

    /* Check if an error occured, and clean up if so. */
    err = alGetError();
    if(err != AL_NO_ERROR)
    {
        fprintf(stderr, "OpenAL Error: %s\n", alGetString(err));
        if(buffer && alIsBuffer(buffer))
            alDeleteBuffers(1, &buffer);
        return 0;
    }

    return buffer;
}