コード例 #1
0
ファイル: SamplePool.cpp プロジェクト: EQ4/LittleGPTracker
void SamplePool::Load() {

	Path sampleDir("samples:");

	I_Dir *dir=FileSystem::GetInstance()->Open(sampleDir.GetPath().c_str()) ;
	if (!dir) {
		return ;
	}

	// First, find all wav files

	dir->GetContent("*.wav") ;
	IteratorPtr<Path> it(dir->GetIterator()) ;
	count_=0 ;

	for(it->Begin();!it->IsDone();it->Next()) {
		Path &path=it->CurrentItem() ;
//		Trace::Dump("Got sample name '%s'",name) ;
		loadSample(path.GetPath().c_str()) ;
		if (count_==MAX_PIG_SAMPLES) {
		   Trace::Error("Warning maximum sample count reached") ;
		   break ;
		} ;

	} ;

	// now, let's look at soundfonts

	dir->GetContent("*.sf2") ;
	IteratorPtr<Path> it2(dir->GetIterator()) ;

	for(it2->Begin();!it2->IsDone();it2->Next()) {
		Path &path=it2->CurrentItem() ;
		loadSoundFont(path.GetPath().c_str()) ;
	} ;

	delete dir ;

	// now sort the samples

	int rest=count_ ;
	while(rest>0) {
		int index=0 ;
		for (int i=1;i<rest;i++) {
			if (strcmp(names_[i],names_[index])>0) {
				index=i ;
			};
		} ;
		SoundSource *tWav=wav_[index] ;
		char *tName=names_[index] ;
		wav_[index]=wav_[rest-1] ;
		names_[index]=names_[rest-1] ;
		wav_[rest-1]=tWav;
		names_[rest-1]=tName ;
		rest-- ;
	} ;
} ;
コード例 #2
0
ファイル: SamplePool.cpp プロジェクト: EQ4/LittleGPTracker
int SamplePool::ImportSample(Path &path) {

	if (count_==MAX_PIG_SAMPLES) return -1 ;

	// construct target path

	std::string dpath="samples:" ;
	dpath+=path.GetName() ;
	Path dstPath(dpath.c_str()) ;

    // Opens files

	I_File *fin=FileSystem::GetInstance()->Open(path.GetPath().c_str(),"r") ;
	if (!fin) {
		Trace::Error("Failed to open input file %s",path.GetPath().c_str()) ;
		return -1;
	} ;
	fin->Seek(0,SEEK_END) ;
	long size=fin->Tell() ;
	fin->Seek(0,SEEK_SET) ;

	I_File *fout=FileSystem::GetInstance()->Open(dstPath.GetPath().c_str(),"w") ;
	if (!fout) {
		fin->Close() ;
		delete (fin) ;
		return -1 ;
	} ;

	// copy file to current project

	char buffer[IMPORT_CHUNK_SIZE] ;
	while (size>0) {
		int count=(size>IMPORT_CHUNK_SIZE)?IMPORT_CHUNK_SIZE:size ;
		fin->Read(buffer,1,count) ;
		fout->Write(buffer,1,count) ;
		size-=count ;
	} ;

	fin->Close() ;
	fout->Close() ;
	delete(fin) ;
	delete(fout) ;

	// now load the sample

	bool status=loadSample(dstPath.GetPath().c_str()) ;

	SetChanged() ;
	SamplePoolEvent ev ;
	ev.index_=count_-1 ;
	ev.type_=SPET_INSERT ;
	NotifyObservers(&ev) ;
	return status?(count_-1):-1 ;
};
コード例 #3
0
ファイル: sound.c プロジェクト: DusteDdk/Wizznic
void loadMenuSamples()
{
  loadSample( DATADIR"data/snd/menumove.ogg", SND_MENUMOVE );
  loadSample( DATADIR"data/snd/menuclick.ogg", SND_MENUCLICK );
  loadSample( DATADIR"data/snd/rocketboom.ogg", SND_ROCKETBOOM );
  loadSample( DATADIR"data/snd/rocketlaunch.ogg", SND_ROCKETLAUNCH );
  loadSample( packGetFile("themes/oldskool/snd", "winner.ogg"), SND_WINNER);
  loadSample( packGetFile("themes/oldskool/snd", "loser.ogg"), SND_LOSER);
}
コード例 #4
0
bool GUI::runTests()
{
  cout << "Gui::runTests() iteration: " << testIteration << endl;
  
  if ( testIteration < 10 )
  {
    if ( testIteration % 2 == 0 )
      loadSample( "440hz.wav" );
    else
      loadSample( "220hz.wav" );
    
    testIteration++;
  }
  else
  {
    // wait, let the memory settle, then quit
    Glib::signal_timeout().connect( sigc::bind_return( sigc::mem_fun(*this, &GUI::quit), 10000), true);
    return false;
  }
  
  Glib::signal_timeout().connect( sigc::mem_fun(*this, &GUI::runTests), 4000);
  
  return false;
}
コード例 #5
0
void QSoundEffectPrivate::setSource(const QUrl &url)
{
    if (url.isEmpty()) {
        m_source = QUrl();
        unloadSample();
        return;
    }

    m_source = url;

    if (m_networkAccessManager == 0)
        m_networkAccessManager = new QNetworkAccessManager(this);

    m_stream = m_networkAccessManager->get(QNetworkRequest(m_source));

    unloadSample();
    loadSample();
}
コード例 #6
0
void SoundLooper::strEvent(eventtype et, char *data){
	if(et == EVENT_SAMPLE_LOAD) {
		loadSample(data);
	}
}
コード例 #7
0
ファイル: sound.c プロジェクト: DusteDdk/Wizznic
void loadSamples(const char* sndDir, const char* musicFile)
{
  loadSample( packGetFile(sndDir,"click.ogg"), SND_CLICK );
  loadSample( packGetFile(sndDir,"brickmove.ogg"), SND_BRICKMOVE );
  loadSample( packGetFile(sndDir,"brickgrab.ogg"), SND_BRICKGRAB );
  loadSample( packGetFile(sndDir,"brickbreak.ogg"), SND_BRICKBREAK );
  loadSample( packGetFile(sndDir,"scoretick.ogg"), SND_SCORECOUNT );
  loadSample( packGetFile(sndDir,"countdown.ogg"), SND_COUNTDOWNTOSTART );
  loadSample( packGetFile(sndDir,"start.ogg"), SND_START );
  loadSample( packGetFile(sndDir,"timeout.ogg"), SND_TIMEOUT );
  loadSample( packGetFile(sndDir,"victory.ogg"), SND_VICTORY );
  loadSample( packGetFile(sndDir,"timeout.ogg"), SND_TIMEOUT );
  loadSample( packGetFile(sndDir,"onewaymove.ogg"), SND_ONEWAY_MOVE );
  loadSample( packGetFile(sndDir,"teleported.ogg"), SND_TELEPORTED );
  loadSample( packGetFile(sndDir,"switchactivate.ogg"), SND_SWITCH_ACTIVATED );
  loadSample( packGetFile(sndDir,"switchinactive.ogg"), SND_SWITCH_DEACTIVATED );
  loadSample( packGetFile(sndDir,"brickswap.ogg"), SND_BRICKSWAP );
  loadSample( packGetFile(sndDir,"brickcopy.ogg"), SND_BRICKCOPY );
  loadSample( packGetFile(sndDir,"brickswapdenied.ogg"), SND_BRICKSWAP );
  loadSample( packGetFile(sndDir,"brickcopydenied.ogg"), SND_BRICKCOPY );
  loadSample( packGetFile(sndDir, "winner.ogg"), SND_WINNER);
  loadSample( packGetFile(sndDir, "loser.ogg"), SND_LOSER);

  //Music load code
  if(setting()->disableMusic) return;
  if( !musicFile ) return;

  //Load ingame song if not allready loaded.
  if(strcmp(lastLoadedSongFn, packGetFile("./",musicFile))!=0 && !setting()->userMusic)
  {
    //Free old song if loaded.
    if(mus[1])
    {
      Mix_FreeMusic(mus[1]);
    }
    strcpy(lastLoadedSongFn, packGetFile("./",musicFile));
    mus[1]=Mix_LoadMUS( lastLoadedSongFn );
    if(!mus[1])
      printf("Couldn't load music: '%s'\n",packGetFile("./",musicFile));

    mPos[1] = 0.0f;

    if( !Mix_PlayingMusic() )
    {
      Mix_FadeInMusicPos(mus[1], -1, MUSIC_FADETIME,mPos[1]);
    }
  }

}