News:

Printed Amstrad Addict magazine announced, check it out here!

Main Menu
avatar_ervin

cpcTelera cpct_akp_musicPlay()

Started by ervin, 16:15, 27 September 15

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

ervin

Hi everyone.

Has anyone managed to get music and sfx working in the same BIN file, compiled using cpctelera?

I'm not trying to play music and sfx at the same time.
I've got music playing on the title screen, then during the game I have sfx only.

However, no matter what I try, when I call cpct_akp_musicPlay() to play the sfx during the game, I get little bits of the title screen's music playing as well.

I've got this in my initGame() routine (which shows the title screen, waits for a keypress, then starts the game):

cpct_akp_stop();
decompressMusic();
cpct_akp_musicInit(AUDIO_BUFFER);

// print title screen, and wait for keypress while repeatedly calling cpct_akp_musicPlay()

cpct_akp_stop();
decompressSfx();
cpct_akp_SFXInit(AUDIO_BUFFER);


decompressMusic() and decompressSfx() are uncompressing music and sfx files respectively (I'm doing this as I don't have much memory left, and I don't want uncompressed music and uncompressed sfx in memory at the same time).
The title screen music plays fine, and the sound fx play fine too, but the sfx also play a nano-second of music.

When I play sfx, I do this:
(Note that I manage the duration of sfx manually, and stop them with cpct_akp_stop() as required)

cpct_akp_SFXPlay(1,15,48,0,0,AY_CHANNEL_C);
cpct_akp_musicPlay();


From my understanding, this queues up the sfx to play, and then the sfx is played with the cpct_akp_musicPlay() command.
But cpct_akp_musicPlay() tries to play the music as well, even though the music data has been overwritten by the sfx data!
:-[

Is music data temporarily kept in an internal buffer (managed by arkos player)?
I know I'm probably making some sort of silly mistake, but I just can't seem to figure it out.

[EDIT #1] Also, it seems that when returning to the title screen (after game over), the first note of music is joined by an instance of sfx!

[EDIT #2] Aaaaand, SOLVED!!!

This has fixed it:

cpct_akp_stop();
decompressMusic();
cpct_akp_musicInit(AUDIO_BUFFER);
cpct_akp_SFXInit(AUDIO_BUFFER);

// print title screen, and wait for keypress while repeatedly calling cpct_akp_musicPlay()

cpct_akp_stop();
decompressSfx();
cpct_akp_musicInit(AUDIO_BUFFER);
cpct_akp_SFXInit(AUDIO_BUFFER);


Re-initialising both music and sfx at the same time is the solution.
HOORAY!!!!
8)


ronaldo

@ervin: I see you've found a solution for your particular problem, However, I think you will find interesting this discussion we had about Arkos Tracker and CPCtelera.

Please, always keep in mind that cpct_akp_musicPlay must be manually called at the Hz frequency you want Music and/or SFX to be played. So, if your SFX/Music is playing at 50Hz, you should call this function 50 times per second, as accurately synchronized as possible. Normally, the appropriate way for achieving that is calling the function immediately after synchronizing with VSYNC or an interruption.

ervin

Quote from: ronaldo on 18:41, 27 September 15
@ervin: I see you've found a solution for your particular problem, However, I think you will find interesting this discussion we had about Arkos Tracker and CPCtelera.

Please, always keep in mind that cpct_akp_musicPlay must be manually called at the Hz frequency you want Music and/or SFX to be played. So, if your SFX/Music is playing at 50Hz, you should call this function 50 times per second, as accurately synchronized as possible. Normally, the appropriate way for achieving that is calling the function immediately after synchronizing with VSYNC or an interruption.

Thanks @ronaldo.
Actually I should have thanked you in that thread, because it was *very* helpful in getting my own music/sfx to work.
You might say it was instrumental in solving the problems I was having.
;D

My title screen music is indeed being called right after vsync, and the timing of it is working well.
Sfx however can't be synchronised to 50hz because the game's frame rate fluctuates. So I'm just trying different things to make the sfx sound reasonably consistent. I think I've found a pretty good way of doing so.


ronaldo

If your framerate is not constant, you can hook your music calls to system interrupts. By doing that, you can ensure music gets called at a constant Hz rate. I cannot think of other way to do it. If you were thinking of a different way and it works, I'd be very interested :).

ervin

Quote from: ronaldo on 08:47, 28 September 15
If your framerate is not constant, you can hook your music calls to system interrupts. By doing that, you can ensure music gets called at a constant Hz rate. I cannot think of other way to do it. If you were thinking of a different way and it works, I'd be very interested :) .

Unfortunately I disable interrupts in a few places in my program, as I need to use the alternate register set a lot.
The only way I've been able to get sfx working is by calling cpct_akp_musicPlay() right after calling cpct_akp_SFXPlay().

If I try to call it once per frame, I either get a weird echoing sound, or I have trouble silencing an sfx that has run past its duration.
:(

It's ok - the method I'm using seems to work well.

ronaldo

Well, as long as your SFX are short enough to fit in the PSG registers, they may play well calling cpct_akp_musicPlay only once :).

Fessor

How complex are the SFX? Wouldnt it work by using the classic "SOUND"-Command (or its equivalent in CPCTelera) for this purpose?


AMSDOS

Quote from: Fessor on 10:33, 29 September 15
How complex are the SFX? Wouldnt it work by using the classic "SOUND"-Command (or its equivalent in CPCTelera) for this purpose?


I think ervin's project is working past the scope of Firmware, which would eliminate any chance of using the SOUND command.
* Using the old Amstrad Languages :D   * with the Firmware :P
* I also like to problem solve code in BASIC :)   * And type-in Type-Ins! :D

Home Computing Weekly Programs
Popular Computing Weekly Programs
Your Computer Programs
Updated Other Program Links on Profile Page (Update April 16/15 phew!)
Programs for Turbo Pascal 3

ervin

Quote from: AMSDOS on 12:30, 29 September 15

I think ervin's project is working past the scope of Firmware, which would eliminate any chance of using the SOUND command.

That is correct, and it is one thing (of many) I love about cpctelera: being able to disable the firmware, but still being able to do stuff easily!

Powered by SMFPacks Menu Editor Mod