|Page (3) of 4 - 11/30/04||email article||print page|
Scripting in DVD Studio Pro, Series 2Part 2: Bit-wise operations and binary number conversion Interlude: Thinking in binary, working in decimal
The longer, more accurate answer that by using this value, we're masking off all of the bits except bits 11 and 14 because 18432 is the decimal equivalent of the 16-bit binary number 0100100000000000.
Now aren't you glad you didn't skip ahead to the next section?
OK, I can represent this a bit more visually to help you figure out how 0100100000000000 is the same as 18432. Remember, each bit in SPRM 15 has its own value, starting with 1 at bit 0 and doubling up to 32768 at bit 15. Here's a little chart to show this, with the bit order running highest to lowest (15 to 0).
So what if we want to turn off all of these except bits 14 and 11? In binary, we write out a 0 for all of the bits we want turned off, and a 1 for all of the ones we want turned on, as in the bottom row in the following table.
And so, if you read the off and on bits left to right, you wind up with 0100100000000000. Add up the values of the bits for the bits that are on, and you get 2048+16384=18432. That's why 18432 is the decimal equivalent of the binary number 0100100000000000. And you must do the conversion from binary to decimal because DVD Studio Pro doesn't allow you to enter binary numbers.
If you don't want to have to refer to a table each time you do this, you can easily visualize the binary in your head, and then use a binary conversion calculator to give you the decimal equivalent. You can download a freeware binary converter called Haxor from http://gamma.nic.fi/~eraiha-s/products/haxor/haxor.html. (If you want to get even more crazy and write your scripts in hex, like the spec programmers do, Haxor can also do binary to hex conversions.)
At any rate, you should now know what the DVD Studio Pro manual is talking about when it's telling you to mask off bits in an SPRM. Let's continue with our script now.
Finding the answer to our bit-wise operation
So we now have two commands in our script. The first moves the value of SPRM 15 into GPRM 7. The second asks the question, "Does the value in GPRM 7 include bits 11 and 14?" (In other words, are 2048 and 16384 included in the total value of SPRM 15?)
Well, a DVD player is not going to give you a simple yes or no answer. What it's going to give you is an "on" (1) and "off" (0) answer in binary translated to decimal. So there are four possible answers to our question:
0=Neither DTS nor AC-3 capabilities (binary 0000000000000000)
2048=DTS capability, no AC-3 capability (binary 0000100000000000)
16384=AC-3 capability, no DTS capability (binary 0100000000000000)
18432=Both DTS and AC-3 capabilities (binary 0100100000000000)
But for all practical purposes, we can rule out 2048 because I don't think there's an audio player in the world that has DTS capability but doesn't have AC-3 capability. There are many that have both DTS and AC-3; many that have just AC-3; and a few that have neither AC-3 nor DTS (though this last is probably just a limited phenomenon in PAL countries). So let's just concern ourselves with 18432, 16384 and 0.
So we just need to add three commands to account for these three possible answers. All three will be "Set System Stream" commands.
1. The first of the three will set the system stream to an "Immediate Value" of Audio: Audio Stream 2 (Our DTS track) if GPRM 7 is equal to an immediate value of 18432. Remember, this means that the player has both DTS and AC-3 capabilities, and therefore we want our DTS track to play, since DTS is generally of higher quality for DVD-Video than AC-3.
Related Keywords:apple dvd studio pro, scripting, sprm, gprm, bit-wise operations, binary numbers
Source:Digital Media Online. All Rights Reserved