Example #1
0
status_t
Core::Init() 
{
	switch(gCronoSettings.Engine)
	{
		case CRONO_FILE_ENGINE:
			LoadSoundFile();
		break;

		case CRONO_DEFAULT_ENGINE:
		case CRONO_SINE_ENGINE:
		case CRONO_TRIANGLE_ENGINE:
		case CRONO_SAWTOOTH_ENGINE:
			LoadGeneratedSounds();
		break;
	}

 	if (kFileFormat.type != B_MEDIA_RAW_AUDIO)
 		return B_ERROR;
 
	if (kPlayer != NULL)
		delete kPlayer;

	kPlayer = new BSoundPlayer(&kFileFormat.u.raw_audio, 
		"CronoPlayback", PlayBuffer);


	kLimit = (size_t)((kFileFormat.u.raw_audio.frame_rate
		*(kFileFormat.u.raw_audio.channel_count+1))*60);
}
Example #2
0
void CUnitDefHandler::LoadSound(GuiSoundSet& gsound, const string& fileName, const float volume)
{
	const int id = LoadSoundFile(fileName);
	if (id > 0)
	{
		GuiSoundSet::Data soundData(fileName, id, volume);
		gsound.sounds.push_back(soundData);
	}
}
Example #3
0
void CGeneral::LoadSound()
{
   if (g_fNoSound) {
      memset(m_snd, 0, sizeof(m_snd));
      return;
   }

   if (m_fSndLoaded) {
      return;
   }

   m_fSndLoaded = true;

   int i;

   for (i = 0; i < NUM_SOUND; i++) {
      assert(*soundfile[i]);
      m_snd[i] = LoadSoundFile(va("%s%s.wav", SOUND_DIR, soundfile[i]));
   }
}
DWORD CSoundLoader::OnLoadFile(DWORD size, void *params)
{
	VERIFY_MESSAGE_SIZE(size, sizeof(TCHAR *));
	TCHAR *pFileName = (TCHAR *)params;
	
	StdString fileName = pFileName;

	fileName.tolower();

	DWORD retval = MSG_HANDLED_STOP;
	CHashString hszFileName(fileName);

	set<DWORD>::iterator fileIter = m_FilesLoaded.find(hszFileName.GetUniqueID());
	if (fileIter != m_FilesLoaded.end())
	{
		// this file has already been loaded (hopefully correctly)
		return retval;
	}

	StdString extension, currentToken;
	fileName.GetToken(_T("."), currentToken);

	while (_tcscmp(currentToken, _T("")) != 0)
	{
		extension = currentToken;
		fileName.GetToken(_T("."), currentToken);
	}
	
	static CHashString hszWav(_T("wav"));
	static CHashString hszOgg(_T("ogg"));
	static CHashString hszMP3(_T("mp3"));
	static CHashString hszXmp(_T("xmp"));

	CHashString hszExt(extension);
	DWORD extID = hszExt.GetUniqueID();

	if ((extID == hszWav.GetUniqueID()) ||
		(extID == hszOgg.GetUniqueID()) ||
		(extID == hszMP3.GetUniqueID()))
	{
		bool success = LoadSoundFile(fileName, &hszExt);
		if (!success)
		{
			m_ToolBox->Log(LOGWARNING, _T("Failed to load sound %s\n"), (const TCHAR*)fileName);
			retval = MSG_WARNING;
		}
		else
		{
			m_FilesLoaded.insert(hszFileName.GetUniqueID());
		}
	}

	else if (extID == hszXmp.GetUniqueID())
	{
		bool success = LoadPlaylistFile(fileName);
		if (!success)
		{
			m_ToolBox->Log(LOGWARNING, _T("Failed to load playlist %s\n"), (const TCHAR*)fileName);
			retval = MSG_WARNING;
		}
		else
		{
			m_FilesLoaded.insert(hszFileName.GetUniqueID());
		}
	}

	return retval;
}
Example #5
0
void LoadGameData(void)
{
    SDL_Surface *tmp;

    /* The player's ship is stored as a 8640x96 image.
       This strip contains 90 individual images of the ship, rotated in
       four-degree increments. Take a look at fighter.bmp in an image
       viewer to see exactly what this means. */
    tmp = SDL_LoadBMP("fighter.bmp");
    if (tmp == NULL) {
	fprintf(stderr, "Unable to load ship image: %s\n", SDL_GetError());
	exit(1);
    }
	
    /* Set the color key on the ship animation strip to black.
       Enable RLE acceleration for a performance boost. */
    SDL_SetColorKey(tmp, SDL_SRCCOLORKEY|SDL_RLEACCEL, 0);
	
    /* Optimize the entire strip for fast display. */
    ship_strip = SDL_DisplayFormat(tmp);
    if (ship_strip == NULL) {
	/* We were unable to convert the image (for some foul reason),
	   but we can still use the copy we already have. This will
	   involve a performance loss. However, this should never happen. */
	ship_strip = tmp;
    } else SDL_FreeSurface(tmp);
	
    /* Now load the star tiles. Each tile is 64x64, assembled into a strip.
       We'll derive the number of tiles from the width of the loaded bitmap. */
    tmp = SDL_LoadBMP("back-stars.bmp");
    if (tmp == NULL) {
	fprintf(stderr, "Unable to load background tiles: %s\n", SDL_GetError());
	exit(1);
    }
	
    /* Determine how many star tiles are in the strip. We'll assume that the
       foreground and background strips contain the same number of stars. */
    num_star_tiles = tmp->w / 64;
    num_star_tiles = 4;
	
    /* Attempt to optimize this strip for fast blitting. */
    back_star_tiles = SDL_DisplayFormat(tmp);
    if (back_star_tiles == NULL)
	back_star_tiles = tmp;
    else
	SDL_FreeSurface(tmp);	

    /* Load the front (parallaxing) set of star tiles. */
    tmp = SDL_LoadBMP("front-stars.bmp");
    if (tmp == NULL) {
	printf("Unable to load parallax tiles: %s\n", SDL_GetError());
	exit(1);
    }
	
    /* Set a black color key and request RLE acceleration. */
    SDL_SetColorKey(tmp, SDL_SRCCOLORKEY | SDL_RLEACCEL, 0);

    /* Attempt to optimize this strip for fast blitting. */
    front_star_tiles = SDL_DisplayFormat(tmp);
    if (front_star_tiles == NULL)
	front_star_tiles = tmp;
    else
	SDL_FreeSurface(tmp);	

    /* Load sound data. */
    if (audio_enabled) {
	if (LoadSoundFile("engine.wav", &engine_sound) != 0) {
	    printf("Unable to load engine.wav.\n");
	    exit(1);
	}
		
	if (LoadSoundFile("phaser.wav", &phaser_sound) != 0) {
	    printf("Unable to load phaser.wav.\n");
	    exit(1);
	}
    }
}
Example #6
0
void CGeneral::LoadSound()
{
   if (g_fNoSound) {
      return;
   }

   m_snd[SND_DISCARD1] = LoadSoundFile(SOUND_DIR "discard.wav");
   m_snd[SND_DISCARD2] = LoadSoundFile(SOUND_DIR "discard2.wav");
   m_snd[SND_DING] = LoadSoundFile(SOUND_DIR "ding.wav");
   m_snd[SND_SOUND1] = LoadSoundFile(SOUND_DIR "snd1.wav");
   m_snd[SND_SOUND2] = LoadSoundFile(SOUND_DIR "snd2.wav");
   m_snd[SND_SOUND3] = LoadSoundFile(SOUND_DIR "snd3.wav");
   m_snd[SND_SOUND4] = LoadSoundFile(SOUND_DIR "snd4.wav");
   m_snd[SND_REACH] = LoadSoundFile(SOUND_DIR "reach.wav");

   m_snd[SND_BOOM] = LoadSoundFile(SOUND_DIR "boom.wav");
   m_snd[SND_FLASH] = LoadSoundFile(SOUND_DIR "flash.wav");
   m_snd[SND_FIRE] = LoadSoundFile(SOUND_DIR "fire.wav");
}
Example #7
0
// ==============================  INPUT HANDLING  ========================================
long TsounEditForm::DoControlClick( long arg, void *ptr )
{
#ifdef __MWERKS__
	#pragma unused(ptr)
#endif

	XGListControl *pList = dynamic_cast<XGListControl *>(GetWindow()->FindViewByID( 12314 ));
	int sel = pList->GetValue();

	tag_entry* e;
	tag new_id;
	
	switch( arg )
	{
		case 12302: // Choose a tag
			new_id = pick_tag_of_type( 'stli', GetTag( 12302 ), fEntry );
			if( new_id != 0 )
			{
				def.subtitle_string_list_tag = new_id;
				
				SetTag( 12302, 'stli', new_id );
				SetValues();
			}
			
		break; 
		
		case 12303: // Open tag window
			e = get_entry( 'stli', GetTag( 12302 ) );
			if( e )
				TRevengeApp::OpenItem( e );
		break;
		
		case 12315: // Add
			{
				assert( def.number_of_permutations < MAXIMUM_PERMUTATIONS_PER_SOUND );
				
				XGFileSpecifier *fs = NULL;

#if OPT_MACOS
				fs = XGFileSpecifier::OpenDialog( 129 );
#endif
#if OPT_WINOS
				fs = XGFileSpecifier::OpenDialog( "Wave Audio File|*.wav","WAV" );
#endif
#if OPT_XWIN
				fs = XGFileSpecifier::OpenDialog( "wav" );
#endif
		
			if( !fs )
				return 0;
			
			if( LoadSoundFile( def, fs ) == LOAD_SOUND_ERROR_SUCCESS )
			{
				pList->Insert( def.number_of_permutations, def.sound_permutations[def.number_of_permutations].name );
				pList->SetValue( def.number_of_permutations );
				
				def.number_of_permutations++;
				
				// update perutations size and sound_offset
				def.permutations_size += sizeof(sound_permutation_data);
				def.sound_offset += sizeof(sound_permutation_data);
				
				DoListSelect( 12314, NULL );
			}
			
			delete fs;
		}
		break;
		
		case 12316: // Duplicate
		{
			assert( def.number_of_permutations < MAXIMUM_PERMUTATIONS_PER_SOUND );
			assert( sel != -1 && sel < def.number_of_permutations && sel < MAXIMUM_PERMUTATIONS_PER_SOUND );
			
			int perm = def.number_of_permutations;
			int sample_size;
			
			// update our sound_size
			if( def.sampled_sound_headers[sel].flags & _sound_is_ima_compressed_flag )
				sample_size = def.sampled_sound_headers[sel].number_of_samples * sizeof(apple_ima_packet_chunk);
			else
				sample_size = def.sampled_sound_headers[sel].number_of_samples << def.sampled_sound_headers[sel].physical_bytes_per_sample_minus_one;
			
			def.sound_size += (sample_size + sizeof(sampled_sound_header));
			
			// copy the headers to the new permutaion slot
			def.sound_permutations[perm] = def.sound_permutations[sel];
			def.sampled_sound_headers[perm] = def.sampled_sound_headers[sel];
			
			// make a duplicate of the samples buffer
			assert( def.sampled_sound_headers[sel].samples );
			
			def.sampled_sound_headers[perm].samples = malloc( sample_size );
			memcpy( def.sampled_sound_headers[perm].samples, def.sampled_sound_headers[sel].samples, sample_size );

			def.number_of_permutations++;

			// update perutations size and sound_offset
			def.permutations_size += sizeof(sound_permutation_data);
			def.sound_offset += sizeof(sound_permutation_data);
			
			// update the permutation list			
			SetValues();
		}
		
		break;
		
		case 12317: // Delete
		{
			assert( def.number_of_permutations > 0 );
			assert( sel > -1 && sel < def.number_of_permutations && sel < MAXIMUM_PERMUTATIONS_PER_SOUND );
			
			int sample_size;
			int ii;
			
			// update our sound_size
			if( def.sampled_sound_headers[sel].flags & _sound_is_ima_compressed_flag )
				sample_size = def.sampled_sound_headers[sel].number_of_samples * sizeof(apple_ima_packet_chunk);
			else
				sample_size = def.sampled_sound_headers[sel].number_of_samples << def.sampled_sound_headers[sel].physical_bytes_per_sample_minus_one;
				
			def.sound_size -= (sample_size - sizeof(sampled_sound_header));
			assert( def.sound_size >= 0 );
			
			// free any data associated with our victim permutation
			assert( def.sampled_sound_headers[sel].samples ); // there is something wrong if no data here
			if( def.sampled_sound_headers[sel].samples )
				free( def.sampled_sound_headers[sel].samples );
			
			// move everything past the sel back one
			for( ii = sel; ii + 1 < def.number_of_permutations; ii++ )
			{
				def.sound_permutations[ii] = def.sound_permutations[ii + 1];
				def.sampled_sound_headers[ii] = def.sampled_sound_headers[ii + 1];
			}
			
			// zero out the extra permutation
			memset( &def.sound_permutations[ii], 0x00, sizeof(sound_permutation_data) );
			memset( &def.sampled_sound_headers[ii], 0x00, sizeof(sampled_sound_header) );
			
			def.number_of_permutations--;

			// update perutations size and sound_offset
			def.permutations_size -= sizeof(sound_permutation_data);
			def.sound_offset -= sizeof(sound_permutation_data);
			
			// remove the item from the permutation list
			SetValues();
		}

		break;
		
		case 12319: // Play sound
		{
			assert( def.number_of_permutations > 0 );
			assert( sel > -1 && sel < def.number_of_permutations && sel < MAXIMUM_PERMUTATIONS_PER_SOUND );
			
			PlaySoundFile();
		}
		
		break;
		
		default:
			return -1;
	}
	
	UpdatePermutationControls();
	
	return 0;
}