1 /*----------------------------------------------------------------------------- 2 3 ST-Sound ( YM files player library ) 4 5 YM Music Driver 6 7 -----------------------------------------------------------------------------*/ 8 9 /*----------------------------------------------------------------------------- 10 * ST-Sound, ATARI-ST Music Emulator 11 * Copyright (c) 1995-1999 Arnaud Carre ( http://leonard.oxg.free.fr ) 12 * All rights reserved. 13 * 14 * Redistribution and use in source and binary forms, with or without 15 * modification, are permitted provided that the following conditions 16 * are met: 17 * 1. Redistributions of source code must retain the above copyright 18 * notice, this list of conditions and the following disclaimer. 19 * 2. Redistributions in binary form must reproduce the above copyright 20 * notice, this list of conditions and the following disclaimer in the 21 * documentation and/or other materials provided with the distribution. 22 * 23 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 24 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 25 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 26 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 27 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 28 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 29 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 30 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 31 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 32 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 33 * SUCH DAMAGE. 34 * 35 -----------------------------------------------------------------------------*/ 36 37 38 #ifndef __YMMUSIC__ 39 #define __YMMUSIC__ 40 41 #include "YmTypes.h" 42 #include "StSoundLibrary.h" 43 #include "Ym2149Ex.h" 44 #include "Ymload.h" 45 #include "digidrum.h" 46 47 #define YMTPREC 16 48 #define MAX_VOICE 8 49 50 typedef enum 51 { 52 YM_V2, 53 YM_V3, 54 YM_V4, 55 YM_V5, 56 YM_V6, 57 YM_VMAX, 58 59 YM_TRACKER1=32, 60 YM_TRACKER2, 61 YM_TRACKERMAX, 62 63 YM_MIX1=64, 64 YM_MIX2, 65 YM_MIXMAX, 66 } ymFile_t; 67 68 typedef struct 69 { 70 ymu32 sampleStart; 71 ymu32 sampleLength; 72 ymu16 nbRepeat; 73 ymu16 replayFreq; 74 } mixBlock_t; 75 76 typedef struct 77 { 78 ymu32 size; 79 ymu8 * pData; 80 ymu32 repLen; 81 } digiDrum_t; 82 83 typedef struct 84 { 85 ymint nbVoice; 86 ymu32 nbVbl; 87 ymu8 * pDataBufer; 88 ymu32 currentVbl; 89 ymu32 flags; 90 ymbool bLoop; 91 } ymTrackerPartoche_t; 92 93 94 typedef struct 95 { 96 ymu8 * pSample; 97 ymu32 sampleSize; 98 ymu32 samplePos; 99 ymu32 repLen; 100 yms32 sampleVolume; 101 ymu32 sampleFreq; 102 ymbool bLoop; 103 ymbool bRunning; 104 } ymTrackerVoice_t; 105 106 typedef struct 107 { 108 ymu8 noteOn; 109 ymu8 volume; 110 ymu8 freqHigh; 111 ymu8 freqLow; 112 } ymTrackerLine_t; 113 114 115 enum 116 { 117 A_STREAMINTERLEAVED = 1, 118 A_DRUMSIGNED = 2, 119 A_DRUM4BITS = 4, 120 A_TIMECONTROL = 8, 121 A_LOOPMODE = 16, 122 }; 123 124 125 class CYmMusic 126 { 127 128 public: 129 CYmMusic(ymint _replayRate=44100); 130 ~CYmMusic(); 131 132 ymbool load(const char *pName); 133 ymbool loadMemory(void *pBlock,ymu32 size); 134 135 void unLoad(void); 136 ymbool isSeekable(void); 137 ymbool update(ymsample *pBuffer,ymint nbSample); 138 ymu32 getPos(void); 139 ymu32 getMusicTime(void); 140 ymu32 setMusicTime(ymu32 time); 141 void restart(void); 142 void play(void); 143 void pause(void); 144 void stop(void); 145 void setVolume(ymint volume); 146 int getAttrib(void); 147 void getMusicInfo(ymMusicInfo_t *pInfo); 148 void setLoopMode(ymbool bLoop); 149 const char *getLastError(void); readYmRegister(ymint reg)150 int readYmRegister(ymint reg) { return ymChip.readRegister(reg); } setLowpassFilter(ymbool bActive)151 void setLowpassFilter(ymbool bActive) { ymChip.setFilter(bActive); } 152 getMusicOver(void)153 ymbool getMusicOver(void) const { return (bMusicOver); } GetNbFrame()154 ymint GetNbFrame() const { return nbFrame; } GetStreamInc()155 ymint GetStreamInc() const { return streamInc; } GetDataStream()156 const ymu8* GetDataStream() const { return pDataStream; } readYmClock()157 ymu32 readYmClock() { return ymChip.getClock(); } 158 159 160 //------------------------------------------------------------- 161 // WAVE Generator 162 //------------------------------------------------------------- 163 int waveCreate(char *fName); 164 165 ymbool bMusicOver; 166 167 private: 168 169 ymbool checkCompilerTypes(); 170 171 void setPlayerRate(int rate); 172 void setAttrib(int _attrib); 173 void setLastError(const char *pError); 174 ymu8 *depackFile(ymu32 size); 175 ymbool deInterleave(void); 176 void readYm6Effect(ymu8 *pReg,int code,int prediv,int count); 177 void player(void); 178 void setTimeControl(ymbool bFlag); 179 180 181 CYm2149Ex ymChip; 182 const char *pLastError; 183 ymFile_t songType; 184 int nbFrame; 185 int loopFrame; 186 int currentFrame; 187 int nbDrum; 188 digiDrum_t *pDrumTab; 189 int musicTime; 190 ymu8 *pBigMalloc; 191 ymu8 *pDataStream; 192 ymbool bLoop; 193 ymint fileSize; 194 ymbool ymDecode(void); 195 ymint playerRate; 196 ymint attrib; 197 volatile ymbool bMusicOk; 198 volatile ymbool bPause; 199 ymint streamInc; 200 ymint innerSamplePos; 201 ymint replayRate; 202 203 ymchar *pSongName; 204 ymchar *pSongAuthor; 205 ymchar *pSongComment; 206 ymchar *pSongType; 207 ymchar *pSongPlayer; 208 209 //------------------------------------------------------------- 210 // ATARI Digi Mix Music. 211 //------------------------------------------------------------- 212 void readNextBlockInfo(void); 213 void stDigitMix(ymsample *pWrite16,int nbs); 214 void computeTimeInfo(void); 215 void setMixTime(ymu32 time); 216 217 ymint nbRepeat; 218 ymint nbMixBlock; 219 mixBlock_t *pMixBlock; 220 ymint mixPos; 221 ymu8 *pBigSampleBuffer; 222 ymu8 *pCurrentMixSample; 223 ymu32 currentSampleLength; 224 ymu32 currentPente; 225 ymu32 currentPos; 226 227 228 struct TimeKey 229 { 230 ymu32 time; 231 ymu16 nRepeat; 232 ymu16 nBlock; 233 }; 234 235 ymint m_nbTimeKey; 236 TimeKey * m_pTimeInfo; 237 ymu32 m_musicLenInMs; 238 ymu32 m_iMusicPosAccurateSample; 239 ymu32 m_iMusicPosInMs; 240 241 //------------------------------------------------------------- 242 // YM-Universal-Tracker 243 //------------------------------------------------------------- 244 void ymTrackerInit(int volMaxPercent); 245 void ymTrackerUpdate(ymsample *pBuffer,int nbSample); 246 void ymTrackerDesInterleave(void); 247 void ymTrackerPlayer(ymTrackerVoice_t *pVoice); 248 void ymTrackerVoiceAdd(ymTrackerVoice_t *pVoice,ymsample *pBuffer,int nbs); 249 250 int nbVoice; 251 ymTrackerVoice_t ymTrackerVoice[MAX_VOICE]; 252 int ymTrackerNbSampleBefore; 253 ymsample ymTrackerVolumeTable[256*64]; 254 int ymTrackerFreqShift; 255 256 257 }; 258 259 /* 260 int version; 261 SD pos; 262 UD inc; 263 UD timeSec; 264 UD timeMin; 265 UD loopSec; 266 UD loopMin; 267 UD nbVbl; 268 UD vblRestart; 269 UD ymFreq; 270 UD playerFreq; 271 UB *pRegister; 272 UB *pFileBuffer; 273 UD fileSize; 274 UD attrib; 275 char *pSongName; 276 char *pSongComment; 277 char *pSongAuthor; 278 mixBlock_t *pMixBlock; 279 long nbMixBlock; 280 UD nbDrum; 281 digiDrum_t *pDrumTab; 282 int nbVoice; 283 ymu32 currentVbl; 284 int bTimeControl; 285 int timeTotal; 286 int ymtFreqShift; 287 */ 288 289 #endif 290