Jump to content
Sign in to follow this  
grappigegovert

TUN/PCM Converter

Recommended Posts

grappigegovert

I just noticed I get the buzzing too when I convert it directly to wav instead of ogg.

I'm looking into it.

Share this post


Link to post
Share on other sites
ZANTHERA

Just used this to convert all of my PC songs into OGG so I can listen to them, thanks for this, now that I know what the random files are called I'll change their names. There are even a few here that are not on my PS1 list so I'll add those.

 

Also what is with the freaky looking waveforms? They look so odd compared to my PS1 rips, they go in the plus and minus in such large blocks.

Share this post


Link to post
Share on other sites
Sunchipp
On 2/8/2015 at 6:32 PM, grappigegovert said:

Preview: (old version)


The download must feature the newer version or something then I can't get this to work

Share this post


Link to post
Share on other sites
grappigegovert
12 hours ago, Sunchipp said:

The download must feature the newer version or something then I can't get this to work

The new version works almost identical (visually), which is why I haven't updated the gif.
What kind of problem are you running into?

Share this post


Link to post
Share on other sites
Sunchipp
1 hour ago, grappigegovert said:

The new version works almost identical (visually), which is why I haven't updated the gif.
What kind of problem are you running into?

that makes sense cause it's mostly everything that was shown on the gif. I've done what that has instructed but the exe just shuts off after a second when the TUN file is imported

Share this post


Link to post
Share on other sites
grappigegovert

So, you dragged a .tun file on the 'from tun' bat file, but it did not generate an ogg file?

Share this post


Link to post
Share on other sites
grappigegovert

Per @EnvyNival's request, the source code of this tool is now public (Check the OT)
Keep in mind that the conversion done by this tool isn't 100% accurate (see the buzzing and weird waveform issues above).
I think the game uses a custom audio format. Luckily the ADPCM IMA Westwood codec this program assumes it to be is close enough to get semi-usable results.

Share this post


Link to post
Share on other sites
grappigegovert

I sent this in response to a message I've received inquiring about this tool and figured I might as well post it in this topic:

The tool is fairly simple:
When converting a tun/pcm file to something it reads the samplerate (in pcm files) and the number of channels from the header and (if stereo) split the audio data into two files.
These two files are then fed into sox with the command line:

sox -M -t ima -r <samplerate> <channel1path> -t ima -r <samplerate> <channel2path> <outputfile>

or, if there is only one channel:

sox -t ima -r <samplerate> <channel1path> <outputfile>


Now for the conversion from an arbitrary format to tun/pcm I, for some reason, decided to let the program do the conversion in-memory instead of via an intermediary file. This makes the source code a little confusing :old_whistle:
I'll explain how to do it via an intermediary file as it's easier.
Given that the input file is stereo, the two channels are extracted with these two commands:

sox <inputfile> -r <samplerate> -t ima <channel1output> remix 1
sox <inputfile> -r <samplerate> -t ima <channel2output> remix 2

These two channels are then merged into one file, and an appropriate header is added to it.
The sample rate is set to 22050 for tun files, and for pcm files the sample rate of the input file is used.

 

The header of a tun file looks like this:

41 4C 50 20 08 00 00 00 41 44 50 43 4D 00 00 02

The first four bytes are the characters "ALP "
Next is a four-byte integer indicating the offset to the data
The last byte, '0x02' is the number of audio channels in the file.

The header of a pcm file looks like this:

41 4C 50 20 0C 00 00 00 41 44 50 43 4D 00 00 01 11 2B 00 00

This header is 4 bytes longer, as indicated by the data-offset.
The last four bytes that are pcm-exclusive indicate the sample rate (in this example 11025)

The data (as interpreted by this tool) is, as stated in a few posts back Westwood IMA ADPCM, with the channels interleaved per-byte.
If you strip the header, you can use ffmpeg to decode the files with this command:

ffmpeg -f u8 -acodec adpcm_ima_ws -ar <samplerate> -ac <channelamount> -i <inputfile> <outputfile>

ffmpeg doesn't support encoding in this codec, unfortunately.

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Sign in to follow this  

  • Recently Browsing   0 members

    No registered users viewing this page.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.