English Amiga Board


Go Back   English Amiga Board > Coders > Coders. Asm / Hardware

 
 
Thread Tools
Old 18 March 2021, 21:18   #1
8bitbubsy
Registered User
 
8bitbubsy's Avatar
 
Join Date: Sep 2009
Location: Norway
Posts: 1,711
Question about the 14-bit Paula trick

I don't fully understand how I convert a signed 16-bit PCM sample into an 8-bit pair for 14-bit Paula output...

I have played around with it a bit, and the only way I can make it sound good is by doing this:
Code:
move.w	d0,d1	; d1 = -32768..32767
lsr.b	#2,d1	; hi byte = normal sample, lo byte = low-vol (vol 1) sample
But this surely seems wrong?! Using logical bitshifting (not arithmetic) means that the lower byte is 0..63 instead of -32..31. If I do asr.b instead, I hear background noise that is not supposed to be there.
Can anyone explain why this is? And maybe I'm doing it all wrong?
8bitbubsy is offline  
Old 18 March 2021, 21:34   #2
ross
Defendit numerus
 
ross's Avatar
 
Join Date: Mar 2017
Location: Crossing the Rubicon
Age: 53
Posts: 4,474
The sign bit is only on bit 15, on bit 7 there some lower significance part of the 16 bit signed integer.
So it is sure better a logical than an arithmetic shift for the lower byte.
ross is offline  
Old 18 March 2021, 21:36   #3
8bitbubsy
Registered User
 
8bitbubsy's Avatar
 
Join Date: Sep 2009
Location: Norway
Posts: 1,711
Quote:
Originally Posted by ross View Post
The sign bit is on bit 15, on bit 7 there some lower significance part of the integer.
So it is sure better a logical than an arithmetic shift for the lower byte.
Ahh of course, that makes complete sense! Can't believe I didn't see that, lol.
So ideally I should insert the sign bit in bit 6 and 7 after the lsr?

EDIT: How about just subtracting 32 from d1.b? Is that correct?

Last edited by 8bitbubsy; 18 March 2021 at 21:57.
8bitbubsy is offline  
Old 18 March 2021, 21:48   #4
ross
Defendit numerus
 
ross's Avatar
 
Join Date: Mar 2017
Location: Crossing the Rubicon
Age: 53
Posts: 4,474
I don't think it makes a difference, just a little bias in the signal.

Test by ear if it's different for you
ross is offline  
Old 18 March 2021, 22:07   #5
8bitbubsy
Registered User
 
8bitbubsy's Avatar
 
Join Date: Sep 2009
Location: Norway
Posts: 1,711
Seems like the 0..63 range is correct, or at least anything else I try makes it sound (and look) wrong. So maybe the "lower 6 bits" part just shouldn't be signed (-32..31).
This is a bit confusing to me, though!
8bitbubsy is offline  
Old 18 March 2021, 22:19   #6
ross
Defendit numerus
 
ross's Avatar
 
Join Date: Mar 2017
Location: Crossing the Rubicon
Age: 53
Posts: 4,474
Well it actually makes sense, you are always adding-up at the most significant part of the sample, you surely generate all the valid 2^14 theoretical combinations, in a linear way.

For simplicity try to think how it work around the zero point and you will see that make sense.
ross is offline  
Old 19 March 2021, 08:45   #7
meynaf
son of 68k
 
meynaf's Avatar
 
Join Date: Nov 2007
Location: Lyon / France
Age: 51
Posts: 5,323
Following code converts 16-bit sample to the 8-bit pair :
Code:
; d3=16-bit sample -> d4=high byte, d5=low byte
 move.w d3,d4
 eori.w #$8000,d4
 bpl.s .pos1
 neg.w d4
.pos1
 move.b d4,d5
 lsr.w #8,d4
 lsr.b #2,d5
 tst.w d3
 bpl.s .pos2
 neg.b d4
 neg.b d5
.pos2
Not my own code, i ripped that somewhere so i can't really explain why it is done this way. It appears to be working fine. I just removed the "volume boost" part.
Also note that the 14-bit trick works best if calibrated (in that case, the code becomes a lot more complicated). In any case, better use a table.
meynaf is offline  
Old 19 March 2021, 09:03   #8
8bitbubsy
Registered User
 
8bitbubsy's Avatar
 
Join Date: Sep 2009
Location: Norway
Posts: 1,711
I'll try it and see how it works out.

Regarding calibration, that requires unique calibration per Amiga machine, right?
If not, then no problem, the stuff I'm doing is already for generating a LUT. The reason I want it to be fast is because I am calculating a lot of LUT entries, but precision is more important.
8bitbubsy is offline  
Old 19 March 2021, 09:12   #9
meynaf
son of 68k
 
meynaf's Avatar
 
Join Date: Nov 2007
Location: Lyon / France
Age: 51
Posts: 5,323
Yes it needs unique calibration per Amiga machine.
meynaf is offline  
Old 19 March 2021, 09:13   #10
8bitbubsy
Registered User
 
8bitbubsy's Avatar
 
Join Date: Sep 2009
Location: Norway
Posts: 1,711
Alright, I'm not going to bother with the calibration then.
8bitbubsy is offline  
Old 19 March 2021, 09:22   #11
ross
Defendit numerus
 
ross's Avatar
 
Join Date: Mar 2017
Location: Crossing the Rubicon
Age: 53
Posts: 4,474
Quote:
Originally Posted by meynaf View Post
Following code converts 16-bit sample to the 8-bit pair :
This is for unsigned 16-bit sample and extend the sign on the lower byte of the new signed couple.
ross is offline  
Old 19 March 2021, 09:56   #12
8bitbubsy
Registered User
 
8bitbubsy's Avatar
 
Join Date: Sep 2009
Location: Norway
Posts: 1,711
But I thought you weren't supposed to store the lower 6 bits as signed -32..31?
8bitbubsy is offline  
Old 19 March 2021, 10:03   #13
ross
Defendit numerus
 
ross's Avatar
 
Join Date: Mar 2017
Location: Crossing the Rubicon
Age: 53
Posts: 4,474
Quote:
Originally Posted by 8bitbubsy View Post
But I thought you weren't supposed to store the lower 6 bits as signed -32..31?
This code uses a reverse polarity output.
Why did the coder do such a thing? Maybe it sounded better in his equipment

And has been proven there are many ways to generate a '14-bit' signal on the Amiga and none of them bring perfect results yet.
So the method used in the first message is no more wrong than the others
ross is offline  
Old 19 March 2021, 10:09   #14
8bitbubsy
Registered User
 
8bitbubsy's Avatar
 
Join Date: Sep 2009
Location: Norway
Posts: 1,711
Ah, so maybe it's stored as -63..0?
8bitbubsy is offline  
Old 19 March 2021, 10:21   #15
ross
Defendit numerus
 
ross's Avatar
 
Join Date: Mar 2017
Location: Crossing the Rubicon
Age: 53
Posts: 4,474
Quote:
Originally Posted by 8bitbubsy View Post
Ah, so maybe it's stored as -63..0?
In this case, yes.

But, it seems better to me, for a 16-bit signed sample, to use values from 0 to 63 in the lowest byte.
In a perspective of pure additive mixing it seems fair that the low byte 'fills' the gap between the magnitude higher bytes, that have 64x_volume than the low.
But it is absolutely not certain that I'm right, indeed I would like to have the opinion of others.
ross is offline  
Old 19 March 2021, 11:17   #16
meynaf
son of 68k
 
meynaf's Avatar
 
Join Date: Nov 2007
Location: Lyon / France
Age: 51
Posts: 5,323
Quote:
Originally Posted by ross View Post
This is for unsigned 16-bit sample and extend the sign on the lower byte of the new signed couple.
Sorry, i didn't remove the trick that allows doing this once the table is filled :
Code:
 move.w (a0)+,d0		; our sample
 move.w (a3,d0.w*2),d0
 move.b d0,(a2)+		; low
 lsr.w #8,d0
 move.b d0,(a1)+		; high
meynaf is offline  
Old 19 March 2021, 13:05   #17
robinsonb5
Registered User
 
Join Date: Mar 2012
Location: Norfolk, UK
Posts: 1,153
Just in case you're not already aware of this document, it might be useful:
http://bax.comlab.uni-rostock.de/dl/...mTheoretic.pdf
robinsonb5 is offline  
 


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools

Similar Threads
Thread Thread Starter Forum Replies Last Post
double Copper trick question.. mateusz_s Coders. Blitz Basic 14 21 October 2021 13:33
24-bit + Picasso96 (stupid question) studiox support.WinUAE 10 22 July 2011 14:58
Question about 32-bit ram sink support.WinUAE 7 12 January 2011 12:02
Simple 14 bit audio question... Thorham Coders. General 7 06 June 2010 10:55
32 and 64 bit sprite control words question FrenchShark Coders. General 8 10 January 2008 02:32

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +2. The time now is 09:46.

Top

Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2024, vBulletin Solutions Inc.
Page generated in 0.10659 seconds with 15 queries