OpenTTD Source  20240919-master-gdf0233f4c2
dmusic.cpp File Reference
#include "../stdafx.h"
#include "../debug.h"
#include "../os/windows/win32.h"
#include "../core/mem_func.hpp"
#include "../thread.h"
#include "../fileio_func.h"
#include "../base_media_base.h"
#include "dmusic.h"
#include "midifile.hpp"
#include "midi.h"
#include <windows.h>
#include <dmksctrl.h>
#include <dmusicc.h>
#include <mutex>
#include "../safeguards.h"

Go to the source code of this file.

Data Structures

struct  DLSFile
 A DLS file. More...
 
struct  DLSFile::DLSRegion
 An instrument region maps a note range to wave data. More...
 
struct  DLSFile::DLSInstrument
 Instrument definition read from a DLS file. More...
 
struct  DLSFile::DLSWave
 Wave data definition from a DLS file. More...
 
struct  PlaybackSegment
 

Macros

#define INITGUID
 
#define FOURCC_INFO   mmioFOURCC('I', 'N', 'F', 'O')
 
#define FOURCC_fmt   mmioFOURCC('f', 'm', 't', ' ')
 
#define FOURCC_data   mmioFOURCC('d', 'a', 't', 'a')
 

Functions

 PACK_N (struct ChunkHeader { FOURCC type;DWORD length;}, 2)
 A RIFF chunk header.
 
 PACK_N (struct WAVE_DOWNLOAD { DMUS_DOWNLOADINFO dlInfo;ULONG ulOffsetTable[2];DMUS_WAVE dmWave;DMUS_WAVEDATA dmWaveData;}, 2)
 Buffer format for a DLS wave download.
 
static uint8_t ScaleVolume (uint8_t original, uint8_t scale)
 
static void TransmitChannelMsg (IDirectMusicBuffer *buffer, REFERENCE_TIME rt, uint8_t status, uint8_t p1, uint8_t p2=0)
 
static void TransmitSysex (IDirectMusicBuffer *buffer, REFERENCE_TIME rt, const uint8_t *&msg_start, size_t &remaining)
 
static void TransmitStandardSysex (IDirectMusicBuffer *buffer, REFERENCE_TIME rt, MidiSysexMessage msg)
 
static void TransmitNotesOff (IDirectMusicBuffer *buffer, REFERENCE_TIME block_time, REFERENCE_TIME cur_time)
 Transmit 'Note off' messages to all MIDI channels.
 
static void MidiThreadProc ()
 
static void * DownloadArticulationData (int base_offset, void *data, const std::vector< CONNECTION > &artic)
 
static const char * LoadDefaultDLSFile (const char *user_dls)
 

Variables

static const int MS_TO_REFTIME = 1000 * 10
 DirectMusic time base is 100 ns.
 
static const int MIDITIME_TO_REFTIME = 10
 Time base of the midi file reader is 1 us.
 
struct {
   bool   shutdown
 flag to indicate playback thread shutdown
 
   bool   playing
 flag indicating that playback is active
 
   bool   do_start
 flag for starting playback of next_file at next opportunity
 
   bool   do_stop
 flag for stopping playback at next opportunity
 
   int   preload_time
 preload time for music blocks.
 
   uint8_t   new_volume
 volume setting to change to
 
   MidiFile   next_file
 upcoming file to play
 
   PlaybackSegment   next_segment
 segment info for upcoming file
 
_playback
 
static std::thread _dmusic_thread
 Handle to our worker thread.
 
static HANDLE _thread_event = nullptr
 Event to signal the thread that it should look at a state change.
 
static std::mutex _thread_mutex
 Lock access to playback data that is not thread-safe.
 
static IDirectMusic * _music = nullptr
 The direct music object manages buffers and ports.
 
static IDirectMusicPort * _port = nullptr
 The port object lets us send MIDI data to the synthesizer.
 
static IDirectMusicBuffer * _buffer = nullptr
 The buffer object collects the data to sent.
 
static std::vector< IDirectMusicDownload * > _dls_downloads
 List of downloaded DLS instruments.
 
static FMusicDriver_DMusic iFMusicDriver_DMusic
 

Detailed Description

Playing music via DirectMusic.

Definition in file dmusic.cpp.