Permalink
Browse files

fix longstanding Win32::Sound::Volume bug (RT #28113 and #43776)

  • Loading branch information...
1 parent 607dc01 commit fa01afc3ebb9563c4ef299e8ac589ab0d10a5bd4 @dada committed Jul 26, 2011
Showing with 10 additions and 10 deletions.
  1. +6 −6 Sound.pm
  2. +4 −4 Sound.xs
View
@@ -94,9 +94,9 @@ sub Version { $VERSION }
sub Volume {
my(@in) = @_;
- # Allows '0%'..'100%'
- $in[0] =~ s{ ([\d\.]+)%$ }{ int($1*100/255) }ex if defined $in[0];
- $in[1] =~ s{ ([\d\.]+)%$ }{ int($1*100/255) }ex if defined $in[1];
+ # Allows '0%'..'100%'
+ $in[0] =~ s{ ([\d\.]+)%$ }{ int($1*65535/100) }ex if defined $in[0];
+ $in[1] =~ s{ ([\d\.]+)%$ }{ int($1*65535/100) }ex if defined $in[1];
_Volume(@in);
}
@@ -134,9 +134,9 @@ sub new {
sub Volume {
my(@in) = @_;
- # Allows '0%'..'100%'
- $in[0] =~ s{ ([\d\.]+)%$ }{ int($1*255/100) }ex if defined $in[0];
- $in[1] =~ s{ ([\d\.]+)%$ }{ int($1*255/100) }ex if defined $in[1];
+ # Allows '0%'..'100%'
+ $in[0] =~ s{ ([\d\.]+)%$ }{ int($1*65535/100) }ex if defined $in[0];
+ $in[1] =~ s{ ([\d\.]+)%$ }{ int($1*65535/100) }ex if defined $in[1];
_Volume(@in);
}
View
@@ -348,8 +348,8 @@ PPCODE:
if(mmr == MMSYSERR_NOERROR) {
if(GIMME == G_ARRAY) {
EXTEND(SP, 2);
- XST_mIV(0, (long) volume & 0x00FF);
- XST_mIV(1, (long) (volume & 0xFF00) >> 8);
+ XST_mIV(0, (long) volume & 0x0000FFFF);
+ XST_mIV(1, (long) (volume >> 16) & 0x0000FFFF);
XSRETURN(2);
} else {
XSRETURN_IV(volume);
@@ -360,7 +360,7 @@ PPCODE:
}
break;
case 1:
- volume = SvIV(ST(0)) | SvIV(ST(0)) << 8;
+ volume = SvIV(ST(0)) | SvIV(ST(0)) << 16;
mmr = waveOutSetVolume((HWAVEOUT) WAVE_MAPPER, volume);
if(mmr == MMSYSERR_NOERROR) {
XSRETURN_YES;
@@ -370,7 +370,7 @@ PPCODE:
}
break;
default:
- volume = SvIV(ST(0)) | SvIV(ST(1)) << 8;
+ volume = SvIV(ST(0)) | SvIV(ST(1)) << 16;
mmr = waveOutSetVolume((HWAVEOUT) WAVE_MAPPER, volume);
if(mmr == MMSYSERR_NOERROR) {
XSRETURN_YES;

0 comments on commit fa01afc

Please sign in to comment.