Author Topic: Extracting gm.dls samples for tiny demo trackers  (Read 1850 times)

0 Members and 1 Guest are viewing this topic.

Offline Jim

  • Founder Member
  • DBF Aficionado
  • ********
  • Posts: 5098
  • Karma: 380
    • View Profile


gm.dls is the Windows midi patch bank, it's 3.28Mb long and it's got a few hundred samples in it that might be useful for tiny trackers.
I reversed the format by hand - the file is just a RIFF with blocks for waves and waveheaders.
In fact, though, the format's no secret and it's documented at the midi organisation's own website http://www.midi.org/about-midi/dls/abtdls.shtml

The attached sample code and exe will play back all the samples in the bank.

Jim
« Last Edit: April 16, 2007 by Jim »
Challenge Trophies Won:

Offline va!n

  • Pentium
  • *****
  • Posts: 1334
  • Karma: 106
    • View Profile
    • http://www.secretly.de
Re: Extracting gm.dls samples for tiny demo trackers
« Reply #1 on: April 06, 2007 »
the exe does not works on my XP system.... windows dont like to run the exe
Asus P5Q, Intel Q8200, 6 GB DDR2, Radeon 4870, Windows7 x64
http://www.secretly.de
Challenge Trophies Won:

Offline Jim

  • Founder Member
  • DBF Aficionado
  • ********
  • Posts: 5098
  • Karma: 380
    • View Profile
Re: Extracting gm.dls samples for tiny demo trackers
« Reply #2 on: April 06, 2007 »
You're missing msvcrt8.dll.  My mistake, I should have built it static.  I'll update the zip.  Why, oh why, did Microsoft change the message from the useful 'can't find msvcrt8.dll' to the utterly useless 'some component is missing'?

Jim
« Last Edit: April 06, 2007 by Jim »
Challenge Trophies Won:

Offline benny!

  • Senior Member
  • DBF Aficionado
  • ********
  • Posts: 4130
  • Karma: 223
  • in this place forever!
    • View Profile
    • bennyschuetz.com - mycroBlog
Re: Extracting gm.dls samples for tiny demo trackers
« Reply #3 on: April 06, 2007 »
gm.dls is the Windows midi patch bank, it's 3.28Mb long and it's got a few hundred samples
in it that might be useful for tiny trackers.

Nice ... didn't know of the existance before to be honest. Could come handy indeed for tiny
trackers.


I reversed the format by hand - the file is just a RIFF with blocks for waves and waveheaders.
In fact, though, the format's no secret and it's documented at the midi organisation's own website
http://www.midi.org/about-midi/dls/abtdls.shtml

The attached sample code and exe will play back all the samples in the bank.

Works fine here - will have a look on the code later. Thanks for sharing !!!
[ mycroBLOG - POUET :: whatever keeps us longing - for another breath of air - is getting rare ]

Challenge Trophies Won:

Offline Paul

  • Pentium
  • *****
  • Posts: 1490
  • Karma: 47
    • View Profile
Re: Extracting gm.dls samples for tiny demo trackers
« Reply #4 on: April 06, 2007 »
I'm sorry to say but it doesn't do anything :S

A window opens and closes before i have time to see anything ???

If it helps I'm running windows 2000 sp4(I think)
I will bite you - http://s5.bitefight.se/c.php?uid=31059
Challenge Trophies Won:

Offline Jim

  • Founder Member
  • DBF Aficionado
  • ********
  • Posts: 5098
  • Karma: 380
    • View Profile
Re: Extracting gm.dls samples for tiny demo trackers
« Reply #5 on: April 06, 2007 »
The path is hardcoded to use C:\windows\system32\drivers\gm.dls.  If it's not there it'll just exit.  If you're on Win2K I suspect it's not there.

Jim
Challenge Trophies Won:

Online Shockwave

  • good/evil
  • Founder Member
  • DBF Aficionado
  • ********
  • Posts: 16787
  • Karma: 439
  • evil/good
    • View Profile
    • My Homepage
Re: Extracting gm.dls samples for tiny demo trackers
« Reply #6 on: April 06, 2007 »
It works here K+
Shockwave ^ Codigos
Challenge Trophies Won:

Offline Jim

  • Founder Member
  • DBF Aficionado
  • ********
  • Posts: 5098
  • Karma: 380
    • View Profile
Re: Extracting gm.dls samples for tiny demo trackers
« Reply #7 on: April 06, 2007 »
->benny!  It's an idea Taj came up with (don't know if it was his idea first) and he posted it again the other day in his answer to va!n on 4k coding.  It's too good an idea to go by the wayside so I thought I'd code it up.

Jim
Challenge Trophies Won:

Offline benny!

  • Senior Member
  • DBF Aficionado
  • ********
  • Posts: 4130
  • Karma: 223
  • in this place forever!
    • View Profile
    • bennyschuetz.com - mycroBlog
Re: Extracting gm.dls samples for tiny demo trackers
« Reply #8 on: April 06, 2007 »
@Jim:
Yup. Really interesting. I will have a closer look to the quality of the instruments
in the dll when I have some time ...

And btw. K++ for sharing code (and for testing the "other thing")
[ mycroBLOG - POUET :: whatever keeps us longing - for another breath of air - is getting rare ]

Challenge Trophies Won:

Offline taj

  • Bytes hurt
  • DBF Aficionado
  • ******
  • Posts: 4810
  • Karma: 189
  • Scene there, done that.
    • View Profile
Re: Extracting gm.dls samples for tiny demo trackers
« Reply #9 on: April 16, 2007 »
Jim,

thanks for sharing this. Somethings wrong though. I'm using xp, sp2, gm.dls where it should be, but the exe plays maybe 20 samples then no more...it continues to run seemingly forever but the sonud just crackles out.

I was unable to build code using VC++ express  here so I cant switch on debug and give you info. Sorry not much more help.

One suggestion for tiny trackers using this technique...you could make the code smaller by doing this:
1. Writing a parser to find the wav data and output start of data and length for each sample into say a .h file in a structure.
Code: [Select]
// Uncomment the instruments you want...         
// each samples entry :  address , size
// each samples entry :  address , size
#ifndef __GM_H__

#define __GM_H__

typedef struct wsegmentstruct {
unsigned int address;             // address in gm.dls of this sample
unsigned int length;          // length of this sample
} wsegment;

wsegment GMsamples[]={
//280156,2890, //0
//283212,2848, //1
//286226,12024, //2
//298418,6250, //3
//304836,4820, //4
//309824,15356, //5
//325346,488, //6
//326000,202, //7
//326368,196, //8
//326730,2192, //9
.
.
.
}

then in your 4k code you only need to:
open file
loop:
 read sample
 create header

which should be (is) tiny.


Chris
« Last Edit: April 16, 2007 by taj »
Challenge Trophies Won:

Offline Jim

  • Founder Member
  • DBF Aficionado
  • ********
  • Posts: 5098
  • Karma: 380
    • View Profile
Re: Extracting gm.dls samples for tiny demo trackers
« Reply #10 on: April 16, 2007 »
Yeah, it's a bit buggy.  When all the pcm channels are full on the sound card it goes bang.  I fixed it on my own version - waveOutUnprepare() is returning STILL_PLAYING and I'm ignoring it.

The idea was really to show how to parse the file! That bit of it always worked :)

I'm using the same parser to parse some midi files too now, but that's going to need a lot more work.

<edit>I've updated the zip in the original post to fix the bug.  It plays for several minutes.

Jim
« Last Edit: April 16, 2007 by Jim »
Challenge Trophies Won:

Offline benny!

  • Senior Member
  • DBF Aficionado
  • ********
  • Posts: 4130
  • Karma: 223
  • in this place forever!
    • View Profile
    • bennyschuetz.com - mycroBlog
Re: Extracting gm.dls samples for tiny demo trackers
« Reply #11 on: April 30, 2007 »
Useful tool related to this topic :

http://www.pouet.net/prod.php?which=30541
[ mycroBLOG - POUET :: whatever keeps us longing - for another breath of air - is getting rare ]

Challenge Trophies Won:

Offline taj

  • Bytes hurt
  • DBF Aficionado
  • ******
  • Posts: 4810
  • Karma: 189
  • Scene there, done that.
    • View Profile
Re: Extracting gm.dls samples for tiny demo trackers
« Reply #12 on: April 30, 2007 »
You have to love blackpawn.
Challenge Trophies Won:

Offline rbz

  • Founder Member
  • DBF Aficionado
  • ********
  • Posts: 2325
  • Karma: 392
    • View Profile
    • http://www.rbraz.com/
Re: Extracting gm.dls samples for tiny demo trackers
« Reply #13 on: May 02, 2007 »
You have to love blackpawn.
Indeed :)

And finally I have created my own routines to extract those samples, blackpawn gave me the last clue I was looking for, because the way that Jim did it  was hard to me to understand  :P

I'm using a header file with samples offset and parser code, something like what you have did Chris  :kewl:

Tiny 4k tracker - here I go!
rbz ^ Codigos
Challenge Trophies Won:

Offline taj

  • Bytes hurt
  • DBF Aficionado
  • ******
  • Posts: 4810
  • Karma: 189
  • Scene there, done that.
    • View Profile
Re: Extracting gm.dls samples for tiny demo trackers
« Reply #14 on: May 02, 2007 »
Yeah thats very cool rbraz, question is...what sound playback will you use in the end?
I see three options:
1. Copy data from samples into a bi buffer by hanjd, applying envelopes etc as you go.
    The play the whole buffer using playsound.

2. Use MMIO - no ide about this , never used it.

3. Use directsound buffers...this i sthe way I tried, lots of hassle and bugs and then I fonud out you
cant use the FX (my reason for going this way) because you need to use a COM interface which costs bytes!

So any ideas?

Chris
Challenge Trophies Won:

Offline rbz

  • Founder Member
  • DBF Aficionado
  • ********
  • Posts: 2325
  • Karma: 392
    • View Profile
    • http://www.rbraz.com/
Re: Extracting gm.dls samples for tiny demo trackers
« Reply #15 on: May 02, 2007 »
Sorry Chris, I'm not sure yet, I'll try first with a buffer and playsound and probably do some tests with directsound too. I don't know anything about MMIO  :(
rbz ^ Codigos
Challenge Trophies Won:

Offline Jim

  • Founder Member
  • DBF Aficionado
  • ********
  • Posts: 5098
  • Karma: 380
    • View Profile
Re: Extracting gm.dls samples for tiny demo trackers
« Reply #16 on: May 02, 2007 »
waveOut is the technique I used in the ripping code above to play the samples.  It's nice and simple.  Almost everything you need is in that sample, except the synchronisation you might want.

Or there's DirectSound, which I posted a sample of here http://dbfinteractive.com/index.php?topic=1540.0.
The one whopper I've found in dsound is if you create the primary buffer as a hardware buffer, some drivers will ignore the sample rate you supply and replace it with another one (usually you ask for 44.1KHz and it plays at 48KHz).  This is due to a bug in Microsoft's original dsound driver sample (over 10yrs ago) which everyone just copied!

Jim
Challenge Trophies Won:

Offline taj

  • Bytes hurt
  • DBF Aficionado
  • ******
  • Posts: 4810
  • Karma: 189
  • Scene there, done that.
    • View Profile
Re: Extracting gm.dls samples for tiny demo trackers
« Reply #17 on: May 03, 2007 »
Jim,

I tried the directsound route and got it down to about 350 bytes (measured using apack) including loading samples and playing them from their own secondary buffers. I was forced to use a primary buffer in software - was ok. But then found out about the FX requiring COM which annoyed the hell out of me (kb doesnt mention that in his articles probably because he was aiming at 64k where the extra few hundred bytes arent a problem). I also had trouble working out the frequency (never solved it but mayeb I will one day) and getting rid of clicking in the buffers. The source is all in that code I sent out in grodfis2 directory.

In the end I wish I'd tried MMIO instead of directsound but I bet that has issues too.

In all grodfis2 got to the level of sequencing and playing 8 trakcs with 8 instruments and apart from the music data was coming in around 600 bytes. So directsound is ok but without using its advanced features it hardly seems worth it.
Challenge Trophies Won:

Offline Jim

  • Founder Member
  • DBF Aficionado
  • ********
  • Posts: 5098
  • Karma: 380
    • View Profile
Re: Extracting gm.dls samples for tiny demo trackers
« Reply #18 on: May 03, 2007 »
Quote
...getting rid of clicking in the buffers...
Ideally you run the code to fill the buffers on a different thread which is waiting for Windows events triggered by the primary buffer crossing some boundaries, but that would be a lot more bytes.

Why does COM take up so much more space?  Because of the GUIDs and the need to import the IUnknown interfaces?

Jim
Challenge Trophies Won:

Offline taj

  • Bytes hurt
  • DBF Aficionado
  • ******
  • Posts: 4810
  • Karma: 189
  • Scene there, done that.
    • View Profile
Re: Extracting gm.dls samples for tiny demo trackers
« Reply #19 on: May 03, 2007 »
Jim,

I'm not sure. Im not a PC programmer so I dont know a lot about this stuff, it would be a good area for DBF to investigate! I tried to produce a COM based exe once and it seemed to me that some sort of code is placed before your own, like a redirection table maybe? I looked at the asm but being no expert I couldn't tell what it was about. This is the problem with not being a programmer by trade, you run out of knowledge. For SAPI, the speech api, its cost me around 350 bytes after compression...frankly unacceptable in 1k or 4k.

I should add this was under GCC, I never tried with VC++ - maybe microsoft, owning COM, are smarter? Fancy trying it Jim?

Damn I try to quit the scene and dbf C++ thread turns into a research group for intros! Bloody hell this is the coolest board on the planet.

Chris
Challenge Trophies Won: