mirror of
https://github.com/libretro/scummvm.git
synced 2024-12-15 06:08:35 +00:00
more cleanup
svn-id: r9982
This commit is contained in:
parent
b62c527fa0
commit
1fc3c0be23
@ -1123,412 +1123,6 @@ int32 Sword2Sound::StreamCompMusic(const char *filename, uint32 musicId, int32 l
|
||||
musStreaming[primaryStream] = 1;
|
||||
musCounter[primaryStream] = 250;
|
||||
return RD_OK;
|
||||
|
||||
/*
|
||||
HRESULT hr;
|
||||
LPVOID lpv1, lpv2;
|
||||
DWORD dwBytes1, dwBytes2;
|
||||
uint32 i,j;
|
||||
int32 v0, v1;
|
||||
uint16 *data16;
|
||||
uint8 *data8;
|
||||
|
||||
// Do not allow compressed and uncompressed music to be streamed at the same time.
|
||||
if (compressedMusic == 2)
|
||||
return (RDERR_FXFUCKED);
|
||||
|
||||
compressedMusic = 1;
|
||||
|
||||
if (musStreaming[0] + musStreaming[1] == 0) // No music streaming at present.
|
||||
{
|
||||
i = 0;
|
||||
|
||||
musLooping[i] = looping; // Save looping info
|
||||
strcpy(musFilename[i], filename); // And tune id's
|
||||
musId[i] = musicId;
|
||||
|
||||
if (IsMusicMute()) // Don't start streaming if the volume is off.
|
||||
return (RD_OK);
|
||||
|
||||
if (!fpMus[0])
|
||||
fpMus[0] = fopen(filename, "rb"); // Always use fpMus[0] (all music in one cluster) musFilePos[i] for different pieces of music.
|
||||
if (fpMus[0] == NULL)
|
||||
return(RDERR_INVALIDFILENAME);
|
||||
|
||||
if (fseek(fpMus[0], (musicId+1)*8, SEEK_SET)) // Seek to music index
|
||||
{
|
||||
fclose(fpMus[0]);
|
||||
fpMus[0] = 0;
|
||||
return (RDERR_READERROR);
|
||||
}
|
||||
|
||||
if (fread(&musFilePos[i], sizeof(uint32), 1, fpMus[0]) != 1) // Read music index
|
||||
{
|
||||
fclose(fpMus[0]);
|
||||
fpMus[0] = 0;
|
||||
return (RDERR_READERROR);
|
||||
}
|
||||
|
||||
if (fread(&musEnd[i], sizeof(uint32), 1, fpMus[0]) != 1) // Read music length
|
||||
{
|
||||
fclose(fpMus[0]);
|
||||
fpMus[0] = 0;
|
||||
return (RDERR_READERROR);
|
||||
}
|
||||
|
||||
if (!musEnd[i] || !musFilePos[i]) // Check that music is valid (has length & offset)
|
||||
{
|
||||
fclose(fpMus[0]);
|
||||
fpMus[0] = 0;
|
||||
return (RDERR_INVALIDID);
|
||||
}
|
||||
|
||||
musEnd[i] += musFilePos[i]; // Calculate the file position of the end of the music
|
||||
|
||||
streamCursor[i] = 0; // Reset streaming cursor and store looping flag
|
||||
|
||||
memset(&wfMus[i], 0, sizeof(PCMWAVEFORMAT)); // Set up wave format (no headers in cluster)
|
||||
wfMus[i].wf.wFormatTag = WAVE_FORMAT_PCM;
|
||||
wfMus[i].wf.nChannels = 1;
|
||||
wfMus[i].wf.nSamplesPerSec = 22050;
|
||||
wfMus[i].wBitsPerSample = 16;
|
||||
wfMus[i].wf.nBlockAlign = 2;
|
||||
wfMus[i].wf.nAvgBytesPerSec = 44100;
|
||||
|
||||
// Reset the sample format and size
|
||||
memset(&dsbdMus[i], 0, sizeof(DSBUFFERDESC));
|
||||
dsbdMus[i].dwSize = sizeof(DSBUFFERDESC);
|
||||
// dsbdMus[i].dwFlags = DSBCAPS_CTRLDEFAULT;
|
||||
dsbdMus[i].dwBufferBytes = 3 * wfMus[i].wf.nAvgBytesPerSec; // 3 seconds
|
||||
dsbdMus[i].lpwfxFormat = (LPWAVEFORMATEX) &wfMus[i];
|
||||
|
||||
// Create a temporary buffer
|
||||
if ((data8 = malloc(dsbdMus[i].dwBufferBytes/2)) == NULL) // Allocate a compressed data buffer
|
||||
{
|
||||
fclose(fpMus[0]);
|
||||
fpMus[0] = 0;
|
||||
return(RDERR_OUTOFMEMORY);
|
||||
}
|
||||
|
||||
// Seek to start of the compressed music
|
||||
if (fseek(fpMus[0], musFilePos[i], SEEK_SET))
|
||||
{
|
||||
fclose(fpMus[0]);
|
||||
fpMus[0] = 0;
|
||||
free(data8);
|
||||
return (RDERR_INVALIDID);
|
||||
}
|
||||
|
||||
// Read the compressed data in to the buffer
|
||||
if (fread(data8, sizeof(uint8), dsbdMus[i].dwBufferBytes/2, fpMus[0]) != dsbdMus[i].dwBufferBytes/2)
|
||||
{
|
||||
fclose(fpMus[0]);
|
||||
fpMus[0] = 0;
|
||||
free(data8);
|
||||
return (RDERR_INVALIDID);
|
||||
}
|
||||
|
||||
// Store the current position in the file for future streaming
|
||||
musFilePos[i] = ftell(fpMus[0]);
|
||||
|
||||
// Create the music buffer
|
||||
hr = IDirectSound_CreateSoundBuffer(lpDS, &dsbdMus[i], &lpDsbMus[i], NULL);
|
||||
if (hr == DS_OK)
|
||||
{
|
||||
hr = IDirectSoundBuffer_Lock(lpDsbMus[i], 0, dsbdMus[i].dwBufferBytes, &lpv1, &dwBytes1, &lpv2, &dwBytes2, 0);
|
||||
|
||||
if (hr == DSERR_BUFFERLOST)
|
||||
|
||||
{
|
||||
IDirectSoundBuffer_Restore(lpDsbMus[i]);
|
||||
hr = IDirectSoundBuffer_Lock(lpDsbMus[i], 0, dsbdMus[i].dwBufferBytes, &lpv1, &dwBytes1, &lpv2, &dwBytes2, 0);
|
||||
}
|
||||
|
||||
if (hr == DS_OK)
|
||||
{
|
||||
// decompress the music into the music buffer.
|
||||
data16 = (uint16*)lpv1;
|
||||
|
||||
data16[0] = *((int16*)data8); // First sample value
|
||||
j=1;
|
||||
|
||||
while (j<(dwBytes1/2)-1)
|
||||
{
|
||||
if (GetCompressedSign(data8[j+1]))
|
||||
data16[j] = data16[j-1] - (GetCompressedAmplitude(data8[j+1])<<GetCompressedShift(data8[j+1]));
|
||||
else
|
||||
data16[j] = data16[j-1] + (GetCompressedAmplitude(data8[j+1])<<GetCompressedShift(data8[j+1]));
|
||||
j++;
|
||||
}
|
||||
|
||||
// Never need to fill lpv2 because we started at the begining of the sound buffer
|
||||
|
||||
// Store the value of the last sample ready for next batch of decompression
|
||||
musLastSample[i] = data16[j-1];
|
||||
|
||||
// Free the decompression buffer and unlock the buffer now that we've filled it
|
||||
free(data8);
|
||||
IDirectSoundBuffer_Unlock(lpDsbMus[i], lpv1, dwBytes1, lpv2, dwBytes2);
|
||||
|
||||
// Modify the volume according to the master volume and music mute state
|
||||
if (musicMuted)
|
||||
v0 = v1 = 0;
|
||||
else
|
||||
{
|
||||
v0 = volMusic[0];
|
||||
v1 = volMusic[1];
|
||||
}
|
||||
|
||||
if (v0 > v1)
|
||||
{
|
||||
IDirectSoundBuffer_SetVolume(lpDsbMus[i], musicVolTable[v0]);
|
||||
IDirectSoundBuffer_SetPan(lpDsbMus[i], musicVolTable[v1*16/v0]);
|
||||
}
|
||||
else
|
||||
{
|
||||
if (v1 > v0)
|
||||
{
|
||||
IDirectSoundBuffer_SetVolume(lpDsbMus[i], musicVolTable[v1]);
|
||||
IDirectSoundBuffer_SetPan(lpDsbMus[i], -musicVolTable[v0*16/v1]);
|
||||
}
|
||||
else
|
||||
{
|
||||
IDirectSoundBuffer_SetVolume(lpDsbMus[i], musicVolTable[v1]);
|
||||
IDirectSoundBuffer_SetPan(lpDsbMus[i], 0);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// Start the sound effect playing
|
||||
IDirectSoundBuffer_Play(lpDsbMus[i], 0, 0, DSBPLAY_LOOPING);
|
||||
|
||||
// Recorder some last variables
|
||||
musStreaming[i] = 1;
|
||||
musCounter[i] = 250;
|
||||
|
||||
// and exit the function.
|
||||
}
|
||||
else
|
||||
{
|
||||
// Opps Failed to lock the sound buffer
|
||||
fclose(fpMus[0]);
|
||||
fpMus[0] = 0;
|
||||
return(RDERR_LOCKFAILED);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
// Opps Failed to create the sound buffer
|
||||
fclose(fpMus[0]);
|
||||
fpMus[0] = 0;
|
||||
return(RDERR_CREATESOUNDBUFFER);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (musStreaming[0] + musStreaming[1] == 2) // Both streams in use, try to find a fading stream
|
||||
{
|
||||
if (musFading[0])
|
||||
i = 0;
|
||||
else
|
||||
i = 1;
|
||||
|
||||
musFading[i] = 0;
|
||||
IDirectSoundBuffer_Stop(lpDsbMus[i]);
|
||||
IDirectSoundBuffer_Release(lpDsbMus[i]);
|
||||
musStreaming[i] = 0;
|
||||
}
|
||||
|
||||
if (musStreaming[0] + musStreaming[1] == 1) // Some music is already streaming
|
||||
{
|
||||
i = musStreaming[0]; // Set i to the free channel
|
||||
|
||||
musLooping[i] = looping; // Save looping info
|
||||
strcpy(musFilename[i], filename); // And tune id's
|
||||
musId[i] = musicId;
|
||||
|
||||
if (IsMusicMute()) // Don't start streaming if the volume is off.
|
||||
return (RD_OK);
|
||||
|
||||
if (!fpMus[0])
|
||||
fpMus[0] = fopen(filename, "rb"); // Always use fpMus[0] (all music in one cluster) musFilePos[i] for different pieces of music.
|
||||
if (fpMus[0] == NULL)
|
||||
return(RDERR_INVALIDFILENAME);
|
||||
|
||||
|
||||
if (!musFading[1-i]) // Start other music stream fading out
|
||||
musFading[1 - i] = -16;
|
||||
|
||||
streamCursor[i] = 0; // Reset the streaming cursor for this sample
|
||||
|
||||
if (fseek(fpMus[0], (musicId+1)*8, SEEK_SET)) // Seek to music index
|
||||
{
|
||||
fclose(fpMus[0]);
|
||||
fpMus[0] = 0;
|
||||
return (RDERR_READERROR);
|
||||
}
|
||||
|
||||
if (fread(&musFilePos[i], sizeof(uint32), 1, fpMus[0]) != 1) // Read music index
|
||||
{
|
||||
fclose(fpMus[0]);
|
||||
fpMus[0] = 0;
|
||||
return (RDERR_READERROR);
|
||||
}
|
||||
|
||||
if (fread(&musEnd[i], sizeof(uint32), 1, fpMus[0]) != 1) // Read music length
|
||||
{
|
||||
fclose(fpMus[0]);
|
||||
fpMus[0] = 0;
|
||||
return (RDERR_READERROR);
|
||||
}
|
||||
|
||||
if (!musEnd[i] || !musFilePos[i]) // Check that music is valid (has length & offset)
|
||||
{
|
||||
fclose(fpMus[0]);
|
||||
fpMus[0] = 0;
|
||||
return (RDERR_INVALIDID);
|
||||
}
|
||||
|
||||
musEnd[i] += musFilePos[i]; // Calculate the file position of the end of the music
|
||||
|
||||
memset(&wfMus[i], 0, sizeof(PCMWAVEFORMAT)); // Set up the music format info
|
||||
wfMus[i].wf.wFormatTag = WAVE_FORMAT_PCM;
|
||||
wfMus[i].wf.nChannels = 1;
|
||||
wfMus[i].wf.nSamplesPerSec = 22050;
|
||||
wfMus[i].wBitsPerSample = 16;
|
||||
wfMus[i].wf.nBlockAlign = 2;
|
||||
wfMus[i].wf.nAvgBytesPerSec = 44100;
|
||||
|
||||
// Reset the sample format and size
|
||||
memset(&dsbdMus[i], 0, sizeof(DSBUFFERDESC));
|
||||
dsbdMus[i].dwSize = sizeof(DSBUFFERDESC);
|
||||
// dsbdMus[i].dwFlags = DSBCAPS_CTRLDEFAULT;
|
||||
dsbdMus[i].dwBufferBytes = 3 * wfMus[i].wf.nAvgBytesPerSec; // 3 seconds
|
||||
dsbdMus[i].lpwfxFormat = (LPWAVEFORMATEX) &wfMus[i];
|
||||
|
||||
// Allocate a compressed data buffer
|
||||
if ((data8 = malloc(dsbdMus[i].dwBufferBytes/2)) == NULL)
|
||||
{
|
||||
fclose(fpMus[0]);
|
||||
fpMus[0] = 0;
|
||||
return(RDERR_OUTOFMEMORY);
|
||||
}
|
||||
|
||||
// Seek to start of the compressed music
|
||||
if (fseek(fpMus[0], musFilePos[i], SEEK_SET))
|
||||
{
|
||||
fclose(fpMus[0]);
|
||||
fpMus[0] = 0;
|
||||
free(data8);
|
||||
return (RDERR_INVALIDID);
|
||||
}
|
||||
|
||||
// Read the compressed data in to the buffer
|
||||
if (fread(data8, sizeof(uint8), dsbdMus[i].dwBufferBytes/2, fpMus[0]) != dsbdMus[i].dwBufferBytes/2)
|
||||
{
|
||||
fclose(fpMus[0]);
|
||||
fpMus[0] = 0;
|
||||
free(data8);
|
||||
return (RDERR_INVALIDID);
|
||||
}
|
||||
|
||||
// Store the current position in the file for future streaming
|
||||
musFilePos[i] = ftell(fpMus[0]);
|
||||
|
||||
// Create the sound effect sample buffer
|
||||
hr = IDirectSound_CreateSoundBuffer(lpDS, &dsbdMus[i], &lpDsbMus[i], NULL);
|
||||
if (hr == DS_OK)
|
||||
{
|
||||
hr = IDirectSoundBuffer_Lock(lpDsbMus[i], 0, dsbdMus[i].dwBufferBytes, &lpv1, &dwBytes1, &lpv2, &dwBytes2, 0);
|
||||
|
||||
if (hr == DSERR_BUFFERLOST)
|
||||
{
|
||||
IDirectSoundBuffer_Restore(lpDsbMus[i]);
|
||||
hr = IDirectSoundBuffer_Lock(lpDsbMus[i], 0, dsbdMus[i].dwBufferBytes, &lpv1, &dwBytes1, &lpv2, &dwBytes2, 0);
|
||||
}
|
||||
|
||||
if (hr == DS_OK)
|
||||
{
|
||||
|
||||
// decompress the music into the music buffer.
|
||||
data16 = (uint16*)lpv1;
|
||||
|
||||
data16[0] = *((int16*)data8); // First sample value
|
||||
j=1;
|
||||
|
||||
while (j<(dwBytes1/2)-1)
|
||||
{
|
||||
if (GetCompressedSign(data8[j+1]))
|
||||
data16[j] = data16[j-1] - (GetCompressedAmplitude(data8[j+1])<<GetCompressedShift(data8[j+1]));
|
||||
else
|
||||
data16[j] = data16[j-1] + (GetCompressedAmplitude(data8[j+1])<<GetCompressedShift(data8[j+1]));
|
||||
j++;
|
||||
}
|
||||
|
||||
// Never need to fill lpv2 because we started at the begining of the sound buffer
|
||||
|
||||
// Store the value of the last sample ready for next batch of decompression
|
||||
musLastSample[i] = data16[j-1];
|
||||
|
||||
// Free the compressiong buffer and unlock the buffer now that we've filled it
|
||||
free(data8);
|
||||
IDirectSoundBuffer_Unlock(lpDsbMus[i], lpv1, dwBytes1, lpv2, dwBytes2);
|
||||
|
||||
// Modify the volume according to the master volume and music mute state
|
||||
if (musicMuted)
|
||||
v0 = v1 = 0;
|
||||
else
|
||||
{
|
||||
v0 = volMusic[0];
|
||||
v1 = volMusic[1];
|
||||
}
|
||||
|
||||
|
||||
if (v0 > v1)
|
||||
{
|
||||
IDirectSoundBuffer_SetVolume(lpDsbMus[i], musicVolTable[v0]);
|
||||
IDirectSoundBuffer_SetPan(lpDsbMus[i], musicVolTable[v1*16/v0]);
|
||||
}
|
||||
else
|
||||
{
|
||||
if (v1 > v0)
|
||||
{
|
||||
IDirectSoundBuffer_SetVolume(lpDsbMus[i], musicVolTable[v1]);
|
||||
IDirectSoundBuffer_SetPan(lpDsbMus[i], -musicVolTable[v0*16/v1]);
|
||||
}
|
||||
else
|
||||
{
|
||||
IDirectSoundBuffer_SetVolume(lpDsbMus[i], musicVolTable[v1]);
|
||||
IDirectSoundBuffer_SetPan(lpDsbMus[i], 0);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// Start the sound effect playing
|
||||
IDirectSoundBuffer_Play(lpDsbMus[i], 0, 0, DSBPLAY_LOOPING);
|
||||
|
||||
// Record the last variables for streaming and looping
|
||||
musStreaming[i] = 1;
|
||||
musCounter[i] = 250;
|
||||
}
|
||||
else
|
||||
{
|
||||
// Opps failed to lock the sound buffer
|
||||
fclose(fpMus[0]);
|
||||
fpMus[0] = 0;
|
||||
return(RDERR_LOCKFAILED);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
// Opps failed to create the sound buffer
|
||||
fclose(fpMus[0]);
|
||||
fpMus[0] = 0;
|
||||
return(RDERR_CREATESOUNDBUFFER);
|
||||
}
|
||||
}
|
||||
}
|
||||
*/
|
||||
}
|
||||
|
||||
void Sword2Sound::UpdateCompSampleStreaming(void) {
|
||||
@ -1562,19 +1156,13 @@ void Sword2Sound::UpdateCompSampleStreaming(void) {
|
||||
if (v0 > v1) {
|
||||
volume = musicVolTable[v0];
|
||||
pan = (musicVolTable[v1 * 16 / v0] / 2) - 127;
|
||||
// IDirectSoundBuffer_SetVolume(lpDsbMus[i], musicVolTable[v0]);
|
||||
// IDirectSoundBuffer_SetPan(lpDsbMus[i], musicVolTable[v1*16/v0]);
|
||||
} else {
|
||||
if (v1 > v0) {
|
||||
volume = musicVolTable[v1];
|
||||
pan = (musicVolTable[v0 * 16 / v1] / 2) + 127;
|
||||
// IDirectSoundBuffer_SetVolume(lpDsbMus[i], musicVolTable[v1]);
|
||||
// IDirectSoundBuffer_SetPan(lpDsbMus[i], -musicVolTable[v0*16/v1]);
|
||||
} else {
|
||||
volume = musicVolTable[v1];
|
||||
pan = 0;
|
||||
// IDirectSoundBuffer_SetVolume(lpDsbMus[i], musicVolTable[v1]);
|
||||
// IDirectSoundBuffer_SetPan(lpDsbMus[i], 0);
|
||||
}
|
||||
g_engine->_mixer->setChannelVolume(soundHandleMusic[i], volume);
|
||||
g_engine->_mixer->setChannelPan(soundHandleMusic[i], pan);
|
||||
@ -1672,212 +1260,6 @@ void Sword2Sound::UpdateCompSampleStreaming(void) {
|
||||
}
|
||||
}
|
||||
DipMusic();
|
||||
|
||||
/*
|
||||
|
||||
uint32 i,j,k;
|
||||
int32 v0, v1;
|
||||
int32 len;
|
||||
int32 readCursor, writeCursor;
|
||||
int32 dwBytes1, dwBytes2;
|
||||
LPVOID lpv1, lpv2;
|
||||
HRESULT hr;
|
||||
uint16 *data16;
|
||||
uint8 *data8;
|
||||
int fade;
|
||||
|
||||
|
||||
for (i=0; i<MAXMUS; i++)
|
||||
{
|
||||
if (musStreaming[i])
|
||||
{
|
||||
if (musFading[i])
|
||||
{
|
||||
if (musFading[i] < 0)
|
||||
{
|
||||
if (++musFading[i] == 0)
|
||||
{
|
||||
IDirectSoundBuffer_Stop(lpDsbMus[i]);
|
||||
IDirectSoundBuffer_Release(lpDsbMus[i]);
|
||||
musStreaming[i] = 0;
|
||||
musLooping[i] = 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
// Modify the volume according to the master volume and music mute state
|
||||
if (musicMuted)
|
||||
v0 = v1 = 0;
|
||||
else
|
||||
{
|
||||
v0 = (volMusic[0] * (0 - musFading[i]) / 16);
|
||||
v1 = (volMusic[1] * (0 - musFading[i]) / 16);
|
||||
}
|
||||
|
||||
if (v0 > v1)
|
||||
{
|
||||
IDirectSoundBuffer_SetVolume(lpDsbMus[i], musicVolTable[v0]);
|
||||
IDirectSoundBuffer_SetPan(lpDsbMus[i], musicVolTable[v1*16/v0]);
|
||||
}
|
||||
else
|
||||
{
|
||||
if (v1 > v0)
|
||||
{
|
||||
IDirectSoundBuffer_SetVolume(lpDsbMus[i], musicVolTable[v1]);
|
||||
IDirectSoundBuffer_SetPan(lpDsbMus[i], -musicVolTable[v0*16/v1]);
|
||||
}
|
||||
else
|
||||
{
|
||||
IDirectSoundBuffer_SetVolume(lpDsbMus[i], musicVolTable[v1]);
|
||||
IDirectSoundBuffer_SetPan(lpDsbMus[i], 0);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (IDirectSoundBuffer_GetCurrentPosition(lpDsbMus[i], &readCursor, &writeCursor) != DS_OK)
|
||||
{
|
||||
// Failed to get read and write positions
|
||||
IDirectSoundBuffer_Stop(lpDsbMus[i]);
|
||||
}
|
||||
|
||||
|
||||
// Caluculate the amount of data to load into the sound buffer
|
||||
len = readCursor - streamCursor[i];
|
||||
if (len < 0)
|
||||
{
|
||||
len += dsbdMus[i].dwBufferBytes; // Wrap around !
|
||||
}
|
||||
|
||||
// Reduce length if it requires reading past the end of the music
|
||||
if (musFilePos[i]+len >= musEnd[i])
|
||||
{
|
||||
len = musEnd[i] - musFilePos[i];
|
||||
fade = 1; // End of music reaced so we'll need to fade and repeat
|
||||
}
|
||||
else
|
||||
fade = 0;
|
||||
|
||||
if (len > 0)
|
||||
{
|
||||
hr = IDirectSoundBuffer_Lock(lpDsbMus[i], streamCursor[i], len, &lpv1, &dwBytes1, &lpv2, &dwBytes2, 0);
|
||||
if (hr == DSERR_BUFFERLOST)
|
||||
{
|
||||
IDirectSoundBuffer_Restore(lpDsbMus[i]);
|
||||
hr = IDirectSoundBuffer_Lock(lpDsbMus[i], streamCursor[i], len, &lpv1, &dwBytes1, &lpv2, &dwBytes2, 0);
|
||||
}
|
||||
|
||||
if (hr == DS_OK)
|
||||
{
|
||||
streamCursor[i] += len;
|
||||
if (streamCursor[i] >= (int32) dsbdMus[i].dwBufferBytes)
|
||||
streamCursor[i] -= dsbdMus[i].dwBufferBytes;
|
||||
|
||||
// Allocate a compressed data buffer
|
||||
if ((data8 = malloc(len/2)) == NULL)
|
||||
{
|
||||
fclose(fpMus[0]);
|
||||
fpMus[0] = 0;
|
||||
musFading[i] = -16;
|
||||
}
|
||||
|
||||
// Seek to update position of compressed music when neccassary (probably never occurs)
|
||||
if (ftell(fpMus[0]) != musFilePos[i])
|
||||
fseek(fpMus[0], musFilePos[i], SEEK_SET);
|
||||
|
||||
// Read the compressed data in to the buffer
|
||||
if (fread(data8, sizeof(uint8), len/2, fpMus[0]) != (size_t)len/2)
|
||||
{
|
||||
fclose(fpMus[0]);
|
||||
fpMus[0] = 0;
|
||||
free(data8);
|
||||
musFading[i] = -16;
|
||||
return;
|
||||
}
|
||||
|
||||
// Update the current position in the file for future streaming
|
||||
musFilePos[i] = ftell(fpMus[0]);
|
||||
|
||||
// decompress the music into the music buffer.
|
||||
data16 = (uint16*)lpv1;
|
||||
|
||||
// Decompress the first byte using the last decompressed sample
|
||||
if (GetCompressedSign(data8[0]))
|
||||
data16[0] = musLastSample[i] - (GetCompressedAmplitude(data8[0])<<GetCompressedShift(data8[0]));
|
||||
else
|
||||
data16[0] = musLastSample[i] + (GetCompressedAmplitude(data8[0])<<GetCompressedShift(data8[0]));
|
||||
|
||||
j = 1;
|
||||
|
||||
// Decompress the rest of lpv1
|
||||
while (j<(uint32)dwBytes1/2)
|
||||
{
|
||||
if (GetCompressedSign(data8[j]))
|
||||
data16[j] = data16[j-1] - (GetCompressedAmplitude(data8[j])<<GetCompressedShift(data8[j]));
|
||||
else
|
||||
data16[j] = data16[j-1] + (GetCompressedAmplitude(data8[j])<<GetCompressedShift(data8[j]));
|
||||
j++;
|
||||
}
|
||||
|
||||
// Store the value of the last sample ready for next batch of decompression
|
||||
musLastSample[i] = data16[j-1];
|
||||
|
||||
if (dwBytes1 < len) // The buffer has wrapped so we need to decompress to lpv2 as well
|
||||
{
|
||||
data16 = (uint16*)lpv2;
|
||||
|
||||
// Decompress first sample int lpv2 from lastsample in lpv1
|
||||
if (GetCompressedSign(data8[j]))
|
||||
data16[0] = musLastSample[i] - (GetCompressedAmplitude(data8[j])<<GetCompressedShift(data8[j]));
|
||||
else
|
||||
data16[0] = musLastSample[i] + (GetCompressedAmplitude(data8[j])<<GetCompressedShift(data8[j]));
|
||||
|
||||
j++;
|
||||
k = 1;
|
||||
|
||||
// Decompress the rest of lpv2
|
||||
while (k<(uint32)dwBytes2/2)
|
||||
{
|
||||
if (GetCompressedSign(data8[j]))
|
||||
data16[k] = data16[k-1] - (GetCompressedAmplitude(data8[j])<<GetCompressedShift(data8[j]));
|
||||
else
|
||||
data16[k] = data16[k-1] + (GetCompressedAmplitude(data8[j])<<GetCompressedShift(data8[j]));
|
||||
j++;
|
||||
k++;
|
||||
}
|
||||
|
||||
// Store the value of the last sample ready for next batch of decompression
|
||||
musLastSample[i] = data16[k-1];
|
||||
}
|
||||
|
||||
// Free the compressed data buffer and unlock the sound buffer.
|
||||
free(data8);
|
||||
IDirectSoundBuffer_Unlock(lpDsbMus[i], lpv1, dwBytes1, lpv2, dwBytes2);
|
||||
|
||||
// End of the music so we need to start fading and start the music again
|
||||
if (fade)
|
||||
{
|
||||
musFading[i] = -16; // Fade the old music
|
||||
|
||||
// Close the music cluster if it's open
|
||||
if (fpMus[0])
|
||||
{
|
||||
fclose(fpMus[0]);
|
||||
fpMus[0] = 0;
|
||||
}
|
||||
|
||||
// Loop if neccassary
|
||||
if (musLooping[i])
|
||||
StreamCompMusic(musFilename[i], musId[i], musLooping[i]);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
DipMusic();
|
||||
*/
|
||||
}
|
||||
|
||||
int32 Sword2Sound::DipMusic() {
|
||||
@ -1958,7 +1340,6 @@ int32 Sword2Sound::DipMusic() {
|
||||
|
||||
int32 Sword2Sound::MusicTimeRemaining() {
|
||||
int i;
|
||||
// int32 readCursor;
|
||||
|
||||
for (i = 0; i < MAXMUS && !musStreaming[i]; i++) {
|
||||
// this is meant to be empty! (James19aug97)
|
||||
@ -1968,8 +1349,6 @@ int32 Sword2Sound::MusicTimeRemaining() {
|
||||
return 0;
|
||||
|
||||
return (musEnd[i] - musFilePos[i]) / 22050;
|
||||
// TODO: plus channel offset
|
||||
// return (((132300 - readCursor) / 2 + (musEnd[i] - musFilePos[i])) / 22050);
|
||||
}
|
||||
|
||||
void Sword2Sound::StopMusic(void) {
|
||||
@ -2019,6 +1398,7 @@ int32 Sword2Sound::UnpauseMusic(void) {
|
||||
|
||||
void Sword2Sound::SetMusicVolume(uint8 volume) {
|
||||
int i;
|
||||
|
||||
for (i = 0; i < MAXMUS; i++) {
|
||||
volMusic[i] = volume;
|
||||
if (musStreaming[i] && !musFading[i] && !musicMuted) {
|
||||
|
Loading…
Reference in New Issue
Block a user