import wave

n = 4

sound = wave.open("pikapikapika_res.wav")
sound_secret = wave.open("pikapikapika_res_secret.wav", "wb")

sound_secret.setnchannels(1)
sound_secret.setsampwidth(sound.getsampwidth())
sound_secret.setframerate(sound.getframerate())

frames = sound.getnframes()

for i in range(frames):
    frame = sound.readframes(1)
    left = int(frame[0])*256 + int(frame[1])
    right = int(frame[2])*256 + int(frame[3])
    pink = left ^ right
    yellow = pink - 2**(15-n)
    blue = yellow*(2**n)-1
    try:
        secret = blue.to_bytes(2, "big")
        sound_secret.writeframes(secret)
    except:
        pass

sound_secret.close()
sound.close()
