English Amiga Board


Go Back   English Amiga Board > Coders > Coders. General

 
 
Thread Tools
Old 22 January 2023, 07:54   #21
Steam Ranger
Registered User

Steam Ranger's Avatar
 
Join Date: May 2022
Location: Adelaide
Posts: 111
How do I apply delta encoding? What file format is it? Can I do it in Audacity?
Steam Ranger is offline  
Old 22 January 2023, 09:59   #22
Karlos
Registered User

 
Join Date: Aug 2022
Location: UK
Posts: 1,841
Quote:
Originally Posted by Steam Ranger View Post
How do I apply delta encoding? What file format is it? Can I do it in Audacity?
1. Start with a current value, initially set to zero.
2. Read the next sample
3. Delta = sample - current
4. Choose the quantized delta value from your table that gets you closest to the the actual sample value.
5. Current = Current + quantized delta
6. Repeat from 2.

The idea here is that each quantised delta step is usually going to undershoot or overshoot the desired target but it's always correcting towards it rather than just drifting off all over the place.
Karlos is offline  
Old 22 January 2023, 11:01   #23
Steam Ranger
Registered User

Steam Ranger's Avatar
 
Join Date: May 2022
Location: Adelaide
Posts: 111
Quote:
Originally Posted by Karlos View Post
1. Start with a current value, initially set to zero.
2. Read the next sample
3. Delta = sample - current
4. Choose the quantized delta value from your table that gets you closest to the the actual sample value.
5. Current = Current + quantized delta
6. Repeat from 2.
And to decode I basically just do the procedure in reverse?
Steam Ranger is offline  
Old 22 January 2023, 12:16   #24
No.3
Registered User

 
Join Date: Sep 2022
Location: Switzerland
Posts: 68
http://aminet.net/package/mus/misc/wavepak
No.3 is offline  
Old 22 January 2023, 14:30   #25
Karlos
Registered User

 
Join Date: Aug 2022
Location: UK
Posts: 1,841
Quote:
Originally Posted by Steam Ranger View Post
And to decode I basically just do the procedure in reverse?
Yeah, except you just directly look up the quantised delta value from the table. The value you store in the compressed stream is just the nybble index position of the quantized delta value in the table.
Karlos is offline  
Old 22 January 2023, 14:31   #26
Karlos
Registered User

 
Join Date: Aug 2022
Location: UK
Posts: 1,841
Quote:
Originally Posted by No.3 View Post
This looks entirely cromulent. Includes source too by the look of it.
Karlos is offline  
Old 22 January 2023, 15:27   #27
koobo
Registered User

koobo's Avatar
 
Join Date: Sep 2019
Location: Finland
Posts: 278
Off topic:
This AGA demo by Union from 1995 had a whole Pink Floyd tune encoded into it: https://www.pouet.net/prod.php?which=7824
koobo is offline  
Old 22 January 2023, 22:44   #28
smack
Registered User
 
Join Date: May 2020
Location: Germany
Posts: 20
All this talk about 4-bit delta and XPK SQSH compression reminds me of a program that I wrote a few (well almost exactly 26 ) years ago:
http://aminet.net/package/mus/play/psmp = IFF-8SVX player (source code included)
smack is offline  
Old 22 January 2023, 23:35   #29
pandy71
Registered User
 
Join Date: Jun 2010
Location: PL
Posts: 2,316
Quote:
Originally Posted by No.3 View Post

Name can be confusing with https://en.wikipedia.org/wiki/WavPack but seem that Wilhelm Noeker was first.

Last edited by pandy71; 22 January 2023 at 23:48.
pandy71 is offline  
Old 22 January 2023, 23:57   #30
Karlos
Registered User

 
Join Date: Aug 2022
Location: UK
Posts: 1,841
Many years ago, I wrote an adaptive, frame based delta encoder for 16 bit audio, intended for sound effects and speech. It had frames encoded as 0, 1, 2, 3, 4 or 5 bits per sample packed into 16 bit words. 0 was a special case for silence encoding (used in noise gated speech). A stream had a uniform output frame length, e.g 1024 samples, but this applied to that stream only. Each frame had a header that contained the actual delta decode table (only as many as the distinct number of values present) followed by the packed data. Although this was somewhat wasteful, the point was that the encoder was free to choose the best N delta values for the set of input samples in the fram. Costs were assigned to each bit depth, 5 being the most expensive (from a compression perspective) while the overall RMS quantisation noise of the output compared to the input was scored for quality. The encoder, with an overall quality parameter value, would weigh the encoding cost against the quantisation error cost and try to find the best fit.

This was all compression time overhead. Decompressing was the same as described in earlier posts, except that the delta table wasn't global, but unique per frame.

The encoder actually had a UI. Screenshot, showing the analysis of a single frame: https://github.com/0xABADCAFE/ancien...shot/xdac1.png

Last edited by Karlos; 23 January 2023 at 00:35.
Karlos is offline  
Old 23 January 2023, 00:31   #31
Karlos
Registered User

 
Join Date: Aug 2022
Location: UK
Posts: 1,841
I should revisit and simplify that some time. For one thing, when you have a frame of hundreds or samples your delta values, when sorted ascending, always follow a sigmoidal sort of shape. Rather than storing the delta values maybe the parameters of the curve of best fit could be used. That does imply more runtime effort to decode, bur there'd be better compression of the frame overall.
Karlos is offline  
Old 23 January 2023, 10:51   #32
Steam Ranger
Registered User

Steam Ranger's Avatar
 
Join Date: May 2022
Location: Adelaide
Posts: 111
Does anyone know where I can get the source code for a media player or something? I want a sample to pick apart and build a working set of audio functions.
Steam Ranger is offline  
Old 23 January 2023, 19:03   #33
paraj
Registered User

 
Join Date: Feb 2017
Location: Denmark
Posts: 579
Quote:
Originally Posted by Steam Ranger View Post
Does anyone know where I can get the source code for a media player or something? I want a sample to pick apart and build a working set of audio functions.
The source code linked in post 13 should be close to what you want (though you may want to strip it down a bit). Otherwise maybe something like http://aminet.net/package/mus/play/playsound could be a decent starting point (a bit old school, but system friendly).

Quote:
Originally Posted by Karlos
The table was to be illustrative rather than a real world example.
Yes, sorry, I'm a dunce.
Quote:
Originally Posted by Karlos
The encoder actually had a UI. Screenshot, showing the analysis of a single frame: https://github.com/0xABADCAFE/ancien...shot/xdac1.png
Very cool! I see there's also very readable source code there. Some neat ideas, and maybe a tweaked version could even make sense for OP's use case. You could precalc a number of tables ahead of time, make optimized decode routines for each bit/sample version (maybe only 0/2/4 or something), and have a tiny header for each frame (the length of which could be optimized to match the playback rate).
paraj is offline  
Old 23 January 2023, 21:23   #34
Karlos
Registered User

 
Join Date: Aug 2022
Location: UK
Posts: 1,841
Quote:
Originally Posted by paraj View Post
The source code linked in post 13 should be close to what you want (though you may want to strip it down a bit). Otherwise maybe something like http://aminet.net/package/mus/play/playsound could be a decent starting point (a bit old school, but system friendly).


Yes, sorry, I'm a dunce.

Very cool! I see there's also very readable source code there. Some neat ideas, and maybe a tweaked version could even make sense for OP's use case. You could precalc a number of tables ahead of time, make optimized decode routines for each bit/sample version (maybe only 0/2/4 or something), and have a tiny header for each frame (the length of which could be optimized to match the playback rate).

Damn I wouldn't call that crap readable, it was like my first day

It's based on a very early C++ framework, before I found my preferred style and had much understanding how to wield it properly. On the plus side, the UI was fully hardware rendered, using a drawing library on top of Warp3D in that example. It's running on an unreleased driver iteration that actually does line drawing on the GPU I had. All the shading (which reflects the signal intensity ranges) are Gouraud shaded rectangles and the character glyphs are actually alpha blended textures.

It's coming back to me now. The lower graph shows the distinct, ordered deltas as the yellow plot, their population as the blue plot (almost always flat you'll notice) and the best fit curve based on the chosen 16 values in white. The overlay of this graph doesn't look that ideal but that's because the horizontal coordinates of each point don't take any weighting of the input values into consideration, they are just evenly spaced.

Last edited by Karlos; 23 January 2023 at 21:41.
Karlos is offline  
Old 23 January 2023, 21:27   #35
Karlos
Registered User

 
Join Date: Aug 2022
Location: UK
Posts: 1,841
On a semi related note, I do have an improved 8 bit format intended for Paula specifically but I've not implemented playback for real, only simulation. If you are interested, it's here https://github.com/0xABADCAFE/paula-hdr

It's very different. Rather than being a second rate 16-bit alternative, it aims to be the best 8-bit. 16 bit data are converted to 8 bit, using gain adjusted frames. The gain adjustment at runtime is intended to happen via Paula channel volume modulation being applied in hardware. So every frame has 8-bit precision but a gain that changes the channel volume. The simulation produces excellent results but I've not implemented it for Paula yet.

Last edited by Karlos; 23 January 2023 at 21:43.
Karlos is offline  
Old 24 January 2023, 16:32   #36
ross
Defendit numerus

ross's Avatar
 
Join Date: Mar 2017
Location: Crossing the Rubicon
Age: 53
Posts: 4,079
Quote:
Originally Posted by Karlos View Post
On a semi related note, I do have an improved 8 bit format intended for Paula specifically but I've not implemented playback for real, only simulation. If you are interested, it's here https://github.com/0xABADCAFE/paula-hdr

It's very different. Rather than being a second rate 16-bit alternative, it aims to be the best 8-bit. 16 bit data are converted to 8 bit, using gain adjusted frames. The gain adjustment at runtime is intended to happen via Paula channel volume modulation being applied in hardware. So every frame has 8-bit precision but a gain that changes the channel volume. The simulation produces excellent results but I've not implemented it for Paula yet.
This is interesting, but there is possibly a flaw in this approach: amplitude modulation is word based, so volume change is per two samples* (usual "14-bit" player is byte based).
Also sure it's faster (than 14-bit) and sounds better than normal 8 bit, but it only works for two maximum usable channels.
In any case I'd like to hear the results, it might be unexpectedly good

An alternative method that had been floating around in my mind a while back was to use copper to apply volume to individual channels.
But it would be annoying because it would require mixing on a frequenncy multiple of video line in order not to lose any other effects with the copper.
Theoretically the result would be absolutely similar to amplitude modulation on a single sample per 4 channels.

EDIT: *actually with modulator channel at doubled frequency you could do it per sample, but then the modulated channel is at half max frequency..

Last edited by ross; 24 January 2023 at 16:49.
ross is offline  
Old 24 January 2023, 17:08   #37
Karlos
Registered User

 
Join Date: Aug 2022
Location: UK
Posts: 1,841
Quote:
Originally Posted by ross View Post
This is interesting, but there is possibly a flaw in this approach: amplitude modulation is word based, so volume change is per two samples* (usual "14-bit" player is byte based).
Also sure it's faster (than 14-bit) and sounds better than normal 8 bit, but it only works for two maximum usable channels.
In any case I'd like to hear the results, it might be unexpectedly good

An alternative method that had been floating around in my mind a while back was to use copper to apply volume to individual channels.
But it would be annoying because it would require mixing on a frequenncy multiple of video line in order not to lose any other effects with the copper.
Theoretically the result would be absolutely similar to amplitude modulation on a single sample per 4 channels.

EDIT: *actually with modulator channel at doubled frequency you could do it per sample, but then the modulated channel is at half max frequency..
That was already taken into consideration. The shortest possible frame is 2 samples of the same overall volume. The actual intention is that a frame would be longer than that, but always a multiple of 2 for the very reason you state.

See: https://github.com/0xABADCAFE/paula-...ee/master/data

The encoded.raw file is 44kHz signed 8 bit with the volume sample (0-64) followed by 16 8-bit signed samples to be played at that volume. It's also mono.

The decoded.raw file is the simulation output where we assume no latency applying the volume modulation in hardware. It's 44kHz 16 bit, mono, little endian encoded because I just did the prototyping on my pc initially. Based on subtracting it from the original 16 bit input and measuring the RMS error, it seems pretty decent.

The original input file is the one that's labelled test_raw16bit_LE.raw

Obviously the real file format would have a header and would probably arrange the data in a way better suited for playback under the proposed channel modulation scheme.

Last edited by Karlos; 24 January 2023 at 17:49.
Karlos is offline  
Old 24 January 2023, 23:00   #38
Karlos
Registered User

 
Join Date: Aug 2022
Location: UK
Posts: 1,841
Just thinking a moment. Let's say the automatic gain adjustment idea works, i.e. using hardware volume modulation updated every "frame". The 8 bit PCM data itself is always as close to normalised in intensity. It makes me wonder if you could then compress that to 4 bit using the basic techniques we've been describing so far. You'd still have better dynamic range than 8 bit overall and much smaller data than 16 bit.
Karlos is offline  
Old 02 February 2023, 23:40   #39
robinsonb5
Registered User

 
Join Date: Mar 2012
Location: Norfolk, UK
Posts: 1,095
I saw a blog post today and immediately thought of this thread:
https://phoboslab.org/log/2023/02/qo...io-compression
Maybe it could be adapted for Amiga use - or maybe not - but either way there's some good information there - I hope it least makes for interesting reading.
robinsonb5 is offline  
Old 03 February 2023, 00:42   #40
ross
Defendit numerus

ross's Avatar
 
Join Date: Mar 2017
Location: Crossing the Rubicon
Age: 53
Posts: 4,079
Quote:
Originally Posted by robinsonb5 View Post
I saw a blog post today and immediately thought of this thread:
https://phoboslab.org/log/2023/02/qo...io-compression
Maybe it could be adapted for Amiga use - or maybe not - but either way there's some good information there - I hope it least makes for interesting reading.
Yes, it may be adapted but it definitely wouldn't be as fast as an ADPCM decoder.
From a quick look the only sticking point would be a multiplication per sample (data structures designed for 64-bit architectures can simply be redesigned).

For sure for a (fast?) 020+ machine.
ross 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
Compressed filelist.txt jbl007 project.Amiga File Server 1 11 November 2017 22:54
fs-uae and cd32 compressed audio deejay support.FS-UAE 3 24 March 2014 20:17
ADF file compressed with RAR pucci support.WinUAE 5 16 October 2011 12:37
Compressed HDF saving BippyM request.UAE Wishlist 5 17 October 2005 23:12
Multi-Disk Compressed ADF? TheOutrider support.WinUAE 10 02 October 2003 10:44

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 07:41.


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