SEQ sample (Sega MIDI-style music playback) for SRL#108
SEQ sample (Sega MIDI-style music playback) for SRL#108Frogbull wants to merge 12 commits intoReyeMe:mainfrom
Conversation
Heavely inspired by the Jo Engine sample made by jfsantos (João Felipe Santos) https://github.com/jfsantos/mid2seq
ReyeMe
left a comment
There was a problem hiding this comment.
Looked through the sample, and the SEQ playback loks simple enough.
But, as is now I cannot let it pass, since it cannot be used properly with other parts of SRL, especially PCM playback.
SRL already includes the sound driver, so there is no need to duplicate that. I would also prefer the backround music functions to be wrapped nicely and available through the Sound class, simmilar to CDDA and PCM.
I guess there is no way to change SEQ without reinitializing sound?
Samples/Sound - SEQ/src/main.cxx
Outdated
|
|
||
| void Initialize_SoundSystem_SEQ_SaturnMIDI(void) | ||
| { | ||
| slInitSound(sddrvstsk, sizeof(sddrvstsk), (uint8_t *)mechs_map, sizeof(mechs_map) ); |
There was a problem hiding this comment.
since slInitSound is already called within SRL, woudn't it be better to implement this as a propper API instead of this hack?
There was a problem hiding this comment.
Yeah, way better and it will avoid conflict with PCM/CDDA
Samples/Sound - SEQ/src/main.cxx
Outdated
| uint8_t seqVolume = 127; | ||
|
|
||
| // Auto-Play the SEQ music track | ||
| slBGMOn((1 << 8) + 0, 0, seqVolume, 0); |
There was a problem hiding this comment.
I am fine with direct SGL calls, but again, woudn't it be better to implement this as proper API?
Also: Magic numbers
There was a problem hiding this comment.
yeah, (1 << 8) + 0 for the track index looks weird. And totaly agreed to make proper API to handle all this properly.
slBGMOn(SongIndex, Priority, Volume, Rate);
SongIndex: Uint16 for SEQ Track Index
Priority: Uint8 for Priority (range only from 0 to 31. The larger the value, the higher the priority)
Volume: Uint8 for Track Volume (range only from 0 to 127)
Rate: Uint8 for Track Rate (range from 0 to 255)
https://www.jo-engine.org/upload/files/SEGA/ST-238-R1-051795.pdf
Samples/Sound - SEQ/src/main.cxx
Outdated
| @@ -0,0 +1,138 @@ | |||
| #include "SDDRVS.DAT" | |||
There was a problem hiding this comment.
sound driver is already included with SRL, and is loaded when initialize is called
There was a problem hiding this comment.
Great, I don't know well your code, if we can track when it's loaded we could set a proper SoundMem Address 👍
There was a problem hiding this comment.
here is where the init will happen https://github.com/ReyeMe/SaturnRingLib/blob/main/saturnringlib/srl_sound.hpp#L50
Samples/Sound - SEQ/src/main.cxx
Outdated
| tonFILE.LoadBytes(0, tonFILE.Size.Bytes, tonBuf); | ||
|
|
||
| // SEQ data | ||
| slDMACopy(seqBuf, (void *)((uint8_t*)SoundMem + 0x21fdc), seqFILE.Size.Bytes); |
There was a problem hiding this comment.
what does this magic number means?
There was a problem hiding this comment.
The driver has probably an allocated buffer for SEQ data starting at +0x21fdc (but I'm not sure)
Samples/Sound - SEQ/src/main.cxx
Outdated
| slDMACopy(seqBuf, (void *)((uint8_t*)SoundMem + 0x21fdc), seqFILE.Size.Bytes); | ||
|
|
||
| // TON data | ||
| slDMACopy(tonBuf, (void *)((uint8_t*)SoundMem + 0x2737c), tonFILE.Size.Bytes); |
There was a problem hiding this comment.
what does this magic number means?
There was a problem hiding this comment.
The driver has probably an allocated buffer for TON data starting at +0x2737c (but I'm not sure)
Samples/Sound - SEQ/src/main.cxx
Outdated
| SRL::Debug::Print(1,9, "Press Left/Right to change the Tempo"); | ||
| if (pad.WasPressed(SRL::Input::Digital::Button::Left)) | ||
| { | ||
| if (musicTempo > -32768+16) |
There was a problem hiding this comment.
slBGMTempo(Tempo)
Tempo: Sint16 (range from -32768 to 32767)
https://www.jo-engine.org/upload/files/SEGA/ST-238-R1-051795.pdf
Do you have -32768 or 32767 defined as max value for a Sint16?
There was a problem hiding this comment.
you can use INT16_MAX, and INT16_MIN
Samples/Sound - SEQ/src/main.cxx
Outdated
| } | ||
| else if (pad.WasPressed(SRL::Input::Digital::Button::Right)) | ||
| { | ||
| if (musicTempo < 32767-16) |
There was a problem hiding this comment.
Same as -32768 (Sint16 max positive value)
Integrated SEQ Support (optional)
With better integration in SRL
SRL_USE_SGL_SOUND_DRIVER = 1
|
Updated:
|
saturnringlib/srl_sound.hpp
Outdated
| } | ||
|
|
||
| #if SRL_ENABLE_AUDIO_SEQ_SUPPORT == 1 | ||
| uint8_t audio_map_seq[] = { |
There was a problem hiding this comment.
why does this need to be defined here?
- constant defined outside of namespace
- constant naming does not follow style quideline
saturnringlib/srl_sound.hpp
Outdated
| #include <sega_pcm.h> | ||
| } | ||
|
|
||
| #if SRL_ENABLE_AUDIO_SEQ_SUPPORT == 1 |
There was a problem hiding this comment.
special define should not be needed, the way you have done it now is a hack that will work with that sample, its not generic
saturnringlib/srl_sound.hpp
Outdated
| SND_ChgMap(0); | ||
|
|
||
| slInitSound(programBuffer, program.Size.Bytes, areaMapBuffer, areaMap.Size.Bytes); | ||
| #if SRL_ENABLE_AUDIO_SEQ_SUPPORT == 1 |
There was a problem hiding this comment.
not a generic solution, and will not allow to load different map during runtime
There was a problem hiding this comment.
I've a new solution that allow CUSTOM.MAP (no more MAP array in the C)
| @@ -0,0 +1,144 @@ | |||
| #define SRL_ENABLE_AUDIO_SEQ_SUPPORT 1 | |||
| #define SoundMem 0x25a0b000 // The playback data is stored starting from address 0xB000 in the MC68000 memory area (0x25A0B000 in the program) https://antime.kapsi.fi/sega/files/ST-237-R1-051795.pdf | |||
There was a problem hiding this comment.
this should be handled within a wrapper, not used by sample directly
Samples/Sound - SEQ/src/main.cxx
Outdated
| SRL::Core::Initialize(SRL::Types::HighColor::Colors::Black); | ||
|
|
||
| // Load and initialize a Saturn SEQ music track (Sega MIDI-style music playback) | ||
| Load_SEQ_SaturnMIDI(); |
There was a problem hiding this comment.
function name does not follow style quidelines
Example, to generate a map: python saturn_map_generator.py input_seq_ton CUSTOM.MAP Example, to convert a MIDI (format 0) file: python saturn_mid2seq.py FF7_Battle.mid FF7.SEQ
- Direct-Read of the MAP file to find the memory offsets (no more magic numbers for the offsets) - Now able to load on the fly any SEQ/TON file - Now able to Pause/Resume
Heavely inspired by the Jo Engine sample made by jfsantos (João Felipe Santos) https://github.com/jfsantos/mid2seq