Log inRegister an accountBrowse CSDbHelp & documentationFacts & StatisticsThe forumsAvailable RSS-feeds on CSDbSupport CSDb Commodore 64 Scene Database
You are not logged in - nap
CSDb User Forums


Forums > C64 Coding > Sample audio on C64, how to do a better conversion?
2020-07-17 08:00
zzarko

Registered: Feb 2003
Posts: 66
Sample audio on C64, how to do a better conversion?

Hi all!

Recently I have found about c64kernel and a movie player based on that code that uses 16MB REU as a storage. (https://github.com/vbguyny/c64kernel). Movie is based on Koala image sequences, and audio is 4bit samples, where playing routine is based on codebase64 code (https://codebase64.org/doku.php?id=base%3Anmi_sample_player) There is a manual that describes how to make a movie at
https://github.com/vbguyny/c64kernel/blob/master/doc/HowToMakeA..

Anyway, I wanted to make an automatic conversion from a movie file to format for that player and have come up with this Bash script:
https://bitbucket.org/zzarko/c64movie

For audio conversion I did this: converted audio to 8-bit unsigned raw format, and then extracted higher 4 bits from every byte. The result isn't bad, but it is somewhat worse than what "Wav to digi" program can produce (Wav to Digi). So, my question is what could I do to make audio conversion better?

I know that there are more advanced audio and video player routines by magicians around here (I enjoy watching their work!), but nevertheless, if you have some advice, please tell.

One of conversions I did this way:
https://www.youtube.com/watch?v=LN3y1koqi3A
2020-07-17 12:20
tlr

Registered: Sep 2003
Posts: 1714
The steps of $d418 volume changes aren't equal in size (more or less exponential). Just taking the upper 4 bits will give you some unwanted distortion. You should probably compensate for that to improve the fidelity.

More modern playback strategies will allow you to do 8-bit (linear) playback though.
2020-07-17 13:22
Krill

Registered: Apr 2002
Posts: 2839
Quoting tlr
The steps of $d418 volume changes aren't equal in size (more or less exponential). Just taking the upper 4 bits will give you some unwanted distortion. You should probably compensate for that to improve the fidelity.
This is true for 6581 oldsid, but not for 8580 newsid, right?

From https://sourceforge.net/p/sidplay-residfp/code/HEAD/tree/trunk/..
    // Non-linearity parameter, 8580 DACs are perfectly linear
    const double _2R_div_R = chipModel == MOS6581 ? 2.20 : 2.00;
That said, i'd really like to have a simple 16-values table with the non-linear curve. =)
2020-07-17 14:49
tlr

Registered: Sep 2003
Posts: 1714
Quoting Krill
Quoting tlr
The steps of $d418 volume changes aren't equal in size (more or less exponential). Just taking the upper 4 bits will give you some unwanted distortion. You should probably compensate for that to improve the fidelity.
This is true for 6581 oldsid, but not for 8580 newsid, right?

From https://sourceforge.net/p/sidplay-residfp/code/HEAD/tree/trunk/..
    // Non-linearity parameter, 8580 DACs are perfectly linear
    const double _2R_div_R = chipModel == MOS6581 ? 2.20 : 2.00;

Nah, that's a different set of DACs. The volume is handled using a 4-bit MDAC. In resid that's calculated in FilterModelConfig/FilterModelConfig8580 (returned by getGain() ).
Though the volume sample method requires some trickery to function on 8580 so it's not ideal there.

I admit to having no experience of 8580 on real HW so I can't really tell if the curve differs. :)
2020-07-17 14:56
chatGPZ

Registered: Dec 2001
Posts: 11114
On real Hardware the curve also changes depending on Filter settings and currently playing voices. Also the impulse response is probably not quite symmetric either... so whatever conversion someone comes up with, it probably must also be tweaked to the player that plays it.
2020-07-17 15:01
tlr

Registered: Sep 2003
Posts: 1714
Interestingly the 6581 datasheet claims "Bits 0-3 (VOL0-VOL3) select 1 of 16 overall volume levels for the final composite audio output. The output volume levels range from no output (0) to maximum volume (15 or $F) in 16 linear steps."
From what I recall it doesn't try to be linear but I might be wrong. Didn't measure it myself.
2020-07-17 15:09
chatGPZ

Registered: Dec 2001
Posts: 11114
The volume level isnt 1:1 related to the "sample value", its a bit less trivial than that :=)
2020-07-17 20:39
Krill

Registered: Apr 2002
Posts: 2839
Okay, but there should be some default non-linear mapping which is a sane compromise for most tunes on most SIDs. Anyone? :)
2020-07-17 21:06
Mixer

Registered: Apr 2008
Posts: 422
Mahoneys Music Run/Stop technical details pdf should have the data IIRC.
2020-07-17 21:59
Durandal

Registered: May 2006
Posts: 30
The Python conversion code we're using for streaming on the Turbo56K BBS, while not specifically taking into account any non linearity of the SID, it does a decent job in most cases.

This code accepts most audio file formats

import librosa
import numpy

y, sr = librosa.load(filename, samplerate, True) #load file

numpy.clip(y, -1, 1, y) #Clip samples
norm = librosa.mu_compress(y, mu=15, quantize=True) #mu-compress and quantize to 16 different values
norm = norm + 8 #offset the samples values
									
bin8 = numpy.uint8(norm) #convert to 8-bit unsigned


bin8 contains 4-bit sample data in the lower nibble of each byte.
2020-07-17 23:51
Krill

Registered: Apr 2002
Posts: 2839
Quoting Durandal
[...]not specifically taking into account any non linearity of the SID[...]
[...]mu_compress[...]
Okay, so my takeaway is that applying μ-law is better than using a linear mapping, no matter if specifically tweaked for SID or not.
 
... 7 posts hidden. Click here to view all posts....
 
Previous - 1 | 2 - Next
RefreshSubscribe to this thread:

You need to be logged in to post in the forum.

Search the forum:
Search   for   in  
All times are CET.
Search CSDb
Advanced
Users Online
Endurion
Airwolf/F4CG
csio/monarchy c+4
icon/The Silents, Sp..
Trash
zscs
Guests online: 103
Top Demos
1 Next Level  (9.8)
2 Mojo  (9.7)
3 Coma Light 13  (9.7)
4 Edge of Disgrace  (9.6)
5 Comaland 100%  (9.6)
6 No Bounds  (9.6)
7 Uncensored  (9.6)
8 Wonderland XIV  (9.6)
9 Bromance  (9.6)
10 Memento Mori  (9.6)
Top onefile Demos
1 It's More Fun to Com..  (9.7)
2 Party Elk 2  (9.7)
3 Cubic Dream  (9.6)
4 Copper Booze  (9.5)
5 TRSAC, Gabber & Pebe..  (9.5)
6 Rainbow Connection  (9.5)
7 Onscreen 5k  (9.5)
8 Wafer Demo  (9.5)
9 Dawnfall V1.1  (9.5)
10 Quadrants  (9.5)
Top Groups
1 Oxyron  (9.3)
2 Nostalgia  (9.3)
3 Booze Design  (9.3)
4 Censor Design  (9.3)
5 Crest  (9.3)
Top Musicians
1 Rob Hubbard  (9.7)
2 Jeroen Tel  (9.6)
3 Stinsen  (9.6)
4 Mutetus  (9.6)
5 Linus  (9.6)

Home - Disclaimer
Copyright © No Name 2001-2024
Page generated in: 0.077 sec.