09-04-2022, 10:40 PM
A silly program to test Impulse Tracker module playback, and PCM data creation from it on QB64 Phoenix Edition v3.1:
Download the Impulse Tracker music file from here:
https://modarchive.org/module.php?189056
Press [ESC] to quit the program.
Create executable and copy the IT file you downloaded into the same folder. I'm sorry about hardwiring the value of "afile$". This should work with any module format, the problem is that the longer the song file is, the longer "_SNDOPEN" takes to load it into RAM. Now this could apply to music tracker modules despite their usually being much smaller than MP3 and WAV and formats like that.
Code: (Select All)
option _explicit
dim afile$, soundf as long
$IF 64BIT THEN
dim as _integer64 soundbg, soundsz, c
$ELSE
dim as long soundbg, soundsz, c
$END IF
dim b as _mem, bb as _byte, h as _byte
dim sacr$(1 to 10)
randomize (timer mod 16)
afile$ = "retro_expirement.it"
print "Please wait, loading song:"
print afile$
soundf = _sndopen(afile$)
if soundf = -1 then print "Failed to open tracker music.": end
b = _memsound(soundf, 1)
soundbg = ConvertOffset(b.OFFSET)
soundsz = ConvertOffset(b.OFFSET + b.SIZE)
soundsz = soundsz - soundbg
c = 0
h = 1
sacr$(h) = space$(3998)
_sndplay soundf
do while c < soundsz
bb = _memget(b, b.OFFSET + c, _byte)
if bb < 32 then bb = 95
mid$(sacr$(h), p, 1) = chr$(bb)
p = p + 1
if p > 3998 then
p = 1
h = h + 1
if h > 10 then exit do
sacr$(h) = space$(3998)
end if
c = c + 1
loop
do
_limit 10
locate 1, 1
print sacr$(int(rnd * 10 + 1));
if not _sndplaying(soundf) then exit do
loop until _keydown(27)
_sndstop soundf
_sndclose soundf
system
FUNCTION ConvertOffset&& (value AS _OFFSET)
$CHECKING:OFF
DIM m AS _MEM 'Define a memblock
m = _MEM(value) 'Point it to use value
$IF 64BIT THEN
dim i64ret as _integer64
'On 64 bit OSes, an OFFSET is 8 bytes in size. We can put it directly into an Integer64
_MEMGET m, m.OFFSET, i64ret 'Get the contents of the memblock and put the values there directly into ConvertOffset&&
ConvertOffset&& = i64ret
$ELSE
dim temp&
'However, on 32 bit OSes, an OFFSET is only 4 bytes. We need to put it into a LONG variable first
_MEMGET m, m.OFFSET, temp& 'Like this
ConvertOffset&& = temp& 'And then assign that long value to ConvertOffset&&
$END IF
_MEMFREE m 'Free the memblock
$CHECKING:ON
END FUNCTION
Download the Impulse Tracker music file from here:
https://modarchive.org/module.php?189056
Press [ESC] to quit the program.
Create executable and copy the IT file you downloaded into the same folder. I'm sorry about hardwiring the value of "afile$". This should work with any module format, the problem is that the longer the song file is, the longer "_SNDOPEN" takes to load it into RAM. Now this could apply to music tracker modules despite their usually being much smaller than MP3 and WAV and formats like that.