Discworld II Mus files

General chat related to ScummVM, adventure gaming, and so on.

Moderator: ScummVM Team

Post Reply
Jeebizz
Posts: 8
Joined: Mon Jun 08, 2009 9:09 pm

Discworld II Mus files

Post by Jeebizz »

I like the music in Discworld II, and I have been trying to figure out how to open the mus files. I downloaded awave, even tried opening them with audacity, and goldwave, but all I get is garbage, and tried all raw formats I can think of. Is there something I am missing?

I would really like to convert the mus files so that I can just listen to them as mp3s or ogg files. Can it actually be done? If so how?
User avatar
md5
ScummVM Developer
Posts: 2250
Joined: Thu Nov 03, 2005 9:31 pm
Location: Athens, Greece

Post by md5 »

The audio in Discworld 2 uses a customized ADPCM encoding. Voices and SFX are encoded using 6-bit ADPCM and music is encoded using 8-bit ADPCM (both @ 22050Hz). The music files themselves got an index at their beginning, with information on the beginning offset of each track, as well as the track length.

Perhaps you could find some program that can handle such audio, or you could modify ScummVM's source to dump music as it plays it.
Seldon
Posts: 101
Joined: Sun Feb 24, 2008 9:53 am
Location: Poland

Post by Seldon »

The topic have been already discussed here.

Here's simple code that I used, to do the task (based on valuable info from DrMcCoy - thanks!):

Code: Select all

#include <iostream>
#include <fstream>

using namespace std;

static const double TinselFilterTable&#91;4&#93;&#91;2&#93; = &#123;
	&#123;0, 0 &#125;,
	&#123;0.9375, 0&#125;,
	&#123;1.796875, -0.8125&#125;,
	&#123;1.53125, -0.859375&#125;
&#125;;

void decode&#40;char* buffer, fstream& output&#41;
&#123;
  const double eVal = 1.007843258;
  static double d0 = 0, d1 = 0;
  double k0, k1, predictor, sample;
  unsigned char start = buffer&#91;0&#93;, filterVal = &#40;start & 0xC0&#41; >> 6;
  int i, code;
  short result;
  
  if &#40;&#40;start & 0x20&#41; != 0&#41; 
  &#123; //Lower 6 bit are negative - Negate
    start = ~&#40;start | 0xC0&#41; + 1;
    predictor = 1 << start;
  &#125; 
  else
  &#123; // Lower 6 bit are positive - Truncate
    start &= 0x1F;
    predictor = &#40;&#40;double&#41; 1.0&#41; / &#40;1 << start&#41;;
  &#125;
  k0 = TinselFilterTable&#91;filterVal&#93;&#91;0&#93;;
  k1 = TinselFilterTable&#91;filterVal&#93;&#91;1&#93;;

  for &#40;i=1;i<=32;i++&#41;
  &#123;
    code = buffer&#91;i&#93; << 8;
  	sample = &#40;double&#41; code;
	sample *= eVal * predictor;
	sample += &#40;d0 * k0&#41; + &#40;d1 * k1&#41;;

	d1 = d0;
	d0 = sample;
	if &#40;sample < -32768.0&#41; sample = 32768.0;
	if &#40;sample > 32767.0&#41; sample = 32767.0;
	result = sample;
    output.put&#40;result & 0xFF&#41;; 
	output.put&#40;&#40;result >> 8&#41; & 0xFF&#41;;
  &#125;
&#125;

int main &#40;int argc, char *argv&#91;&#93;&#41;
&#123;
  char buffer&#91;33&#93;;
  long samples, i;
  
  if &#40;argc != 3&#41;
  &#123;
    cout << "Usage&#58; D2_decode IN_FILENAME OUT_FILENAME" << endl;
    return 1;
  &#125;
  fstream infile &#40;argv&#91;1&#93;, ios&#58;&#58;in | ios&#58;&#58;binary | ios&#58;&#58;ate&#41;;
  fstream outfile &#40;argv&#91;2&#93;, ios&#58;&#58;out | ios&#58;&#58;binary&#41;;

  if &#40;!infile.is_open&#40;&#41;&#41;
  &#123;
    cout << "I can't open input file" << endl; 
    return 1;
  &#125;
  if &#40;!outfile.is_open&#40;&#41;&#41;
  &#123;
    cout << "I can't create output file" << endl; 
    return 1;
  &#125;
  samples = infile.tellg&#40;&#41; / 33;
  infile.seekg &#40;0, ios&#58;&#58;beg&#41;;
  for &#40;i=0;i < samples;i++&#41;
  &#123;
    infile.read &#40;buffer, 33&#41;;
    decode&#40;buffer, outfile&#41;;
  &#125;
  infile.close&#40;&#41;;
  outfile.close&#40;&#41;;

  return 0;
&#125;
Jeebizz
Posts: 8
Joined: Mon Jun 08, 2009 9:09 pm

Post by Jeebizz »

Thanks for the reply, I have looked at the info provided, but as far as the source is concerned, I really have no clue. I have no programming aptitude and I wouldn't understand what I'm looking at, even though the code is right in front of my face.

So I tried the info provided with goldwave, and got 'some' kind of 'wave' with barely any audible results, but with still mostly noise. I guess I'm just stuck. Sorry for my lack of knowledge :(
User avatar
DrMcCoy
ScummVM Developer
Posts: 595
Joined: Sat Dec 17, 2005 1:33 pm
Location: Braunschweig, Germany
Contact:

Post by DrMcCoy »

Jeebizz wrote:So I tried the info provided with goldwave
It's a custom ADPCM algorithm, so GoldWave won't help you there.
Seldon
Posts: 101
Joined: Sun Feb 24, 2008 9:53 am
Location: Poland

Post by Seldon »

Jeebizz wrote:Thanks for the reply, I have looked at the info provided, but as far as the source is concerned, I really have no clue. I have no programming aptitude and I wouldn't understand what I'm looking at, even though the code is right in front of my face.

So I tried the info provided with goldwave, and got 'some' kind of 'wave' with barely any audible results, but with still mostly noise. I guess I'm just stuck. Sorry for my lack of knowledge :(
I you use Windows, then here is compiled program, according with a batch file that will convert all the files. Just unpack these two files into a folder, where *.MUS files are, and run convert.bat. As a result you will get a bunch of *.RAW files, that can be handled by Goldwave for example, and saved in more handy format like ogg.

EDIT:
To properly open files in sound editor you will need this info: the files are saved as raw PCM, 22050 kHz, mono with 16-bit big endian samples.
Jeebizz
Posts: 8
Joined: Mon Jun 08, 2009 9:09 pm

Post by Jeebizz »

Originally posted by Seldon

To properly open files in sound editor you will need this info: the files are saved as raw PCM, 22050 kHz, mono with 16-bit big endian samples.
I tried that, and many other combos of pcm with no endian, little, and big endian, and still nothing. However I will try out this program that was mentioned, I hope it works, and thanks again for the patient replies.
Jeebizz
Posts: 8
Joined: Mon Jun 08, 2009 9:09 pm

Post by Jeebizz »

IT WORKED!! Ran the program, and tried the suggested audio settings. THANKS AGAIN!!! Now I can convert to MP3. WOOHOO!

:D
Jeebizz
Posts: 8
Joined: Mon Jun 08, 2009 9:09 pm

Post by Jeebizz »

Don't want to really start another thread just to supply this info but:

Out of curiosity I tried opening the english.smp files from both discworld I and II. I couldn't get the .smp files from discworld II to open, and the decode to raw program didn't help any.

However, with Discworld I's english.smp, I was able to open it with goldwave as raw as PCM 8-bit mono (no endian), at 22050khz, and it works. I can at least listen to the file all at once. Too bad can't do the same with the files in Discworld II.
Seldon
Posts: 101
Joined: Sun Feb 24, 2008 9:53 am
Location: Poland

Post by Seldon »

Jeebizz wrote:I couldn't get the .smp files from discworld II to open, and the decode to raw program didn't help any.
No wonder, as the program was written to support music files, and for speech different encoding have been used, as MD5 mentioned in 2. post.
Post Reply