16 bit datatype for audio?

Started by
28 comments, last by Aressera 11 years, 8 months ago
I suggest reading up on waveout at http://msdn.microsoft.com/en-us/library/windows/desktop/dd757715(v=vs.85).aspx

The lpData member of WAVEHDR is just a pointer to the buffer. The WAVEHDR itself is a description of one particular buffer you're planning on handing to waveout at some point. Assuming things are set up properly as mentioned below, you'd just cast your pointer to a PBYTE.

The format of the data you should point that at is determined by the WAVEFORMATEX you hand to waveOutOpen, for 16 bit audio, you'd fill in the appropriate fields to indicate 16 bit per sample PCM, either mono or stereo.
Advertisement
bacterius - forgive me, becaus eit seems we have a fundamental breakdown in communication.


i've been coding antialiasing and bandlimiting in c++ for a decade. you can find me in sound on sound and other magazines... i know all my ints and doubles and yummy bits.. please, give me some credit. i know sod all about sdks... i have trauma with sdks... but i have extensive experience actually flipping bits and doing things with them. i eat that way. please understand that i am 100% aware that there's something here i don't know, but it doesn't mean i don't know anything.

*if*
it is not accomplished in the manner i dreamed up,

*how*
is it normally accomplished??

ApochPiQ - thanks for the word. for trivial apps like simple games the 8 bit hole works. i am coding a base script for multimedia.

i'll have to look at other options if this doesn't work, but at present i'm not entirely sold on the idea that it's not done. the format wouldn't accept a 16 bit declaration if that were the case, would it? ;)
neither a follower nor a leader behttp://www.xoxos.net

The lpData member of WAVEHDR is just a pointer to the buffer. The WAVEHDR itself is a description of one particular buffer you're planning on handing to waveout at some point. Assuming things are set up properly as mentioned below, you'd just cast your pointer to a PBYTE.

The format of the data you should point that at is determined by the WAVEFORMATEX you hand to waveOutOpen, for 16 bit audio, you'd fill in the appropriate fields to indicate 16 bit per sample PCM, either mono or stereo.


not understanding your methodology... if i cast a pointer as a PBYTE and direct it to an array of shorts, that doesn't seem viable.

what i have got atm is relaced all the BYTE casts with WORD casts. it works (signal has correct unsigned short amplitude response), but it works bad, and i think it's because of the casting. still picking through.. so hard to believe no one's got an elementary implementation documented for htis anywhere...
neither a follower nor a leader behttp://www.xoxos.net
For the love, there's no need to reply twice within 5 minutes of each other. Just write one big reply. There's also an edit button if you need to make edits or addendums.

Also, get over your ego. This might sound harsh, but I don't care what experience you have (or don't have), and I don't think anyone else does either. It's only hurting you here, becaise, IMO, if you know your ints and doubles and eat bits, you should know you can't "take two bytes and bitshift one of them to make an unsigned char" (because that makes no sense).


i don't need to know the idea of resampling, i would like to become familiar with the convention. of course i'm in over my head, i wouldn't be posting if i could discern how to accomplish this profoundly elementary function as i am.

What I'm suggesting is that this problem isn't profoundly elementary (assuming you want good sounding audio).



..but more importantly, i know what resampling is, i do not know if it's what's normally done here... are you telling me that that's how this is normally handled? each short is split into two unsigned chars that are added sequentially? please, just say so!

I'm not telling you how this is properly handled, because I'm not even sure how to properly re-quantize audio. It's not a trivial problem. Get familiar with PCM audio signals, though. 8-bit PCM signals use 8-bits per sample, with each sample being in the unsigned range of 0 to 255 (a signed sample in the range -128 to 127 is possible but not as common as unsigned for 8-bit PCM). 16-bit PCM signals use 16-bits per sample, with each sample being in the signed range of -32768 to 32767.


at the present time i am not dealing with wavs, i am intending to implement a stream in which i can use the synthesis algorithms i am familiar with. i can synthesize using ints, whatever.. i need to know how to implement whatever variable format it expects.. you know, the stuff that's hard to reference. petzold doesn't cover his use of BYTES in the text.

Like ApochPiQ suggested, find a proper library for this. I use swresample, others use other things.

You're on a game development website in a "Game Programming" forum. This is not a digital signal processing forum. Don't expect everyone here to be able to dish out the exact answer you're looking for. There are other websites that are more suited to your question. We're happy to help, but we're probably not the best crowd to ask this kind of (non-trivial) question.
[size=2][ I was ninja'd 71 times before I stopped counting a long time ago ] [ f.k.a. MikeTacular ] [ My Blog ] [ SWFer: Gaplessly looped MP3s in your Flash games ]

not understanding your methodology... if i cast a pointer as a PBYTE and direct it to an array of shorts, that doesn't seem viable.

what i have got atm is relaced all the BYTE casts with WORD casts. it works (signal has correct unsigned short amplitude response), but it works bad, and i think it's because of the casting. still picking through.. so hard to believe no one's got an elementary implementation documented for htis anywhere...


It is viable, because that PBYTE pointer is actually a LPSTR, which is windows speak for "points at an array of bytes to be interpreted as the API sees fit". The WAVEFORMATEX structure you fill out and hand to waveOutOpen informs the API what data format your provided buffer actually is. I don't know what you're doing for casts where, but if you set it for stereo 16-bit, it is going to want 16-bit signed audio, stored little endian, and IIRC, left channel then right channel for stereo.

The example code they have there is terrible, but so is the waveOut interface in general. That would be why most people use some other API that provides a more humane interface.

And no, splitting a short into two chars will not do what you want, do you understand what each short represents in a 16-bit mono audio waveform?


apparently that's exactly how it is performed,
http://msdn.microsoft.com/en-us/library/windows/desktop/dd797880(v=vs.85).aspx
"16-bit mono.....
Each sample is 2 bytes. Sample 1 is followed by samples 2, 3, 4, and so on. For each sample, the first byte is the low-order byte of channel 0 and the second byte is the high-order byte of channel 0."


will have a bit of a rest now and then try it as a 2x length buffer...
neither a follower nor a leader behttp://www.xoxos.net

bacterius - forgive me, becaus eit seems we have a fundamental breakdown in communication.


i've been coding antialiasing and bandlimiting in c++ for a decade. you can find me in sound on sound and other magazines... i know all my ints and doubles and yummy bits.. please, give me some credit. i know sod all about sdks... i have trauma with sdks... but i have extensive experience actually flipping bits and doing things with them. i eat that way. please understand that i am 100% aware that there's something here i don't know, but it doesn't mean i don't know anything.

Look that's great and I'm happy you're so knowledgeable in DSP and audio processing, but as far as I am concerned, I don't really care about whether you are an audio guru or not. All that matters is that we can communicate. Right now you're not helping.

not understanding your methodology... if i cast a pointer as a PBYTE and direct it to an array of shorts, that doesn't seem viable.[/quote]
The waveOut interface only asks for a pointer to some buffer in memory. It doesn't care whether you give it a PBYTE, a long*, or a void*. It will interpret the buffer depending on the header you specified (where you set the sampling rate, the mono/stereo flag, etc...). What you just need is to send it a properly formed buffer (following the PCM specification).

apparently that's exactly how it is performed,
http://msdn.microsof...0(v=vs.85).aspx
"16-bit mono.....
Each sample is 2 bytes. Sample 1 is followed by samples 2, 3, 4, and so on. For each sample, the first byte is the low-order byte of channel 0 and the second byte is the high-order byte of channel 0."[/quote]
Well done, you discovered how 16-bit mono is represented in memory, where each sample is a 2-byte quantity (i.e. a word). But if you try to use a 16-bit sample and read it as an 8-bit sample, it will not work, because the API will expect each sample to be on 1 byte, whereas your buffer will have 2-byte samples. So you'll be reading "half a sample" each time and the sound will be weird. The simplest form of resampling you could to is take each 2-byte sample, divide it by 256 to obtain a 1-byte sample, and write that back to a new 8-bit buffer. But this doesn't work too well in practice.

“If I understand the standard right it is legal and safe to do this but the resulting value could be anything.”

reaperSMS - cheers. without dealing with formatting in the sdks i'm used to, the consideration that a pointer doesn't have to be sized never occured to me, i can see that now. when i'm finished typing all the replies i can try it lol.



You're on a game development website in a "Game Programming" forum. This is not a digital signal processing forum. Don't expect everyone here to be able to dish out the exact answer you're looking for. There are other websites that are more suited to your question. We're happy to help, but we're probably not the best crowd to ask this kind of (non-trivial) question.


adding 16 bit audio to a windows application really doesn't seem so exotic to computer gaming, does it?
neither a follower nor a leader behttp://www.xoxos.net

[quote name='Cornstalks' timestamp='1344988340' post='4969643']
You're on a game development website in a "Game Programming" forum. This is not a digital signal processing forum. Don't expect everyone here to be able to dish out the exact answer you're looking for. There are other websites that are more suited to your question. We're happy to help, but we're probably not the best crowd to ask this kind of (non-trivial) question.


adding 16 bit audio to a windows application really doesn't seem so exotic to computer gaming, does it?
[/quote]
That's not your real question. Your real question is about resampling audio.
[size=2][ I was ninja'd 71 times before I stopped counting a long time ago ] [ f.k.a. MikeTacular ] [ My Blog ] [ SWFer: Gaplessly looped MP3s in your Flash games ]

That's not your real question. Your real question is about resampling audio.


to resample audio, you must have audio.

i don't have audio, i am a synthesist. no wavs.

if you want to call the direct application of form to a variable resampling, you go ahead now.
neither a follower nor a leader behttp://www.xoxos.net

This topic is closed to new replies.

Advertisement