Skip to content
marselas edited this page Mar 26, 2015 · 3 revisions

Overview

DirectMusic was a Microsoft API that allowed music and sound effects to be composed and played using a flexible, interactive interface. A large number of games and other multimedia products relied on DirectMusic not only for its flexibility, but because it provided a high-level audio interface to Microsoft’s DirectSound API.

Although DirectMusic was deprecated with the release of Windows Vista, and barely runs under Windows 8, a significant amount of legacy audio content is still stored in DirectMusic segment (SGT), RMI (RMI), and MIDI (MID) files.

The purpose of this command-line utility is to allow legacy DirectMusic files to be captured in real-time and saved as uncompressed WAV files. An audio device is required, as the DirectMusic file is played back in real-time, and the data for the wave file is captured directly from the low-level audio mixer.

Please keep in mind that while this utility can play and capture a significant number of SGT files, an SGT file can contain complex information for rendering dynamic soundtracks which is currently beyond the scope of this utility to process correctly.

In testing, 1248 of 1255 SGT format files were successfully converted to uncompressed WAV files. The issues with the remaining files could not be fully investigated at the time as the DirectMusic Producer application which is used for editing SGT files does not run under Windows 8.

Running

Running sgt2wav.exe without any command-line arguments displays a list of the command-line options, and a list of installed audio devices (or endpoints).

The following is the help information displayed when sgt2wav.exe is run on the workstation it was developed on. The list of audio devices on your computer will be different as you undoubtedly have a different audio device installed.

Usage: G:\p4\depot\CodeInfrastructure\sgt2wav\CaptureSharedTimerDriven\Debug\WASAPICaptureSharedTimerDriven.exe [-/ ][Switch][:][Value]

Where Switch is one of the following: ?:Print this help h:Print this help l:Audio Capture Latency (ms) m:Disable the use of MMCSS device:Device (endpoint) ID source:Source DirectMusic sgt, rmi, or mid file

Devices:

  • 0:Wave (ASUS Xonar DX Audio Device) ({0.0.1.00000000}.{1a4601d7-c964-46fc-bf5a-7b04ecdfe81f})
  • 1:Stereo Mix (ASUS Xonar DX Audio Device) ({0.0.1.00000000}.{751467fa-6537-43a8-be1b-34202fe1d6e9})
  • 2:Microphone (ASUS Xonar DX Audio Device) ({0.0.1.00000000}.{aff6f490-ffbf-432b-b931-c62d074e5b3e})
  • 3:Aux (ASUS Xonar DX Audio Device) ({0.0.1.00000000}.{ce68405a-35e6-4ce9-8ebc-aa4f9e4b9e9d})
  • 4:Line In (ASUS Xonar DX Audio Device) ({0.0.1.00000000}.{fb4a0e57-b9ef-4897-aa9d-d1f6f86d8473})

The most typical and basic command-line requires you to 1) specify the audio device from which to capture the WAV file data, and 2) specify the path to a DirectMusic SGT, RMI, or MID file.

Example: sgt2wav.exe -device 1 -source C:\sgt2wav\Crtr_Chicken_Idle.sgt

This will play the file Crtr_Chicken_Idle.sgt, and create a file named Crtr_Chicken_Idle.wav in the same directory.

As the capture is performed in real-time, a one minute audio clip will take one minute to capture. A 20 minute audio clip will take 20 minutes to capture. Etc. Etc. Also, as this data is captured and stored as uncompressed 44 KHz, 32 bit WAV files, the file sizes can be quite large.

The primary reasons that files are stored as uncompressed 44 KHz, 32 bit WAV files are 1) ease of implementation, 2) maximum flexibility for use of the files, and 3) wide availability of other utilities to handle them and/ or compress them in a format of your choice. For example, once we had captured our files to WAV, we used LameXP to convert them to MP3 format.

Building

Written in C++, sgt2wav.exe is setup and configured using Microsoft Visual Studio 2013. However, due to the small number of fairly simple files, it could easily be ported (or upgraded) to another IDE.

sgt2wav.exe was based originally on the DirectMusic PlayAudio sample from the Microsoft DirectX SDK, and the Windows Core Audio CaptureSharedTimerDriven sample from the Microsoft Windows SDK for Windows 7 and .NET Framework 3.5 SP1.

While effort has been made to cleanly integrate the two code bases together and cleanup refactored code, no effort was expended in refactoring or modifying any code outside that which was absolutely necessary.

Building sgt2wav from source also requires a Microsoft DirectX SDK with DirectMusic include and library files. Although the DirectX 8.1 SDK was used for the build, any of the DirectX 9 SDKs could have been used as well.

If you are building using an older DirectX SDK version, you may need to delete the basestd.h file from the DirectX SDK include directory as it will conflict with a newer version in the platform SDK include files that are supplied with the compiler in the IDE.

You may also need to modify the DirectX SDK include file dmerror.h, and add #undef FACILITY_DIRECTMUSIC at the top of the file in order to fix a name collision with the platform SDK winerror.h include file.

When debugging on Windows 8 using Visual Studio, you are likely to encounter an issue where DirectMusic can only be successfully initialized and run once before erroring out. Exiting and restarting Visual Studio will fix the problem. This appears to be a DirectMusic-specific issue outside the application’s ability to fix. For iterative testing, and not debugging, using CTRL+F5 to launch as a separate process from Visual Studio will allow you to test without having to frequently exit and restart the IDE.

Future Work

Although this is a simple utility, there are a number of areas for potential future work for those who want, need, or desire to take it up, including:

  • improved error handling
  • sometimes, it just hangs on exit when capturing / converting very large sgt files
  • occasionally, there is some static or pop at the beginning of a recording. although, this seems to be due to other audio apps being active
  • fix issue that input file always requires qualified (or, at least relative) path
  • better (actual) UI for displaying what’s playing, time elapsed (or hide the dialog box)
  • ability to adjust parameters, e.g.: volume
  • support for streaming out wav data instead of having a massive internal wav buffer. although, I doubt 99% of sgt or midi projects would hit the current memory buffer limit, anyway
  • ability to capture and convert more complex sgt files
Clone this wiki locally