Jump to content
IGNORED

Sample Conversion for A8


Heaven/TQA

Recommended Posts

I am just trying to convert samples for Sheddy's replay routine...

 

What I am using on OSX is Sox and the Sox Wrap GUI.

 

so actually I have a sample in WAV form, 16 bit as input file (sample rate is determintated automaticly), as output I am using RAW format, sample rate of 4000 Hertz, signed linear for data encoding, data size bytes, 1 channel

 

so Sox converts the file to the raw format and downsampling the original sample.

 

Now in Turbo Basic I am doing these steps for conversion in our 4bit sample format:

 

first step is reducing from 8bit to 4 bit... by doing

 

(peek(sample)+128)div16

 

then I am packing the values together by doing this

 

peek(sample)*16+peek(sample+1)

 

but the sample sounds strange and I can even recognise it...

 

but when saving as WAV file itunes plays it correct as 8bit sample mono sample...

 

any help?

Link to comment
Share on other sites

If they're signed samples, you need to alter your calculations.

 

IF SAMP>128 THEN SAMP=SAMP-128 ELSE SAMP=SAMP+128

 

That should adjust to unsigned samples... remember that 0 is midpoint, so 0 will now = 128

127 will = 255

 

255 (-1) will = 127

129 (-127) will = 1

 

Then just do your rounding to get a 4-bit sample.

Link to comment
Share on other sites

so actually I have a sample in WAV form, 16 bit as input file (sample rate is determintated automaticly), as output I am using RAW format, sample rate of 4000 Hertz, signed linear for data encoding, data size bytes, 1 channel

 

so Sox converts the file to the raw format and downsampling the original sample.

 

Like Rybags said, your output is signed linear. You can tell sox to convert it to unsigned linear.

 

Also, I suggest you band filter and normalize the input before you downsample, i.e. cut all frequencies between 100Hz and ~1.8kHz and then maximize the amplitude to 0dB.

 

Depending on the sound you are working with, you might also want to run it through a compressor/limiter and normalize again afterwards. This will make soft sounds louder and loud sounds softer, i.e. it decreases the dynamic range but gets you "more sound per bit".

 

Lastly, during your requantization step in Turbo Basic, you could add some white noise to evenly spread the requantization errors. This is called dithering. Shaped dithering is probably overkill and not really useful going down to only four bits, but if you have some spare time, it might be useful to explore too.

Edited by ivop
Link to comment
Share on other sites

so actually I have a sample in WAV form, 16 bit as input file (sample rate is determintated automaticly), as output I am using RAW format, sample rate of 4000 Hertz, signed linear for data encoding, data size bytes, 1 channel

 

so Sox converts the file to the raw format and downsampling the original sample.

 

Like Rybags said, your output is signed linear. You can tell sox to convert it to unsigned linear.

 

Also, I suggest you band filter and normalize the input before you downsample, i.e. cut all frequencies between 100Hz and ~1.8kHz and then maximize the amplitude to 0dB.

 

Depending on the sound you are working with, you might also want to run it through a compressor/limiter and normalize again afterwards. This will make soft sounds louder and loud sounds softer, i.e. it decreases the dynamic range but gets you "more sound per bit".

 

Lastly, during your requantization step in Turbo Basic, you could add some white noise to evenly spread the requantization errors. This is called dithering. Shaped dithering is probably overkill and not really useful going down to only four bits, but if you have some spare time, it might be useful to explore too.

 

 

is there an atari native tool which can load wav files and convert them to 4bit samples so I can avoid coding errors and mistakes by my own code?

Link to comment
Share on other sites

 

is there an atari native tool which can load wav files and convert them to 4bit samples so I can avoid coding errors and mistakes by my own code?

 

 

Yes,

there are some A8 tools which can load 8bit WAV files and convert them into 4bit sample files... see the attachment here. Of course since most WAV`s are 16Bit you have to convert them to 8Bit on the PC first, before you can convert them to 4Bit on the A8 (ok, there is also a WAV player and converter by Tom Hunt, named The Sound Utility that afaik can load 16Bit WAV`s and play them back as 8Bit and/or save as 4Bit samples)...

 

Attached you find a polish sample converter (SMPCONVx.ATR, where x is side a or side b) that converts 8bit into 4 bit samples. Next I have added my sound players, if you take a look at SNDPLAY2.ATR you will find three tools named WAVCONVx.* (one in TB XL and two in ML), that will convert an 8Bit WAV into 4bit sample. The mentioned Sound Utility is also on the SNDPLAYx.ATR disks (disk 1 or disk 2), but it only works 100% correct under Sparta or Bewe Format (DIR, Exit options do not work correct under DOS 2 derivatives, load+play+save works). Last not least I have added the sample software (SMPSOFTx.ATR) for the 4Bit ANG/Mirage sample cartridge and two images with various sample programs (Sampi.ATR and Sampler.ATR), maybe they are useful, maybe they are not...

 

Afair, WIN 3.x already contained a WAV player/recorder that could convert any 16Bit WAV into 8Bit (I still have this tool under Win 3.1 on my DOS based Pc and I have almost the same tool under WIN XP). Of course there are many other tools for this job on the PC available and I am sure there are also quite many for the Apple out there...

 

greetings, Andreas Koch.

Link to comment
Share on other sites

 

is there an atari native tool which can load wav files and convert them to 4bit samples so I can avoid coding errors and mistakes by my own code?

 

 

Yes,

there are some A8 tools which can load 8bit WAV files and convert them into 4bit sample files... see the attachment here. Of course since most WAV`s are 16Bit you have to convert them to 8Bit on the PC first, before you can convert them to 4Bit on the A8 (ok, there is also a WAV player and converter by Tom Hunt, named The Sound Utility that afaik can load 16Bit WAV`s and play them back as 8Bit and/or save as 4Bit samples)...

 

Attached you find a polish sample converter (SMPCONVx.ATR, where x is side a or side b) that converts 8bit into 4 bit samples. Next I have added my sound players, if you take a look at SNDPLAY2.ATR you will find three tools named WAVCONVx.* (one in TB XL and two in ML), that will convert an 8Bit WAV into 4bit sample. The mentioned Sound Utility is also on the SNDPLAYx.ATR disks (disk 1 or disk 2), but it only works 100% correct under Sparta or Bewe Format (DIR, Exit options do not work correct under DOS 2 derivatives, load+play+save works). Last not least I have added the sample software (SMPSOFTx.ATR) for the 4Bit ANG/Mirage sample cartridge and two images with various sample programs (Sampi.ATR and Sampler.ATR), maybe they are useful, maybe they are not...

 

Afair, WIN 3.x already contained a WAV player/recorder that could convert any 16Bit WAV into 8Bit (I still have this tool under Win 3.1 on my DOS based Pc and I have almost the same tool under WIN XP). Of course there are many other tools for this job on the PC available and I am sure there are also quite many for the Apple out there...

 

greetings, Andreas Koch.

 

thx Andreas,

 

I will have a look tomorrow.

 

Cheers.

 

Hve

Link to comment
Share on other sites

If they're signed samples, you need to alter your calculations.

 

IF SAMP>128 THEN SAMP=SAMP-128 ELSE SAMP=SAMP+128

 

That should adjust to unsigned samples... remember that 0 is midpoint, so 0 will now = 128

127 will = 255

 

255 (-1) will = 127

129 (-127) will = 1

 

Then just do your rounding to get a 4-bit sample.

 

8-bit signed would range from -128..127 so you would have to do "IF SAMP>=128" or try like:

 

SAMP = ASC(CHR$(SAMP+128))

 

or use ASM to toggle buffer at (203) from signed<->unsigned:

 

LDY #TotalSamples

TOGGLE: LDA (203),Y

EOR #128

STA (203),Y

INY

BNE TOGGLE

Link to comment
Share on other sites

If they're signed samples, you need to alter your calculations.

 

IF SAMP>128 THEN SAMP=SAMP-128 ELSE SAMP=SAMP+128

 

That should adjust to unsigned samples... remember that 0 is midpoint, so 0 will now = 128

127 will = 255

 

255 (-1) will = 127

129 (-127) will = 1

 

Then just do your rounding to get a 4-bit sample.

 

8-bit signed would range from -128..127 so you would have to do "IF SAMP>=128" or try like:

 

SAMP = ASC(CHR$(SAMP+128))

 

or use ASM to toggle buffer at (203) from signed<->unsigned:

 

LDY #TotalSamples

TOGGLE: LDA (203),Y

EOR #128

STA (203),Y

INY

BNE TOGGLE

 

That should be LDY #256-TotalSamples. I do have a Windows utility to convert 16-bit/8-bit sound to 4-bit nibbles and normalize them but it does LSB nibble for first sample rather than MSB nibble.

Link to comment
Share on other sites

I just use a quick/dirty Basic program in the emulator... run it in turbo it's over and done with in seconds.

 

Another advantage is you can just use 48,000 Hz sampled data, then just put some code in to do averaging on groups to downsample to 4 or 8 KHz.

 

Audacity is handy, as you can just Export Raw in a unsigned 8-bit integer. But the program itself is at times annoying and seems to have a few bugs.

Link to comment
Share on other sites

I just use a quick/dirty Basic program in the emulator... run it in turbo it's over and done with in seconds.

 

Another advantage is you can just use 48,000 Hz sampled data, then just put some code in to do averaging on groups to downsample to 4 or 8 KHz.

 

Audacity is handy, as you can just Export Raw in a unsigned 8-bit integer. But the program itself is at times annoying and seems to have a few bugs.

 

Better yet, write code to play the 8-bit signed data on the Atari using frequency modulation and you won't have to worry about converting it to 4-bits or making it unsigned. Perhaps, add some fast lossless decompressor to save space.

Link to comment
Share on other sites

  • 4 weeks later...

Andreas, I have played around with the tools but did not find in a short notice a tool where I simply can load a .wav file?

 

Andy, TMR or Pete as c64 guys... is there a tool where I can simply convert 16 bit wav files (short ones) into 4 bit raw files which I can then use on A8?

 

Adobe Audition, or its prior name Cool Edit Pro..

You can use any bit depth you want, 1bit, 2bit 3bit etc.. And saving works beautifully, though it doesn't pack them into nybbles for you..

I'll have a dig through my old 2600 and 7800 stuff and see I'm sure I've got one, I don't have any 64 tools for that since I hate 4 bit samples on the 64 ;)

 

If not it's 2 minutes knock one up..

 

But I can't recommend enough using Audition or CEP enough to at least prepare the samples..

Link to comment
Share on other sites

Here's an old one from my 2600 days.. It's not packing into nibbles (I was playing with 5 bit playback) but you can change it *very* easily.. And the output bit depth is part of the command line..

 

It chucks out something looking like this:

;	
;	Fri Aug 15 18:25:43 2003

;	Source File: CBRZ_7680.wav
;	Bits: 5bit Unsigned
;	Amp:: 1.50
;	Rate: 7680
;	Length: 0.14 seconds
;	Length: 1109 samples
;	Padding: 2048 bytes
;	
.byte	$0f,$10,$0f,$10,$0e,$0f,$0f,$0f,$0e,$10,$11,$11,$0c,$15,$1a,$00
.byte	$08,$1f,$1f,$1f,$19,$00,$00,$00,$06,$19,$1a,$00,$00,$08,$17,$1f
.byte	$1f,$1f,$1d,$11,$00,$0d,$0e,$00,$00,$00,$00,$0f,$1e,$1f,$1f,$1f
.byte	$1f,$1f,$1f,$16,$11,$00,$00,$00,$00,$00,$00,$09,$11,$1f,$1f,$1f
.byte	$1f,$1f,$1f,$1f,$1c,$03,$00,$00,$00,$00,$00,$00,$02,$0b,$1b,$1f
.byte	$1f,$1f,$1f,$1f,$1d,$0f,$03,$00,$00,$00,$00,$00,$06,$15,$1c,$1f
.byte	$1f,$1f,$1f,$1f,$1f,$19,$0d,$02,$00,$00,$00,$00,$00,$03,$15,$1f
.byte	$1f,$1f,$1f,$1f,$1f,$1c,$0e,$04,$01,$00,$00,$00,$00,$07,$14,$0c
.byte	$1b,$1b,$1e,$1e,$1b,$1f,$1e,$12,$06,$03,$00,$02,$00,$01,$07,$18

Edited by andym00
Link to comment
Share on other sites

Andreas, I have played around with the tools but did not find in a short notice a tool where I simply can load a .wav file?

 

Andy, TMR or Pete as c64 guys... is there a tool where I can simply convert 16 bit wav files (short ones) into 4 bit raw files which I can then use on A8?

 

 

hmm,

 

a) you mean you have not found an A8 tool with which you can load and playback WAV files ?!? Simply use Tom Hunt`s The Sound Utility to do so. You can find this tool on the image SNDPLAY2.ATR under the name WAVPLAY.COM (isn`t it obvious that WAVPLAY plays WAV files ?!? If it doesn`t play 16 Bit WAV, then try it with 8 Bit WAV, thought it plays both)... ok, allthough the program runs on 64k machines, its good to have more RAM on the A8 (the program supports up to 1024k RAM to playback WAV files)...

 

b) you mean you have not found an A8 tool with which you can load and convert 8bit WAV files into 4 Bit samples ?!? Simply use one of the three available WAV converters to do so. You can find these converters on the image SNDPLAY2.ATR under the names WAVCONV1.*, WAVCONV2.* and WAVCONV3.* (where extenders are COM and TUR; COM files can be loaded under DOS option "L" binary load or with LOA FILENAME.EXT; TUR files can be loaded under TB XL)...

 

Just checked the image SNDPLAY2.ATR again and the above mentioned WAV programs are there ! Under DOS 2 or DOS 2.5 use option "L" to load them, under Turbo-DOS XL/XE (which is on this disk, so 64k required) use LOA FILENAME.EXT to do so (alternatively type in LOA WAV- and press Return or type in WAV and then press SHIFT-Return to load any of these files)...

 

c) you mean you have not found a PC or MAC tool with which you can load and playback and/or convert 16 Bit WAV files into 8 BIT WAV files ?!? Well, I don`t have a Mac, so I cannot name any programs here. On the PC try one of the standard Windows WAV players and/or converters (Win 3.x has them, Win XP has them as well) or try WAVOSAUR or a similar program which you may find via internet...

 

-Andreas Koch.

 

 

P.S.: Attached the WAV-Player in Bewe/SpartaDOS format again; the image contains Bewe-DOS 1.3 and a Ramdisk driver (type RAMDISK 8 to install it), as well as the WAV-Player and a WAV-converter (in TB XL). Load the WAV-player by typing in WAVPLAY and press Return. When the WAV-player has loaded you have to press a lot of keys to load and playback a WAV file: 1-9 DIR of drive 1-9, then F to set the filename, L to load the file and P to playback the file; for WAV files use a speed of 0-5, for 4 Bit samples use higher speed rates (e.g. 54); you may also use M to configure your memory (64k, 128k, 256k, 512k, 1024k); to read the docfile under BeweDOS use TYPE *.DOC

Link to comment
Share on other sites

Yes.... just reminded me... I was in the Berzerk forum where I posted my thoughts... so I know Mr. Piper... ;)

 

is there any chance to compile this for Leopard?

 

but if not...then I need to boot WINDOWS.... baeh... ;)

 

You should just be able to do GCC main.cpp it uses nothing special and is no more complex than a typical hello world program :)

Afraid my Macs off being fixed, and I don't use the thing for programming, so the above is just a guess ;)

 

edit: assuming you've got xcode and all that installed..

Edited by andym00
Link to comment
Share on other sites

Yes.... just reminded me... I was in the Berzerk forum where I posted my thoughts... so I know Mr. Piper... ;)

 

is there any chance to compile this for Leopard?

 

but if not...then I need to boot WINDOWS.... baeh... ;)

 

You should just be able to do GCC main.cpp it uses nothing special and is no more complex than a typical hello world program :)

Afraid my Macs off being fixed, and I don't use the thing for programming, so the above is just a guess ;)

 

edit: assuming you've got xcode and all that installed..

 

I give xcode a shot and see if it will compiled or via gcc and terminal.... you know...I am oldschool coder and not an IDE modern one... ;)

Link to comment
Share on other sites

can someone please compile these 2 tools Andy has posted? I just seen that there is no xcode on my latest osx installation and here on my wife's pc obviously there is no gcc... ;)

 

http://developer.apple.com/technology/Xcode.html

 

:)

i know where to download... ;)

 

but I have a 4gb umts stick here... and just downloaded 1gb PES 2010 demo from xbox live... ;)

Link to comment
Share on other sites

can someone please compile these 2 tools Andy has posted? I just seen that there is no xcode on my latest osx installation and here on my wife's pc obviously there is no gcc... ;)

 

http://developer.apple.com/technology/Xcode.html

 

:)

i know where to download... ;)

 

but I have a 4gb umts stick here... and just downloaded 1gb PES 2010 demo from xbox live... ;)

 

I also wrote a SPS software that does WAV -> NIB (nibble) conversion as well as lossless compression. It does first sample in LSB nibble and 2nd sample in MSB nibble if that's what you are looking for...

Link to comment
Share on other sites

what I am searching is a simple tool where I can load a sample in WAV format which then can be downsampled to 4khz 4bit resolution to use it on A8... prefarable OS X or Windows tool....

 

Use Audacity (or if you must sox or something) to process the wav how you want, convert it to 8bit unsigned, and use the mashsamples tool contraption..

 

The samplerate on the command line is the output sample rate..

so mashsamples in.wav 3900 out.bin

And it expects unsigned 8 bit samples as input..

Convert it to the desired sample rate using Audacity or Sox or something because the samplerate conversion in mash samples is shite, aka rougher than a very rough thing..

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...