示例#1
0
/**
**  Ask the sound server to register a sound (and currently to load it)
**  and to return an unique identifier for it. The unique identifier is
**  memory pointer of the server.
**
**  @param files   An array of wav files.
**  @param number  Number of files belonging together.
**
**  @return        the sound unique identifier
*/
CSound *RegisterSound(const char *files[], unsigned number)
{
	unsigned i;
	CSound *id;

	id = new CSound;
	if (number > 1) { // load a sound group
		id->Sound.OneGroup = new CSample *[number];
		id->Number = number;
		for (i = 0; i < number; ++i) {
			id->Sound.OneGroup[i] = LoadSample(files[i]);
			if (!id->Sound.OneGroup[i]) {
				delete id;
				return NO_SOUND;
			}
		}
	} else { // load a unique sound
		id->Sound.OneSound = LoadSample(files[0]);
		if (!id->Sound.OneSound) {
			delete id;
			return NO_SOUND;
		}
		id->Number = ONE_SOUND;
	}
	id->Range = MAX_SOUND_RANGE;
	return id;
}
示例#2
0
void CInstrumentEditorDPCM::OnBnClickedLoad()
{
	CDMCFileSoundDialog OpenFileDialog(TRUE, 0, 0, OFN_HIDEREADONLY | OFN_FILEMUSTEXIST | OFN_ALLOWMULTISELECT | OFN_EXPLORER, _T("Delta modulated samples (*.dmc)|*.dmc|All files|*.*||"));

//	OpenFileDialog.m_pOFN->lpstrInitialDir = theApp.GetSettings()->GetPath(PATH_DMC);

	if (OpenFileDialog.DoModal() == IDCANCEL)
		return;

	theApp.GetSettings()->SetPath(OpenFileDialog.GetPathName(), PATH_DMC);

	if (OpenFileDialog.GetFileName().GetLength() == 0) {
		// Multiple files
		POSITION Pos = OpenFileDialog.GetStartPosition();
		while (Pos) {
			CString Path = OpenFileDialog.GetNextPathName(Pos);
			CString FileName = Path.Right(Path.GetLength() - Path.ReverseFind('\\') - 1);
			LoadSample(Path, FileName);
		}
	}
	else {
		// Single file
      LoadSample(OpenFileDialog.GetPathName(), OpenFileDialog.GetFileName());
	}
}
示例#3
0
/**
**  Ask the sound server to register a sound (and currently to load it)
**  and to return an unique identifier for it. The unique identifier is
**  memory pointer of the server.
**
**  @param files   An array of wav files.
**  @param number  Number of files belonging together.
**
**  @return        the sound unique identifier
**
**  @todo FIXME: Must handle the errors better.
*/
CSound *RegisterSound(const std::vector<std::string> &files)
{
	CSound *id = new CSound;
	size_t number = files.size();

	if (number > 1) { // load a sound group
		id->Sound.OneGroup = new CSample *[number];
		memset(id->Sound.OneGroup, 0, sizeof(CSample *) * number);
		id->Number = number;
		for (unsigned int i = 0; i < number; ++i) {
			id->Sound.OneGroup[i] = LoadSample(files[i]);
			if (!id->Sound.OneGroup[i]) {
				//delete[] id->Sound.OneGroup;
				delete id;
				return NO_SOUND;
			}
		}
	} else { // load a unique sound
		id->Sound.OneSound = LoadSample(files[0]);
		if (!id->Sound.OneSound) {
			delete id;
			return NO_SOUND;
		}
		id->Number = ONE_SOUND;
	}
	id->Range = MAX_SOUND_RANGE;
	return id;
}
Buleys::Buleys(QWidget *parent, Qt::WFlags flags)
    : QWidget(parent, flags)
    , m_NumberCase(0)
    , m_ShowFileContents(true)
{
    ui.setupUi(this);
    // reload settings
    QSettings settings("CodeJam", "Buleys");
    m_FileInPath = settings.value("fileInPath", "").toString();
    m_SampleTableFromWebSite = settings.value("sampleTableFromWebSite", "").toString();

    if(m_FileInPath != "") {
        // re-load a previously loaded file
        LoadFile();
    }
    else if(m_SampleTableFromWebSite != "") {
        LoadSample();
    }

    connect(ui.pUseSampleButton, SIGNAL(clicked(bool)), this, SLOT(LoadSample()));
    connect(&m_watcher, SIGNAL(progressValueChanged(int)), ui.pProgressBar, SLOT(setValue(int)));
    connect(&m_watcher, SIGNAL(finished()), this, SLOT(EventFinishedComputation()));
    ui.pFailedButton->hide();

    move(0, 50);
    restoreGeometry(settings.value("geometry").toByteArray());
}
示例#5
0
/**
**  Play a sound file
**
**  @param name  Filename of a sound to play
**
**  @return      Channel number the sound is playing on, -1 for error
*/
int PlaySoundFile(const std::string &name)
{
	CSample *sample = LoadSample(name);
	if (sample) {
		return PlaySample(sample);
	}
	return -1;
}
示例#6
0
bool Sound::load(std::string const& filename)
{	
	if(driver == NULL) return false;
	//cout<<"Sound::load";
	//cerr << "Loading sound: " << filename.native_file_string() << endl;
	m_sound = LoadSample(filename, 1);
	return ( m_sound.get() && m_sound->avail() );
}
示例#7
0
/**
**  Load a sample
**
**  @param name  File name of sample (short version).
**
**  @return      General sample loaded from file into memory.
**
**  @todo  Add streaming, caching support.
*/
CSample *LoadSample(const std::string &name)
{
	const std::string filename = LibraryFileName(name.c_str());
	CSample *sample = LoadSample(filename.c_str(), PlayAudioLoadInMemory);

	if (sample == NULL) {
		fprintf(stderr, "Can't load the sound '%s'\n", name.c_str());
	}
	return sample;
}
void ReverseWords::dropEvent( QDropEvent* event )
{
	const QMimeData* pMime = event->mimeData();
	if(pMime->hasUrls()) {
		m_FileInPath = pMime->urls().first().toLocalFile();
		LoadFile();
	}
	else if(pMime->hasText()) {
		m_SampleTableFromWebSite = pMime->text();
		LoadSample();
	}
}
示例#9
0
int DoMainMenu()
{
    int rtval = -1;
    char *pa = (char*) GraphicsDF->get("palette");

    PlayMusic("solution.s3m");
    
    DoneInteract();
    ClearScr();
    SetPalette(pa);
    MenuSnd = LoadSample("menu", FALSE);
    FlashSnd = LoadSample("flash", FALSE);

    while (rtval == -1) {
        rtval = ProcessMenu("mmnu0", "mmnu1");
        if (rtval == 0) /*new game*/ {
            rtval = ProcessMenu("mmnu2", "mmnu3"); // dificulty
            if (rtval == 3) {rtval = -1; continue;}
            switch (rtval) {
                case 0 : ActualDifficulty = 'e'; break;
                case 1 : ActualDifficulty = 'n'; break;
                case 2 : ActualDifficulty = 'h'; break;                
            }
            rtval = 0;
            break;
        }
    }

    FreeSample(MenuSnd);
    FreeSample(FlashSnd);
    ClearScr();
    SetPalette(Palette);
    InitInteract();
    memfree(pa);
    return rtval;
}
示例#10
0
/**
**  Play a sound file
**
**  @param name      Filename of a sound to play
**  @param listener  Optional lua callback
**
**  @return          Channel number the sound is playing on, -1 for error
*/
int PlayFile(const std::string &name, LuaActionListener *listener)
{
	int channel = -1;
	CSample *sample = LoadSample(name);

	if (sample) {
		channel = PlaySample(sample);
		if (channel != -1) {
			SetChannelVolume(channel, MaxVolume);
			SetChannelFinishedCallback(channel, PlaySoundFileCallback);
			ChannelMap[channel] = listener;
		}
	}
	return channel;
}
bool CAudioManager::LoadAssetFile(std::string filename){
  CLog *pLog = CLog::Instance();

  //read assets.dat file
  CFileReader cfr(filename);
  if(cfr.IsValid() == false)
    return false; //file is invalid or contains no usable data

  //validate asset data and add to appropriate vectors
  std::string parameter;
  std::string assetType;
  SOUND_FILE_DATA     tempSound;

  for(int i = 0; i < cfr.GetNumberOfLines(); ++i){

    //process only lines with 2 or more terms
    if(cfr.GetNumberOfTermsFromLine(i) > 1){
      assetType = cfr.GetTerm(cfr.GetLineFromFile(i), 1);
     
      if(assetType == "soundfile" && cfr.GetNumberOfTermsFromLine(i) == 4){
        parameter = cfr.GetTerm(cfr.GetLineFromFile(i), 2);//sound ID
        tempSound.soundID = atoi(parameter.c_str());
        parameter = cfr.GetTerm(cfr.GetLineFromFile(i), 3);//filename
        tempSound.filename = parameter;
        parameter = cfr.GetTerm(cfr.GetLineFromFile(i), 4);//description
        tempSound.description = parameter;
        m_assetSoundData.push_back(tempSound);
        pLog->Log("****** soundfile added *******");
        pLog->Log("soundID", tempSound.soundID);
        pLog->Log("filename", tempSound.filename);
        pLog->Log("description", tempSound.description);        
      }
    }
  }

  //load sound information
  for(int i = 0; i < m_assetSoundData.size(); ++i){
    LoadSample(m_assetSoundData[i].soundID,
               "assets\\sounds\\" + m_assetSoundData[i].filename);
    pLog->Log("Loaded into memory", m_assetSoundData[i].filename);
  }

  return true;
}
示例#12
0
/**
**  Play a music file.
**
**  @param file  Name of music file, format is automatically detected.
**
**  @return      0 if music is playing, -1 if not.
*/
int PlayMusic(const std::string &file)
{
	if (!SoundEnabled() || !IsMusicEnabled()) {
		return -1;
	}
	const std::string name = LibraryFileName(file.c_str());
	DebugPrint("play music %s\n" _C_ name.c_str());
	CSample *sample = LoadSample(name.c_str(), PlayAudioStream);

	if (sample) {
		StopMusic();
		MusicChannel.Sample = sample;
		MusicPlaying = true;
		return 0;
	} else {
		DebugPrint("Could not play %s\n" _C_ file.c_str());
		return -1;
	}
}
示例#13
0
void LoadSounds_Game() {
	sfxGame.smpNinja = LoadSample("data/sounds/throw.wav",4);
	sfxGame.smpPickup = LoadSample("data/sounds/pickup.wav",2);
	sfxGame.smpBump = LoadSample("data/sounds/bump.wav", 2);
	sfxGame.smpDeath[0] = LoadSample("data/sounds/death1.wav", 2);
	sfxGame.smpDeath[1] = LoadSample("data/sounds/death2.wav", 2);
	sfxGame.smpDeath[2] = LoadSample("data/sounds/death3.wav", 2);	
	
	sfxGame.smpTeamScore = LoadSample("data/sounds/teamscore.wav",2);
	if( sfxGame.smpTeamScore.get() == NULL ) {
		notes << "LoadSounds: cannot load teamscore.wav" << endl;
		sfxGame.smpTeamScore = sfxGeneral.smpNotify;
	}
	
	// preload game sounds
	for(Iterator<std::string>::Ref f = FileListIter("data/sounds/game"); f->isValid(); f->next())
		loadGameSound(GetBaseFilename(f->get()));
}
示例#14
0
IT_File* ITFile_Load( char *filename ) {

	IT_File *itf;
	int i;

	u32 messageOffset;

	u32 *instrumentOffsets;
	u32 *sampleOffsets;
	u32 *patternOffsets;

	myfile = fopen( filename, "rb" );

	itf = (IT_File*)malloc(sizeof(IT_File));
	memset( itf, 0, sizeof( IT_File ) );

	read32(); // IMPM
	fread( itf->SongName, 1, 26, myfile );
	itf->PatternHighlight = read16();
	itf->OrdNum = read16();
	itf->InsNum = read16();
	itf->SmpNum = read16();
	itf->PatNum = read16();
	itf->Cwtv = read16();
	itf->Cmwt = read16();
	itf->Flags = read16();
	itf->Special = read16();
	itf->GlobalVolume = read8();
	itf->MasterVolume = read8();
	itf->InitialSpeed = read8();
	itf->InitialTempo = read8();
	itf->PanningSeparation = read8();
	itf->PitchWheelDepth = read8();
	itf->MessageLength = read16();
	messageOffset = read32();
	read32(); // reserved
	for( i = 0; i < 64; i++ )
		itf->InitialChannelPanning[i] = read8();
	for( i = 0; i < 64; i++ )
		itf->InitialChannelVolume[i] = read8();
	itf->OrderList = (u8*)malloc( itf->OrdNum );
	for( i = 0; i < itf->OrdNum; i++ )
		itf->OrderList[i] = read8();
	
	instrumentOffsets = (u32*)malloc( itf->InsNum * 4 );
	sampleOffsets = (u32*)malloc( itf->SmpNum * 4 );
	patternOffsets = (u32*)malloc( itf->PatNum * 4 );

	for( i = 0; i < itf->InsNum; i++ )
		instrumentOffsets[i] = read32();
	for( i = 0; i < itf->SmpNum; i++ )
		sampleOffsets[i] = read32();
	for( i = 0; i < itf->PatNum; i++ )
		patternOffsets[i] = read32();
	
	// load instruments
	itf->Instruments = (IT_Instrument*)malloc( sizeof(IT_Instrument) * itf->InsNum );
	for( i = 0; i < itf->InsNum; i++ ) {
		memset( itf->Instruments+i,0,sizeof( IT_Instrument ) ); 
		if( instrumentOffsets[i] ) {
			fseek( myfile, instrumentOffsets[i], SEEK_SET );
			LoadInstrument( itf->Instruments+i );
		}
	}

	// load samples
	itf->Samples = (IT_Sample*)malloc( sizeof(IT_Sample) * itf->SmpNum );
	for( i = 0; i < itf->SmpNum; i++ ) {
		memset( itf->Samples+i, 0, sizeof( IT_Sample ) );
		if( sampleOffsets[i] ) {
			fseek( myfile, sampleOffsets[i], SEEK_SET );
			LoadSample( itf->Samples + i );
		}
	}

	// load patterns
	itf->Patterns = (IT_Pattern*)malloc( sizeof(IT_Pattern) * itf->PatNum );
	for( i = 0; i < itf->PatNum; i++ ) {
		memset( itf->Patterns+i, 0, sizeof( IT_Pattern ) );
		if( patternOffsets[i] ) {
			fseek( myfile, patternOffsets[i], SEEK_SET );
			LoadPattern( itf->Patterns + i );
		}
	}

	// read message
	if( itf->MessageLength ) {
		fseek( myfile, messageOffset, SEEK_SET );
		itf->Message = malloc( itf->MessageLength+1 );
		itf->Message[itf->MessageLength] = 0;
		fread( itf->Message, 1, itf->MessageLength, myfile );
	}

	return itf;
}
示例#15
0
bool JResourceManager::LoadResource(const string& resourceName)
{
	string path = /*mResourceRoot + */resourceName;

//	TiXmlDocument doc(path.c_str());
//	
//	if (!doc.LoadFile()) return false;
	
	JGE *engine = JGE::GetInstance();
	if (engine == NULL) return false;

	JFileSystem *fileSystem = JFileSystem::GetInstance();
	if (fileSystem == NULL) return false;

	if (!fileSystem->OpenFile(path.c_str())) return false;

	int size = fileSystem->GetFileSize();
	char *xmlBuffer = new char[size];
	fileSystem->ReadFile(xmlBuffer, size);

	TiXmlDocument doc;
	doc.Parse(xmlBuffer);

	TiXmlNode* resource = 0;
	TiXmlNode* node = 0;
	TiXmlElement* element = 0;

	resource = doc.FirstChild("resource"); 
	if (resource)
	{
		element = resource->ToElement();
		printf("---- Loading %s:%s\n", element->Value(), element->Attribute("name"));

		for (node = resource->FirstChild(); node; node = node->NextSibling())
		{
			element = node->ToElement();
			if (element != NULL)
			{
				if (strcmp(element->Value(), "texture")==0)
				{
					CreateTexture(element->Attribute("name"));
				}
				else if (strcmp(element->Value(), "quad")==0)
				{
					string quadName = element->Attribute("name");
					string textureName = element->Attribute("texture");
					float x = 0.0f;
					float y = 0.0f;
					float width = 16.0f;
					float height = 16.0f;
					float value;
					float hotspotX = 0.0f;
					float hotspotY = 0.0f;
					
					if (element->QueryFloatAttribute("x", &value) == TIXML_SUCCESS)
						x = value;
					
					if (element->QueryFloatAttribute("y", &value) == TIXML_SUCCESS)
						y = value;

					if (element->QueryFloatAttribute("width", &value) == TIXML_SUCCESS)
						width = value;

					if (element->QueryFloatAttribute("height", &value) == TIXML_SUCCESS)
						height = value;

					if (element->QueryFloatAttribute("w", &value) == TIXML_SUCCESS)
						width = value;

					if (element->QueryFloatAttribute("h", &value) == TIXML_SUCCESS)
						height = value;

					if (element->QueryFloatAttribute("hotspot.x", &value) == TIXML_SUCCESS)
						hotspotX = value;
					else
						hotspotX = width/2;

					if (element->QueryFloatAttribute("hotspot.y", &value) == TIXML_SUCCESS)
						hotspotY = value;
					else
						hotspotY = height/2;

// 					if (element->QueryFloatAttribute("regx", &value) == TIXML_SUCCESS)
// 						hotspotX = width/2;
// 
// 					if (element->QueryFloatAttribute("regy", &value) == TIXML_SUCCESS)
// 						hotspotY = height/2;
				
					int id = CreateQuad(quadName, textureName, x, y, width, height);
					if (id != INVALID_ID)
					{
						GetQuad(id)->SetHotSpot(hotspotX, hotspotY);
					}
				}
				else if (strcmp(element->Value(), "font")==0)
				{
				}
				else if (strcmp(element->Value(), "music")==0)
				{
					LoadMusic(element->Attribute("name"));
				}
				else if (strcmp(element->Value(), "sample")==0)
				{
					LoadSample(element->Attribute("name"));
				}
// 				else if (strcmp(element->Value(), "effect")==0)
// 				{
// 					RegisterParticleEffect(element->Attribute("name"));
// 				}
// 				else if (strcmp(element->Value(), "motion_emitter")==0)
// 				{
// 					RegisterMotionEmitter(element->Attribute("name"));
// 				}
			}
		}
		
	}
	
	fileSystem->CloseFile();
	delete[] xmlBuffer;
//	JGERelease();

	return true;
}
示例#16
0
cOAL_Sample* cOAL_Device::LoadSample(const string &asFilename)
{
	return LoadSample(String2WString(asFilename));
}
示例#17
0
bool CSound::Create (void)
{
	
    if (Mix_OpenAudio(44100, AUDIO_S16LSB, 2, 1024) < 0) {
        // failure
        theLog.WriteLine ("Sound           => !!! Could not initialise SDL_mixer Library. Error is : %s", Mix_GetError());

        // Get out
        return false;
    }
    
    Mix_AllocateChannels(32); // this was the default in FMOD
	
    //---------------------
    // Load the sound data
    //---------------------

    if (!LoadSample (SAMPLE_BOMB_DROP             , SND_BOMB_DROP              ) ||
        !LoadSample (SAMPLE_BOMBER_DEATH          , SND_BOMBER_DEATH           ) ||
        !LoadSample (SAMPLE_BOMB_BOUNCE           , SND_BOMB_BOUNCE            ) ||
        !LoadSample (SAMPLE_BOMBER_PUNCH          , SND_BOMBER_PUNCH           ) ||
        !LoadSample (SAMPLE_BOMBER_THROW          , SND_BOMBER_THROW           ) ||
        !LoadSample (SAMPLE_BOMBER_LOSE_ITEM      , SND_BOMBER_LOSE_ITEM       ) ||
        !LoadSample (SAMPLE_BREAK_1               , SND_BREAK_1                ) ||
        !LoadSample (SAMPLE_BREAK_2               , SND_BREAK_2                ) ||
        !LoadSample (SAMPLE_DRAW_GAME             , SND_DRAW_GAME              ) ||
        !LoadSample (SAMPLE_EXPLOSION_01_1        , SND_EXPLOSION_01_1         ) ||
        !LoadSample (SAMPLE_EXPLOSION_01_2        , SND_EXPLOSION_01_2         ) ||
        !LoadSample (SAMPLE_EXPLOSION_02_1        , SND_EXPLOSION_02_1         ) ||
        !LoadSample (SAMPLE_EXPLOSION_02_2        , SND_EXPLOSION_02_2         ) ||
        !LoadSample (SAMPLE_EXPLOSION_03_1        , SND_EXPLOSION_03_1         ) ||
        !LoadSample (SAMPLE_EXPLOSION_03_2        , SND_EXPLOSION_03_2         ) ||
        !LoadSample (SAMPLE_EXPLOSION_04_1        , SND_EXPLOSION_04_1         ) ||
        !LoadSample (SAMPLE_EXPLOSION_04_2        , SND_EXPLOSION_04_2         ) ||
        !LoadSample (SAMPLE_EXPLOSION_05_1        , SND_EXPLOSION_05_1         ) ||
        !LoadSample (SAMPLE_EXPLOSION_05_2        , SND_EXPLOSION_05_2         ) ||
        !LoadSample (SAMPLE_EXPLOSION_06_1        , SND_EXPLOSION_06_1         ) ||
        !LoadSample (SAMPLE_EXPLOSION_06_2        , SND_EXPLOSION_06_2         ) ||
        !LoadSample (SAMPLE_EXPLOSION_07_1        , SND_EXPLOSION_07_1         ) ||
        !LoadSample (SAMPLE_EXPLOSION_07_2        , SND_EXPLOSION_07_2         ) ||
        !LoadSample (SAMPLE_EXPLOSION_08_1        , SND_EXPLOSION_08_1         ) ||
        !LoadSample (SAMPLE_EXPLOSION_08_2        , SND_EXPLOSION_08_2         ) ||
        !LoadSample (SAMPLE_EXPLOSION_09_1        , SND_EXPLOSION_09_1         ) ||
        !LoadSample (SAMPLE_EXPLOSION_09_2        , SND_EXPLOSION_09_2         ) ||
        !LoadSample (SAMPLE_EXPLOSION_10_1        , SND_EXPLOSION_10_1         ) ||
        !LoadSample (SAMPLE_EXPLOSION_10_2        , SND_EXPLOSION_10_2         ) ||
        !LoadSample (SAMPLE_HURRY                 , SND_HURRY                  ) ||
        !LoadSample (SAMPLE_ITEM_FUMES            , SND_ITEM_FUMES             ) ||
        !LoadSample (SAMPLE_MENU_NEXT             , SND_MENU_NEXT              ) ||
        !LoadSample (SAMPLE_MENU_PREVIOUS         , SND_MENU_PREVIOUS          ) ||
        !LoadSample (SAMPLE_MENU_BEEP             , SND_MENU_BEEP              ) ||
        !LoadSample (SAMPLE_MENU_ERROR            , SND_MENU_ERROR             ) ||
        !LoadSample (SAMPLE_PAUSE                 , SND_PAUSE                  ) ||
        !LoadSample (SAMPLE_PICK_ITEM_1           , SND_PICK_ITEM_1            ) ||
        !LoadSample (SAMPLE_PICK_ITEM_2           , SND_PICK_ITEM_2            ) ||
        !LoadSample (SAMPLE_RING_DING             , SND_RING_DING              ) ||
        !LoadSample (SAMPLE_SICK_1                , SND_SICK_1                 ) ||
        !LoadSample (SAMPLE_SICK_2                , SND_SICK_2                 ) ||
        !LoadSample (SAMPLE_SICK_3                , SND_SICK_3                 ) ||
        !LoadSample (SAMPLE_VICTORY               , SND_VICTORY                ) ||
        !LoadSample (SAMPLE_WALL_CLAP_1           , SND_WALL_CLAP_1            ) ||
        !LoadSample (SAMPLE_WALL_CLAP_2           , SND_WALL_CLAP_2            ) ||
        !LoadSample (SAMPLE_WINNER                , SND_WINNER                 ))
    { // songs are loaded when they are needed
        // Failure, get out (error is logged by the LoadSample() and LoadSong() methods)
        return false;
    }

    m_SoundOK = true;

    // Everything went right
    return true;
}
示例#18
0
static void loadGameSound(const std::string& name) {	
	SmartPointer<SoundSample> s = LoadSample("data/sounds/game/" + name, 1);
	if(s.get())
		sfxGame.gameSounds[GetBaseFilenameWithoutExt(name)] = s;
}