spotlessmind1975 / ugbasic

An isomorphic BASIC language compiler for retrocomputers
Apache License 2.0
92 stars 16 forks source link

MUSIC does not work under cpc #1009

Closed poppichicken closed 2 days ago

poppichicken commented 2 days ago

hi Marco.

page 198:

image

This compiles, but doesn't play anything. Has it been implemented on CPC?

Note that I used "example.mid" from your examples folder. If I used "what_a_wonderful_world.mid" from the examples folder, the CPC would make some random sounds and then appear to crash.

 BITMAP ENABLE(320,200,4)
 COLOR BORDER WHITE
 CLS BLACK
 DEFINE KEYBOARD ASYNC

 soundtrack := LOAD MUSIC ("example.mid") 
 MUSIC soundtrack
spotlessmind1975 commented 2 days ago

Hi @poppichicken , and thank you for your kind bug report!

I just checked the sources, and the implementation is there. Now I'll check why nothing plays. But keep in mind that the MIDI format is not played directly, but converted internally to the IMF format before being stored in the executable. So, at the moment, it seems that IMF audio does not play. I'll investigate.

Thank you again!

spotlessmind1975 commented 2 days ago

Hi @poppichicken , finally I fixed this issue.

First of all I added two test files to the repository: scale.mid and scale.mscz, which can be opened with the program MuseScore Studio (64-bit) 4.4.3-242971445. I then changed your example program to open this file.

image

As you can see, this file contains a tempered scale composed of 12 notes, ranging from NOTE C5 to the NOTE C6, with various volume levels. I purposely created the file so simple, so as not to create too much confusion induced by the multiplexing mechanisms of the IMF audio channels. So, this MIDI soundtrack is translated into IMF with the following sequence of commands:

PICCOLO (FLUTE) 
NOTE C5 (49/255 volume level) for about 120 ms
NOTE D5 (49/255 volume level) for about 120 ms
NOTE E5 (96/255 volume level) for about 120 ms
...

The commands are played correctly.

All the problems has been fixed in HOTFIX v1.16.4 [rev. 20241110] for cpc target. I kindly ask you to use UGBASIC-IDE to download the new version of the compiler or, if you use the command line, to download it directly by accessing this link: https://ugbasic.iwashere.eu/install

Thank you!

poppichicken commented 1 day ago

That's very cool. It works well.