CPCWiki forum

General Category => Programming => Topic started by: teopl on 21:32, 02 February 19

Title: cpctelera arkos 2 conversion problem
Post by: teopl on 21:32, 02 February 19
Hi everyone!

I have a problem trying to play Arkos2 song using cpctelera 1.4 - the sound just doesn't play.

I have attached zip with code and everything showing 2 versions which differ only in generated music (.h and .s) but the version with music generated from Arkos2 doesn't play.

More detailed info:

Version OK:
---
- used Arkos1 song "molusk.aks"
- converted with script like this: "cpct_aks2c -m 0x40 -o all_music -od src -id song00 assets/molusk.aks"
- script used Arkos1 conversion binary with only "-a" option to set address

Version NOT OK:
---
- used Arkos2 song "excellence.aks"
-  converted with script like this: "cpct_aks2c.arkos2.sh -m 0x40 -o all_music -od src -id song00 assets/excellence.aks"
- script used Arkos2 conversion binary with options "-adr" for address and "-bin" to export binary

PS

I have read similar topic here "www.cpcwiki.eu/forum/programming/(cpctelera)-help-needed-for-converted-arkos-player-2/" but I just don't understand the issue, so any help would be great...
Title: Re: cpctelera arkos 2 conversion problem
Post by: Arnaud on 11:27, 03 February 19
Hello,
first of all, Arkos2 is not compatible with Arkos1 and CPCTelera provides only Arkos1 support.
You cannot use either the converter and the player of CPCTelera to play Arkos2 songs and Fx.

For information Arkos2 provides the players in Arkos Tracker 2\players

Here a working version of your code for Arkos2, i used another song (HarmelessGrenard).
The zip contains the player LightWeight (in arkos2PLayer/) compatible with SDCC/CPCTelera.

To export another song go to "File -> Export -> Export as LightWeight (AKL)" and export as "Source File" you can uncheck "Generate configuration file"
Save your file with .s extension, and you'll have to make some simple modifications in the file (see song/grenade.s as example)

Have fun with Arkos2  :)
Arnaud

Title: Re: cpctelera arkos 2 conversion problem
Post by: teopl on 13:28, 03 February 19
Thank you Arnaud, all worked well - your code and also I managed to export and use my song.

I have put the song on 0x40 (I am not sure what is first safe place to put it - any idea?) and these are the code changes I made on the exported song:

(https://i.imgur.com/FZnGH2x.png)
Title: Re: cpctelera arkos 2 conversion problem
Post by: Arnaud on 13:36, 03 February 19
When exporting song in src assembly, there is no need to specify the memory address, the C compiler will locate the song data for us.

This new feature of Arkos2 is really useful !
Title: Re: cpctelera arkos 2 conversion problem
Post by: teopl on 14:14, 03 February 19
But where is the song then located in memory?

(Sorry if I missed something - I don't quite understand the memory layout and how everything works)

My logic to move the song to 0x40 was:

Since the stack grows from 0xC000 downwards, I wanted to pack memory like this:

0x0040 - 0x ? ? ? ? : song
0x ? ? ? ? - 0x$$$$ : code/gfx (this is done by setting Z80CODELOC variable in cpctelera build_config.mk)

So the stack can have largest space possible (0x$$$$ - 0xC000) and also leave the possibility to move the stack to maybe use double buffering for graphics later...

Title: Re: cpctelera arkos 2 conversion problem
Post by: teopl on 16:53, 03 February 19
Btw, here is short script which makes the conversion compatible with my cpctelera code: (so this can be done automatically in the build process)

You just need Arkos2 conversion binary "SongToLightweight.exe".

Code: [Select]
SONG_NAME="Arkos2Song"
SONG_INPUT="assets/${SONG_NAME}.aks"
SONG_OUTPUT="src/song_${SONG_NAME}.s"
SONG_ADR="0x40"
./tools/arkos2/SongToLightweight.exe -adr ${SONG_ADR} --labelPrefix "${SONG_NAME}_" -spadr ".org" -spbyte ".db" -spword ".dw"  -sppostlbl ":" ${SONG_INPUT} ${SONG_OUTPUT} >/dev/null 2>&1
perl -i -p -e "s/^.*\.org.*\n/\t\.area __${SONG_NAME}_SongStart \(ABS\)\n\t\.org ${SONG_ADR}\n/g" ${SONG_OUTPUT}
perl -i -p -e "s/db \"ATLW\"/\.ascii \"ATLW\"/g" ${SONG_OUTPUT}
perl -i -p -e "s/${SONG_NAME}_SongStart:/_${SONG_NAME}_SongStart::/g" ${SONG_OUTPUT}
Title: Re: cpctelera arkos 2 conversion problem
Post by: Arnaud on 20:11, 03 February 19
But where is the song then located in memory?

The song will added in memory with your game code and other data from 0x40, you don't have to bother where it is located.
If your game or your song is too large it will possibly overwrite the stack location, but you'll see the size of your program at the end of the build process in the Highest address information.

To sum up :
0x0040 - 0x ? ? ? ? : Song / Code / Gfx (Z80CODELOC = 0x40)
0x$$$$ - 0xC000 : Stack Default location (can be changed with cpct_setStackLocation)

Title: Re: cpctelera arkos 2 conversion problem
Post by: teopl on 21:43, 03 February 19
Well that is great, I tested this and it works, thank you again!

If someone needs this:

0) Download Arnaud's attached source (The player code is a little different then the one provided in Arkos2 player folder)

1) Z80CODELOC := 0x0040

2) Convert Arkos2 song to cpctelera compatible source:

Code: [Select]
SONG_NAME="Arkos2Song"
SONG_INPUT="assets/${SONG_NAME}.aks"
SONG_OUTPUT="src/song_${SONG_NAME}.s"
./tools/arkos2/SongToLightweight.exe --labelPrefix "${SONG_NAME}_" -spadr ".org" -spbyte ".db" -spword ".dw"  -sppostlbl ":" ${SONG_INPUT} ${SONG_OUTPUT} >/dev/null 2>&1
perl -i -p -e "s/db \"ATLW\"/\.ascii \"ATLW\"/g" ${SONG_OUTPUT}
perl -i -p -e "s/${SONG_NAME}_SongStart:/_${SONG_NAME}_SongStart::/g" ${SONG_OUTPUT}
Title: Re: cpctelera arkos 2 conversion problem
Post by: teopl on 01:07, 21 July 19
Since this is better topic to talk about arkos2 and cpctelera then this http://www.cpcwiki.eu/forum/programming/cpctelera-sdcc-order-of-variables-in-struct/

I will attach here example cpctelera+arkos2 project made based on this tutorial: http://www.julien-nevo.com/arkostracker/index.php/exporting-and-using-a-music/

So if you need arkos2 with cpctelera you can start from this:

Code: [Select]
- download attached zip
- run:
./make_all_with_colors.sh
./run.sh

The player is AKG, taken from Arkos2 bundle, but I suggest to use Lightweight player since it occupies less memory.

@Targhan (http://www.cpcwiki.eu/forum/profile/?u=110) I think I found issue when using Disark on PlayerLightweight.asm :

The generated sdcc assembler file has a line which will not compile:

Code: [Select]
PLY_LW_ME_PITCHUPDOWN_NEGATIVESPEED: res 7,d
    or a
    sbc hl,de
    sbc a,0

instead of:

Code: [Select]
PLY_LW_ME_PITCHUPDOWN_NEGATIVESPEED: res 7,d
    or a
    sbc hl,de
    sbc a,#0
Title: Re: cpctelera arkos 2 conversion problem
Post by: Targhan on 21:00, 21 July 19
You are corrrect!! I don't understand how I could miss that, since I tested it, but it is corrected in the next version which should be released next week. Thanks for reporting!
Title: Re: cpctelera arkos 2 conversion problem
Post by: teopl on 23:13, 21 July 19
Great to hear that there is new version on the way! :)

I must admit that I am still having issues when using arkos2 player in my game (the attached example worked ok but in game it has "random" crashes), so I think I will revert to arkos1 until better times (like when it's integrated in cpctelera or when I have time to investigate further).

I guess the issue is on my side but anyway... no time to bother with that but I will leave the arkos2 code inside so it can be switched later.
Title: Re: cpctelera arkos 2 conversion problem
Post by: Targhan on 23:42, 21 July 19
The AT2 player is proven, test united, and used in many projects so I'm pretty sure I'm not to blame :). What you can do is try to import it as a binary blob first, see if there random crash still happen. Remember that SP and ALL the registers (including the auxiliary ones) are used by the player.
Title: Re: cpctelera arkos 2 conversion problem
Post by: teopl on 00:45, 22 July 19
Well what can I say, thanks for motivating me to find a problem... :)

It was indeed in my code... (not even worth mentioning)

So now, again I am back to Arkos2... what a journey...
Title: Re: cpctelera arkos 2 conversion problem
Post by: teopl on 14:53, 10 August 19
Hi, I have new issue.

I attached updated Arkos2 + cpctelera project. (with new arkos2 sources and binaries)

Problem is that if I can't play second subsong (index 1) so if you change this:

Code: [Select]
ld      a, #0
to this:

Code: [Select]
ld      a, #1
and do:

Code: [Select]
make clean; ./make_all_with_colors.sh; ./run.sh
it will not play although the subsong is playable from Arkos2 player. Any ideas? (from the code, the A register should contain subsong index)

Also I am wondering:

1. Can I actually save memory if using several subsongs which share instruments (in one file) compared to several songs (in separate files)?
2. Can I do song compression/decompression before doing INIT? If yes, is that useful in terms of saving memory?
Title: Re: cpctelera arkos 2 conversion problem
Post by: Targhan on 15:46, 10 August 19
I don't know anything about cpctelera, but I just tested your AKS file with the AKG and LW players, and both subsongs plays perfectly. So the problem must come from your side.

Quote
1. Can I actually save memory if using several subsongs which share instruments (in one file) compared to several songs (in separate files)?
That's what Subsongs are for. All the subsongs share the same instruments, arpeggio and pitch tables, saving a bit of memory. Though this is probably not what costs the most in a song, you can still save a few hundred bytes for complex songs.

Quote
2. Can I do song compression/decompression before doing INIT? If yes, is that useful in terms of saving memory?
Compression will save data on disc. The music player will need the music fully decompressed in memory, so unless I didn't understand what you mean, no, you won't save any memory. Or maybe you want to unpack your song only when needed? Then yes, if you don't want to/can't load songs from disc, yes, it will save memory, but only while the song is NOT playing. But at some point, you'll have the compressed and uncompressed song in memory... Makes sure you have enough of it.
Title: Re: cpctelera arkos 2 conversion problem
Post by: Targhan on 16:01, 10 August 19
Additional question, are you sure you exported both subsongs, and not only the first one?
Title: Re: cpctelera arkos 2 conversion problem
Post by: teopl on 16:37, 10 August 19
Thanks for the explanation and yes that's it: I didn't export second subsong... Thanks!

So, I added this to command line exporter:
Code: [Select]
--subsongsAndPsgs s1p1,s2p1
About compression / decompression, I understand, so it's like any other resource - I can compress it, but will I gain more free memory it depends on the usage.

I saw that there is option: --exportSeveralFiles so I may experment a little with it to try to see if I can save memory in case of several compressed subsongs and only one decompressed which is currently playing. (or maybe even split subsongs to more smaller subsongs...)

Edit: wrong topic...
Title: Re: cpctelera arkos 2 conversion problem
Post by: cperezgrin on 13:43, 02 July 20
Thanks to both of you for this way to use Arkos 2 songs with the current version of cpctelera. But I have some problems when exporting. It seems some features are not supported for AKL format like "Warning: Track &A, line &A: Effect 3 not supported in this format."
Is there an easy way to solve this? I have to say that I'm not familiarised with trackers, maybe there's a simple fix.

Also thanks to Targhan for his Tracker
Title: Re: cpctelera arkos 2 conversion problem
Post by: Targhan on 18:50, 02 July 20
This is "normal". AKL (=lightweight) and AKM (minimalist) are smaller players that you use if you want to save some memory. However, they are also more limited, hence the warnings. Please read the documentation (http://www.julien-nevo.com/arkostracker/index.php/the-players/) for more information.

My suggestion is to start with the AKG player, which is the "generic" player, and suited for most projects.

... Or you can simply remove the use of the incriminated effect, if your song doesn't suffer from it.
Title: Re: cpctelera arkos 2 conversion problem
Post by: prototano on 14:57, 09 November 20
Thanks to this post and following the instructions of http://www.julien-nevo.com/arkostracker/index.php/using-a-song-in-production-using-any-assembler/  :D :D
I was able to get cpctelera + arkos2 working together.
I want to share another example:
https://github.com/cmp102/cpctelera/tree/a2c567f8b5bc2b092d68e865c12c74dd7c502938/examples/medium/arkostracker2
This is a cpctelera's fork with all tools and makefile's macros needed to integrate arkos2 on cpctelera in a similar way as arkos1 does. (It only works on linux and only uses the AKM player).
Video of the example:
https://www.youtube.com/watch?v=5S8n5FEkXms
Thank you a lot guys!   :D
Title: Re: cpctelera arkos 2 conversion problem
Post by: Arnaud on 19:36, 09 November 20
Thanks to this post and following the instructions of http://www.julien-nevo.com/arkostracker/index.php/using-a-song-in-production-using-any-assembler/  :D :D
I was able to get cpctelera + arkos2 working together.
I want to share another example:
https://github.com/cmp102/cpctelera/tree/a2c567f8b5bc2b092d68e865c12c74dd7c502938/examples/medium/arkostracker2
This is a cpctelera's fork with all tools and makefile's macros needed to integrate arkos2 on cpctelera in a similar way as arkos1 does. (It only works on linux and only uses the AKM player).
Thank you a lot guys!   :D
Thanks ! :)
Title: Re: cpctelera arkos 2 conversion problem
Post by: cperezgrin on 19:50, 24 November 20
I'm back with this issue.
I managed to play arkos2 song with Lightweight format  with Arnaud example, but I need to do it with genereic format (AKG). This should be easy as I only need to change the call from PLY_LW_... to PLY_AKG_ But I noticed that the players included in Arkos2 (Arkos2\players\playerAkg\sources) are in .asm format and can't be simple renamed to .s to be included in the cpctelera make. I also noticed that the Lightweight player included in the first posts is different to the one included in Arkos2.
So I think there is need some kind of transformation to make those player functionable in cpctelera. The question is, is there already any PlayerAKG.s that compiles in cpctelera in the same way as PlayerLightweight.s does? I'm really a noob in ASM, maybe there's a easy way from the Arkos2 source file, but I don't know how.
Thanks
Title: Re: cpctelera arkos 2 conversion problem
Post by: prototano on 20:23, 24 November 20
You can get a cpctelera's assembly version of the player if you compile it with rasm and disassembles it with disark.
I have a attach a version of AKM which we used on Promotion (Already converted to cpctelera's assembly).
Title: Re: cpctelera arkos 2 conversion problem
Post by: prototano on 20:53, 24 November 20
I'm back with this issue.
I managed to play arkos2 song with Lightweight format  with Arnaud example, but I need to do it with genereic format (AKG). This should be easy as I only need to change the call from PLY_LW_... to PLY_AKG_ But I noticed that the players included in Arkos2 (Arkos2\players\playerAkg\sources) are in .asm format and can't be simple renamed to .s to be included in the cpctelera make. I also noticed that the Lightweight player included in the first posts is different to the one included in Arkos2.
So I think there is need some kind of transformation to make those player functionable in cpctelera. The question is, is there already any PlayerAKG.s that compiles in cpctelera in the same way as PlayerLightweight.s does? I'm really a noob in ASM, maybe there's a easy way from the Arkos2 source file, but I don't know how.
Thanks
Also the Akg version.  ;D
Title: Re: cpctelera arkos 2 conversion problem
Post by: cperezgrin on 10:33, 25 November 20
Thanks @prototano (https://www.cpcwiki.eu/forum/index.php?action=profile;u=3973) (and very nice game Promotion)
I can now compile the new AKGPlayer, but the song doesn't play. I think the problem is when I include the song in the project. I'm doing it in a similar way I saw for Lightweight
./music/SongToAkg.exe --labelPrefix  "song" -spadr ".org" -spbyte ".db" -spword ".dw"  -sppostlbl ":" music/song.aks src/m_songAKG.s ; perl -i -p -e "s/db \"AT20\"/\.ascii \"AT20\"/g" src/m_songAKG.s ; perl -i -p -e "s/songStart:/_songAKGStart::/g" src/m_songAKG.s ; rm src/m_songAKG.s.bak
In the zip attached is the 'project'. With u8 player initialised to 0, the Lightweight player will start and plays ok. With player <>0, AKG player starts but don't play right
How should I process aks file to be included in a cpctelera project with AKG format?Any help will be welcome, thanks
Title: Re: cpctelera arkos 2 conversion problem
Post by: Targhan on 12:16, 25 November 20
Mmmh, I don't know cpctelera or the scripts you're using, but why do you use the "spbyte" "spword" on export? Export the song normally, and use Disark to convert the source properly into a format understood by SDCC.
Title: Re: cpctelera arkos 2 conversion problem
Post by: cperezgrin on 15:33, 25 November 20
Hi, because I don't really know what I'm doing  :picard: . My knowledge about ASM, binary, ... is very short. I saw a way to convert aks files to LightWeight that works in cpctelera. So, I thought converting it to AKG could be in a similar way.
Also, I don't know how to use Disark to convert the .asm genereted from SongToAkg.exe into a file that would read cpctelera. I'm used to Arkos1 songs, where I only need to write a line in a cfg file.
Title: Re: cpctelera arkos 2 conversion problem
Post by: Targhan on 15:57, 25 November 20
We've got a tutorial about all that that is being currently proofreading, so don't worry too much. I'll notify as soon as it is up.
Title: Re: cpctelera arkos 2 conversion problem
Post by: Targhan on 16:00, 25 November 20
In the meantime, everything about Disark is explained here:
http://www.julien-nevo.com/arkostracker/index.php/using-a-song-in-production-using-any-assembler/

That, plus the various files above in this thread, and you might be able to sort this out on your own.. Or ask for help or wait for the tutorial :).
Title: Re: cpctelera arkos 2 conversion problem
Post by: prototano on 17:34, 25 November 20
@cperezgrin (https://www.cpcwiki.eu/forum/index.php?action=profile;u=2791) I have attach a working project with AKG, But it's including de arkostraker2 tools and rasm compiled for linux. If you are using windows you will have to replace them for their corresponding version and maybe some minor changes on cfg/music_conversion.mk.

De makefile rules that I made will generate the following commands:

#Generates a intermediate folder

mkdir -p obj/__aks2

touch obj/__aks2/.folder

#Converts the song

arkostraker2utils/SongToAkg assets/sound/music.aks obj/__aks2/music1.asm --exportPlayerConfig --labelPrefix

music1_arkostraker2utils/rasm obj/__aks2/music1.asm -o obj/__aks2/music1 -s -sl -sq

arkostraker2utils/Disark obj/__aks2/music1.bin src/assets/sound/music1.s --symbolFile obj/__aks2/music1.sym --sourceProfile sdcc

# Converts the sfx

arkostraker2utils/SongToSoundEffects assets/sound/soundEffects.aks obj/__aks2/sfx.asm --exportPlayerConfig --labelPrefix sfx_

arkostraker2utils/rasm obj/__aks2/sfx.asm -o obj/__aks2/sfx -s -sl -sq

arkostraker2utils/Disark obj/__aks2/sfx.bin src/assets/sound/sfx.s --symbolFile obj/__aks2/sfx.sym --sourceProfile sdcc

# Converts the player

cp arkostraker2utils/players/PlayerAkg.asm obj/__aks2/PlayerAkg.asm

cp arkostraker2utils/players/PlayerAkg_SoundEffects.asm obj/__aks2/PlayerAkg_SoundEffects.asm

touch obj/__aks2/PlayerHead.asm

echo ""                                                          > obj/__aks2/PlayerHead.asm

echo 'PLY_AKG_HARDWARE_CPC = 1'                  >> obj/__aks2/PlayerHead.asm

echo 'PLY_AKG_MANAGE_SOUND_EFFECTS = 1'          >> obj/__aks2/PlayerHead.asm

echo 'include "music1_playerconfig.asm"' >> obj/__aks2/PlayerHead.asm ;

echo 'include "sfx_playerconfig.asm"'  >> obj/__aks2/PlayerHead.asm ;

echo 'include "PlayerAkg.asm"'                                   >> obj/__aks2/PlayerHead.asm

arkostraker2utils/rasm obj/__aks2/PlayerHead.asm -o obj/__aks2/PlayerAkg -s -sl -sq

arkostraker2utils/Disark obj/__aks2/PlayerAkg.bin src/assets/sound/PlayerAkg.s --symbolFile obj/__aks2/PlayerAkg.sym --sourceProfile sdcc
Title: Re: cpctelera arkos 2 conversion problem
Post by: cperezgrin on 19:45, 25 November 20
Man, you really deserve a beer or whatever you want. What a great help to me!!
 Not only I have managed to make it play with a main.c (I can't code in ASM yet) but also I have integrated this into my current project very easy, with a few changes.
@ronaldo (https://www.cpcwiki.eu/forum/index.php?action=profile;u=1227), if you have time (I know you haven't), take a look at prototano's code. He has integrate arkos2 in a very similar way as arkos1 is now. This should be easy to make cpctelera v1.6 compatible with arkos2. I haven't try sfx yet, but music plays ok!
Title: Re: cpctelera arkos 2 conversion problem
Post by: prototano on 23:22, 25 November 20
Man, you really deserve a beer or whatever you want. What a great help to me!!
 Not only I have managed to make it play with a main.c (I can't code in ASM yet) but also I have integrated this into my current project very easy, with a few changes.
@ronaldo (https://www.cpcwiki.eu/forum/index.php?action=profile;u=1227), if you have time (I know you haven't), take a look at prototano's code. He has integrate arkos2 in a very similar way as arkos1 is now. This should be easy to make cpctelera v1.6 compatible with arkos2. I haven't try sfx yet, but music plays ok!
Thank you  :D
I already have integrated arkostracker2 on my cpctelera's fork (only with AKM player) and with C bindings that don't need any assembly code.
https://github.com/cmp102/cpctelera/tree/arkostracker2

But I think the way as I implemented it don't fit very well on the mainline cpctelera. The way to generate the songs and the player is a bit messy.

Title: Re: cpctelera arkos 2 conversion problem
Post by: cperezgrin on 09:40, 26 November 20
Messy, but functional in a very easy way. That's all I'm asking for :D
Thanks again