mirror of
https://github.com/kichikuou/system3-sdl2.git
synced 2026-10-01 03:18:07 +03:00
Fix Y103 command (play_pcm)
* The parameter is the number of times to loop, e.g. Y103,2: will play the sound twice. This still does not work on Windows because PlaySound() does not support specifying the loop count. * Get AMSE data size from its header. This fixes audio glitch at the end of sounds.
This commit is contained in:
@@ -100,7 +100,7 @@ void MAKO::get_mark(int* mark, int* loop)
|
||||
}
|
||||
}
|
||||
|
||||
void MAKO::play_pcm(int page, bool loop)
|
||||
void MAKO::play_pcm(int page, int loops)
|
||||
{
|
||||
static const char header[44] = {
|
||||
'R' , 'I' , 'F' , 'F' , 0x00, 0x00, 0x00, 0x00,
|
||||
@@ -117,7 +117,8 @@ void MAKO::play_pcm(int page, bool loop)
|
||||
std::vector<uint8_t> buffer = amse.load(page);
|
||||
if (!buffer.empty()) {
|
||||
// AMSE形式 (乙女戦記)
|
||||
int samples = (buffer.size() - 12) * 2;
|
||||
uint32_t amse_size = SDL_SwapLE32(*reinterpret_cast<uint32_t*>(&buffer[8]));
|
||||
int samples = (amse_size - 12) * 2;
|
||||
int total = samples + 0x24;
|
||||
|
||||
wav_buffer.resize(total + 8);
|
||||
@@ -130,14 +131,14 @@ void MAKO::play_pcm(int page, bool loop)
|
||||
wav_buffer[41] = (samples >> 8) & 0xff;
|
||||
wav_buffer[42] = (samples >> 16) & 0xff;
|
||||
wav_buffer[43] = (samples >> 24) & 0xff;
|
||||
for (size_t i = 12, p = 44; i < buffer.size(); i++) {
|
||||
for (uint32_t i = 12, p = 44; i < amse_size; i++) {
|
||||
wav_buffer[p++] = buffer[i] & 0xf0;
|
||||
wav_buffer[p++] = (buffer[i] & 0x0f) << 4;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (muspcm_load_data(wav_buffer.data(), wav_buffer.size()))
|
||||
EM_ASM({ xsystem35.audio.pcm_start(0, $0); }, loop ? 0 : 1);
|
||||
EM_ASM({ xsystem35.audio.pcm_start(0, $0); }, loops);
|
||||
}
|
||||
|
||||
void MAKO::stop_pcm() {
|
||||
|
||||
Reference in New Issue
Block a user