Jump to content

TUN/PCM Converter


grappigegovert
 Share

Recommended Posts

grappigegovert

2021 Edit:

FFmpeg has added support for LEGO Racers' tun and pcm files as of version 4.4.
I advise everyone to use that instead of this program as this program isn't 100% correct.

Thanks to mumboking for bringing this to my attention.

 

 

Original post:

Although I had already posted my ima2tun program >here, 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: http://oresome.rockraidersunited.com/download/346

Note: This download includes a copy of SoX 14.4.2, also available at http://sox.sourceforge.net/.

The source code is available at https://gist.github.com/grappigegovert/4cc9424351f8f8998a62a926ccf20b01

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

Edited by grappigegovert
Add info about new ffmpeg update
Link to comment
Share on other sites

Fluffy Cupcake

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.

Link to comment
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. ;)

Link to comment
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.

Link to comment
Share on other sites

Fluffy Cupcake

^ 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

Link to comment
Share on other sites

Fluffy Cupcake

 

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.

Link to comment
Share on other sites

grappigegovert

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, >but that did nothing.

Link to comment
Share on other sites

Fluffy Cupcake

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 >the ones from the PS1 version still sound better. The compression on the PC version is that bad.

Link to comment
Share on other sites

grappigegovert

@Xiron, 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)
Link to comment
Share on other sites

grappigegovert

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. :(

  • Like 1
Link to comment
Share on other sites

grappigegovert

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?

Link to comment
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.

Link to comment
Share on other sites

Fluffy Cupcake

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.

Link to comment
Share on other sites

grappigegovert

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

Link to comment
Share on other sites

  • 5 months later...
Fluffy Cupcake

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.

Link to comment
Share on other sites

grappigegovert

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
Link to comment
Share on other sites

  • 8 months later...
Fluffy Cupcake

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?)

Link to comment
Share on other sites

grappigegovert

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.

  • Like 3
Link to comment
Share on other sites

  • 8 months later...

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.

Link to comment
Share on other sites

grappigegovert

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?

Link to comment
Share on other sites

 Share

×
×
  • 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.