Made AGI's 4-channel PCjr sound not need structure packing pragmas anymore. Also added more use of little endian reading macros.

svn-id: r28624
This commit is contained in:
Kari Salminen 2007-08-15 15:55:38 +00:00
parent 429af74320
commit 4d83eef351
2 changed files with 24 additions and 19 deletions

View File

@ -420,7 +420,7 @@ void SoundMgr::startSound(int resnum, int flag) {
}
chn[i].ins = waveform;
chn[i].size = WAVEFORM_SIZE;
chn[i].ptr = (struct AgiNote *)(song + (song[i << 1] | (song[(i << 1) + 1] << 8)));
chn[i].ptr = song + READ_LE_UINT16(song + i * 2);
chn[i].timer = 0;
chn[i].vol = 0;
chn[i].end = 0;
@ -586,7 +586,7 @@ void SoundMgr::playMidiSound() {
}
chn[0].timer = *p++;
chn[0].ptr = (struct AgiNote *)p;
chn[0].ptr = p;
if (*p >= 0xfc) {
debugC(3, kDebugLevelSound, "end of sequence");
@ -603,24 +603,25 @@ void SoundMgr::playSampleSound() {
#endif /* USE_IIGS_SOUND */
void SoundMgr::playAgiSound() {
int i, freq;
int i;
AgiNote note;
for (playing = i = 0; i < (_vm->_soundemu == SOUND_EMU_PC ? 1 : 4); i++) {
playing |= !chn[i].end;
note.read(chn[i].ptr); // Read a single note (Doesn't advance the pointer)
if (chn[i].end)
continue;
if ((--chn[i].timer) <= 0) {
stopNote(i);
freq = ((chn[i].ptr->frq0 & 0x3f) << 4) | (int)(chn[i].ptr->frq1 & 0x0f);
if (freq) {
uint8 v = chn[i].ptr->vol & 0x0f;
playNote(i, freq * 10, v == 0xf ? 0 : 0xff - (v << 1));
if (note.freqDiv != 0) {
int volume = (note.attenuation == 0x0F) ? 0 : (0xFF - note.attenuation * 2);
playNote(i, note.freqDiv * 10, volume);
}
chn[i].timer = ((int)chn[i].ptr->durHi << 8) | chn[i].ptr->durLo;
chn[i].timer = note.duration;
if (chn[i].timer == 0xffff) {
chn[i].end = 1;
@ -634,7 +635,7 @@ void SoundMgr::playAgiSound() {
}
#endif
}
chn[i].ptr++;
chn[i].ptr += 5; // Advance the pointer to the next note data (5 bytes per note)
}
}
}

View File

@ -177,20 +177,24 @@ struct IIgsSampleHeader {
bool finalize(Common::SeekableReadStream &uint8Wave);
};
#include "common/pack-start.h"
/**
* AGI sound note structure.
*/
struct AgiNote {
uint8 durLo; /**< LSB of note duration */
uint8 durHi; /**< MSB of note duration */
uint8 frq0; /**< LSB of note frequency */
uint8 frq1; /**< MSB of note frequency */
uint8 vol; /**< note volume */
};
uint16 duration; ///< Note duration
uint16 freqDiv; ///< Note frequency divisor (10-bit)
uint8 attenuation; ///< Note volume attenuation (4-bit)
#include "common/pack-end.h"
/** Reads an AgiNote through the given pointer. */
void read(uint8 *ptr) {
duration = READ_LE_UINT16(ptr);
uint16 freqByte0 = *(ptr + 2); // Bits 4-9 of the frequency divisor
uint16 freqByte1 = *(ptr + 3); // Bits 0-3 of the frequency divisor
// Merge the frequency divisor's bits together into a single variable
freqDiv = ((freqByte0 & 0x3F) << 4) | (freqByte1 & 0x0F);
attenuation = *(ptr + 4) & 0x0F;
}
};
/**
* AGI engine sound channel structure.
@ -200,7 +204,7 @@ struct ChannelInfo {
#define AGI_SOUND_MIDI 0x0002
#define AGI_SOUND_4CHN 0x0008
uint32 type;
struct AgiNote *ptr;
uint8 *ptr; // Pointer to the AgiNote data
int16 *ins;
int32 size;
uint32 phase;