Adding music to a program

The place for codemasters or beginners to talk about programming any language for the Spectrum.
Post Reply
User avatar
Jbizzel
Dynamite Dan
Posts: 1537
Joined: Mon May 04, 2020 4:34 pm
Location: Hull
Contact:

Adding music to a program

Post by Jbizzel »

I have made a tune on beepola, save as a code only tap file.

I have my game that calls the tune with

Code: Select all

randomize usr val "60000"
But how do I make these all into 1 tap file so they work together?

Im using zx basic for the program. It's my first time adding music to a game, I feel like I'm so close lol - please help!
User avatar
Jbizzel
Dynamite Dan
Posts: 1537
Joined: Mon May 04, 2020 4:34 pm
Location: Hull
Contact:

Re: Adding music to a program

Post by Jbizzel »

Note that it is possible to join .TAP files by simply stringing them together; for example, in DOS / Windows: COPY /B FILE1.TAP + FILE2.TAP ALL.TAP ; or in Unix/Linux: cp file1.tap all.tap && cat file2.tap >> all.tap
Maybe I can do this...
User avatar
Ast A. Moore
Rick Dangerous
Posts: 2641
Joined: Mon Nov 13, 2017 3:16 pm

Re: Adding music to a program

Post by Ast A. Moore »

Load them into the RAM one after another, carefully noting the length of each tune and adding it to the staring address. Then save everything as a single block.

To play each tune, you simply poke in the address of each tune before launching the player.

For example, if you have tune #1 with a length of 1359 bytes, and tune #2 with a length of 125 bytes, load the first song at address 60000, the second one at 61360. Then save them both as a single contiguous block with a length of 1484 bytes (1359+125).
Every man should plant a tree, build a house, and write a ZX Spectrum game.

Author of A Yankee in Iraq, a 50 fps shoot-’em-up—the first game to utilize the floating bus on the +2A/+3,
and zasm Z80 Assembler syntax highlighter.
User avatar
Jbizzel
Dynamite Dan
Posts: 1537
Joined: Mon May 04, 2020 4:34 pm
Location: Hull
Contact:

Re: Adding music to a program

Post by Jbizzel »

[mention]Ast A. Moore[/mention] thanks.

I feel I am a long way for being able to try what you are saying. I'm very much a beginner.

Here is where I got too.. I now have a tap file that I created like this:

I made a basic loader in fuse
I then made a code block only tap file with beepola
I used cmd in windows to join the 2 tap files together

...and my first success - I run the new .tap file and it loads and plays the tune.

Only I am confused as to why this worked - maybe you can help?

My beelpol track I compiled like this... The compile to address is "60000"

Image

my basic loader loaded my code is like this...


Image

So what is the reason for the compile to address is "60000" in beepola if my loader is doing something different and it works? I actually expected it to not work! Sorry if I seem out of my depth, its because I am!! :D
User avatar
Ast A. Moore
Rick Dangerous
Posts: 2641
Joined: Mon Nov 13, 2017 3:16 pm

Re: Adding music to a program

Post by Ast A. Moore »

Jbizzel wrote: Tue Feb 16, 2021 9:31 pm So what is the reason for the compile to address is "60000" in beepola if my loader is doing something different and it works? I actually expected it to not work! Sorry if I seem out of my depth, its because I am!! :D
Probably because the memory is clear, and the CPU executes a bunch of NOPs from address 40000 all the way to 60000. Try adding the following line in your loader before the RANDOMIZE USR statement:

Code: Select all

25 POKE 50000,201
This should drop you back into BASIC before the player routine starts executing.

P.S. It’s not a good idea to concatenate TAP files, because aside from actual data, they contain additional information relevant to the container itself. You’ll end up with a bunch of garbage at the “joint” of the files.
Every man should plant a tree, build a house, and write a ZX Spectrum game.

Author of A Yankee in Iraq, a 50 fps shoot-’em-up—the first game to utilize the floating bus on the +2A/+3,
and zasm Z80 Assembler syntax highlighter.
User avatar
utz
Microbot
Posts: 116
Joined: Wed Nov 15, 2017 9:04 am
Contact:

Re: Adding music to a program

Post by utz »

Ast A. Moore wrote: Tue Feb 16, 2021 10:04 pm P.S. It’s not a good idea to concatenate TAP files, because aside from actual data, they contain additional information relevant to the container itself. You’ll end up with a bunch of garbage at the “joint” of the files.
Is that really true? The .tap format is pretty much made to facilitate concatenating, afaik. Each header+data chunk is self-contained, there is no meta-data across blocks.
User avatar
Jbizzel
Dynamite Dan
Posts: 1537
Joined: Mon May 04, 2020 4:34 pm
Location: Hull
Contact:

Re: Adding music to a program

Post by Jbizzel »

Ast A. Moore wrote: Tue Feb 16, 2021 10:04 pm
Probably because the memory is clear, and the CPU executes a bunch of NOPs from address 40000 all the way to 60000. Try adding the following line in your loader before the RANDOMIZE USR statement:

Code: Select all

25 POKE 50000,201
This should drop you back into BASIC before the player routine starts executing.

P.S. It’s not a good idea to concatenate TAP files, because aside from actual data, they contain additional information relevant to the container itself. You’ll end up with a bunch of garbage at the “joint” of the files.
So my loader code does not influence where the code goes in the spectrum memory, but the way beepola saves the code block does? This that correct?

I will try as you suggest and load it all into fuse to create the tap file. I'm still grabbling with the very basics really! Thanks for your help [mention]Ast A. Moore[/mention]
User avatar
Ast A. Moore
Rick Dangerous
Posts: 2641
Joined: Mon Nov 13, 2017 3:16 pm

Re: Adding music to a program

Post by Ast A. Moore »

utz wrote: Tue Feb 16, 2021 10:38 pm
Ast A. Moore wrote: Tue Feb 16, 2021 10:04 pm P.S. It’s not a good idea to concatenate TAP files, because aside from actual data, they contain additional information relevant to the container itself. You’ll end up with a bunch of garbage at the “joint” of the files.
Is that really true? The .tap format is pretty much made to facilitate concatenating, afaik. Each header+data chunk is self-contained, there is no meta-data across blocks.
Sure, you can concatenate it for use in an emulator. What I was warning against was using this method for merging the data chunks themselves.
Every man should plant a tree, build a house, and write a ZX Spectrum game.

Author of A Yankee in Iraq, a 50 fps shoot-’em-up—the first game to utilize the floating bus on the +2A/+3,
and zasm Z80 Assembler syntax highlighter.
User avatar
Ast A. Moore
Rick Dangerous
Posts: 2641
Joined: Mon Nov 13, 2017 3:16 pm

Re: Adding music to a program

Post by Ast A. Moore »

Jbizzel wrote: Tue Feb 16, 2021 10:39 pm So my loader code does not influence where the code goes in the spectrum memory, but the way beepola saves the code block does? This that correct?
Because you leave out the argument in your LOAD "" CODE statement, the Spectrum will load the data at the address specified in the header (which is set by Beepola). If you want to force-load the code at an arbitrary address, you’ll need to specify it, i.e. LOAD "" CODE 45000. Note, however, that Beepola’s players are not freely relocatable. If you load and run them at an address other than what was specified in Beepola itself, you’ll likely crash the Spectrum.

The songs themselves can be placed anywhere in memory, however.
Every man should plant a tree, build a house, and write a ZX Spectrum game.

Author of A Yankee in Iraq, a 50 fps shoot-’em-up—the first game to utilize the floating bus on the +2A/+3,
and zasm Z80 Assembler syntax highlighter.
AndyC
Dynamite Dan
Posts: 1409
Joined: Mon Nov 13, 2017 5:12 am

Re: Adding music to a program

Post by AndyC »

Jbizzel wrote: Tue Feb 16, 2021 10:39 pm
Ast A. Moore wrote: Tue Feb 16, 2021 10:04 pm
Probably because the memory is clear, and the CPU executes a bunch of NOPs from address 40000 all the way to 60000. Try adding the following line in your loader before the RANDOMIZE USR statement:

Code: Select all

25 POKE 50000,201
This should drop you back into BASIC before the player routine starts executing.

P.S. It’s not a good idea to concatenate TAP files, because aside from actual data, they contain additional information relevant to the container itself. You’ll end up with a bunch of garbage at the “joint” of the files.
So my loader code does not influence where the code goes in the spectrum memory, but the way beepola saves the code block does? This that correct?

I will try as you suggest and load it all into fuse to create the tap file. I'm still grabbling with the very basics really! Thanks for your help @Ast A. Moore
It would matter if you put an address after CODE, i.e

LOAD "" CODE 40000

but since you didn't it just loads at the default address, which Beepola presumably sets to the address you specified.
User avatar
Jbizzel
Dynamite Dan
Posts: 1537
Joined: Mon May 04, 2020 4:34 pm
Location: Hull
Contact:

Re: Adding music to a program

Post by Jbizzel »

thanks that is really clear. So.. what I've learnt from you guys today is...

a code block has header information in it telling the spectrum where to save the code to if no code address is specified by the loader. But you can specify the location the code is saved to using the loader CODE command with a memory address. Doing this overrides the address specified in the beepola code's header, and is not a good idea as it my crash the beepola music player. Hope I got that right.
User avatar
Ast A. Moore
Rick Dangerous
Posts: 2641
Joined: Mon Nov 13, 2017 3:16 pm

Re: Adding music to a program

Post by Ast A. Moore »

Jbizzel wrote: Tue Feb 16, 2021 11:14 pm telling the spectrum where to save the code to . . . the code is saved to using the loader CODE command
Correct, except that those saves should be loads.
Every man should plant a tree, build a house, and write a ZX Spectrum game.

Author of A Yankee in Iraq, a 50 fps shoot-’em-up—the first game to utilize the floating bus on the +2A/+3,
and zasm Z80 Assembler syntax highlighter.
User avatar
Jbizzel
Dynamite Dan
Posts: 1537
Joined: Mon May 04, 2020 4:34 pm
Location: Hull
Contact:

Re: Adding music to a program

Post by Jbizzel »

[mention]Ast A. Moore[/mention]

Cooking on gas now - thanks for you method, it seems a lot better to load the code into the spectrum to combine it if for no other reason than you learn more about whats happening.

I am taking it slow.. baby steps. Here is an update.

I have loaded my music at 60000
I have loaded my game at 30000 (my game has a randomize usr val "60000" statement in it)

then I ran the line:

Code: Select all

Randomize usr val "60000"
and ... my game loaded... and the music played :P :lol: :o :D Over joyed!

the end is in sight. Now I just have to put everything together and save it out to tap.

update, saved it all with my basic loader and I now have a tap file with a game that has beepola music. Thank you.
Last edited by Jbizzel on Wed Feb 17, 2021 6:25 pm, edited 1 time in total.
User avatar
Ast A. Moore
Rick Dangerous
Posts: 2641
Joined: Mon Nov 13, 2017 3:16 pm

Re: Adding music to a program

Post by Ast A. Moore »

Cool. Keep at it!
Every man should plant a tree, build a house, and write a ZX Spectrum game.

Author of A Yankee in Iraq, a 50 fps shoot-’em-up—the first game to utilize the floating bus on the +2A/+3,
and zasm Z80 Assembler syntax highlighter.
User avatar
TMD2003
Rick Dangerous
Posts: 2045
Joined: Fri Apr 10, 2020 9:23 am
Location: Airstrip One
Contact:

Re: Adding music to a program

Post by TMD2003 »

[mention]Jbizzel[/mention] - how easy or not would you say Beepola was to use, on a scale of "Escape The Room, CSSCGC 2020" to "Battletoads on the NES"?
Spectribution: Dr. Jim's Sinclair computing pages.
Features my own programs, modified type-ins, RZXs, character sets & UDGs, and QL type-ins... so far!
User avatar
Jbizzel
Dynamite Dan
Posts: 1537
Joined: Mon May 04, 2020 4:34 pm
Location: Hull
Contact:

Re: Adding music to a program

Post by Jbizzel »

[mention]TMD2003[/mention] Its very easy - I mean it might sound crap, but its very easy to use.

it really depends on how musical you are. I can't read music but had a keyboard handy that meant I could try notes out and get a tune. Then I just repeated the tune in beepola.

compiling the track is easy too, beepola makes a tap file and gives you options for how the track will play in your game.

I haven't got as far as multiple tracks as in [mention]Ast A. Moore[/mention] example - I'm working towards that.
User avatar
Jbizzel
Dynamite Dan
Posts: 1537
Joined: Mon May 04, 2020 4:34 pm
Location: Hull
Contact:

Re: Adding music to a program

Post by Jbizzel »

Image

So, for multiple tracks you save the first track with the beepola player included and then other tracks I assume you save a song data only?

Then load them a one code block.

then beepola's documentation suggests this poke code to select the song.

Code: Select all

10 LET PlayerAddr = 60000
20 LET SongAddr = 61000
30 POKE PlayerAddr + 25,SongAddr - 256 * INT(SongAddr /2 56)
40 POKE PlayerAddr + 26,INT(SongAddr / 256)
User avatar
Ast A. Moore
Rick Dangerous
Posts: 2641
Joined: Mon Nov 13, 2017 3:16 pm

Re: Adding music to a program

Post by Ast A. Moore »

Jbizzel wrote: Thu Feb 18, 2021 2:17 pm So, for multiple tracks you save the first track with the beepola player included and then other tracks I assume you save a song data only?

Then load them a one code block.
You can save each song individually and then combine them into a single code block. I don’t remember if it’s possible to save Beepola’s players separately as well. If it is, you could do that. In any event, you can separate the song form the player at any time later and then move the song to a convenient place in memory.
Every man should plant a tree, build a house, and write a ZX Spectrum game.

Author of A Yankee in Iraq, a 50 fps shoot-’em-up—the first game to utilize the floating bus on the +2A/+3,
and zasm Z80 Assembler syntax highlighter.
User avatar
TMD2003
Rick Dangerous
Posts: 2045
Joined: Fri Apr 10, 2020 9:23 am
Location: Airstrip One
Contact:

Re: Adding music to a program

Post by TMD2003 »

Jbizzel wrote: Wed Feb 17, 2021 11:40 pm @TMD2003 Its very easy - I mean it might sound crap, but its very easy to use.

it really depends on how musical you are. I can't read music but had a keyboard handy that meant I could try notes out and get a tune. Then I just repeated the tune in beepola.

compiling the track is easy too, beepola makes a tap file and gives you options for how the track will play in your game.

I haven't got as far as multiple tracks as in @Ast A. Moore example - I'm working towards that.
It's definitely worth a shot, then. I've been reading music in one form or another since the launch of the Toastrack, so I'm well ahead on that front.
Spectribution: Dr. Jim's Sinclair computing pages.
Features my own programs, modified type-ins, RZXs, character sets & UDGs, and QL type-ins... so far!
User avatar
Jbizzel
Dynamite Dan
Posts: 1537
Joined: Mon May 04, 2020 4:34 pm
Location: Hull
Contact:

Re: Adding music to a program

Post by Jbizzel »

TMD2003 wrote: Thu Feb 18, 2021 4:06 pm
Jbizzel wrote: Wed Feb 17, 2021 11:40 pm @TMD2003 Its very easy - I mean it might sound crap, but its very easy to use.

it really depends on how musical you are. I can't read music but had a keyboard handy that meant I could try notes out and get a tune. Then I just repeated the tune in beepola.

compiling the track is easy too, beepola makes a tap file and gives you options for how the track will play in your game.

I haven't got as far as multiple tracks as in @Ast A. Moore example - I'm working towards that.
It's definitely worth a shot, then. I've been reading music in one form or another since the launch of the Toastrack, so I'm well ahead on that front.
If you can read music then you should have no trouble :)
Post Reply