Exemplo n.º 1
0
/*
======================
S_StartBackgroundTrack
======================
*/
void S_Base_StartBackgroundTrack( const char *intro, const char *loop, float volume, float loopVolume ) {
	if ( !intro ) {
		intro = "";
	}
	if ( !loop || !loop[0] ) {
		loop = intro;
	}
	Com_DPrintf( "S_StartBackgroundTrack( %s, %s, %f, %f )\n", intro, loop, volume, loopVolume );

	if(!*intro)
	{
		S_Base_StopBackgroundTrack();
		return;
	}

	s_backgroundVolume = Com_Clamp(0, 10, volume);
	s_backgroundLoopVolume = Com_Clamp(0, 10, loopVolume);

	if( !loop ) {
		s_backgroundLoop[0] = 0;
	} else {
		Q_strncpyz( s_backgroundLoop, loop, sizeof( s_backgroundLoop ) );
	}

	S_OpenBackgroundStream( intro );
}
Exemplo n.º 2
0
/*
==================
S_StopAllSounds
==================
*/
void S_Base_StopAllSounds(void) {
	if ( !s_soundStarted ) {
		return;
	}

	// stop the background music
	S_Base_StopBackgroundTrack();

	S_Base_ClearSoundBuffer ();
}
Exemplo n.º 3
0
Arquivo: dma.c Projeto: icanhas/yantar
static void
S_Base_StopAllSounds(void)
{
    if(!s_soundStarted)
        return;

    /* stop the background music */
    S_Base_StopBackgroundTrack();

    S_Base_ClearSoundBuffer ();
}
Exemplo n.º 4
0
/*
======================
S_Base_StartBackgroundTrack
======================
*/
static void S_Base_StartBackgroundTrack( const char *intro, const char *loop ){
	if ( !intro ) {
		intro = "";
	}
	if ( !loop || !loop[0] ) {
		loop = intro;
	}
	//Com_DPrintf( "S_StartBackgroundTrack( %s, %s )\n", intro, loop );
	//Com_Printf( "S_StartBackgroundTrack( %s, %s )\n", intro, loop );

	if(!*intro)
	{
		S_Base_StopBackgroundTrack();
		return;
	}

	Q_strncpyz( s_backgroundLoop, loop, sizeof( s_backgroundLoop ) );

	S_OpenBackgroundStream( intro );
}
Exemplo n.º 5
0
/*
======================
S_StartBackgroundTrack
======================
*/
void S_Base_StartBackgroundTrack( const char *intro, const char *loop ){
	if ( !intro ) {
		intro = "";
	}
	if ( !loop || !loop[0] ) {
		loop = intro;
	}
	Com_DPrintf( "S_StartBackgroundTrack( %s, %s )\n", intro, loop );

	if(!*intro)
	{
		S_Base_StopBackgroundTrack();
		return;
	}

	if( !loop ) {
		s_backgroundLoop[0] = 0;
	} else {
		Q_strncpyz( s_backgroundLoop, loop, sizeof( s_backgroundLoop ) );
	}

	// close the background track, but DON'T reset s_rawend
	// if restarting the same back ground track
	if(s_backgroundStream)
	{
		S_CodecCloseStream(s_backgroundStream);
		s_backgroundStream = NULL;
	}

	// Open stream
	s_backgroundStream = S_CodecOpenStream(intro);
	if(!s_backgroundStream) {
		Com_Printf( S_COLOR_YELLOW "WARNING: couldn't open music file %s\n", intro );
		return;
	}

	if(s_backgroundStream->info.channels != 2 || s_backgroundStream->info.rate != 22050) {
		Com_Printf(S_COLOR_YELLOW "WARNING: music file %s is not 22k stereo\n", intro );
	}
}
Exemplo n.º 6
0
Arquivo: dma.c Projeto: icanhas/yantar
static void
S_Base_StartBackgroundTrack(const char *intro, const char *loop)
{
    if(!intro)
        intro = "";
    if(!loop || !loop[0])
        loop = intro;
    comdprintf("sndstartbackgroundtrack( %s, %s )\n", intro, loop);

    if(!*intro) {
        S_Base_StopBackgroundTrack();
        return;
    }

    if(!loop)
        s_backgroundLoop[0] = 0;
    else
        Q_strncpyz(s_backgroundLoop, loop, sizeof(s_backgroundLoop));

    /* close the background track, but DON'T reset s_rawend
     * if restarting the same back ground track */
    if(s_backgroundStream) {
        S_CodecCloseStream(s_backgroundStream);
        s_backgroundStream = NULL;
    }

    /* Open stream */
    s_backgroundStream = S_CodecOpenStream(intro);
    if(!s_backgroundStream) {
        comprintf(S_COLOR_YELLOW "WARNING: couldn't open music file %s\n",
                  intro);
        return;
    }

    if(s_backgroundStream->info.channels != 2 ||
            s_backgroundStream->info.rate != 22050)
        comprintf(S_COLOR_YELLOW
                  "WARNING: music file %s is not 22k stereo\n",
                  intro);
}
Exemplo n.º 7
0
/*
======================
S_UpdateBackgroundTrack
======================
*/
void S_UpdateBackgroundTrack( void ) {
	int		bufferSamples;
	int		fileSamples;
	byte	raw[30000];		// just enough to fit in a mac stack frame
	int		fileBytes;
	int		r;

	if(!s_backgroundStream) {
		return;
	}

	// don't bother playing anything if musicvolume is 0
	if ( s_musicVolume->value <= 0 ) {
		return;
	}

	// see how many samples should be copied into the raw buffer
	if ( s_rawend[0] < s_soundtime ) {
		s_rawend[0] = s_soundtime;
	}

	while ( s_rawend[0] < s_soundtime + MAX_RAW_SAMPLES ) {
		bufferSamples = MAX_RAW_SAMPLES - (s_rawend[0] - s_soundtime);

		// decide how much data needs to be read from the file
		fileSamples = bufferSamples * s_backgroundStream->info.rate / dma.speed;

		if (!fileSamples)
			return;

		// our max buffer size
		fileBytes = fileSamples * (s_backgroundStream->info.width * s_backgroundStream->info.channels);
		if ( fileBytes > sizeof(raw) ) {
			fileBytes = sizeof(raw);
			fileSamples = fileBytes / (s_backgroundStream->info.width * s_backgroundStream->info.channels);
		}

		// Read
		r = S_CodecReadStream(s_backgroundStream, fileBytes, raw);
		if(r < fileBytes)
		{
			fileBytes = r;
			fileSamples = r / (s_backgroundStream->info.width * s_backgroundStream->info.channels);
		}

		if(r > 0)
		{
			// add to raw buffer
			S_Base_RawSamples(0, fileSamples, s_backgroundStream->info.rate,
				s_backgroundStream->info.width, s_backgroundStream->info.channels, raw, s_musicVolume->value, -1);
		}
		else
		{
			// loop
			if(s_backgroundLoop[0])
			{
				S_CodecCloseStream(s_backgroundStream);
				s_backgroundStream = NULL;
				S_Base_StartBackgroundTrack( s_backgroundLoop, s_backgroundLoop );
				if(!s_backgroundStream)
					return;
			}
			else
			{
				S_Base_StopBackgroundTrack();
				return;
			}
		}

	}
}
Exemplo n.º 8
0
/*
======================
S_UpdateBackgroundTrack
======================
*/
void S_UpdateBackgroundTrack( void ) {
	int		bufferSamples;
	int		fileSamples;
	byte	raw[30000];		// just enough to fit in a mac stack frame
	int		fileBytes;
	int		r;
	static	float	musicVolume = 0.5f;

	if(!s_backgroundStream) {
		return;
	}

	// graeme see if this is OK
	musicVolume = (musicVolume + (s_musicVolume->value * 2))/4.0f;

	// don't bother playing anything if musicvolume is 0
	if ( musicVolume <= 0 ) {
		return;
	}

	// see how many samples should be copied into the raw buffer
	if ( s_rawend < s_soundtime ) {
		s_rawend = s_soundtime;
	}

	while ( s_rawend < s_soundtime + MAX_RAW_SAMPLES ) {
		bufferSamples = MAX_RAW_SAMPLES - (s_rawend - s_soundtime);

		// decide how much data needs to be read from the file
		fileSamples = (bufferSamples * dma.speed) / s_backgroundStream->info.rate;

		// our max buffer size
		fileBytes = fileSamples * (s_backgroundStream->info.width * s_backgroundStream->info.channels);
		if ( fileBytes > sizeof(raw) ) {
			fileBytes = sizeof(raw);
			fileSamples = fileBytes / (s_backgroundStream->info.width * s_backgroundStream->info.channels);
		}

		// Read
		r = S_CodecReadStream(s_backgroundStream, fileBytes, raw);
		if(r < fileBytes)
		{
			fileBytes = r;
			fileSamples = r / (s_backgroundStream->info.width * s_backgroundStream->info.channels);
		}

		if(r > 0)
		{
			// add to raw buffer
			S_Base_RawSamples( fileSamples, s_backgroundStream->info.rate,
				s_backgroundStream->info.width, s_backgroundStream->info.channels, raw, musicVolume );
		}
		else
		{
			// loop
			if(s_backgroundLoop[0])
			{
				S_OpenBackgroundStream( s_backgroundLoop );
				if(!s_backgroundStream)
					return;
			}
			else
			{
				S_Base_StopBackgroundTrack();
				return;
			}
		}

	}
}
Exemplo n.º 9
0
Arquivo: dma.c Projeto: icanhas/yantar
void
sndupdatebackgroundtrack(void)
{
    int	bufferSamples;
    int	fileSamples;
    byte	raw[30000];	/* just enough to fit in a mac stack frame */
    int	fileBytes;
    int	r;

    if(!s_backgroundStream)
        return;
    if(s_musicVolume->value <= 0)
        return;

    /* see how many samples should be copied into the raw buffer */
    if(s_rawend[0] < s_soundtime)
        s_rawend[0] = s_soundtime;
    while(s_rawend[0] < s_soundtime + MAX_RAW_SAMPLES) {
        bufferSamples = MAX_RAW_SAMPLES - (s_rawend[0] - s_soundtime);

        /* decide how much data needs to be read from the file */
        fileSamples = bufferSamples * s_backgroundStream->info.rate /
                      dma.speed;

        if(!fileSamples)
            return;

        /* our max buffer size */
        fileBytes = fileSamples *
                    (s_backgroundStream->info.width *
                     s_backgroundStream->info.channels);
        if(fileBytes > sizeof(raw)) {
            fileBytes = sizeof(raw);
            fileSamples = fileBytes /
                          (s_backgroundStream->info.width *
                           s_backgroundStream->info.channels);
        }

        r = S_CodecReadStream(s_backgroundStream, fileBytes, raw);
        if(r < fileBytes) {
            fileBytes = r;
            fileSamples = r / (s_backgroundStream->info.width *
                               s_backgroundStream->info.channels);
        }

        if(r > 0)
            /* add to raw buffer */
            S_Base_RawSamples(0, fileSamples,
                              s_backgroundStream->info.rate,
                              s_backgroundStream->info.width,
                              s_backgroundStream->info.channels, raw,
                              s_musicVolume->value,
                              -1);
        else {
            /* loop */
            if(s_backgroundLoop[0]) {
                S_CodecCloseStream(s_backgroundStream);
                s_backgroundStream = NULL;
                S_Base_StartBackgroundTrack(s_backgroundLoop,
                                            s_backgroundLoop);
                if(!s_backgroundStream)
                    return;
            } else {
                S_Base_StopBackgroundTrack();
                return;
            }
        }

    }
}