English Amiga Board


Go Back   English Amiga Board > Coders > Coders. General

 
 
Thread Tools
Old 11 March 2020, 13:48   #1
Siekmanski
Registered User

Siekmanski's Avatar
 
Join Date: Nov 2019
Location: Groningen / the Netherlands
Posts: 7
How to pre-calculate the Protracker mt_PeriodTable

Hi,

How did Karsten Obarski ( coder of the first Amiga SoundTracker ) calculate the period table?
How did Lars Hamre ( coder of Protracker ) calculate the fine_tune stages?

Started coding a Protracker2.3 Replay routine for Windows using the Microsoft Assembler ( Masm )
To shave some bytes of the executable, I want to pre-calculate the "mt_PeriodTable".
Wrote a routine assuming a western equal-tempered scale, but ended up with 37 mismatches.

Code:
Calculate_mt_PeriodTable:
    mov         edi,offset PeriodTable+576 ; Start at the second half of the Period Table memory buffer
    movss       xmm0,BasePeriod         ; Best possible period match: 906.9023 -> ( 3546895 / 3911 )
    movss       xmm1,xmm0
    mov         dl,2                    ; Split the Period Table in 2 halves
split_LP:
    mov         dh,8                    ; 8 fine tune stages per half Period Table
next_finetune_step:
    mov         cl,36                   ; 3 octaves ( 3 * 12 notes )
octaves_LP:
    cvtss2si    eax,xmm0                ; Convert period float to 32 bit integer
    mov         [edi],ax                ; Save period value as 16 bit integer
    divss       xmm0,twelfth_root_of_2  ; Calculate next period value in the present octave -> 2^(1/12) = 1.059463
    add         edi,2
    dec         cl
    jnz         octaves_LP
    divss       xmm1,semitone           ; Calculate next fine tune step -> 2^(1/12/8) = 1.007246
    movss       xmm0,xmm1
    dec         dh
    jnz         next_finetune_step
    mov         edi,offset PeriodTable  ; Jump to the start of the Period Table memory buffer
    dec         dl
    jnz         split_LP                ; Code size 70 bytes
Is there some logic I'm missing in the original mt_PeriodTable?
Or do I need to write some reconstruction code to repair the 37 mismatches?

The challenge is to write the smallest piece of code that matches 100% the original "mt_PeriodTable".
Siekmanski is offline  
Old 11 March 2020, 14:24   #2
robinsonb5
Registered User
 
Join Date: Mar 2012
Location: Norfolk, UK
Posts: 688
Quote:
Originally Posted by Siekmanski View Post
How did Karsten Obarski ( coder of the first Amiga SoundTracker ) calculate the period table?
How did Lars Hamre ( coder of Protracker ) calculate the fine_tune stages?

Started coding a Protracker2.3 Replay routine for Windows using the Microsoft Assembler ( Masm )
To shave some bytes of the executable, I want to pre-calculate the "mt_PeriodTable".
Wrote a routine assuming a western equal-tempered scale, but ended up with 37 mismatches.
This thread should be some help - but unfortunately, there's no simple solution - the problem appears to be have been floating-point rounding errors in the BASIC implementation used when generating the original period values back in the day.
https://eab.abime.net/showthread.php?t=69675

(I was looking absent-mindedly at your assembly code, wondering why it looked strange, until the penny dropped - it's X86 assembly! In an Amiga forum! Sacrilege! )
robinsonb5 is offline  
Old 11 March 2020, 14:54   #3
meynaf
son of 68k
meynaf's Avatar
 
Join Date: Nov 2007
Location: Lyon / France
Age: 47
Posts: 3,689
I completely fail to see the point in attempting to shave bytes out of a Windows executable...
meynaf is offline  
Old 11 March 2020, 15:11   #4
robinsonb5
Registered User
 
Join Date: Mar 2012
Location: Norfolk, UK
Posts: 688
Quote:
Originally Posted by meynaf View Post
I completely fail to see the point in attempting to shave bytes out of a Windows executable...
4K / 64K demos exist in the Windows world too...
robinsonb5 is offline  
Old 11 March 2020, 15:45   #5
meynaf
son of 68k
meynaf's Avatar
 
Join Date: Nov 2007
Location: Lyon / France
Age: 47
Posts: 3,689
Quote:
Originally Posted by robinsonb5 View Post
4K / 64K demos exist in the Windows world too...
In todays windows world, really ?
Considering the amount of work to do for just a simple 2D screen setup and for just playing a sound, i seriously doubt anything useful can be done with such a small executable size...
meynaf is offline  
Old 11 March 2020, 15:45   #6
Siekmanski
Registered User

Siekmanski's Avatar
 
Join Date: Nov 2019
Location: Groningen / the Netherlands
Posts: 7
Quote:
Originally Posted by robinsonb5 View Post
This thread should be some help - but unfortunately, there's no simple solution - the problem appears to be have been floating-point rounding errors in the BASIC implementation used when generating the original period values back in the day.
https://eab.abime.net/showthread.php?t=69675

(I was looking absent-mindedly at your assembly code, wondering why it looked strange, until the penny dropped - it's X86 assembly! In an Amiga forum! Sacrilege! )
I will admit, sacrilege, but the knowledge of the Amiga trackers is here on this forum I hope.

Thanks for the link to the thread ( missed that thread ), it seems a bit more difficult than I thought.....
The most mismatches are in the Tuning 0 and -8 stages (28).
See if I can create some kind of small period repair code......
Siekmanski is offline  
Old 11 March 2020, 16:06   #7
DanScott
Lemon. / Core Design

DanScott's Avatar
 
Join Date: Mar 2016
Location: Sunny Bournemouth, UK
Posts: 581
Quote:
Originally Posted by meynaf View Post
In todays windows world, really ?
Considering the amount of work to do for just a simple 2D screen setup and for just playing a sound, i seriously doubt anything useful can be done with such a small executable size...
WHAT??? have you not seen some of the amazing 4k and 64k productions???

[ Show youtube player ]

[ Show youtube player ]

just a couple....
DanScott is offline  
Old 11 March 2020, 16:08   #8
Siekmanski
Registered User

Siekmanski's Avatar
 
Join Date: Nov 2019
Location: Groningen / the Netherlands
Posts: 7
Quote:
Originally Posted by meynaf View Post
In todays windows world, really ?
Considering the amount of work to do for just a simple 2D screen setup and for just playing a sound, i seriously doubt anything useful can be done with such a small executable size...
You really don't need to write that much code to set up audio and graphics in todays windows.
DirectSound and Direct3D9 or OpenGL are your friends in the Windows Demos world.
Siekmanski is offline  
Old 11 March 2020, 16:54   #9
meynaf
son of 68k
meynaf's Avatar
 
Join Date: Nov 2007
Location: Lyon / France
Age: 47
Posts: 3,689
Quote:
Originally Posted by Siekmanski View Post
You really don't need to write that much code to set up audio and graphics in todays windows.
DirectSound and Direct3D9 or OpenGL are your friends in the Windows Demos world.
Is some code snippet available somewhere ?
What i've seen so far is much code.
meynaf is offline  
Old 11 March 2020, 17:08   #10
meynaf
son of 68k
meynaf's Avatar
 
Join Date: Nov 2007
Location: Lyon / France
Age: 47
Posts: 3,689
Quote:
Originally Posted by DanScott View Post
WHAT??? have you not seen some of the amazing 4k and 64k productions???
No, i haven't.


Quote:
Originally Posted by DanScott View Post
just a couple....
Neither of them accept to work on my setup.
meynaf is offline  
Old 11 March 2020, 17:13   #11
StingRay
move.l #$c0ff33,throat

StingRay's Avatar
 
Join Date: Dec 2005
Location: Berlin/Joymoney
Posts: 6,367
Quote:
Originally Posted by meynaf View Post
Considering the amount of work to do for just a simple 2D screen setup and for just playing a sound, i seriously doubt anything useful can be done with such a small executable size...

1k with sound:
https://www.pouet.net/prod.php?which=32194
StingRay is offline  
Old 11 March 2020, 17:18   #12
meynaf
son of 68k
meynaf's Avatar
 
Join Date: Nov 2007
Location: Lyon / France
Age: 47
Posts: 3,689
Quote:
Originally Posted by StingRay View Post
Which, again, doesn't work out of the box. At least not for me.
meynaf is offline  
Old 11 March 2020, 17:38   #13
DanScott
Lemon. / Core Design

DanScott's Avatar
 
Join Date: Mar 2016
Location: Sunny Bournemouth, UK
Posts: 581
and of course, the classic Amiga demo Nexus 7, remade in 8k :P

[ Show youtube player ]
DanScott is offline  
Old 11 March 2020, 17:49   #14
StingRay
move.l #$c0ff33,throat

StingRay's Avatar
 
Join Date: Dec 2005
Location: Berlin/Joymoney
Posts: 6,367
Quote:
Originally Posted by meynaf View Post
Which, again, doesn't work out of the box. At least not for me.

And still, size optimised Windows productions have existed for a long time already, if they run on your system or not doesn't change that fact.
StingRay is offline  
Old 11 March 2020, 18:18   #15
meynaf
son of 68k
meynaf's Avatar
 
Join Date: Nov 2007
Location: Lyon / France
Age: 47
Posts: 3,689
Quote:
Originally Posted by StingRay View Post
And still, size optimised Windows productions have existed for a long time already, if they run on your system or not doesn't change that fact.
I haven't said otherwise.
It's just that they do only small part of a correct setup and work on a limited amount of machines (and don't multitask properly, etc). It indeed makes it a lot easier to write small code.
I suppose anyway it's inherent to windows boxes that simple things never work properly everywhere.

Doing graphics and sound has never been a problem for me on the miggy but on peecees there is always something that goes wrong. Sigh.

I can't imagine playing protracker (with correct quality) with just a few kb of windows code.
Yet if it is about removing bytes out of the exe, it may be better to use a module packer such as Player 6.1 (P61A). Some probably have a shorter replay routine as well.
meynaf is offline  
Old 11 March 2020, 20:59   #16
Siekmanski
Registered User

Siekmanski's Avatar
 
Join Date: Nov 2019
Location: Groningen / the Netherlands
Posts: 7
I managed to produce a 100% correct mt_PeriodTable with only 144 bytes of code.
That's 12.5% of the original size, 1152 - 144 = 1008 bytes lost.
Think I can make it even smaller.....
Siekmanski is offline  
Old 11 March 2020, 21:10   #17
meynaf
son of 68k
meynaf's Avatar
 
Join Date: Nov 2007
Location: Lyon / France
Age: 47
Posts: 3,689
Quote:
Originally Posted by Siekmanski View Post
I managed to produce a 100% correct mt_PeriodTable with only 144 bytes of code.
That's 12.5% of the original size, 1152 - 144 = 1008 bytes lost.
Think I can make it even smaller.....
Have you considered using fixed point or changing rounding method ?
meynaf is offline  
Old 11 March 2020, 21:29   #18
Siekmanski
Registered User

Siekmanski's Avatar
 
Join Date: Nov 2019
Location: Groningen / the Netherlands
Posts: 7
Yes I have, it's not a rounding error ( tested them all ), round to nearest gives the best possible result.
Even higher resolution ( doubles ) gives the same result.
You end up with 32 periods that are 1 to high and 5 are 1 to low.
Siekmanski 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
How to calculate possible blit times? Steril707 Coders. Asm / Hardware 14 28 October 2016 13:41
Calculate offset using labels Beska Coders. Asm / Hardware 7 09 May 2016 19:56
Calculate Time-Tracks Pixel width? AGS Coders. General 22 10 March 2015 20:19
Calculate a color gradient. AGS Coders. Asm / Hardware 13 11 February 2015 12:20
Megaball (pre-4.0) Haxxy request.Old Rare Games 1 18 June 2009 19:00

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 11:51.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2020, vBulletin Solutions Inc.
Page generated in 0.08441 seconds with 14 queries