Jump to content
IGNORED

Using Wave Samples for VCS programming


Recommended Posts

Now I want to learn how to do wave samples, but first, I want to understand the basics, so the primitive, cycle wasting way. First, I loaded the .wav song into Audacity, saved the sequance I want to play as a headerless binary, then used bin2hex on it, so I got a hex text file. I wrote a little piece of code like this, copying the beginning of the REALLY long code for Wavetable.
 
ldy #0
sty AUDC0
.Loop
iny
lda WaveTable,y
sta AUDV0
jmp .Loop
 
WaveTable
hex 80808080 80808080 80808080 7F808080
hex 7F7F8080 80807F7F 8080807F 7F80807F
hex 7F80807F 7F80807F 7F80807F 7F7F8080
hex 7F7F8080 7F7F807F 80807F80 80807F80
hex 80807F80 80807F80 80807F7F 807F7F80
hex 80807F80 80808080 7F808080 7F807F80
hex 80807F7F 807F7F7F 807F8080 7F7F807F
hex 7F7F807F 7F7F807F 807F807F 807F7F80
hex 80808080 80808080 80808080 7F808080
hex 7F808080 7F808080 7F808080 80808080
hex 807F7F80 7F808080 8080807F 807F7F7F
hex 8080807F 807F7F7F 807F7F80 807F807F
hex 807F8080 7F80807F 7F7F807F 7F7F807F
hex 807F807F 807F807F 7F7F8080 7F7F807F
hex 7F7F807F 7F7F807F 7F7F8080 7F80807F
hex 7F7F807F 7F808080 7F808080 7F7F7F80
hex 7F807F80 80807F80 807F8080 80807F80
hex 7F80807F 7F807F80 7F807F7F 7F808080
hex 807F7F80 80808080 8080807F 7F7F7F7F
 
First, I tryied it with a hex code like 00010203 04050607 08090a0b 0c0d0e0f and after adding sleep 64 before the jmp, I heard it pulsating, so it worked. So I tried the one above, but it only generates noise. What is the duration (number of cycles) between two notes played you recommend?
Edited by MemberAtarian
Link to comment
Share on other sites

Are you playing one nibble at a time here?  I'm not sure how your compiler is dealing with these hex numbers but I think you should be processing one hex digit at a time (0-F only).  Typically, you would store two 4 bit nibbles in one byte, use the byte as is for the right nibble, then lsr 4 times to use the left nibble.  Example attached.  It looks like it wastes about 130 cycles between wave changes (not notes)

hello.wav

Edited by BNE Jeff
added cycle answer
Link to comment
Share on other sites

31 minutes ago, BNE Jeff said:

Are you playing one nibble at a time here?  I'm not sure how your compiler is dealing with these hex numbers but I think you should be processing one hex digit at a time (0-F only).  Typically, you would store two 4 bit nibbles in one byte, use the byte as is for the right nibble, then lsr 4 times to use the left nibble.  Example attached.  It looks like it wastes about 130 cycles between wave changes (not notes)

hello.wav 4.59 kB · 0 downloads

I just looked up some examples and tried to make it simpler, so there are no deltas to decide which note to import. Can you attach some kind of code too? :)

Link to comment
Share on other sites

Woops. Sorry about that..  I was in a little bit of a hurry getting ready for work.  Correct files attached now..

 

For my samples I used Audacity on its crappiest quality- I believe it was 8 bit mono audio at the slowest rate.  Then I ran it through something called Wav2Atari which is written in Perl.  It converts .wavs to the 4 bit format you're going to want.  Not sure what you mean by deltas to decide which note to import.  With samples, your not working with notes directly, you're building the waves with your data.  

hello.asm HELLO.BIN

  • Like 1
Link to comment
Share on other sites

4 hours ago, BNE Jeff said:

Then I ran it through something called Wav2Atari which is written in Perl.  It converts .wavs to the 4 bit format you're going to want.  Not sure what you mean by deltas to decide which note to import.  With samples, your not working with notes directly, you're building the waves with your data.  

Deltas were someting to decide which hexa part of the data should the program import, I guess it"s for compressing.

What is this Wav2Atari? Even google has absolute zero results about it.

Edited by MemberAtarian
Link to comment
Share on other sites

Nice!  Yeah for longer samples, you'll have to use bank switching.  I don't recall exactly, but I think generally you only get 3 seconds or so of speech into 4 K.  Of course you can adjust the quality to get more or less than that.  I don't recall offhand seeing speech that didn't have a blank screen either, though I'm sure its out there.

 

Its a matter of holding the sample routine's hand... every 100 cycles more or less...  without ever letting go.  Easily said, but it will get in the way of everything you do in the vertical blank, kernel, overscan, subroutines, indexes, and surely other things.  And you'll pay for it with degraded game and graphics quality as well.  And.. you mentioned sampling a song- even harder because you can't vary the rate much- you'll go out of tune.  

 

I made a half-hearted attempt a while back. (attached)  It's got the stable kernel, but the speech is still not right.  It takes a few seconds for you to realize its saying "Hello" really really slowly.  Maybe its time to debug it.

SpeechKernel10.asm SpeechKernel10.asm.bin

Link to comment
Share on other sites

5 minutes ago, BNE Jeff said:

Nice!  Yeah for longer samples, you'll have to use bank switching.  I don't recall exactly, but I think generally you only get 3 seconds or so of speech into 4 K.  Of course you can adjust the quality to get more or less than that.  I don't recall offhand seeing speech that didn't have a blank screen either, though I'm sure its out there.

 

Its a matter of holding the sample routine's hand... every 100 cycles more or less...  without ever letting go.  Easily said, but it will get in the way of everything you do in the vertical blank, kernel, overscan, subroutines, indexes, and surely other things.  And you'll pay for it with degraded game and graphics quality as well.  And.. you mentioned sampling a song- even harder because you can't vary the rate much- you'll go out of tune.  

 

I made a half-hearted attempt a while back. (attached)  It's got the stable kernel, but the speech is still not right.  It takes a few seconds for you to realize its saying "Hello" really really slowly.  Maybe its time to debug it.

Soundz like a really drunk robot. :D Maybe this could lead to a new speech synthetiser :D

Link to comment
Share on other sites

All of the samples in Draconian took 4,659 bytes of storage.

 

-rw-r--r--@ 1 darrellspice  staff  1243 Aug 21  2017 BLASTOffChipmunk.pds

-rw-r--r--@ 1 darrellspice  staff   986 Aug 21  2017 SpyShipSighted.pds

-rw-r--r--@ 1 darrellspice  staff   476 Aug 24  2017 alert.pds

-rw-r--r--@ 1 darrellspice  staff   990 Aug 21  2017 battlestations.pds

-rw-r--r--@ 1 darrellspice  staff   889 Aug 21  2017 condred3.pds

 

Nice!  The above text was copy/pasted from my terminal session:
871344158_ScreenShot2019-06-19at8_21_53PM.thumb.png.0322ac1b357715796268a4498f20c5ca.png

 


 

those files are binary, included into the ROM via INCBIN, then 15 bytes of padding are added after each one:

PADDING = 15    
    
sample_alert:
    INCBIN "./samples/alert.pds"
sample_alert_size = * - sample_alert 
    ds PADDING, $88  ; sample will play beyond size, so pad with silence
    
sample_battlestations:
    INCBIN "./samples/battlestations.pds"
sample_battlestations_size = * - sample_battlestations 
    ds PADDING, $88  ; sample will play beyond size, so pad with silence
    
sample_blastoff:
    INCBIN "./samples/BLASTOffChipmunk.pds"
sample_blastoff_size = * - sample_blastoff 
    ds PADDING, $88  ; sample will play beyond size, so pad with silence

sample_conditionred:
    INCBIN "./samples/condred3.pds"
sample_conditionred_size = * - sample_conditionred 
    ds PADDING, $88  ; sample will play beyond size, so pad with silence

sample_spyship:
    INCBIN "./samples/SpyShipSighted.pds"
sample_spyship_size = * - sample_spyship 
    ds PADDING, $88  ; sample will play beyond size, so pad with silence
    
    echo "---- samples use ", [* - sample_alert]d


 

Link to comment
Share on other sites

this:

    INCLUDE "vcs.h"
    INCLUDE "macro.h"

 

and this:

    INCBIN "./samples/alert.pds"
    INCBIN "./samples/battlestations.pds"
    INCBIN "./samples/BLASTOffChipmunk.pds"
    INCBIN "./samples/condred3.pds"
    INCBIN "./samples/SpyShipSighted.pds"

 

are doing similar things, including external files in your project.  Difference is how they include them.

 

INCLUDE is used for text files, dasm treats their contents exactly the same as your source code - it parses them, decodes value, etc.

 

INCBIN is used for binary files, dasm does not parse them at all, just copies their contents directly into your ROM file.

 

Doing a hex dump lets you see the bytes within the file.  Each byte contains 2 samples so 8, 8, 8, b, 0, 8, a, 3, etc are the values that will be put into AUDV0 when saying "alert".

Darrells-Mac-Pro:samples darrellspice$ hexdump alert.pds
0000000 88 8b 08 a3 b6 6b 59 86 86 78 d3 ab 3b 66 b4 a7
0000010 57 67 e4 8d 2c 65 c4 a8 59 57 d6 ac 2b 76 b6 97
0000020 49 19 e1 db 0f 47 d3 b4 75 5f 67 e3 98 4a 79 65
0000030 93 f6 6e 45 d4 7b 56 76 6f 35 f5 4e 63 c8 18 5f
0000040 a2 9d 43 e5 3d 72 6f 82 ad 53 e7 36 b4 6f 52 cb
0000050 62 ea 04 a6 fb 42 fa 1a a7 24 6d d4 4c c5 3b 84
0000060 65 af 52 bd 52 b9 53 6c e7 19 d6 4a 96 34 ed 41
0000070 dd 81 5d 63 8f 72 5f a5 26 a5 4e c5 1d c7 28 a4
0000080 4f c5 1c d8 06 c4 5f c4 2e c6 19 a3 6f a3 3d b5
0000090 18 c2 8e 80 7f 92 2b 75 fa 33 ec 53 77 4e d5 1b
00000a0 d7 27 a2 7e 72 7e 81 7a 46 f4 3d 93 e7 44 8f 08
00000b0 e1 ac 0d 1a e1 ac 0e 83 a3 ca 2c a1 e1 c3 5f 38
00000c0 d3 99 2d 08 e0 dc 0e 1a 62 f3 8d 38 94 63 cb 3d
00000d0 64 d0 e2 ad 1e 91 e1 d1 5f 0d b0 f3 a3 6f 0c a0
00000e0 e1 b4 8d 0e 82 e0 d2 ba 1f 55 d0 e1 e7 5e 39 94
00000f0 91 f2 bb 0d 59 73 f2 ab 0e 48 65 f1 da 1f 2b 46
0000100 e1 e6 3e 0e 29 b2 e3 5d 1e 1c 94 e2 8b 3d 1e 57
0000110 d0 c8 79 2f 1b b0 e4 a5 4f 0d 80 f0 e3 7d 1f 53
0000120 e0 e2 8c 2f 36 d1 e1 aa 4d 37 b2 d1 c8 6e 1a 94
0000130 c0 c7 7d 0b 85 b1 d7 8c 1b 85 c0 b8 7d 1b 76 c1
0000140 b9 6d 19 94 c0 9c 4d 47 92 f0 6e 2c 85 a1 f2 5f
0000150 2a d2 d6 76 5b 57 d1 da 0a 55 d3 b7 8c 0e 42 f1
0000160 9e 1d 95 36 6f 1a 78 c2 9b 16 c7 74 9d 1a 63 95
0000170 bd 19 e8 83 57 b5 c2 5f 84 b2 9f 34 97 c5 1b 88
0000180 5c 8c 71 f8 77 0b 77 7c 81 e5 5d 26 7c b8 61 bf
0000190 43 66 6f 32 d5 9a 08 b1 b3 eb 4b 36 d3 58 66 6f
00001a0 92 a5 3e 64 c1 69 4f 77 e0 8d 1e b1 76 5f 86 e5
00001b0 1d 74 74 75 4e 92 bb 31 db 59 a3 24 bb 43 b6 5b
00001c0 c2 8d 53 b4 cc a6 b9 35 b8 07 c1 5b 6d 87 79 76
00001d0 4b b7 68 94 78 8e b0 d5 69 88 87 77    

 

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...