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 Composing > Converting samples to 3 bit
2011-04-08 04:23
TWW

Registered: Jul 2009
Posts: 541
Converting samples to 3 bit

What I want to do:

Play a 3 voice SID tune - while using the 3 LSB's of $d418 to play samples simultaniously (3rd bit of $d418 always set so one always hear the tune).


Problem:

#1: Making samples <- Suggestion for FW/PD tool to make samples with (win7x64).
#2: Converting the sample to 3 bits from however bit-width it was greated from tool in #1 <- The correct mathematical way or a converter to do it.
#3: Any good tip on how to make the samples as "clean" as possible in addition to higher sample frequency? (i.e. any pitfalls I should try to avoid like sampling with too high bit-width or such(which might lead to a bad conversion etc.))? <- Yeah I totally don't know what I'm talking about here in #3 so bear with me 8-D

/TWW
2011-04-08 07:19
ready.

Registered: Feb 2003
Posts: 441
about point 3: the Nyquist–Shannon sampling theorem says that if you want to reproduce a sampled signal, the sampling frequency fs must be at least twice the bandwidth B of the signal. So, considering that an audio signal frequncy spectrum goes from 0 Hz to B Hz:

fs > 2 * B

so, once you selected the sampling freq fs at which each sample is reproduced, you must apply a low pass filter to your audio signal that cuts all frequencies higher that fs/2.

If you don't do so, you will hear the effect of aliasing, which sounds much like unwanted noise.

sorry no idea about point 1 & 2

my 2 cents.
2011-04-08 07:51
TWW

Registered: Jul 2009
Posts: 541
Quote: about point 3: the Nyquist–Shannon sampling theorem says that if you want to reproduce a sampled signal, the sampling frequency fs must be at least twice the bandwidth B of the signal. So, considering that an audio signal frequncy spectrum goes from 0 Hz to B Hz:

fs > 2 * B

so, once you selected the sampling freq fs at which each sample is reproduced, you must apply a low pass filter to your audio signal that cuts all frequencies higher that fs/2.

If you don't do so, you will hear the effect of aliasing, which sounds much like unwanted noise.

sorry no idea about point 1 & 2

my 2 cents.


Alright, let me see if I got that right:

After deciding what frequency i will do the playback;

-> Remove all frequencies from the sample which are at 2x the playback frequency (i.e. if playback is at 20kHz, the sample should not conatin any audio signal higher then 40 kHz).

Instead of applying a LP-Filter for post processing is it possible to sample only certain frequency span (0-40Khz f.ex) thus eliminating the need for a LP filter later?

I guess this falls back to question #1...

EDIT: I found a software program called "Wavosaur" (suitable name don't u think^^) where I can play around with filters, samplerates and bit-width.

I have a sample 22050 Hz / 8 Bit Mono. However lower bit rates isn't supported so I still need to convert the 8 bit into a 3 bit.

The output file is .wav so I believe it uses signed numbers for presenting the data. For converting the sample I would have to ABSolute the data first, then multiply a factor of 3/8 to the result and voilla, 3 bits scaled representation... IMHO, this is probably a really bad way to do it and there is for sure some 'better result' yielding way?
2011-04-08 09:33
The Human Code Machine

Registered: Sep 2005
Posts: 110
For resampling I use the free r8brain, but I also didn't find a good tool to change the bit depth to any bit depth. Most tools only support 16 bit and 8 bit depth. You can lower the bit depth yourself by dividing the sample value by 2 for each bit. So a simple LSR should do the trick. My Mod-Converter adds a random dither while lowering 8 bit to 7 or 6 bit, but I don't know, if this helps at 3 bits. Forgot this link: Soundslogical Resampler but the demo download link is broken. Optimal would be a tool supporting noise shaping and or dithering.
2011-04-08 10:38
ready.

Registered: Feb 2003
Posts: 441
@TWW: no, it's the other way around: if playback is at 20kHz, the sample should not conatin any audio signal higher then 20/2=10 kHz

"sampling only certain frequency span" is exaclty what a filter does, so you end up needing the LP-filter.


2011-04-08 11:10
TWW

Registered: Jul 2009
Posts: 541
@ The Human Code Machine: A LSR would yieald 4 bits so still I'm 1 bit short. But I get your drift. Find the shrinkage factor and do it.

But I came to the same conclusion as you, more then just raw shrinkage (^^) needs to be applied to get a good result.

Has anyone had the chance to try out "Soundslogical Resampler"? It states it can handle various bit-width but ofcourse the demo is screwed. I don't mind dishing out some 20-30 $ (good echange rate anywasy) for it but would like to know if it works first...


@ Ready:

Alright, I got it now 8-D. Sample in "X"kHz but no sounds higher then "X/2"Khz for cleanest sound playback (hence the LP filter). It seems this can be post processed though in the proggie i mentioned above. If not I'll ask again^^ Thanx!
2011-04-08 11:16
SIDWAVE
Account closed

Registered: Apr 2002
Posts: 2238
why all this complicated stuff ?

soundforge, wavelab, audition - save as 4 bit unsigned raw.
(or save as 8 bit unsigned raw 8000 hz (THE old way)

convert to 3 bit in realtime on c64 with some code.



those programs resample as it shall be done, and so you dont have to do anything of that.
2011-04-08 12:09
ready.

Registered: Feb 2003
Posts: 441
@rambones: I am 99% sure most of those programs have automatic functions for "clean" re-sampling (i.e.: built in LP-filter and everything), but I just wanted to point out the theory, just in case TWW or others wanted to do the re-sampling in their own way.

I am working on a sound sampler for user-port and noticed the importance of the LP-filter for getting rid of aliasing noise.
2011-04-08 12:26
The Human Code Machine

Registered: Sep 2005
Posts: 110
@TWW For each bit less you'll need one LSR. If you want convert 8 bit samples to 3 bit samples you'll have to LSR 5 times.
2011-04-08 12:45
chatGPZ

Registered: Dec 2001
Posts: 11114
and remember to save them as unsigned before, or that shifting stuff will give you something like nu metal =)
2011-04-08 14:03
TWW

Registered: Jul 2009
Posts: 541
THCM:

5 LSRs?

8 bit sample gives an unsigned number between 0 to 255
3 bit sample gives an unsigned number between 0 to 7

so if the value = 161 in 8 bit the value in 3 bit should be equevivalent to:

161/255*7 = 4

If you take 161 and do 5 LSRs you get: 5

So I don't think it's entirely accurate to do it this way. I could how ever be terribly wrong here :) (it has happened before^^)

@ rambones: Can you also save in 3 bit? (25% less space right of the bat^^)
2011-04-08 14:28
ready.

Registered: Feb 2003
Posts: 441
@TWW: the correct math is:

161/256*8=5

which yelds to 5 times LSR

2011-04-08 15:01
TWW

Registered: Jul 2009
Posts: 541
Quote: @TWW: the correct math is:

161/256*8=5

which yelds to 5 times LSR



Actually the correct math is:

INT(161/256*8) = 5

If you rely on the rounding it does not work correctly (for some of the values in the byte range).

Anyways, the LSR x 5 is waterproof (yes I was wrong but to my defense I did mention that as a slight posibility^^).



Then the remaining question is:

Is this good enough or would a converter taking into account THCM's suggestion above regarding noise shaping and/or dithering be a (mouch?) better result?
2011-04-08 15:38
ready.

Registered: Feb 2003
Posts: 441
I guess the answer can be given by testing several conversion algorithms only.
2011-04-08 15:53
SIDWAVE
Account closed

Registered: Apr 2002
Posts: 2238
The leading sample programs can only save as 2/4/8/16+ etc.
2011-04-08 17:05
TWW

Registered: Jul 2009
Posts: 541
Alright. I guess that's sorted then :)

Thanx to all involved and taking the time to reply!
2011-04-08 20:30
ready.

Registered: Feb 2003
Posts: 441
but back to the original problem of not hearing the SID when $d418 = 0. Is it really a problem? I haven't tested but the zero would be played for just a very short period of time (sampling time), and would hardly be noticable.
2011-04-09 01:49
TWW

Registered: Jul 2009
Posts: 541
If I understood you correctly;

The point of doing 3 bit samples is that you can have the 4th bit (bit #3) set at all times, thus making any sound produced by the SID hearble even though you use the 3 LSBs (bit 0, 1 & 2) to modulate samples. This will effectivly give you 3 sid voices + 1 "3 bit sample voice". i.e. $d418 would never be zero but instead range from 8 to 15 depending on sampledata.

If I didn't understand you correctly: What?
2011-04-09 05:49
chatGPZ

Registered: Dec 2001
Posts: 11114
that idea is somewhat broken, what you really should do is simply use 4 bit samples and be done with it, there is no need to sacrifice that one bit at all.
2011-04-09 14:27
TWW

Registered: Jul 2009
Posts: 541
Alright. I'll do some testing on the whole matter and see what I come up with. I do however see ready.'s point of $d418 being 0 during sample playing but then again how much does it matter?

Let's for the sake of argument say that it is a problem for a sid-tune playing at the same time. with 4 bit samples you could then probably do "lsr + ora #$08" and get away with it (yes this is one thing I'm gonna test soon(tm)).

If this is the case, why not just have the sample in 3 bits to begin with (Maybee even processed a bit better then a straight lsr) and then gain a 25% memory boost in the process?

Or maybee I should just shut up and test it 8-D
2011-04-09 15:08
chatGPZ

Registered: Dec 2001
Posts: 11114
the point is that the average level of an audio sample is pretty much exactly half its amplitude. so playing a 4 bit sample along a sid tune practically equals playing the sid tune at half volume. now if you reduce the sample to 3 bits and offset it by 8 (by setting bit 3) that will equal playing the sid tune at 75% original volume.

so you are really trying to solve a problem that does not exist, you are only making it worse =)
2011-04-09 20:24
GT
Account closed

Registered: Sep 2008
Posts: 308
ORA #8
Done.
2011-04-10 08:11
linde

Registered: Jul 2006
Posts: 47
So you want to store them in three bits per sample? That's a minimal memory gain in most cases I think, (you could try some 1-bit linear encoding instead) but if you really want to try, I could make a tool to convert 8 bit raw to 3 bit raw.
2011-04-10 11:08
TWW

Registered: Jul 2009
Posts: 541
Ok I see that 4 bits is sufficient in most cases.


But for the share fun of it, It would be fun to try the 3 bit approach yielding 75% volume (on average) vs. the 50% vulume (avg.) achieved through 4 bit.

I "picture" the samples to be stored in layers over the same bytes (Yeah I know that sounds weird) like this:

11122233 34445556 66777888 11122233 34445556 66777888 etc.

So if I want to play sample #1:
lda byte 1
and #%11100000
sec
rol
rol
rol
rol

sta $02
lda $d418

and #$f0
ora $02
sta $d418

or if the hi-nybble of $d418 is known at playtime:

lda byte 1
and #%11100000
sec
rol
rol
rol
rol
ora #$X0 // Hi-nybble
sta $d418

Then increase the byte-fetcher with 3 and do again. An index-table would be faster to use if cycles are an isse vs. memory (as usual^^)

@ Groepaz: I like making problems (hehe). But seriously imho it's a quality vs. memory+slightly higer volume issue(maybee^^)

@ Geir: yes agreed for 4 bit playback.

@ Linde: A cross platform tool for prepping the samples would be cool if it uses a "better" aproacht (dithering or noise shaping?) then just dividing each byte with 32 (5 X LSRs). If this wasn't what you had in mind, it would be easy to da a straight converter tool on the c64 to convert from 4 bit or even 8 bits Unsigned RAW (if memory is enough).
2011-04-11 20:13
algorithm

Registered: May 2002
Posts: 702
I would not bother with the 3 bit conversion. Even though the samples will use less space, it is more awkward for the bits to be extracted from packed bytes as well as the noise involved.
As the samples are updated thousands of times per second, there is less likelihood of muting the other audio if using the traditional 4 bit method

Severe issues ofcourse is that the digi's will be near or enough quiet on a new sid chip (unless using one or more channels to boost the digi)

I would recommend 8 bit all the way with compression (vq and/or delta modulation) but of course this method uses sid channels
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
Røly/Mayday!
DJ Gruby/TRiAD
MaD ][/Starship
d'Arc/Topaz Beerline
Exploding Fi../Techn..
Didi/Laxity
Dymo/G★P
algorithm
Guests online: 101
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 Memento Mori  (9.6)
10 Bromance  (9.5)
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 Swappers
1 Derbyshire Ram  (10)
2 Jerry  (9.8)
3 Violator  (9.8)
4 Acidchild  (9.7)
5 Starlight  (9.6)

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