Welcome Guest!

Did you know you that by registering, you can gain access to new special powers? You’ll be able to reply to Topics, create your own Topics, talk in our Chatbox, message members, manage your profile, access extra content and much more! Best of all, this message & ads will vanish!

Sign in to follow this  
Followers 0
grappigegovert

TUN/PCM Converter

28 posts in this topic

Although I had already posted my ima2tun program Please login or register to see this link. , I've decided that a separate topic might be more easy to find.
This zip file contains my ima2tun program tunconverter, SoX, and some handy-dandy batch files that do all the command-line work.

To convert any* music file to .TUN/PCM, simply drag it onto the 'to-tun' batch file.
It then creates a .tun file with the same name in the same folder.
It's also possible to drag a .tun/.pcm file onto the 'from-tun or pcm' batch file to convert it to .ogg (filetype be changed in the batch file)

Changelog:

Spoiler

v3 (2016-05-01):

Fixed PCM sample rate change

Fixed converting mono input sound files

 

v2.1 (2015-08-21):
Bugfix: sample rate was not automatically converted to 22050Hz when creating tun files.

v2 (2015-02-15):
I recoded most of the program, and it can now convert to pcm files aswell.
All the sox stuff is now managed internallly.
The program is now built with .NET 4.0, to make it compatible with winXP.


TUN files have a fixed sample rate of 22050Hz, but PCM files can have any sample rate.
The number of channels in a TUN/PCM file is either 1 or 2.

Preview: (old version)
gallery_4344_345_1365950.gif

Download: Please login or register to see this link.

Note: This download includes a copy of SoX 14.4.2, also available at Please login or register to see this link. .

O.T.:
Is GameIntr.tun used in the game?

9 people like this

Share this post


Link to post
Share on other sites

Glad you decided to make a separate topic! I never did see the other post.

 

Yay, finally real custom audio can be a thing in this game! :D

 

Edit: I was about to say it isn't working, but that's because I was trying to convert across different drives.

 

Edit 2: Some .tun files convert and get sent to the temp folder with no problems, but others that end up in the same folder as where it converted from gives me a "sox WARN adpcms: "temp channel1.ima: ADPCM state errors: 2178"

and another as the same line above except with channel2.ima and error 2202 instead.

The file I get that from is Circuit1.tun.

Share this post


Link to post
Share on other sites

Thanks for splitting this off! :D Yes, it was best you made a new topic for the tool. Although this is fairly straight-forward, some people may still want a quick on using it. I'll try to schedule some time in soon for a tutorial revision to do just that. ;)

Share this post


Link to post
Share on other sites

^ I was able to get Circuit 1 to convert just fine. For what it's worth, I copy each .tun into the tunconverter folder before running the batch file on it. For me, it spits the converted .ogg  file out in the same folder, not in temp.

Share this post


Link to post
Share on other sites

^ I was able to get Circuit 1 to convert just fine. For what it's worth, I copy each .tun into the tunconverter folder before running the batch file on it. For me, it spits the converted .ogg  file out in the same folder, not in temp.

I do the same thing.

The ones that convert fine to temp, but the ones that have a similar error to the one mentioned above convert to the same output folder as file, as it should.

 

[member=grappigegovert]; Did you intentionally force the program to convert to 22050Hz? I'm just wondering in case 44100 may be possible, as it has been many times across other games where people thought it was just 22050 only and not anything higher.

 

Also, PCM converter coming next? : 3

Share this post


Link to post
Share on other sites

Also, PCM converter coming next? : 3

 

No, because PCM = TUN but at a different Hz. :P

Share this post


Link to post
Share on other sites

It works like a charm. Many thanks.

Share this post


Link to post
Share on other sites

 

Also, PCM converter coming next? : 3

 

No, because PCM = TUN but at a different Hz. :P

Well I couldn't convert a .PCM using the .tun converter.

Share this post


Link to post
Share on other sites

Some .tun files convert and get sent to the temp folder with no problems, but others that end up in the same folder as where it converted from gives me a "sox WARN adpcms: "temp channel1.ima: ADPCM state errors: 2178" and another as the same line above except with channel2.ima and error 2202 instead.

I don't really know what the warnings mean, but they don't affect the converted file, so you can just ignore those.

The only reason I can think of for the files not appearing in the right folder, is a permission error of some kind. (are the files in %programfiles% perhaps?)

In that case, I suggest first copying them over to a folder which has public write access, and then dragging them onto the batch file.

I will look into the PCM files next. (Are they not simply renamed tun files?)

Edit:

Unfortunately the tun files have to be 22050hz, or they won't play at the right speed.

I have already tried editing the header, Please login or register to see this link.

Share this post


Link to post
Share on other sites

I'm curious what it sounds like in HQ. Will you post a download link here when you converted them all?

Share this post


Link to post
Share on other sites

The only reason I can think of for the files not appearing in the right folder, is a permission error of some kind. (are the files in %programfiles% perhaps?)

In that case, I suggest first copying them over to a folder which has public write access, and then dragging them onto the batch file.

It's in the "TunConverter" on my Desktop. No permission problems there, and the .tun is in the same folder as the .bat (which I am dragging on to).

 

I'm curious what it sounds like in HQ. Will you post a download link here when you converted them all?

Let's just say Please login or register to see this link. still sound better. The compression on the PC version is that bad.

1 person likes this

Share this post


Link to post
Share on other sites

@Please login or register to see this link. , if there is no error at all, I have no idea what the problem could be.

The line

move tempoutput.ogg "%%~dpnA.ogg"
should move the file from the temp folder to the folder where the input file is. ('%%~dpna' means drive+path+name of variable %%A, which is the input file)

Share this post


Link to post
Share on other sites

So,

I did some more research, and it looks like the only difference with pcm files is that pcm files can have any sample rate instead of a fixed 22050Hz.
I've updated the program to support pcm files.
I have also tried adding the sample rate to the header of a tun file like in a pcm file, but that did nothing. :(

1 person likes this

Share this post


Link to post
Share on other sites

Yay for PCM having any sample rate! Still a sad disappointing thing for .TUNs.

Share this post


Link to post
Share on other sites

I did some more testing.
The sample rate for tun files can be edited in the exe file, and will play fine at 44100Hz when changed to that.
I noticed that the speed for pcm files is off. It looks like they play at 0.75x speed[?] For example, when I replaced a pcm file with a tun file it played slower than normal, and when I then changed the sample rate to something like 28000 instead of 22050, it would play at normal speed.
Does anyone have an idea what might be causing that or are pcm files just weird?

Share this post


Link to post
Share on other sites

So awesome that the specifics of the format have been cracked :D

 

Just a small note if you want to convert to MP3, place "libmp3lame.dll" - the LAME dll - in the same directory as all the other files. The files will convert to MP3.

Share this post


Link to post
Share on other sites

The sample rate for tun files can be edited in the exe file, and will play fine at 44100Hz when changed to that.

Offset [with version] or patching feature added to program, please.

Share this post


Link to post
Share on other sites

Offset [with version] or patching feature added to program, please.

1999 nodrm: 2nd result when searching for 0x22560000 (22050) at offset 0x1A1A4, change that to 0x44AC0000 (44100).

All tun files will now play at double samplerate/speed

Share this post


Link to post
Share on other sites

My .tun files are ingame slowed down and I don't know why

Share this post


Link to post
Share on other sites

Is the hertz on the file you converted 22050Hz? Any other hertz (44100hz is one files are commonly at by default) will make it run at a different speed.

Share this post


Link to post
Share on other sites

Whoops, thanks for pointing that out, DorneyLeechekes. That's definitely a bug in my program. It is supposed to convert the audio file to a sample rate of 22050Hz automatically, which it didn't do.
I have fixed it and updated the download link in the OP.

Edited by grappigegovert

Share this post


Link to post
Share on other sites

The PCM to .ogg isn't working very well, I'm getting 8481hz on voice clips when it should come out as 11025hz (that hz sound normal).

 

8481 is 77% (76.92517006802721% to be exact) of normal speed - which is close to the 0.75 you were mentioning earlier here:

On 2015-02-19 at 6:31 AM, grappigegovert said:

I noticed that the speed for pcm files is off. It looks like they play at 0.75x speed[?]

 

 

On 2015-02-19 at 6:31 AM, grappigegovert said:

For example, when I replaced a pcm file with a tun file it played slower than normal,

and when I then changed the sample rate to something like 28000 instead of 22050, it would play at normal speed.
Does anyone have an idea what might be causing that or are pcm files just weird?

It depends on the sample format of your sound file. For example if the sample format is at 16-bit it plays normally, if it at 32-bit you will need to double the hz to get it to play normally. For 24-bit, I can only imagine it somewhere in between if you leave the hz alone (0.75 speed?)

Share this post


Link to post
Share on other sites

Looks like I was doing all kinds of wonky stuff on those PCM files.

I have released an update which should fix that and some other bugs.

3 people like this

Share this post


Link to post
Share on other sites

Okay, I tried this out for some of the songs that weren't in the PS1 version of the game, and it gave me weird errors like

 

SoX\sox.exe WARN adpcms: xdtpa0pa.ice: ADPCM state errors: 933
SoX\sox.exe WARN adpcms: b4yf0y5l.uqq: ADPCM state errors: 1014
Done
Press any key to continue . . .

 

and when I listened to the converted file, it had this weird low buzzing sound in the background in my right ear. Every track I tried was like this.

 

edit: even weirder is that it only does this with the music from the final game. the music from the demo converts perfectly fine.

Share this post


Link to post
Share on other sites

Hmm... it outputs the same kind of warning messages for me, but it converts fine, without buzzing sound.
Can you send me one of your tun files to compare maybe?

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0