/* ================= S_StreamBackgroundTrack ================= */ void S_StreamBackgroundTrack( void ) { int bufferSamples; int fileSamples; byte raw[MAX_RAW_SAMPLES]; int r, fileBytes; float musicVolume = 0.5f; if( !s_bgTrack.stream ) 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 < soundtime ) s_rawend = soundtime; while( s_rawend < soundtime + MAX_RAW_SAMPLES ) { wavdata_t *info = FS_StreamInfo( s_bgTrack.stream ); bufferSamples = MAX_RAW_SAMPLES - (s_rawend - soundtime); // decide how much data needs to be read from the file fileSamples = bufferSamples * info->rate / dma.speed; // our max buffer size fileBytes = fileSamples * ( info->width * info->channels ); if( fileBytes > sizeof( raw )) { fileBytes = sizeof( raw ); fileSamples = fileBytes / ( info->width * info->channels ); } // read r = FS_ReadStream( s_bgTrack.stream, fileBytes, raw ); if( r < fileBytes ) { fileBytes = r; fileSamples = r / ( info->width * info->channels ); } if( r > 0 ) { // add to raw buffer // FIXME: apply musicVolume S_StreamRawSamples( fileSamples, info->rate, info->width, info->channels, raw ); } else { // loop if( s_bgTrack.loopName[0] ) { FS_CloseStream( s_bgTrack.stream ); s_bgTrack.stream = NULL; S_StartBackgroundTrack( s_bgTrack.loopName, s_bgTrack.loopName ); if( !s_bgTrack.stream ) return; } else { S_StopBackgroundTrack(); return; } } } }
/* ================= S_StreamBackgroundTrack ================= */ void S_StreamBackgroundTrack( void ) { int bufferSamples; int fileSamples; byte raw[MAX_RAW_SAMPLES]; int r, fileBytes; if( !dma.initialized ) return; if( !s_bgTrack.stream ) return; if( s_listener.streaming ) return; // we are playing movie or somewhat // don't bother playing anything if musicvolume is 0 if( !s_musicvolume->value || s_listener.paused || s_listener.stream_paused ) return; if( !cl.background ) { // pause music by source type if( s_bgTrack.source == key_game && cls.key_dest == key_menu ) return; if( s_bgTrack.source == key_menu && cls.key_dest != key_menu ) return; } else if( cls.key_dest == key_console ) return; // see how many samples should be copied into the raw buffer if( s_rawend < soundtime ) s_rawend = soundtime; while( s_rawend < soundtime + MAX_RAW_SAMPLES ) { wavdata_t *info = FS_StreamInfo( s_bgTrack.stream ); bufferSamples = MAX_RAW_SAMPLES - (s_rawend - soundtime); // decide how much data needs to be read from the file fileSamples = bufferSamples * ((float)info->rate / SOUND_DMA_SPEED ); if( fileSamples <= 1 ) return; // no more samples need // our max buffer size fileBytes = fileSamples * ( info->width * info->channels ); if( fileBytes > sizeof( raw )) { fileBytes = sizeof( raw ); fileSamples = fileBytes / ( info->width * info->channels ); } // read r = FS_ReadStream( s_bgTrack.stream, fileBytes, raw ); if( r < fileBytes ) { fileBytes = r; fileSamples = r / ( info->width * info->channels ); } if( r > 0 ) { // add to raw buffer S_StreamRawSamples( fileSamples, info->rate, info->width, info->channels, raw ); } else { // loop if( s_bgTrack.loopName[0] ) { FS_FreeStream( s_bgTrack.stream ); s_bgTrack.stream = FS_OpenStream( va( "media/%s", s_bgTrack.loopName )); Q_strncpy( s_bgTrack.current, s_bgTrack.loopName, sizeof( s_bgTrack.current )); if( !s_bgTrack.stream ) return; S_CheckLerpingState(); } else { S_StopBackgroundTrack(); return; } } } }