Page 1 of 2

New audio upload: Music Player Library for BASIC Programs

Posted: Sat Jan 09, 2021 10:11 pm
by DusanStrakl



Music Player Library for BASIC Programs




View File






I wrote a library to enable BASIC programs play music in the background.

It is compatible with Simplest Effects Sound library I released a while ago.

To demo the library I included two BASIC programs:

PLAY.BAS - Playing Twinkle Twinkle Little Star - it demonstrates the BASIC program doing other stuff including calling simple Effects 

HOUSE.BAS - Playing House of the Rising Sun - it demonstrates a bit more complex music

 

Full Tutorial and source code is available from my blog:

https://www.8bitcoding.com/p/music-player-library-for-basic-programs.html






 

New audio upload: Music Player Library for BASIC Programs

Posted: Mon Jan 11, 2021 9:42 am
by kliepatsch

Pretty cool! Very easy to use, once one read the documentation on your page.

And the example songs are a good starting point to experiment and make our own ?

I hope someone will use this for their games written in BASIC


New audio upload: Music Player Library for BASIC Programs

Posted: Mon Jan 11, 2021 1:18 pm
by kliepatsch

I have noticed that there seems to be a bug that the end of the song data is not used during playback.

See as an example the attached song, where I have the same four notes played twice in a row. However, only the first time, all four notes are played, whereas the second time only the first three notes are played.

Or am I doing something wrong? (Simply Ctrl+C, Ctrl+V the source into the emulator).


MYSONG.TXT

New audio upload: Music Player Library for BASIC Programs

Posted: Tue Jan 12, 2021 1:57 am
by DusanStrakl


12 hours ago, kliepatsch said:




I have noticed that there seems to be a bug that the end of the song data is not used during playback.



See as an example the attached song, where I have the same four notes played twice in a row. However, only the first time, all four notes are played, whereas the second time only the first three notes are played.



Or am I doing something wrong? (Simply Ctrl+C, Ctrl+V the source into the emulator).



MYSONG.TXT 746 B · 4 downloads



Thank you for compliments.

You made just a minor error. You are not loading all the data to memory. 64 bytes of music plus 9 bytes of header data so you have to change the FOR loop to read total of 73 bytes.


New audio upload: Music Player Library for BASIC Programs

Posted: Tue Jan 12, 2021 4:01 pm
by kliepatsch


14 hours ago, DusanStrakl said:




You made just a minor error. You are not loading all the data to memory. 64 bytes of music plus 9 bytes of header data so you have to change the FOR loop to read total of 73 bytes.



Ah silly me ?

Here's a short song made for the Music Player Library. Again simply  Ctrl+C  Ctrl+V  it into the emulator. Feel free to modify and use it everyone if you see fit.


DANDELION.TXT

New audio upload: Music Player Library for BASIC Programs

Posted: Wed Jan 13, 2021 4:28 am
by DusanStrakl


12 hours ago, kliepatsch said:




Ah silly me ?



Here's a short song made for the Music Player Library. Again simply  Ctrl+C  Ctrl+V  it into the emulator. Feel free to modify and use it everyone if you see fit.



DANDELION.TXT 2.76 kB · 4 downloads



Wow, this is great tune. Can I include it on my blog (of course with full credits)? Perhaps there will be more that I could add and build a little library of songs for the player.


New audio upload: Music Player Library for BASIC Programs

Posted: Wed Jan 13, 2021 1:46 pm
by kliepatsch

Yes, no problem!


New audio upload: Music Player Library for BASIC Programs

Posted: Wed Jan 13, 2021 3:57 pm
by kliepatsch

Hi Dusan,

I've come around to trying out the possibility to create custom instruments. I am having a couple of issues.


  • The Volume setting seems to be at the position of what's called "sustain", and the "Volume" setting doesn't seem to change anything


  • For the ADSR, are the parameters doing what they should?


  • What is the additional sustain parameter supposed to do? How long continuous notes are held?


I'm utterly perplexed by the result the attached test file is giving me.

Also, in your blog you say there's 5 predefined instruments, but actually there are 6, so I guess it's only 2 free slots (but it doesn't matter since we can poke into existing ones).

Thanks in advance

Edit: To clarify what I was trying to do with that file. Basically I wanted a short, percussive envelope (an Attack-Decay envelope so-to-say). Because that wasn't turning out how I expected, I began messing around, setting the volume to 0 and making the sound "continuous" which both didn't happen.

TEST_2.TXT


New audio upload: Music Player Library for BASIC Programs

Posted: Thu Jan 14, 2021 1:58 am
by DusanStrakl

Hmm this is indeed unusual result but also parameters are a bit unusual and it would require some time to debug to understand what exactly is happening.

To achieve a short percussive envelope I would use setting like this:

Triangle wave

AD = $10                          - very short attack, no decay

SR = $08                          - no sustain, medium long 200ms release

Not continuous

Max Volume = 63

Sustain Volume = 63

LR = 3                              - my documentation should state that 11 is binary for left and right channel so decimal 3, will update my post

 

or in code:

10 LOAD"PLAY.PRG",8,1,$9000

20 FOR N=0 TO 64+8

30 READ A

40 POKE $6000+N,A

50 NEXT N

100 REM SETUP CUSTOM INTRUMENTS

110 SYS $9006

120 M=PEEK(4)+PEEK(5)*256+6*8

130 POKE   M,128

140 POKE M+1,$10

150 POKE M+2,$08

160 POKE M+3,0

165 POKE M+4,63

170 POKE M+5,63

190 POKE M+6,3

800 REM PLAY SONG

810 POKE 2,$00

820 POKE 3,$60

830 SYS $9000

840 END

999 REM

1000 REM ===== HEADER DATA =====

1001 REM

1010 DATA 4        :REM NUMBER OF VOICES

1020 DATA 9        :REM TEMPO

1030 DATA 64,0     :REM LENGTH (16 BITS)

1040 DATA 1        :REM AUTOREPEAT ON

1049 REM

1050 REM ===== INSTRUMENTS =====

1051 REM

1060 DATA 6,0,0,0 : REM CUSTOM INSTRUMENT

1099 REM

1100 REM ===== MUSIC DATA =====

1101 REM

1110 DATA 40, 0, 0, 0,    0, 0, 0, 0,    0, 0, 0, 0,    0, 0, 0, 0

1120 DATA  0, 0, 0, 0,    0, 0, 0, 0,    0, 0, 0, 0,    0, 0, 0, 0

1130 DATA 40, 0, 0, 0,    0, 0, 0, 0,    0, 0, 0, 0,    0, 0, 0, 0

1140 DATA  0, 0, 0, 0,    0, 0, 0, 0,    0, 0, 0, 0,    0, 0, 0, 0

 

Please let me know if this creates the effect you were going for? I will try to find some time over the Weekend to investigate strange result your settings created.

 


New audio upload: Music Player Library for BASIC Programs

Posted: Thu Jan 14, 2021 8:46 am
by kliepatsch

Thanks. Yes, that is giving me what I want.

I need to apologize because yesterday, I haven't properly looked at your documentation. Now I understand that the two ADSR bytes give four durations, and the sustain level parameter is the extra one. That is useful to know, and I will try again with that knowledge. But the "looping" I was observing yesterday seems to be a bug.