mirror of
https://github.com/kichikuou/system3-sdl2.git
synced 2026-10-01 19:37:55 +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:
+5
-4
@@ -408,7 +408,7 @@ void MAKO::get_mark(int* mark, int* loop)
|
||||
midi->get_mark(mark, loop);
|
||||
}
|
||||
|
||||
void MAKO::play_pcm(int page, bool loop)
|
||||
void MAKO::play_pcm(int page, int loops)
|
||||
{
|
||||
static char header[44] = {
|
||||
'R' , 'I' , 'F' , 'F' , 0x00, 0x00, 0x00, 0x00, 'W' , 'A' , 'V' , 'E' , 'f' , 'm' , 't' , ' ' ,
|
||||
@@ -424,7 +424,8 @@ void MAKO::play_pcm(int page, bool loop)
|
||||
std::vector<uint8_t> buffer = amse.load(page);
|
||||
if (!buffer.empty()) {
|
||||
// AMSE形式 (乙女戦記)
|
||||
int samples = (static_cast<int>(buffer.size()) - 12) * 2;
|
||||
uint32_t amse_size = SDL_SwapLE32(*reinterpret_cast<uint32_t*>(&buffer[8]));
|
||||
int samples = (static_cast<int>(amse_size) - 12) * 2;
|
||||
int total = samples + 0x24;
|
||||
|
||||
wav_buffer.resize(total + 8);
|
||||
@@ -437,13 +438,13 @@ 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;
|
||||
}
|
||||
}
|
||||
}
|
||||
PlaySound((LPCTSTR)wav_buffer.data(), NULL, SND_ASYNC | SND_MEMORY | (loop ? SND_LOOP : 0));
|
||||
PlaySound((LPCTSTR)wav_buffer.data(), NULL, SND_ASYNC | SND_MEMORY | (loops ? 0 : SND_LOOP));
|
||||
}
|
||||
|
||||
void MAKO::stop_pcm()
|
||||
|
||||
Reference in New Issue
Block a user