Browse Source

Verify that the bit depth argument in love.sound.newSoundData is valid / supported.

Alex Szpakowski 10 years ago
parent
commit
57fa9994af
1 changed files with 4 additions and 1 deletions
  1. 4 1
      src/modules/sound/SoundData.cpp

+ 4 - 1
src/modules/sound/SoundData.cpp

@@ -41,6 +41,9 @@ SoundData::SoundData(Decoder *decoder)
 	, bitDepth(0)
 	, bitDepth(0)
 	, channels(0)
 	, channels(0)
 {
 {
+	if (decoder->getBitDepth() != 8 && decoder->getBitDepth() != 16)
+		throw love::Exception("Invalid bit depth: %d", decoder->getBitDepth());
+
 	size_t bufferSize = 524288; // 0x80000
 	size_t bufferSize = 524288; // 0x80000
 	int decoded = decoder->decode();
 	int decoded = decoder->decode();
 
 
@@ -117,7 +120,7 @@ void SoundData::load(int samples, int sampleRate, int bitDepth, int channels, vo
 	if (sampleRate <= 0)
 	if (sampleRate <= 0)
 		throw love::Exception("Invalid sample rate: %d", sampleRate);
 		throw love::Exception("Invalid sample rate: %d", sampleRate);
 
 
-	if (bitDepth <= 0)
+	if (bitDepth != 8 && bitDepth != 16)
 		throw love::Exception("Invalid bit depth: %d", bitDepth);
 		throw love::Exception("Invalid bit depth: %d", bitDepth);
 
 
 	if (channels <= 0)
 	if (channels <= 0)