@@ -136,7 +136,7 @@ func loadfile(filepath):
136136
137137 var data = bytes .subarray (data_entry_point , data_entry_point + audio_data_size - 1 )
138138
139- if bits_per_sample in [24 , 32 ]:
139+ if bits_per_sample in [8 , 24 , 32 ]:
140140 newstream .data = convert_to_16bit (data , bits_per_sample )
141141 else :
142142 newstream .data = data
@@ -171,7 +171,7 @@ func loadfile(filepath):
171171 print ("ERROR: Wrong filetype or format" )
172172 file .close ()
173173
174- # Converts .wav data from 24 or 32 bits to 16
174+ # Converts .wav data from 8, 24 or 32 bits to 16
175175#
176176# These conversions are SLOW in GDScript
177177# on my one test song, 32 -> 16 was around 3x slower than 24 -> 16
@@ -184,6 +184,15 @@ func loadfile(filepath):
184184func convert_to_16bit (data : PoolByteArray , from : int ) -> PoolByteArray :
185185 print ("converting to 16-bit from %d " % from )
186186 var time = OS .get_ticks_msec ()
187+ # 8 bit so we just scale it into two bytes:
188+ if from == 8 :
189+ var j = 0
190+ var spb := StreamPeerBuffer .new ()
191+ spb .resize (data .size () * 2 )
192+ for i in range (0 , data .size (), 1 ):
193+ spb .put_16 ((data [i ] * 65535 ) / 255 - 32768 )
194+ j += 2
195+ return spb .data_array
187196 # 24 bit .wav's are typically stored as integers
188197 # so we just grab the 2 most significant bytes and ignore the other
189198 if from == 24 :
0 commit comments