Convert a value in one number range to a value in another number range?
-
I can't seem to figure this out... I have a value within the range of 0 to 40 and I want to be able to convert that into a value in the range of 0 to 10,000. This is for a simple music player that I have built into one of my programs. I'm using C# and DirectX.AudioVideoPlayback to play mp3 files. I have a working custom slider control that has a range from 0 to 40. This will be used to adjust the volume of an mp3. The problem is that volume in DirectX.AudioVideoPlayback ranges from 0 to 10,000 (technically -10,000 to 0... 0 being max volume). Therefore I need to figure out a formula to convert a value from my custom slider control that is in the range 0 to 40, to a value DirectX.AudioVideoPlayback can use which is in the range of 0 to 10,000. Also these values are integers and the conversion doesn't have to be exact, just close enough. I'm bad at math, so any ideas?
-
I can't seem to figure this out... I have a value within the range of 0 to 40 and I want to be able to convert that into a value in the range of 0 to 10,000. This is for a simple music player that I have built into one of my programs. I'm using C# and DirectX.AudioVideoPlayback to play mp3 files. I have a working custom slider control that has a range from 0 to 40. This will be used to adjust the volume of an mp3. The problem is that volume in DirectX.AudioVideoPlayback ranges from 0 to 10,000 (technically -10,000 to 0... 0 being max volume). Therefore I need to figure out a formula to convert a value from my custom slider control that is in the range 0 to 40, to a value DirectX.AudioVideoPlayback can use which is in the range of 0 to 10,000. Also these values are integers and the conversion doesn't have to be exact, just close enough. I'm bad at math, so any ideas?
did you consider multiplying by 250? :)
Luc Pattyn [Forum Guidelines] [My Articles]
Voting for dummies? No thanks. X|
-
did you consider multiplying by 250? :)
Luc Pattyn [Forum Guidelines] [My Articles]
Voting for dummies? No thanks. X|
-
-
I can't seem to figure this out... I have a value within the range of 0 to 40 and I want to be able to convert that into a value in the range of 0 to 10,000. This is for a simple music player that I have built into one of my programs. I'm using C# and DirectX.AudioVideoPlayback to play mp3 files. I have a working custom slider control that has a range from 0 to 40. This will be used to adjust the volume of an mp3. The problem is that volume in DirectX.AudioVideoPlayback ranges from 0 to 10,000 (technically -10,000 to 0... 0 being max volume). Therefore I need to figure out a formula to convert a value from my custom slider control that is in the range 0 to 40, to a value DirectX.AudioVideoPlayback can use which is in the range of 0 to 10,000. Also these values are integers and the conversion doesn't have to be exact, just close enough. I'm bad at math, so any ideas?
To that things you can always use the Rule of 3 (literal traduction from "Regla de 3" on spanish, don't know the correct name) RangeMax1 ----- RangeMax2 Value1 -------- Value2 To know the equivalent of one value into another different range. Lets say you have the RangeMax1, RangeMax2 and Value1 and you want to know the Value2. It is made with:
Value2 = (RangeMax2 * Value1) / RangeMax1
if you want to find Value1 then:Value1 = (RangeMax1 * Value2) / RangeMax2
You multiply the 2 members of the fully known diagonal, and divide with the other number in the diagonal of the desired value. If you use the RangeMaxes and the Unit... you have the generic formule of your transformation or the coeficient you need. 40 ------ 10000 1 ------- x x = 10000 * 1 / 40; x = 250 EDIT: I forgot to say, that the range has to be in absolute width. I mean [-2, 18], translates into 0 ---- 20, you should afterwards adapt the calculated value. Let's say... I have the value -1,5 in the range [-5, 10] and want to know its equivalent in the range [5, 42] 10 - (-5) = 15 42 - 5 = 37 -1,5 - (-5) = 3,5 15 ------ 37 3,5 ----- x x = (37 * 3,5) / 15 = 8,633 8,633 + 5 = 13,633 the equivalent is 13,633Regards. -------- M.D.V. ;) If something has a solution... Why do we have to worry about?. If it has no solution... For what reason do we have to worry about? Help me to understand what I'm saying, and I'll explain it better to you “The First Rule of Program Optimization: Don't do it. The Second Rule of Program Optimization (for experts only!): Don't do it yet.” - Michael A. Jackson Rating helpfull answers is nice, but saying thanks can be even nicer.
-
I can't seem to figure this out... I have a value within the range of 0 to 40 and I want to be able to convert that into a value in the range of 0 to 10,000. This is for a simple music player that I have built into one of my programs. I'm using C# and DirectX.AudioVideoPlayback to play mp3 files. I have a working custom slider control that has a range from 0 to 40. This will be used to adjust the volume of an mp3. The problem is that volume in DirectX.AudioVideoPlayback ranges from 0 to 10,000 (technically -10,000 to 0... 0 being max volume). Therefore I need to figure out a formula to convert a value from my custom slider control that is in the range 0 to 40, to a value DirectX.AudioVideoPlayback can use which is in the range of 0 to 10,000. Also these values are integers and the conversion doesn't have to be exact, just close enough. I'm bad at math, so any ideas?
The multiplication by 250 suggestion is the easiest, but the human ear response isn't linear; it's logarithmic. A range of 0 to 40 dB corresponds to a range of 0 to 10,000 mW power level exactly, so I suggest that a conversion implementing the equation: DirectX.AudioVideoPlayback.Volume = 10^(MySlider.Volume/10) might be more useful.
"A Journey of a Thousand Rest Stops Begins with a Single Movement"
-
The multiplication by 250 suggestion is the easiest, but the human ear response isn't linear; it's logarithmic. A range of 0 to 40 dB corresponds to a range of 0 to 10,000 mW power level exactly, so I suggest that a conversion implementing the equation: DirectX.AudioVideoPlayback.Volume = 10^(MySlider.Volume/10) might be more useful.
"A Journey of a Thousand Rest Stops Begins with a Single Movement"
:omg: :doh: :doh: :doh: I totally forgot that it was Audio... you are totally right, the conversion must consider the change between dB and electrical units. I would give you a 5 if I was not in the firm. (I'll do it when I'm home)
Regards. -------- M.D.V. ;) If something has a solution... Why do we have to worry about?. If it has no solution... For what reason do we have to worry about? Help me to understand what I'm saying, and I'll explain it better to you “The First Rule of Program Optimization: Don't do it. The Second Rule of Program Optimization (for experts only!): Don't do it yet.” - Michael A. Jackson Rating helpfull answers is nice, but saying thanks can be even nicer.
-
The multiplication by 250 suggestion is the easiest, but the human ear response isn't linear; it's logarithmic. A range of 0 to 40 dB corresponds to a range of 0 to 10,000 mW power level exactly, so I suggest that a conversion implementing the equation: DirectX.AudioVideoPlayback.Volume = 10^(MySlider.Volume/10) might be more useful.
"A Journey of a Thousand Rest Stops Begins with a Single Movement"
Since the allowed range for the volume (according to OP) is
-10,000 to 0
, maybe the effect is already accounted by theDirectX
function. I.e. maybe the function accepts sound level instead of volume. :)If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler. -- Alfonso the Wise, 13th Century King of Castile.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong. -- Iain Clarke
[My articles] -
To that things you can always use the Rule of 3 (literal traduction from "Regla de 3" on spanish, don't know the correct name) RangeMax1 ----- RangeMax2 Value1 -------- Value2 To know the equivalent of one value into another different range. Lets say you have the RangeMax1, RangeMax2 and Value1 and you want to know the Value2. It is made with:
Value2 = (RangeMax2 * Value1) / RangeMax1
if you want to find Value1 then:Value1 = (RangeMax1 * Value2) / RangeMax2
You multiply the 2 members of the fully known diagonal, and divide with the other number in the diagonal of the desired value. If you use the RangeMaxes and the Unit... you have the generic formule of your transformation or the coeficient you need. 40 ------ 10000 1 ------- x x = 10000 * 1 / 40; x = 250 EDIT: I forgot to say, that the range has to be in absolute width. I mean [-2, 18], translates into 0 ---- 20, you should afterwards adapt the calculated value. Let's say... I have the value -1,5 in the range [-5, 10] and want to know its equivalent in the range [5, 42] 10 - (-5) = 15 42 - 5 = 37 -1,5 - (-5) = 3,5 15 ------ 37 3,5 ----- x x = (37 * 3,5) / 15 = 8,633 8,633 + 5 = 13,633 the equivalent is 13,633Regards. -------- M.D.V. ;) If something has a solution... Why do we have to worry about?. If it has no solution... For what reason do we have to worry about? Help me to understand what I'm saying, and I'll explain it better to you “The First Rule of Program Optimization: Don't do it. The Second Rule of Program Optimization (for experts only!): Don't do it yet.” - Michael A. Jackson Rating helpfull answers is nice, but saying thanks can be even nicer.