MasterofGalaxies / THPConv

Port of THPConv, Nintendo's THP creator, to Linux
5 stars 1 forks source link

Crackling/skipping audio #1

Open alucryd opened 2 years ago

alucryd commented 2 years ago

Hi, I don't think it's an issue with your binary as the official THPConv.exe from the Wii SDK produces the same result, but I'm hoping you may have some insight. I'm undubing some ISOs and adding subs to THP videos, the resulting videos play fine on real hardware, but the audio is crackling/skipping quite a bit.

The Linux binary just segfaults here (address boundary error, both yours and the one I compiled) so I've been using the Windows binary via wine. I tried mixing and matching the official Wii THPConv.exe binary and yours with the dsptool.dll from both the GameCube and Wii SDK, all combinations produce that crackling audio. Interestingly they all play with no audio issue via mpv, but not in dolphin or on real hardware.

Here are the steps I'm doing:

ffmpeg -i $argv.thp -vcodec libx264 -vf 'bwdif=mode=send_frame' -qp 0 $argv.mkv # deinterlace and convert to lossless x264
ffmpeg -i $argv.thp -vn $argv.wav # extract audio as raw PCM
ffmpeg -i $argv.mkv -vcodec libx264 -preset ultrafast -g 10000 -sc_threshold 40 -pass 1 -passlogfile $argv -f null /dev/null # compute scene changes for subtitles
ffmpeg -i $argv.mkv -vf subtitles=$argv.ass -q:v 3 -an "$argv-%04d.jpg" # burn subtitles and save as jpg images
wine THPConv.exe -j '*.jpg' -s $argv.wav -d {$argv}_new.thp # create the thp file

Do you have any idea what the problem could be? I have yet to try the whole process on Windows, but I'll probably do that soon.

Lord-Giganticus commented 2 years ago

Hi there, I’ve spent a long time trying to understand the format and the program. As far as I know trying to make a valid audio file is very bugged. It seems to require a pcm16le audio, but ffmpeg can’t seem to provide a wav file that isn’t corrupted. There is a program that does work, but the audio doesn’t seem to be in the right pitch. (Program is called mplayer, there’s a exe that works in one of my repos) Until I find a better way to generate the audio, the issue isn’t really fixable.

Lord-Giganticus commented 2 years ago

UPDATE: After mention of THP on Supper Mario Broth, a reply by Techmuse revealed to me that the WAV file uses ADPCM (likely the Nintendo one used in both wii/gcn sdks). I also discovered that using -f wav as a ffmpeg flag doesn't make the audio corrupt when playing the file back in VLC. I will test these new finds on console when I can.

alucryd commented 2 years ago

Thanks for taking the time. I also experienced the same corruption when trying to get anything other than wav out of ffmpeg.

It seems the particular adpcm format used in the gamecube can only be decoded in ffmpeg, not encoded:

 D.AIL. adpcm_4xm            ADPCM 4X Movie
 DEAIL. adpcm_adx            SEGA CRI ADX ADPCM
 D.AIL. adpcm_afc            ADPCM Nintendo Gamecube AFC
 D.AIL. adpcm_agm            ADPCM AmuseGraphics Movie AGM
 D.AIL. adpcm_aica           ADPCM Yamaha AICA
 DEAIL. adpcm_argo           ADPCM Argonaut Games
 D.AIL. adpcm_ct             ADPCM Creative Technology
 D.AIL. adpcm_dtk            ADPCM Nintendo Gamecube DTK
 D.AIL. adpcm_ea             ADPCM Electronic Arts
 D.AIL. adpcm_ea_maxis_xa    ADPCM Electronic Arts Maxis CDROM XA
 D.AIL. adpcm_ea_r1          ADPCM Electronic Arts R1
 D.AIL. adpcm_ea_r2          ADPCM Electronic Arts R2
 D.AIL. adpcm_ea_r3          ADPCM Electronic Arts R3
 D.AIL. adpcm_ea_xas         ADPCM Electronic Arts XAS
 DEAIL. adpcm_g722           G.722 ADPCM (decoders: g722 ) (encoders: g722 )
 DEAIL. adpcm_g726           G.726 ADPCM (decoders: g726 ) (encoders: g726 )
 DEAIL. adpcm_g726le         G.726 ADPCM little-endian (decoders: g726le ) (encoders: g726le )
 D.AIL. adpcm_ima_acorn      ADPCM IMA Acorn Replay
 DEAIL. adpcm_ima_alp        ADPCM IMA High Voltage Software ALP
 DEAIL. adpcm_ima_amv        ADPCM IMA AMV
 D.AIL. adpcm_ima_apc        ADPCM IMA CRYO APC
 DEAIL. adpcm_ima_apm        ADPCM IMA Ubisoft APM
 D.AIL. adpcm_ima_cunning    ADPCM IMA Cunning Developments
 D.AIL. adpcm_ima_dat4       ADPCM IMA Eurocom DAT4
 D.AIL. adpcm_ima_dk3        ADPCM IMA Duck DK3
 D.AIL. adpcm_ima_dk4        ADPCM IMA Duck DK4
 D.AIL. adpcm_ima_ea_eacs    ADPCM IMA Electronic Arts EACS
 D.AIL. adpcm_ima_ea_sead    ADPCM IMA Electronic Arts SEAD
 D.AIL. adpcm_ima_iss        ADPCM IMA Funcom ISS
 D.AIL. adpcm_ima_moflex     ADPCM IMA MobiClip MOFLEX
 D.AIL. adpcm_ima_mtf        ADPCM IMA Capcom's MT Framework
 D.AIL. adpcm_ima_oki        ADPCM IMA Dialogic OKI
 DEAIL. adpcm_ima_qt         ADPCM IMA QuickTime
 D.AIL. adpcm_ima_rad        ADPCM IMA Radical
 D.AIL. adpcm_ima_smjpeg     ADPCM IMA Loki SDL MJPEG
 DEAIL. adpcm_ima_ssi        ADPCM IMA Simon & Schuster Interactive
 DEAIL. adpcm_ima_wav        ADPCM IMA WAV
 DEAIL. adpcm_ima_ws         ADPCM IMA Westwood
 DEAIL. adpcm_ms             ADPCM Microsoft
 D.AIL. adpcm_mtaf           ADPCM MTAF
 D.AIL. adpcm_psx            ADPCM Playstation
 D.AIL. adpcm_sbpro_2        ADPCM Sound Blaster Pro 2-bit
 D.AIL. adpcm_sbpro_3        ADPCM Sound Blaster Pro 2.6-bit
 D.AIL. adpcm_sbpro_4        ADPCM Sound Blaster Pro 4-bit
 DEAIL. adpcm_swf            ADPCM Shockwave Flash
 D.AIL. adpcm_thp            ADPCM Nintendo THP
 D.AIL. adpcm_thp_le         ADPCM Nintendo THP (Little-Endian)
 D.AIL. adpcm_vima           LucasArts VIMA audio
 D.AIL. adpcm_xa             ADPCM CDROM XA
 DEAIL. adpcm_yamaha         ADPCM Yamaha
 D.AIL. adpcm_zork           ADPCM Zork

Unfortunately trying to pass -acodec copy or any of the encodable adpcm formats produces an unusable wav file as far as THPConv is concerned :/

Lord-Giganticus commented 1 year ago

I have figured out the reason to the issue, it appears the audio has to be in pcm16le format AND be in 32k sample rate, otherwise it WILL sound weird.

alucryd commented 1 year ago

Awesome, thanks for the heads up! Will get back to my undubs when I have a bit of time, I can't believe it's been a year already, time flew right by.