working on wav2ay

The place for codemasters or beginners to talk about programming any language for the Spectrum.
Post Reply
C.Born
Manic Miner
Posts: 218
Joined: Sat Dec 09, 2017 4:09 pm

Re: working on wav2ay

Post by C.Born »

Seven.FFF wrote: Tue Jan 23, 2018 8:59 pm It seems like what you need is sample rate conversion by irrational factors. I haven't found any audio software that does this, but the technique exists in principle. People have done it by crunching the raw numbers in MATLAB. It looks pretty technical! The upside is that your asm works with raw numbers anyway, so maybe it is not so bad.

https://www.mathworks.com/help/dsp/exam ... ctors.html

In that example (theirs is upsampling, but yours is downsampling), you would maybe use:

Overall Interpolation Factor : 284
Overall Decimation Factor : 3131100 - Is that right?

And, I guess, play around with the filters and other parameters a LOT to get acceptable results!

I don't think you would notice much of a pitch difference between 128K/48K, if you sampled for 284 then dropped a few samples every frame. Would you? It's not like a user would ever play both at the same time.
Hi,
i solved the 'sox problem' ,its just 2 differences in the command line:

Code: Select all

; wav2ay uses
;RUNWAIT("sox input.wav -r 11025 -b -u -c1 Output.raw",@ScriptDir,@SW_HIDE )
;now            sox input.wav -r 12489 -b 8 -e unsigned -c1 Output.raw 
i dont know if 12489 as hz is acceptable, but aslong as the human ear can hear it i am satisfied.
And about the 48k and 128k difference, its not big, but somewhere it might matter with recognizing voices etc.
i asume the bigger problem is that the higher/better the quality the less time there is. i have in mind to lower every thing so that only the player and raw data are in uncontended memory.
User avatar
Seven.FFF
Manic Miner
Posts: 744
Joined: Sat Nov 25, 2017 10:50 pm
Location: USA

Re: working on wav2ay

Post by Seven.FFF »

Nice one! Yes, as long as it sounds good, it's good I think!
Robin Verhagen-Guest
SevenFFF / Threetwosevensixseven / colonel32
NXtel NXTP ESP Update ESP Reset CSpect Plugins
C.Born
Manic Miner
Posts: 218
Joined: Sat Dec 09, 2017 4:09 pm

Re: working on wav2ay

Post by C.Born »

C.Born
Manic Miner
Posts: 218
Joined: Sat Dec 09, 2017 4:09 pm

Re: working on wav2ay

Post by C.Born »

some work in progress:
I am working an RLE version, so the 'raw' file does not need full DEcompression
http://www.cborn.nl/zxfiles/nwAYrle060.asm

and the real 3channel version, i am working on it as well
http://www.cborn.nl/zxfiles/3chsmpl032.asm

And the new decruncher of exomizer is not working yet aswell
http://www.cborn.nl/zxfiles/pbfexb0003.asm
http://www.cborn.nl/zxfiles/pbfexb0003.z80
C.Born
Manic Miner
Posts: 218
Joined: Sat Dec 09, 2017 4:09 pm

Re: working on wav2ay

Post by C.Born »

hello,
some RLE wave sample's work in progress,

Code: Select all

; New Wave Player n_wAYv  based on wav2ay player
; This version is RLE based meaning it needs 1 byte wav data and 1 byte counter
; the samples are 4bits but the RLE is 8bits, maybe a 4bits rle is possible to? then maybe the 2nd digit is a counter that counts to 16??
; 16 counts is not much, is it enough for future develope??
; very much programming if you make a array count for average best?
;   4bits+   4bits=1bytes >  4 bits *16 repeats, good for buzzy noise with loads of quick changes.

; 4+4bits+   8bits=2bytes >4+4 bits *256 repeats, a set off 2 samples, that repeats, only works well for "00","11" etc,  used now!!

;   4bits+ 4+8bits=2bytes >  4 bits *(16+255)= 271 repeats !not +256 since (on) 0 will be dumped, i supose.
;   4bits+  12bits=2bytes >  4 bits *4096 repeats , 4 bits next to sample are high bits ??? comes last!!!
; but matching 2 DIFFERENT samples as 1 rle match is not very good either,
; the change that 2 samples repeat as a set is small although "buzy" sound will have many changes...
; which is not suitable to rle anyway....etc,etc
http://www.cborn.nl/zxfiles/nwAYrle078+bas.tap
http://www.cborn.nl/zxfiles/nwAYrle078.asm

its the most simple RLE, since i started it in basic:

Code: Select all

10 CLEAR 32767
  20 LET ORG=32768: LET TSAMS=3: LET LENADDR=32772: LET SAMADDR=32769
  21 REM ABOVE 2 LINES ALTERED IN COMPILE (CLEAR, ORG,TSAM,LENADDR & SAMADDR)
  30 LOAD ""CODE : REM LOAD PLAYER CODE
  40 LOAD ""CODE : REM LOAD DEFAULT SAMPLE START SETTING
  45 CLS : PRINT "erasing ramdisk": CAT !: LET a$="": FOR x=0 TO 9: LET b$=SCREEN$ (1,x): LET a$=a$+b$: NEXT x: IF a$<>"          " THEN ERASE !a$: GO TO 45
  50 FOR F=1 TO TSAMS
  60 LOAD ""CODE : REM LOAD SETTING FOR SAMPLE LENGTH
  70 LOAD ""CODE : REM LOAD ACTUAL SAMPLE DATA
  80 REM NOW RESAVE DATA TO DISK!
  90 LET LENGTH=(PEEK LENADDR+256*PEEK (LENADDR+1))
  95 LET A$="SAM_"+STR$ (F)
 100 SAVE !A$ CODE SAMADDR,LENGTH
 105 LET A$="SAMLEN_"+STR$ (F)
 110 SAVE !A$ CODE LENADDR,2
 120 NEXT F: REM ** ALL STORED
 121 REM **********************
 122 LET A$="SELECT SAMPLE FROM 1 TO "+STR$ (TSAMS)
 130 CLS : PRINT A$: INPUT SND
 132 IF SND<1 OR SND>TSAMS THEN GO TO 122
 140 GO SUB 150: GO TO 122
 150 LET A$="SAM_"+STR$ (SND)
 160 LET B$="SAMLEN_"+STR$ (SND)
 163 LET x=0: LET src=33000: REM clear mem for decent datablock
 165 POKE src+x,0: LET x=x+1: GO TO 165+(x=1200)
 170 LOAD !A$ CODE : LOAD !B$ CODE 
 180 RANDOMIZE USR ORG: GO SUB 1000: RETURN 
1000 CLS : REM RLE
1010 LET lng=PEEK lenaddr+256*PEEK (lenaddr+1): LET d=16384: LET cnt=0: LET nxt=0
1015 LET des=d+2: REM skip size
1020 LET a=PEEK (src+nxt): POKE des,a
1040 LET cnt=cnt+1: POKE des+1,cnt
1050 LET nxt=nxt+1: IF PEEK (src+nxt)=a AND cnt<255 AND nxt < lng-1 THEN GO TO 1040
1060 IF nxt < lng-1 THEN LET des=des+2: LET cnt=0: GO TO 1020
1065 LET sz=des-(d+2): RANDOMIZE sz: POKE d,PEEK 23670: POKE d+1,PEEK 23671: REM poke size
1080 IF sz>=lng THEN BEEP 1,1: PRINT #0; FLASH 1;"RESULT IS LONGER THEN ORIGINAL"
1100 LPRINT ''"; RLEdat";snd;" ,length: ";sz;" from original:";lng: REM ';' is REMark
1150 LET y=0: FOR x=d TO des-1
1151 LPRINT (CHR$ 13+ "  defb " AND y=0);
1152 LPRINT PEEK x;("," AND y<15 AND x< des-1);
1153 LET y=y+(y<15)-15*(y=15)
1154 NEXT x: LPRINT ''
1160 PRINT #0;AT 1,0;"org:";lng;", now:";PEEK d+256*PEEK (d+1)
1170 SAVE "RLEdat"+STR$ (snd)CODE d,(sz+2)
1500 RETURN 
2000 CLEAR : SAVE "RLEbas21" LINE 1
giving:

Code: Select all

; RLEdat1 ,length: 242
  defb 242,0,187,42,203,1,204,7,187,7,170,6,187,2,204,2
  defb 221,4,205,1,204,3,187,3,171,1,170,1,154,1,153,5
  defb 170,1,186,1,187,1,204,2,221,8,204,2,188,1,187,1
  defb 170,2,153,2,137,1,136,3,153,2,170,1,186,1,187,2
  defb 204,5,221,7,205,1,204,1,188,1,187,1,170,3,153,8
  defb 170,3,187,4,203,1,204,4,221,9,204,2,187,2,171,1
  defb 170,2,153,7,169,1,170,1,186,1,187,5,204,9,221,8
  defb 204,2,188,1,187,2,170,2,154,1,153,7,170,3,187,14
  defb 203,1,204,6,220,1,221,4,205,1,204,3,187,3,171,1
  defb 170,3,153,4,169,1,170,3,186,1,187,13,203,1,204,18
  defb 187,5,170,3,187,25,204,25,187,32,203,1,204,25,187,12
  defb 186,1,187,26,204,5,188,1,187,53,204,12,188,1,187,4
  defb 204,8,188,1,187,37,204,9,188,2,187,10,203,1,204,4
  defb 188,1,187,36,204,9,188,1,187,15,204,4,187,38,204,12
  defb 187,1,203,1,204,8,187,1,204,6,187,39,204,5,187,63
  defb 204,6,187,23

; RLEdat2 ,length: 714
  defb 202,2,187,233,188,1,187,9,188,1,187,2,204,1,187,2
  defb 204,1,188,1,170,1,203,1,188,1,171,1,187,1,204,1
  defb 171,1,186,1,204,1,188,1,170,1,203,1,204,1,171,1
  defb 186,1,204,1,171,1,170,1,204,1,188,1,170,1,203,1
  defb 205,1,155,1,185,1,220,1,172,1,169,1,219,1,189,1
  defb 154,1,202,1,221,1,155,1,168,1,220,1,189,1,136,1
  defb 219,1,222,1,138,1,184,1,237,1,173,1,135,1,219,1
  defb 222,1,106,1,184,1,237,1,173,1,118,1,235,1,222,1
  defb 90,1,183,1,238,1,173,1,117,1,235,1,223,1,90,1
  defb 182,1,254,1,174,1,86,1,218,1,239,1,107,1,146,1
  defb 253,1,206,1,7,1,200,1,254,1,141,1,112,1,235,1
  defb 223,1,26,1,164,1,254,1,190,1,5,1,217,1,255,1
  defb 141,1,96,1,235,1,239,1,9,1,161,1,254,1,207,1
  defb 5,1,199,1,255,1,157,1,48,1,234,1,239,1,91,1
  defb 128,1,252,1,223,1,9,1,163,1,254,1,207,1,5,1
  defb 199,1,255,1,158,1,16,1,217,1,255,1,124,1,80,1
  defb 235,1,239,1,42,1,128,1,253,1,223,1,9,1,161,1
  defb 254,1,207,1,6,1,181,1,255,1,174,1,1,1,216,1
  defb 255,1,157,1,0,1,217,1,255,1,125,1,32,1,234,1
  defb 255,1,108,1,64,1,235,1,255,1,75,1,80,1,251,1
  defb 239,1,43,1,96,1,252,1,239,1,26,1,112,1,252,1
  defb 239,1,10,1,112,1,253,1,239,1,10,1,112,1,253,1
  defb 239,1,42,1,112,1,252,1,239,1,26,1,112,1,252,1
  defb 239,1,42,1,112,1,252,1,239,1,42,1,112,1,252,1
  defb 239,1,75,1,96,1,252,1,239,1,91,1,96,1,236,1
  defb 239,1,107,1,96,1,235,1,255,1,124,1,96,1,235,1
  defb 255,1,140,1,64,1,218,1,255,1,157,1,18,1,201,1
  defb 254,1,173,1,6,1,200,1,254,1,206,1,24,1,182,1
  defb 253,1,206,1,73,1,148,1,237,1,223,1,106,1,148,1
  defb 236,1,238,1,139,1,117,1,218,1,238,1,173,1,102,1
  defb 201,1,238,1,189,1,88,1,184,1,237,1,206,1,105,1
  defb 166,1,237,1,222,1,122,1,133,1,219,1,238,1,156,1
  defb 117,1,218,1,238,1,173,1,87,1,201,1,238,1,190,1
  defb 88,1,167,1,237,1,206,1,122,1,150,1,236,1,222,1
  defb 139,1,134,1,218,1,238,1,172,1,119,1,201,1,237,1
  defb 189,1,121,1,184,1,237,1,206,1,138,1,152,1,219,1
  defb 222,1,156,1,136,1,202,1,221,1,189,1,137,1,185,1
  defb 221,1,205,1,154,1,169,1,220,1,221,1,155,1,153,1
  defb 219,1,221,1,172,1,153,1,202,1,221,1,188,1,154,1
  defb 186,1,220,1,205,1,154,1,169,1,220,1,205,1,171,1
  defb 169,1,203,1,204,1,188,1,170,1,186,1,204,1,188,1
  defb 170,1,186,1,204,1,188,1,171,1,186,1,203,1,204,1
  defb 187,1,170,1,203,1,204,1,187,1,170,1,187,1,204,1
  defb 188,1,171,1,187,1,204,1,188,1,187,2,203,1,188,1
  defb 187,3,188,1,187,3,204,1,187,255,187,16

; RLEdat3 ,length: 298
  defb 42,1,187,255,187,16,171,1,155,1,1,2,0,3,1,1
  defb 176,1,255,5,126,1,64,1,16,2,1,1,251,1,255,4
  defb 207,1,0,1,1,2,3,1,248,1,255,4,12,1,16,1
  defb 0,1,1,1,192,1,255,4,29,1,48,1,16,1,1,1
  defb 250,1,255,4,11,1,1,1,16,1,176,1,255,4,191,1
  defb 16,1,0,1,2,1,250,1,255,4,27,1,0,2,177,1
  defb 254,1,255,2,223,1,9,1,0,2,183,1,254,1,255,2
  defb 239,1,107,1,0,1,96,1,218,1,255,3,207,1,8,1
  defb 0,2,128,1,252,1,255,3,239,1,188,1,153,1,186,1
  defb 236,1,255,2,222,1,139,1,1,1,0,2,96,1,185,1
  defb 220,1,204,1,155,1,120,1,119,1,152,1,186,1,204,1
  defb 188,1,171,1,170,2,186,1,236,1,255,1,205,1,187,1
  defb 189,1,152,1,120,2,102,2,118,1,152,1,169,1,170,1
  defb 171,1,170,3,154,1,153,2,137,1,136,1,119,1,69,1
  defb 1,1,0,17,32,1,84,1,85,2,69,1,35,1,1,1
  defb 0,2,32,1,83,1,102,1,118,1,119,3,103,1,102,2
  defb 119,1,135,1,136,7,153,16,169,1,170,3,154,1,153,4
  defb 169,1,170,15,171,1,170,6,186,1,187,2,171,1,170,5
  defb 187,5,170,1,187,7,170,2,187,255,187,76
i guess i should make an own page to link , thats easier,
Nomad
Manic Miner
Posts: 600
Joined: Thu Dec 28, 2017 12:38 pm

Re: working on wav2ay

Post by Nomad »

Putting in some great work there fella, it always surprises me how much margin there is for optimisation in these seemingly already slick programs. Makes you think what other programs could benefit from a similar makeover and the impact that would have.
C.Born
Manic Miner
Posts: 218
Joined: Sat Dec 09, 2017 4:09 pm

Re: working on wav2ay

Post by C.Born »

Nomad wrote: Sat Feb 03, 2018 1:49 am Putting in some great work there fella, it always surprises me how much margin there is for optimisation in these seemingly already slick programs. Makes you think what other programs could benefit from a similar makeover and the impact that would have.
thanks, if you like it 'at the best' then check
http://www.pouet.net/prodlist.php?platf ... rder=added
http://zxdemo.org/
Nomad
Manic Miner
Posts: 600
Joined: Thu Dec 28, 2017 12:38 pm

Re: working on wav2ay

Post by Nomad »

C.Born wrote: Sat Feb 03, 2018 2:15 am thanks, if you like it 'at the best' then check
http://www.pouet.net/prodlist.php?platf ... rder=added
http://zxdemo.org/
I still have not got past the first link 32 bytes!!! and the programs do things lol. There are so many 'slick rick' techniques in those demos. a decompile pillage is in order I think... Thanks a lot for the link.

Image

Gasman 7b maze...

Code: Select all


	org 0x732f

	rst 0x10
	push bc
	xor (hl)
	dec hl
	ld a,c
	ret po
	xor b
	ret
C.Born
Manic Miner
Posts: 218
Joined: Sat Dec 09, 2017 4:09 pm

Re: working on wav2ay

Post by C.Born »

a simple attempt to "page"
http://cborn.nl/zxfiles/wav2ay/
User avatar
zxbruno
Manic Miner
Posts: 214
Joined: Sun Mar 04, 2018 6:13 am

Re: working on wav2ay

Post by zxbruno »

A few years later, I wonder if there's an easy way of starting with a .WAV file and ending up a .TAP or .TZX file with the player plus the block of code. I've always found digitised audio fascinating.

Related: A long time ago Gasman released a demo that attempted to combine digitised speech and AY music, with some success (he proved it could be done). Are there new ways of playing AY samples during games or are we still saying the Z80 needs to halt everything in order to play them? The Atarin demo seems to contradict those who say the Z80 needs full resources in order to make an AY digital sample sound good.
Post Reply