English Amiga Board


Go Back   English Amiga Board > Coders > Coders. General

 
 
Thread Tools
Old 04 February 2016, 17:08   #201
chaos
Registered User

chaos's Avatar
 
Join Date: Mar 2013
Location: Slovenia
Posts: 133
Any kind of interpolation is faking the data you don't have - that is, you are guessing what might the data between the sampled points you have be. Of course, you can make good guesses, considering typical band-limited signal, so no big changes possible between samples, etc.

There are many ways how to do 'interpolation'. One is just repeating the existing samples some n-times (this is definitely the worst way). A little better is linear interpolation between samples (this also allows fractional upsampling). The best is of course a properly-designed low-pass filter. (In theory, all these methods are actually a sort of a filter, either a Zero-Order Hold, a weighted moving average, or a (windowed) FIR/IIR).

But, just zero stuffing (A0B0...) is *not* enough for proper upsampling without the accompanying filter.
chaos is offline  
AdSense AdSense  
Old 04 February 2016, 21:27   #202
Mrs Beanbag
Glastonbridge Software
Mrs Beanbag's Avatar
 
Join Date: Jan 2012
Location: Edinburgh/Scotland
Posts: 2,202
Quote:
Originally Posted by pandy71 View Post
ABCDEF > A0B0C0D0E0F0 > (lowpass) > AaBbCcDdEeFf but AABBCCDDEEFF is also valid (albeit spectrum after upsampling will be slightly different http://www.dsprelated.com/showarticle/761.php).
But amplitude will be reduced by the zeroes. Can also do a low pass filter on the second example, that will not reduce the amplitude but should otherwise be the same.

Quote:
Problem with sinc is that it is suboptimal from human perception perspective as it introduce ringing.
True, you can actually see it sometimes on images rescaled with such a technique, it is worse with a large window, and much better on smooth functions, not so great on square waves but fine for interpolating sine waves.

I have used a convolution kernel [0, -27, 0, 155, 256, 155, 0, -27, 0] to good effect for upsampling by a factor of 2.
Mrs Beanbag is offline  
Old 05 February 2016, 00:40   #203
pandy71
Registered User
 
Join Date: Jun 2010
Location: PL
Posts: 1,623
Quote:
Originally Posted by Mrs Beanbag View Post
But amplitude will be reduced by the zeroes. Can also do a low pass filter on the second example, that will not reduce the amplitude but should otherwise be the same.
Yes but this is easily corrected by applying gain to product (i.e. multiplying by constant and usually power of 2).

In frequency domain there is a subtle difference - spectral replicas are distributed differently.


Quote:
Originally Posted by Mrs Beanbag View Post
True, you can actually see it sometimes on images rescaled with such a technique, it is worse with a large window, and much better on smooth functions, not so great on square waves but fine for interpolating sine waves.

I have used a convolution kernel [0, -27, 0, 155, 256, 155, 0, -27, 0] to good effect for upsampling by a factor of 2.
256? so on 9 bits (+ sign)?

Quote:
Originally Posted by chaos View Post
Any kind of interpolation is faking the data you don't have - that is, you are guessing what might the data between the sampled points you have be. Of course, you can make good guesses, considering typical band-limited signal, so no big changes possible between samples, etc.
This is not about real or fake data - as you pointed - this is bandlimited world.

Quote:
Originally Posted by chaos View Post
There are many ways how to do 'interpolation'. One is just repeating the existing samples some n-times (this is definitely the worst way). A little better is linear interpolation between samples (this also allows fractional upsampling). The best is of course a properly-designed low-pass filter. (In theory, all these methods are actually a sort of a filter, either a Zero-Order Hold, a weighted moving average, or a (windowed) FIR/IIR).

But, just zero stuffing (A0B0...) is *not* enough for proper upsampling without the accompanying filter.
Fully agree but my point was that you can prepare data already by applying proper low pass filter and decimation is all you need.

Last edited by pandy71; 05 February 2016 at 00:53.
pandy71 is offline  
Old 06 February 2016, 19:20   #204
Mrs Beanbag
Glastonbridge Software
Mrs Beanbag's Avatar
 
Join Date: Jan 2012
Location: Edinburgh/Scotland
Posts: 2,202
Quote:
Originally Posted by pandy71 View Post
256? so on 9 bits (+ sign)?
I am multiplying sample values by these numbers and right-shifting 8 places, the multiples of 0 and 256 optimise out though, and 155 = 128+27.
Mrs Beanbag is offline  
Old 13 July 2016, 11:02   #205
buggs
Registered User

 
Join Date: May 2016
Location: Rostock/Germany
Posts: 52
Faster nearest neighbor resampling

My apologies for hijacking a concluded thread but I thought I might have something worth sharing in terms of nearest-neighbor resampling. Of course, with fast hardware one might think about filtered resampling. On the other hand, to reproduce the "original" Amiga sound on Paula hardware (for good or bad, which depends on the individual point of view), nearest neighbor is the way to go.

I recently got hooked up to 68k Asm again, started tinkering around with my old code and shortly thereafter stumbled upon this thread. Out of my own (historical) knowledge, I first saw the "addx/add" combo for the position update in Jarno Paananen's PS3M. That one is already quite runtime efficient (though not as accurate as Bresenham), even on 68000. Out of my personal experience, I wouldn't recommend step tables. One might save registers but that comes at the cost of the mov from memory which is more costly than two simple adds.

That being said, my tinkering led to a routine that doesn't need the second add of the well known "addx/add" combo.

My first-stage 8 Bit mixing main loop looks like this (with 68000 cycle annotations):
A0=input array
D0=fractional position (upper 16 bits), byte position (lower 16 bits), D4=fractional increment (upper 16 bits), byte increments (lower 16 bits), D2=pointer to current volume table (upper 24 bits), where the lower 8 Bits come from each sample and are addressed as "unsigned"
A2=output
A5=remaining bytes in the output-16
D6=remaining bytes in the input

Code:
.mix_fastloop 
                rept    8
                 move.b (a0,d0.w),d2                               ;14
                 addx.l d4,d0                                           ;8
                 move.l d2,a3                                           ;4
                 move.b (a0,d0.w),d2                                    ;14
                 move.b (a3),d3                                         ;8
                 addx.l d4,d0                                           ;8
                 move.l d2,a3                                           ;4
                 swap   d3                                              ;4
                 move.b (a3),d3                                         ;8
                 move.l d3,(a2)+                                        ;12
                                                                        ;=84 cycles for two bytes (42 cyc per byte w/o check)
                endr
                lea     -16(a5),a5      ; no condition codes changed    ;8
                move.l  a5,d1                                           ;
                swap    d1      ; if( remaining_output_bytes < 16 ) 0xffff else 0x0000
                or.w    d6,d1   ; if( remaining_output_bytes < 16 ) -1 else
                                ;                                   remaining_input_bytes
                lea     (A1,D0.l),A3    ; input: processed bytes
                cmp.w   A3,d1   ; if( D1 < A3 ) -> stop
                bgt.w   .mix_fastloop                              ;48 cycles
                                            ; total 8*68+48 / 16 = 37 cycles/byte
The trick is: I crafted the code to avoid operations that change the "x" bit. Hence, I can leave out the second "add" in the usual "addx/add" combo. The prerequisite is the combination "sub.w d4,d0" "add.l d4,d0" before entering the main loop, thus having the proper state of the "x" bit for the first "addx".

This part of my mixing loop shown above is the "copy" loop, called for the first mixed channel. It doesn't require clearing of the output array (A2). For additional channels to be mixed with said first channel, just two more instructions are added in my routine instead of move.l d3,(a2)+:
Code:
move.l (a2),a6
adda.l  d3,a6
move.l a6,(a2)+
This way, one can mix an arbitrary number of channels into an intermediate 16 bit representation. Please note that I mix to an "unsigned" output format in my intermediate representation which changes the "zero point" with each added channel. I keep track of the number of mixed channels and perform the compensation in the output to ChipRAM stage.

This main loop is quite a bit faster than the old code I used (derived from PS3M) on 68000 and also performs nicely on 68060.

Downsides: The volume table shown in this sniplet is 8 Bit deep. For low volume channels, this method introduces quantization noise in the mixing stage that would be an annoyance when 14 or 16 Bit output of the mixed channels is desired.

Maybe that stuff is of some use to someone. At least, I had fun coding on 68000 again.
buggs is offline  
AdSense AdSense  
 


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

Similar Threads
Thread Thread Starter Forum Replies Last Post
Sound channels switched? bLAZER support.WinUAE 21 28 October 2014 08:43
A600: missing sound channels cosam support.Hardware 28 23 May 2010 06:43
More that 4 Sound Channels??? Dragon3d support.WinUAE 8 01 February 2008 17:30
shufflepuck cafe 4 channels sound is crazy turrican3 support.WinUAE 5 08 November 2007 15:41
help sound 4 channels turrican3 support.WinUAE 37 13 April 2007 09:17

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 08:09.


Powered by vBulletin® Version 3.8.8 Beta 1
Copyright ©2000 - 2018, vBulletin Solutions, Inc.
Page generated in 0.30588 seconds with 12 queries