OpenTTD Source 20241224-master-gee860a5c8e
|
Playing music via DirectMusic. More...
#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 More... | ||
bool playing | ||
flag indicating that playback is active More... | ||
bool do_start | ||
flag for starting playback of next_file at next opportunity More... | ||
bool do_stop | ||
flag for stopping playback at next opportunity More... | ||
int preload_time | ||
preload time for music blocks. More... | ||
uint8_t new_volume | ||
volume setting to change to More... | ||
MidiFile next_file | ||
upcoming file to play More... | ||
PlaybackSegment next_segment | ||
segment info for upcoming file More... | ||
} | _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 | |
Playing music via DirectMusic.
Definition in file dmusic.cpp.
#define FOURCC_data mmioFOURCC('d', 'a', 't', 'a') |
Definition at line 42 of file dmusic.cpp.
#define FOURCC_fmt mmioFOURCC('f', 'm', 't', ' ') |
Definition at line 41 of file dmusic.cpp.
#define FOURCC_INFO mmioFOURCC('I', 'N', 'F', 'O') |
Definition at line 40 of file dmusic.cpp.
#define INITGUID |
Definition at line 10 of file dmusic.cpp.
|
static |
Definition at line 830 of file dmusic.cpp.
|
static |
Definition at line 845 of file dmusic.cpp.
|
static |
Definition at line 578 of file dmusic.cpp.
|
static |
Definition at line 513 of file dmusic.cpp.
|
static |
Definition at line 518 of file dmusic.cpp.
|
static |
Transmit 'Note off' messages to all MIDI channels.
Definition at line 557 of file dmusic.cpp.
References _port, Clamp(), and MS_TO_REFTIME.
|
static |
Definition at line 549 of file dmusic.cpp.
|
static |
Definition at line 529 of file dmusic.cpp.
|
static |
The buffer object collects the data to sent.
Definition at line 144 of file dmusic.cpp.
Referenced by MusicDriver_DMusic::Start(), and MusicDriver_DMusic::Stop().
|
static |
List of downloaded DLS instruments.
Definition at line 146 of file dmusic.cpp.
Referenced by MusicDriver_DMusic::Stop().
|
static |
Handle to our worker thread.
Definition at line 133 of file dmusic.cpp.
Referenced by MusicDriver_DMusic::Start(), and MusicDriver_DMusic::Stop().
|
static |
The direct music object manages buffers and ports.
Definition at line 140 of file dmusic.cpp.
Referenced by MusicDriver_DMusic::Start(), and MusicDriver_DMusic::Stop().
|
static |
The port object lets us send MIDI data to the synthesizer.
Definition at line 142 of file dmusic.cpp.
Referenced by MusicDriver_DMusic::Start(), MusicDriver_DMusic::Stop(), and TransmitNotesOff().
|
static |
Event to signal the thread that it should look at a state change.
Definition at line 135 of file dmusic.cpp.
Referenced by MusicDriver_DMusic::PlaySong(), MusicDriver_DMusic::Start(), MusicDriver_DMusic::Stop(), and MusicDriver_DMusic::StopSong().
|
static |
Lock access to playback data that is not thread-safe.
Definition at line 137 of file dmusic.cpp.
Referenced by MusicDriver_DMusic::PlaySong().
bool do_start |
flag for starting playback of next_file at next opportunity
Definition at line 122 of file dmusic.cpp.
Referenced by CmdMassStartStopVehicle().
bool do_stop |
flag for stopping playback at next opportunity
Definition at line 123 of file dmusic.cpp.
|
static |
Definition at line 149 of file dmusic.cpp.
|
static |
Time base of the midi file reader is 1 us.
Definition at line 37 of file dmusic.cpp.
|
static |
DirectMusic time base is 100 ns.
Definition at line 36 of file dmusic.cpp.
Referenced by TransmitNotesOff().
uint8_t new_volume |
volume setting to change to
Definition at line 126 of file dmusic.cpp.
MidiFile next_file |
upcoming file to play
Definition at line 128 of file dmusic.cpp.
PlaybackSegment next_segment |
segment info for upcoming file
Definition at line 129 of file dmusic.cpp.
bool playing |
flag indicating that playback is active
Definition at line 121 of file dmusic.cpp.
int preload_time |
preload time for music blocks.
Definition at line 125 of file dmusic.cpp.
bool shutdown |
flag to indicate playback thread shutdown
Definition at line 120 of file dmusic.cpp.