Hi, I have a audio mixer up and running and I'm currently impressed with its performance with 16-bit WAV's, but....
(yes there's a "BUT"), 8-bit files sound quite bad, this is what I do to convert an 8-bit sample to a 16-bit sample (I took it from a doc)

1. move 8-bit sample into high byte of WORD
2. XOR out low byte
3. XOR high byte with 128(80h) effectively flipping sign bit (I omit this step because it makes it sound like a bass boost on crack :D)

Anyway the output I get is quite scratchy with 8-bit files, 16-bit files sound crystal clear, but 8-bit sounds scratchy. Can anyone help me?

Thanks in advance.
Posted on 2002-11-24 18:54:53 by x86asm
I forget where I saw it, but I have seen code that puts the same byte in high and low:

mov ah, al

...couldn't hurt to give it a try. :) You don't want to XOR out low byte, IIRC.
Posted on 2002-11-24 19:42:41 by bitRAKE
c'mon, there's an opcode for this!
16-bit snd is signed, and takes 2 bytes
8-bit snd is signed,too, and takes one byte. Put it in AL
movsx ax,al

:) that's all- you've got it converted. It will sound better if you apply a 12dB/oct lowpass filter to the whole converted sound with cutoff of 7kHz
Posted on 2002-11-24 22:51:28 by Ultrano
The low-pass filter is for upsampling.. for just "upquantizing" (8bit -> 16 bit, same sample rate) I'm afraid that apart from MOVSX AX,AL all one can do is add a +/- 128 range of white (or, even better, shaped) noise.. will make the sound more natural.
Posted on 2002-11-25 03:22:18 by Maverick
I have a little "Basic DSP" book, I'll read over it and figure out how to implement a low-pass filter. I think that is my only hope :( Thanks alot guys :D
All the computer code in there is in..BASIC!! :eek:
Posted on 2002-11-25 07:37:22 by x86asm
You can trust my word that lowpass-filtering has nothing to do with upquantizing.. although often you'll find referiments to it because 8 bit samples are usually 8000 or 11025 Hz, and 16 bit samples are usually of 22050 or 44100 Hz.. and upsampling has this time to do with post-filtering.

If you really want to filter it, though, you can find ready to use C code in my old tutorial about filtering:
Posted on 2002-11-25 07:48:05 by Maverick
But you see the problem is that I'm streaming the mixing results to a buffer in 16-bit output mode. I can convert the sample to 16-bit and hear it, but along with it comes white noise out of my speakers, not enough to totally damage the output wave, but enough to become very annoying! I was able to get rid of some of the noise by subtracting some number from the high byte in the sample. But thats a not a very good way
Posted on 2002-11-25 14:52:52 by x86asm
I bet that the problem is that your 8 bit samples are unsigned, while the 16 bit ones are signed.. so convert them this way and tell me if it solved the problem:

Out = ( In - 128 ) * 256

SUB AL,128

Note that if you used MOV AH,AL instead of SHL AX,8 you'd get crossover distortion, because it's signed arithmetic:
Posted on 2002-11-25 15:36:11 by Maverick
I did the following after sign extending the sample into EBX:

sub bx,128
shl bx,8
;Then mixed into output stream

It sounds the same, the noise is a little less. You think it could be the WAV I'm using?
Posted on 2002-11-25 15:46:13 by x86asm
Should I use SAR, so that I don't mess around with the sign bit of the sample?
Posted on 2002-11-25 15:47:16 by x86asm
Excuse me for sounding stupid if I am, but I'm not a full DSP programmer :D
Posted on 2002-11-25 15:49:58 by x86asm
I see you are online. Post here the 8 bit sample, 1 second will be enough. I'll check it out and report soon.
Posted on 2002-11-25 15:59:16 by Maverick
Here it is, unfortunately I need to get to my homework and I dont have a program which can cut the sample down. Its approximately 4 or 5 seconds 8-bit, Stereo, 22.05Khz In the WAVE (I assume for WAVES, the left sample is first and right sample is second). Here it is, the reason is because I want to program a MOD/S3M player, I wa going to do it in DOS (had like 300 lines of code), but I ran into many roadblocks and decided to use DirectSound and Win32. I would like to learn how this stuff is done instead of passing the sound onto DirectSound and letting it handle the stuff. Anyway here is the sample named REM1.wav.

Also I didnt want to pass it on to DirectSound because I don't have a hardware mixing card :(
Its a stupid VIA 686A onboard thing..
Posted on 2002-11-25 16:05:37 by x86asm
Hi x86asm,
The sample sounds a bit distorted, but it's ok.

All the soundcards I wrote a driver for (in Dos) used signed samples in 16 bit.. the file you sent me is 8 bit unsigned.
The correct way to convert it is (to avoid confusions):

;MOVZX EAX,BYTE PTR [ESI] ; fetch the 8 bit *unsigned* sample
SUB EAX,128 ; subtract the bias and convert it to signed 8 bit
SHL EAX,8 ; convert it to signed 16 bit

If its sound still doesn't convince you, send me the converted sample.. so we can spot where the problem really is.
Posted on 2002-11-25 16:15:02 by Maverick
:eek: IT WORKED!!!


Just two questions, you dont have to answer them all:

1. The samples in a MOD/ S3M file are they signed or unsigned?
2. How can I tell if a WAV file is signed or unsigned?
Posted on 2002-11-25 17:29:34 by x86asm
BTW, I do the conversion in real time, the output is outputted by DirectSound at 16-bit, 44100Hz, Stereo, I can resample the audio using a simple step counter but for the MOD and S3M I got a Carry-counter method going.
Posted on 2002-11-25 17:32:32 by x86asm
Sorry, I don't know the MOD/ S3M formats.. real musicians make their own formats. :tongue:
How to tell if a WAV is signed or unsigned? Check the header. You find tons of sites with WAV format description.

Resampling is a damn serious thing.. if you care about quality, that is. There are several techniques, all with pro's and con's. Linear interpolation in your case may be the best comprimise.
Posted on 2002-11-25 17:58:35 by Maverick
One last question Maverick before you vanish off :D, how would you do that conversion if the 8-bit sample was signed?
Posted on 2002-11-25 20:01:19 by x86asm
Ya I know about the resampling algothrims, if I could I would take the easy way out and use the FPU. I read somewhere that instead of using samples you should average them and place them in the output stream. Interpolation is what its called, but I noticed that high frequencies are cut off and I hate that >:-| . If I don't use interpolation it sounds "graty" but personally I like it without interpolation. Maybe because I'm weird :confused:
Posted on 2002-11-25 20:13:59 by x86asm

One last question Maverick before you vanish off :D, how would you do that conversion if the 8-bit sample was signed?
mov ah,
mov , ax
Posted on 2002-11-25 20:27:55 by bitRAKE