Glitch City Laboratories Archives

Glitch City Laboratories closed on 1 September 2020 (announcement). This is an archived copy of a thread from Glitch City Laboratories Forums.

You can join Glitch City Research Institute to ask questions or discuss current developments.

You may also download the archive of this forum in .tar.gz, .sql.gz, or .sqlite.gz formats.

Arbitrary Code Execution Discussion

How to make your own Pikachu cries with ACE - Page 1

How to make your own Pikachu cries with ACE

Posted by: Torchickens
Date: 2019-02-09 01:08:55
1) Set up ACE
2) Set up an ACE memory editor
3) Write the following routine at your access point

061C219F7ECD843E3E02EA00401E003E
002100A019191946232A666F0E040D28
05CD641E18F8F3C5E53E80E0263E77E0
24AFE01A2130FF11FCCB7E12133EFF22
7DFE4020F53E80E01AF025F644E0253E
FFE01B3E20E01C3EFFE01D3E87E01EE1
C1CD5001AFEAF3C0EAF4C03E80E026A
FE01A2130FF11FCCB1A13227DFE4020F
83E80E01AF025E6BBE025AFEA2AC0EA2
BC0EA2CC0EA2DC0F0B8FBC9

(This is a modified version of 3C:4000; that plays the first PCM audio at 2:A000 in SRAM)

4) Get a very short music file you want to use as your Pikachu cry (about 1 second long)

5) Use ffmpeg. According to bg321 and pigdevil2010 on Skeetendo, you'll likely need to downgrade your music file to 4-bit uncompressed PCM, 6000hz.

If not familiar, put ffmpeg in the same folder as your music file, open Notepad and write the following;

ffmpeg  -i "[original music filename with extension (e.g. .mp3) here]" -ac 1 -ar 6000 -acodec adpcm_ms [desired filename].wav
pause

(The pause is optional and is in case there are any errors, otherwise the command prompt will exit automatically. Here there is a new line before pause. I'm unsure if it's needed.)

Save this file as crymaker.bat or anything .bat.

Then, run the .bat file (again it will need to be in the same directory as ffmpeg and your music file).

(Note: I wasn't sure exactly how to get the correct file format Game Freak used, but this works)

6) Your new .wav file will probably not work properly on some operating systems, but if everything went to plan it will work when you import it in the game. The file size of the wav file should be quite small. You will need to use a hex editor (such as HxD, it's free) to copy all the bytes after the "data" ANSI string (for my example this is at 0x98). Save this somewhere (e.g. Pastebin if you want)

7) Use ACE to write the following at 2:A000; 02 03 a0 (+two more bytes that represent the hexadecimal file size.  Use Windows Calculator to take away the end of the file offset and e.g. 0x98 on the hex editor, then add 1 to get the file size. Then swap the digits e.g. the Mario sound effect I used was 03 1C).

In order to write at 2:A000, if you are using BGB emulator, go into the debugger and double click on DA8C (which is just after opening the SRAM bank in your code), then activate ACE early and BGB should pause. Afterwards you can right click and select "go to…". Enter 2:A000, and select OK to jump there in the debugger. From there you should be able to write those bytes (where otherwise they would likely be unchangable FF bytes due to locked SRAM).

8) At 2:A005 paste the bytes from earlier. Usually, there should be just enough space in SRAM for this (SRAM is A000-BFFF or 8192 bytes). If not, get rid of unneeded groups of 00 bytes in the file and modify the file size in step 7 accordingly.

9) Save the game and reset. Now when you run your code, your custom cry should play! Enjoy :)

Example:

Currently the sound quality of custom cries through this method is still very bad. If you listen carefully through the noise though, you can hear "It's a me, Mario!"

https://www.youtube.com/watch?v=gwbnsy9vlPA

I have just added yellow mario.sav and gangnam mon.sav to my Google Sites. https://sites.google.com/site/torchickens2/pokemon-save-files

Re: How to make your own Pikachu cries with ACE

Posted by: Sherkel
Date: 2019-02-09 09:59:16
The sound could probably be made clearer by narrowing down the frequency range and (this is just a guess) making it quieter. Maybe making it closer to whatever the spectrogram of the original Pikachu voices is would help. I don't know how the Game Boy's PCM player works, so I can't really say for sure. Do you have the WAVs you imported (after all conversions.edits were done)?

Re: How to make your own Pikachu cries with ACE

Posted by: konakonaa
Date: 2019-02-09 14:13:05
The audio format used by Pokémon Yellow for the cries is actually 1-bit PCM, not ADPCM. The bad audio quality is a result of the wrong sample format being used.

I have created a small Shell script to do the conversion - it requires FFmpeg and Python 3. Since I'm not exactly sure of the bit endianness used by the game, I have created two versions of the script. Just try each one and see which one sounds better.
EDIT: As pointed out by ISSOtm, the sample format used by Pokémon Yellow is MSB-first - so you should use the first script.
https://pastebin.com/ecguWxip

To use them, you can put them into a .sh file and execute them by passing the input and output file as arguments.

I also made a little tool that you can use to preview how the audio file will sound before putting it into the game.

I hope these tools can be of help to all of you.

Re: How to make your own Pikachu cries with ACE

Posted by: Mefista
Date: 2019-02-09 17:17:57
So…much…meme…power

Re: How to make your own Pikachu cries with ACE

Posted by: Sherkel
Date: 2019-02-09 18:22:14
Now THAT'S what I call an introduction! :O

Thank you for your contributions!

Re: How to make your own Pikachu cries with ACE

Posted by: ISSOtm
Date: 2019-02-10 03:51:15
According to this instruction, bits are played out MSB first.
I guess the correct script to run is the first one, then?

Re: How to make your own Pikachu cries with ACE

Posted by: konakonaa
Date: 2019-02-10 04:14:12
According to this instruction, bits are played out MSB first.
I guess the correct script to run is the first one, then?


Indeed, you should use the first script.

It will output the raw bitstream to the specified file, and you can just copy the data into the .sav file using your hex editor of choice.

Oh yeah, the script doesn't run on Windows, not without MinGW, Cygwin or WSL (which you can get from the Windows 10 Store). I might make a standalone Python script that's cross-platform, to avoid the need of a POSIX-compliant environment.

Re: How to make your own Pikachu cries with ACE

Posted by: Torchickens
Date: 2019-02-10 13:41:27
Wow, thank you konakonaa! Will try this out when I get the chance. :)


So…much…meme…power


Yes!