why audioop causes sound loss for some files?

Viewed 32

i am decoding a wav file and trying to convert it to pcm_s16le to i used audioop.adpcm2lin() function but it causes sound loss for some wave files how to fix it ?

import audioop
import struct
import wave
with open(f"game_music.wav","rb") as wb:
    types = struct.unpack("4s",wb.read(4))[0]
    print(types)
    temp = wb.read(2)
    temp = wb.read(2)
    channels = struct.unpack("H",wb.read(2))[0]
    print(channels)
    temp = wb.read(2)
    sample_rate = struct.unpack("H",wb.read(2))[0]
    print(sample_rate)
    num_samples = struct.unpack("I",wb.read(4))[0]
    print(num_samples)
    audio_data = audioop.adpcm2lin(wb.read(),2,None)[0]
with wave.open(f"game_musics.wav", "w") as wav:
    wav.setnchannels(channels)
    wav.setsampwidth(2)
    wav.setframerate(sample_rate)
    wav.writeframesraw(audio_data)

for example this file working fine . https://drive.google.com/file/d/1XAlZZ6bkSRDsnsch6fL2u708xB7xscTa/view?usp=sharing

but this file corrupts . https://drive.google.com/file/d/1IC8p1TIyEaIi5mwMTWvflCUIhaBaR1BR/view?usp=sharing

if anyone trying to fix then you can use this to test. its orginal version of corrupted file. https://drive.google.com/file/d/1OyuwxMSYxiyh1rMFDJ1_k0bRp_hx5CpX/viewusp=sharing Thanks for helping

0 Answers
Related