Beispiel #1
0
void sfx::load_sound_effects( JsonObject &jsobj )
{
    if( !sound_init_success ) {
        return;
    }
    const id_and_variant key( jsobj.get_string( "id" ), jsobj.get_string( "variant", "default" ) );
    const int volume = jsobj.get_int( "volume", 100 );
    auto &effects = sfx_resources.sound_effects[ key ];

    JsonArray jsarr = jsobj.get_array( "files" );
    while( jsarr.has_more() ) {
        sound_effect new_sound_effect;
        const std::string file = jsarr.next_string();
        new_sound_effect.volume = volume;
        new_sound_effect.resource_id = add_sfx_path( file );

        effects.push_back( new_sound_effect );
    }
}
Beispiel #2
0
static i4_voice_class *load_sfx(s1_sfx_ref &ref)
{
	char buf[200];

	// don't try if no sound
	if (i4_sound_man==&i4_null_sound)
	{
		return 0;
	}

	i4_file_class * fp=i4_open(add_sfx_path(ref.name, buf));
	if (!fp)
	{
		i4_warning("sfx missing %s (%s:%d)\n", ref.name,
				   ref.file_defined_in, ref.line_defined_on);
		return 0;
	}

	i4_sound_info info;
	i4_load_wav_info(fp, info);

	if (info.channels==2)
	{
		i4_warning("%s is stereo sound (waste of memory)\n", ref.name);
	}

	if (info.sample_rate>22*1024)
	{
		i4_warning("%s is %dHz (waste of memory)\n", ref.name, info.sample_rate);
	}
	else if (show_sfx)
	{
		i4_warning("%s is %dHz\n", ref.name, info.sample_rate);
	}


	i4_sound_manager_class::sound_parameters p;
	p.channels=info.channels;
	p.sample_size=info.sample_size;
	p.frequency=info.sample_rate;
	//Newer use looping sounds here (must use i4_stream_wav_player for this)
	//Reason: We won't ever restore the buffer again for non-streamed sfx
	if (ref.flags & S1_3D)
	{
		p.capable_3d=i4_T;
	}

	i4_voice_class * v = i4_sound_man->alloc(info.size, p);
	if (v)
	{
		void * b1,* b2;
		w32 s1,s2;

		v->lock(0, info.size, b1, s1, b2, s2);
		fp->read(b1,s1);
		v->unlock(b1, s1, b2, s2);
	}
	delete fp;

	return v;
}
Beispiel #3
0
void s1_sfx_ref::play(float x, float y, float z)
{
	// int i;
	if (!base_sfx && ((flags&S1_STREAMED)==0))
	{
		return ;
	}

	// sound is too far away
	if ((flags&S1_3D) && get_dist_sqrd(x,y,z)>hearable_distance_sqrd)
	{
		return ;
	}

	int use=find_channel(this, 0);

	if (use!=-1)
	{
		int fail=0;
		i4_voice_class * s=0;

		channels[use].stream=0;
		if (flags&S1_STREAMED)
		{
			char fn[100];
			if (i4_sound_man==&i4_null_sound)
			{
				fail=1;
			}
			else
			{
				i4_file_class * fp=i4_open(add_sfx_path(name,fn));
				if (fp)
				{
					i4_stream_wav_player * stream;
					stream=new i4_stream_wav_player(fp, 64*1024, i4_F, i4_T);
					if (stream->load_failed())
					{
						//i4_warning("stream load failed");
						delete stream;
						fail=1;
					}
					else
					{
						channels[use].stream=stream;
						s=stream->i4_voice();
					}
				}
				else
				{
					fail=1;
				}
			}
		}
		else
		{
			s=i4_sound_man->duplicate_3d(base_sfx);
		}



		if (!fail && s)
		{
			if (flags & S1_3D)
			{
				s->set_3d_position(-y,z,x,i4_T);
			}

			if ((flags &S1_STREAMED)==0)
			{
				s->play();
			}

			channels[use].voice=s;
			channels[use].originator=this;
			channels[use].loop_handler=0;
		}
		else
		{
			channels[use].free();
		}

	}
}