Advertisement
Guest User

Pokémon Yellow 1-bit PCM audio conversion scripts

a guest
Feb 9th, 2019
166
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.43 KB | None | 0 0
  1. # Usage: Paste code into a .sh file, or simply substitute the input and output file names into $1 and $2 if you prefer to
  2. # run it directly.
  3. # The scripts require FFmpeg and Python 3 to be installed. The preview script requires FFplay as well (comes with FFmpeg)
  4.  
  5. #--------------------------------------#
  6. # To convert into 1-bit MSB-first PCM:
  7.  
  8. #!/bin/sh
  9. ffmpeg -i $1 -af highpass=80 -ar 24000 -ac 1 -f u8 - | python3 -c "$(printf "import sys\nfrom struct import pack\nbuffer = sys.stdin.buffer.read(8)\nwhile len(buffer) == 8:\n packed = 0\n for b in buffer:\n packed = (packed << 1) | ((b - 3) >> 7)\n sys.stdout.buffer.write(pack('B', packed))\n buffer = sys.stdin.buffer.read(8)")" > $2
  10.  
  11. #--------------------------------------#
  12. # To convert into 1-bit LSB-first PCM:
  13.  
  14. #!/bin/sh
  15. ffmpeg -i $1 -af highpass=80 -ar 24000 -ac 1 -f u8 - | python3 -c "$(printf "import sys\nfrom struct import pack\nbuffer = sys.stdin.buffer.read(8)\nwhile len(buffer) == 8:\n packed = 0\n for b in buffer:\n packed = (packed >> 1) | ((b - 3) & 128)\n sys.stdout.buffer.write(pack('B', packed))\n buffer = sys.stdin.buffer.read(8)")" > $2
  16.  
  17.  
  18.  
  19. #--------------------------------------#
  20. # If you want to preview the audio:
  21.  
  22. #!/bin/sh
  23. ffmpeg -i $1 -af highpass=80 -ar 24000 -ac 1 -f u8 - | python3 -c "$(printf 'import sys\nsys.stdout.buffer.write(bytes(map(lambda x: ((x - 3) & 128) >> 2, sys.stdin.buffer.read())))')" | ffplay -f u8 -ac 1 -ar 24000 -
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement