STYMulator-0.21a/0000755000175000017500000000000010600713117013366 5ustar gandalfgandalfSTYMulator-0.21a/ChangeLog0000644000175000017500000000106410577674735015172 0ustar gandalfgandalfv0.21a 15-March-2007 - Fixed directory structure and install path for correct RPM packaging v0.21 06-March-2007 - Added GNU/Linux 64bit compatibility (small changes in YmTypes.h, YmUserInterface.cpp files). Verified on RHEL v4 U4 x86_64 - Removed not needed ;-) snd_pcm_hw_params_set_rate_resample function (added to alsa-lib since 1.0.9rc2) due to more portability (sound.cpp) - Added platform info in ym2wav & ymplayer v0.2 11-Jul-2006 - Updated ST-Sound GPL library to version 1.2 - Removed unneeded file player.cpp v0.1 December 2005 - Initial release STYMulator-0.21a/README0000644000175000017500000000260610455734013014260 0ustar gandalfgandalfSTYMulator v0.2 - GNU/Linux player for Atari ST YM files. Copyright (c) 2005-2006 by Grzegorz Tomasz Stanczyk Project Home Page: http://atariarea.krap.pl/stymulator ST-Sound GPL v1.2 (YM files player library) GNU/Linux port by Grzegorz Tomasz Stanczyk Description: ------------ STYMulator is a free (under GNU GPL license - see gpl.txt) YM files music player with curses-based terminal interface for GNU/Linux. It uses GNU/Linux port (stdoundlib directory) of the original ST-Sound GPL v1.2 library by Arnaud Carre (http://leonard.oxg.free.fr). Requirements: ------------- 1. ALSA (Advanced Linux Sound Architecture) sound library (http://www.alsa-project.org) 2. ncurses - a freeware implementation of the System V curses API (man ncurses if available) 3. C/C++ compilator (GCC) STYMulator has been tested on Fedora Core 4, 5. Installation (compilation): --------------------------- Go into src directory and do 'make' then (as root) 'make install' or su -c "make install". Usage: ------ To play music: ymplayer To convert YM to WAV file: ym2wav In the music directory you will find a few example YM tunes. Want more ? The one of the biggest YM music archive is ready to download from http://pacidemo.atarizone.com (YM tunes section) Contact (bugs & ideas): ----------------------- e-mail: linuxdevelop@wp.pl or gstanczyk@mail.atr.bydgoszcz.pl STYMulator-0.21a/COPYING0000644000175000017500000004313310576236365014446 0ustar gandalfgandalf GNU GENERAL PUBLIC LICENSE Version 2, June 1991 Copyright (C) 1989, 1991 Free Software Foundation, Inc. 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA Everyone is permitted to copy and distribute verbatim copies of this license document, but changing it is not allowed. Preamble The licenses for most software are designed to take away your freedom to share and change it. By contrast, the GNU General Public License is intended to guarantee your freedom to share and change free software--to make sure the software is free for all its users. This General Public License applies to most of the Free Software Foundation's software and to any other program whose authors commit to using it. (Some other Free Software Foundation software is covered by the GNU Library General Public License instead.) You can apply it to your programs, too. When we speak of free software, we are referring to freedom, not price. Our General Public Licenses are designed to make sure that you have the freedom to distribute copies of free software (and charge for this service if you wish), that you receive source code or can get it if you want it, that you can change the software or use pieces of it in new free programs; and that you know you can do these things. To protect your rights, we need to make restrictions that forbid anyone to deny you these rights or to ask you to surrender the rights. These restrictions translate to certain responsibilities for you if you distribute copies of the software, or if you modify it. For example, if you distribute copies of such a program, whether gratis or for a fee, you must give the recipients all the rights that you have. You must make sure that they, too, receive or can get the source code. And you must show them these terms so they know their rights. We protect your rights with two steps: (1) copyright the software, and (2) offer you this license which gives you legal permission to copy, distribute and/or modify the software. Also, for each author's protection and ours, we want to make certain that everyone understands that there is no warranty for this free software. If the software is modified by someone else and passed on, we want its recipients to know that what they have is not the original, so that any problems introduced by others will not reflect on the original authors' reputations. Finally, any free program is threatened constantly by software patents. We wish to avoid the danger that redistributors of a free program will individually obtain patent licenses, in effect making the program proprietary. To prevent this, we have made it clear that any patent must be licensed for everyone's free use or not licensed at all. The precise terms and conditions for copying, distribution and modification follow. GNU GENERAL PUBLIC LICENSE TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION 0. This License applies to any program or other work which contains a notice placed by the copyright holder saying it may be distributed under the terms of this General Public License. The "Program", below, refers to any such program or work, and a "work based on the Program" means either the Program or any derivative work under copyright law: that is to say, a work containing the Program or a portion of it, either verbatim or with modifications and/or translated into another language. (Hereinafter, translation is included without limitation in the term "modification".) Each licensee is addressed as "you". Activities other than copying, distribution and modification are not covered by this License; they are outside its scope. The act of running the Program is not restricted, and the output from the Program is covered only if its contents constitute a work based on the Program (independent of having been made by running the Program). Whether that is true depends on what the Program does. 1. You may copy and distribute verbatim copies of the Program's source code as you receive it, in any medium, provided that you conspicuously and appropriately publish on each copy an appropriate copyright notice and disclaimer of warranty; keep intact all the notices that refer to this License and to the absence of any warranty; and give any other recipients of the Program a copy of this License along with the Program. You may charge a fee for the physical act of transferring a copy, and you may at your option offer warranty protection in exchange for a fee. 2. You may modify your copy or copies of the Program or any portion of it, thus forming a work based on the Program, and copy and distribute such modifications or work under the terms of Section 1 above, provided that you also meet all of these conditions: a) You must cause the modified files to carry prominent notices stating that you changed the files and the date of any change. b) You must cause any work that you distribute or publish, that in whole or in part contains or is derived from the Program or any part thereof, to be licensed as a whole at no charge to all third parties under the terms of this License. c) If the modified program normally reads commands interactively when run, you must cause it, when started running for such interactive use in the most ordinary way, to print or display an announcement including an appropriate copyright notice and a notice that there is no warranty (or else, saying that you provide a warranty) and that users may redistribute the program under these conditions, and telling the user how to view a copy of this License. (Exception: if the Program itself is interactive but does not normally print such an announcement, your work based on the Program is not required to print an announcement.) These requirements apply to the modified work as a whole. If identifiable sections of that work are not derived from the Program, and can be reasonably considered independent and separate works in themselves, then this License, and its terms, do not apply to those sections when you distribute them as separate works. But when you distribute the same sections as part of a whole which is a work based on the Program, the distribution of the whole must be on the terms of this License, whose permissions for other licensees extend to the entire whole, and thus to each and every part regardless of who wrote it. Thus, it is not the intent of this section to claim rights or contest your rights to work written entirely by you; rather, the intent is to exercise the right to control the distribution of derivative or collective works based on the Program. In addition, mere aggregation of another work not based on the Program with the Program (or with a work based on the Program) on a volume of a storage or distribution medium does not bring the other work under the scope of this License. 3. You may copy and distribute the Program (or a work based on it, under Section 2) in object code or executable form under the terms of Sections 1 and 2 above provided that you also do one of the following: a) Accompany it with the complete corresponding machine-readable source code, which must be distributed under the terms of Sections 1 and 2 above on a medium customarily used for software interchange; or, b) Accompany it with a written offer, valid for at least three years, to give any third party, for a charge no more than your cost of physically performing source distribution, a complete machine-readable copy of the corresponding source code, to be distributed under the terms of Sections 1 and 2 above on a medium customarily used for software interchange; or, c) Accompany it with the information you received as to the offer to distribute corresponding source code. (This alternative is allowed only for noncommercial distribution and only if you received the program in object code or executable form with such an offer, in accord with Subsection b above.) The source code for a work means the preferred form of the work for making modifications to it. For an executable work, complete source code means all the source code for all modules it contains, plus any associated interface definition files, plus the scripts used to control compilation and installation of the executable. However, as a special exception, the source code distributed need not include anything that is normally distributed (in either source or binary form) with the major components (compiler, kernel, and so on) of the operating system on which the executable runs, unless that component itself accompanies the executable. If distribution of executable or object code is made by offering access to copy from a designated place, then offering equivalent access to copy the source code from the same place counts as distribution of the source code, even though third parties are not compelled to copy the source along with the object code. 4. You may not copy, modify, sublicense, or distribute the Program except as expressly provided under this License. Any attempt otherwise to copy, modify, sublicense or distribute the Program is void, and will automatically terminate your rights under this License. However, parties who have received copies, or rights, from you under this License will not have their licenses terminated so long as such parties remain in full compliance. 5. You are not required to accept this License, since you have not signed it. However, nothing else grants you permission to modify or distribute the Program or its derivative works. These actions are prohibited by law if you do not accept this License. Therefore, by modifying or distributing the Program (or any work based on the Program), you indicate your acceptance of this License to do so, and all its terms and conditions for copying, distributing or modifying the Program or works based on it. 6. Each time you redistribute the Program (or any work based on the Program), the recipient automatically receives a license from the original licensor to copy, distribute or modify the Program subject to these terms and conditions. You may not impose any further restrictions on the recipients' exercise of the rights granted herein. You are not responsible for enforcing compliance by third parties to this License. 7. If, as a consequence of a court judgment or allegation of patent infringement or for any other reason (not limited to patent issues), conditions are imposed on you (whether by court order, agreement or otherwise) that contradict the conditions of this License, they do not excuse you from the conditions of this License. If you cannot distribute so as to satisfy simultaneously your obligations under this License and any other pertinent obligations, then as a consequence you may not distribute the Program at all. For example, if a patent license would not permit royalty-free redistribution of the Program by all those who receive copies directly or indirectly through you, then the only way you could satisfy both it and this License would be to refrain entirely from distribution of the Program. If any portion of this section is held invalid or unenforceable under any particular circumstance, the balance of the section is intended to apply and the section as a whole is intended to apply in other circumstances. It is not the purpose of this section to induce you to infringe any patents or other property right claims or to contest validity of any such claims; this section has the sole purpose of protecting the integrity of the free software distribution system, which is implemented by public license practices. Many people have made generous contributions to the wide range of software distributed through that system in reliance on consistent application of that system; it is up to the author/donor to decide if he or she is willing to distribute software through any other system and a licensee cannot impose that choice. This section is intended to make thoroughly clear what is believed to be a consequence of the rest of this License. 8. If the distribution and/or use of the Program is restricted in certain countries either by patents or by copyrighted interfaces, the original copyright holder who places the Program under this License may add an explicit geographical distribution limitation excluding those countries, so that distribution is permitted only in or among countries not thus excluded. In such case, this License incorporates the limitation as if written in the body of this License. 9. The Free Software Foundation may publish revised and/or new versions of the General Public License from time to time. Such new versions will be similar in spirit to the present version, but may differ in detail to address new problems or concerns. Each version is given a distinguishing version number. If the Program specifies a version number of this License which applies to it and "any later version", you have the option of following the terms and conditions either of that version or of any later version published by the Free Software Foundation. If the Program does not specify a version number of this License, you may choose any version ever published by the Free Software Foundation. 10. If you wish to incorporate parts of the Program into other free programs whose distribution conditions are different, write to the author to ask for permission. For software which is copyrighted by the Free Software Foundation, write to the Free Software Foundation; we sometimes make exceptions for this. Our decision will be guided by the two goals of preserving the free status of all derivatives of our free software and of promoting the sharing and reuse of software generally. NO WARRANTY 11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING, REPAIR OR CORRECTION. 12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. END OF TERMS AND CONDITIONS How to Apply These Terms to Your New Programs If you develop a new program, and you want it to be of the greatest possible use to the public, the best way to achieve this is to make it free software which everyone can redistribute and change under these terms. To do so, attach the following notices to the program. It is safest to attach them to the start of each source file to most effectively convey the exclusion of warranty; and each file should have at least the "copyright" line and a pointer to where the full notice is found. Copyright (C) This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA Also add information on how to contact you by electronic and paper mail. If the program is interactive, make it output a short notice like this when it starts in an interactive mode: Gnomovision version 69, Copyright (C) year name of author Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'. This is free software, and you are welcome to redistribute it under certain conditions; type `show c' for details. The hypothetical commands `show w' and `show c' should show the appropriate parts of the General Public License. Of course, the commands you use may be called something other than `show w' and `show c'; they could even be mouse-clicks or menu items--whatever suits your program. You should also get your employer (if you work as a programmer) or your school, if any, to sign a "copyright disclaimer" for the program, if necessary. Here is a sample; alter the names: Yoyodyne, Inc., hereby disclaims all copyright interest in the program `Gnomovision' (which makes passes at compilers) written by James Hacker. , 1 April 1989 Ty Coon, President of Vice This General Public License does not permit incorporating your program into proprietary programs. If your program is a subroutine library, you may consider it more useful to permit linking proprietary applications with the library. If this is what you want to do, use the GNU Library General Public License instead of this License. STYMulator-0.21a/revision.txt0000644000175000017500000000230410431627550015773 0ustar gandalfgandalfv1.2 ---------------------------------------------------- - new low pass filter routine (faster and no more dynamic allocation) - LZH depacking multi-thread safe - Rare bad division crash fixed. Thanks to Alexandru Simion - memory leak fixed with old format (YM2 and YM3). Thanks to Alexandru Simion - GetInfo time reported in second and millisecond now - Both project files for VisualC++ 6 and .Net 2003 - WARNING: Three files were removed from 1.1b: Depacker.h, Depacker.cpp and lzhxlib.c One file is added: LzhLib.cpp v1.1b ---------------------------------------------------- - runtime build in basic types size checking - some "short" types converted to ymsample v1.1 ---------------------------------------------------- - YmTypes.h added to help multiplatform port - Added Sync-Buzzer sound effect support - Integer only version (no float or double used by default) - Small changes in C interface (ymMusicCreate and ymMusicDestroy added) - little/big endian fixed for bigendian platform (depacking and Ym3b format) - Memory leak fixed in LZHXLIB library - printf fixed in the YM to WAV sample code v1.0 ---------------------------------------------------- - First release. STYMulator-0.21a/readme.html0000644000175000017500000002042210253075706015522 0ustar gandalfgandalf Open Source ST-Sound

Open Source ST-Sound Library by Arnaud Carré
v1.1
10 years later !! :-)

 
History...

In 1995 I created the YM file format and wrote ST-Sound, a program to play ATARI-ST on your PC. I was very happy to see how ST-Sound was popular. MS-Dos player at first, I write a Windows player, a winamp and a netscape plugin. ( then some website use Atari tunes !).

And then time passed and I worked on other stuff. Quite often, some people asked me to release the source code, and I always answered that I should clean some code and add license stuff, so I never take time..

Now it's done ! 2005, ten years after the first ST-Sound creation, here is the ST-Sound library with sample project, all under GPL license. The code is not as clean as I hope but no time to change it. Don't forget almost all that stuff was written in 1995 :-)

Package details

ST-Sound library package comes with four main directories.:

StSoundLibrary

This is the most important directory. Portable ( I hope !! :-)) C++ code to play YM files into your own production. There is a simple "C like" user API, and you just need to include "StSoundLibrary.h" to work with YM files. See tutorial projects for details. Theorically should compile under windows, linux, etc.

YmToWav

Tutorial code. Portable ( I hope !! :-)) code to render an YM file into a WAV file. Works in command line. theorically should compile under windows, linux, etc.

SmallYmPlayer

Tutorial code. Non portable (windows only) real time YM player using StSoundLibrary. Works under windows (use the waveOut sound API)

YmSampleFiles

Only contains a set of YM sample files to fastly test the library without browsing the whole world wide web ! :-)

Compiling

The package is done to work very nicely with Microsoft Visual C++ 6.0 ( Visual .NET is pure bullshit! )

For Visual C++ 6.0 users: Load StSoundGPL.dsw file into your lovely IDE and just build one of the tutorial sample or the main library. Everything should work like a charm without pain.

For other users ( .NET, Linux, Gameboy color or other strange system), just search in your head some very, very oldschool knowledge and build a nice makefile :-) ( should be easy for StSoundLibrary)

Legal infos

ST-Sound library, Copyright (C) 1995-1999 Arnaud Carré ( http://leonard.oxg.free.fr )

ST-Sound library is distributed under GNU GPL license. If you use it in your own production, please include at least that ZIP package and make me a little credits :-). You can find the GPL legal file within that package ( license.txt ).

As almost all YM files on the web are packed with LZH method, ST-Sound includes LZH depacking code written by Haruhiko Okumura and modifyed/improved by Kerwin F. Medina.

Enjoy ATARI-ST sound !!

http://leonard.oxg.free.fr

 

 

STYMulator-0.21a/src/0000755000175000017500000000000010600713024014152 5ustar gandalfgandalfSTYMulator-0.21a/src/stsoundlib/0000755000175000017500000000000010573216575016362 5ustar gandalfgandalfSTYMulator-0.21a/src/stsoundlib/YmMusic.cpp0000644000175000017500000003667610431364166020467 0ustar gandalfgandalf/*----------------------------------------------------------------------------- ST-Sound ( YM files player library ) Copyright (C) 1995-1999 Arnaud Carre ( http://leonard.oxg.free.fr ) YM Music Driver -----------------------------------------------------------------------------*/ /*----------------------------------------------------------------------------- This file is part of ST-Sound ST-Sound is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. ST-Sound is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with ST-Sound; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA -----------------------------------------------------------------------------*/ #include #include #include "YmMusic.h" #define _LINEAR_OVRS // Activate linear oversampling (best quality) Only used for DigiMix and UniversalTracker YM file type // ATARI-ST MFP chip predivisor static const ymint mfpPrediv[8] = {0,4,10,16,50,64,100,200}; CYmMusic::CYmMusic(ymint _replayRate) { pBigMalloc = NULL; pSongName = NULL; pSongAuthor = NULL; pSongComment = NULL; pSongType = NULL; pSongPlayer = NULL; pBigSampleBuffer = NULL; pMixBlock = NULL; replayRate = _replayRate; innerSamplePos = 0; nbDrum = 0; pDrumTab = NULL; setLoopMode(YMFALSE); } void CYmMusic::setTimeControl(ymbool bTime) { if (bTime) attrib |= A_TIMECONTROL; else attrib &= (~A_TIMECONTROL); } CYmMusic::~CYmMusic() { stop(); unLoad(); } void CYmMusic::setLoopMode(ymbool bLoopMode) { bLoop = bLoopMode; } void CYmMusic::setPlayerRate(ymint rate) { playerRate = rate; } ymu32 CYmMusic::getPos() { if (!isSeekable()) return 0; if ((nbFrame>0) && (playerRate>0)) { return ((ymu32)currentFrame*1000)/(ymu32)playerRate; } else return 0; } ymu32 CYmMusic::getMusicTime(void) { if ((nbFrame>0) && (playerRate>0)) { return ((ymu32)nbFrame*1000)/(ymu32)playerRate; } else return 0; } ymu32 CYmMusic::setMusicTime(ymu32 time) { if (!isSeekable()) return 0; ymu32 newTime = 0; if ((songType>=YM_V2) && (songType=getMusicTime()) newTime = 0; currentFrame = (newTime*(ymu32)playerRate)/1000; } else if ((songType>=YM_TRACKER1) && (songType=getMusicTime()) newTime = 0; currentFrame = (newTime*(ymu32)playerRate)/1000; } return newTime; } void CYmMusic::getMusicInfo(ymMusicInfo_t *pInfo) { if (pInfo) { pInfo->pSongName = pSongName; pInfo->pSongAuthor = pSongAuthor; pInfo->pSongComment = pSongComment; pInfo->pSongType = pSongType; pInfo->pSongPlayer = pSongPlayer; if (playerRate>0) { pInfo->musicTimeInMs = (ymu32(nbFrame) * 1000) / (ymu32)playerRate; pInfo->musicTimeInSec = pInfo->musicTimeInMs / 1000; } else { pInfo->musicTimeInSec = 0; pInfo->musicTimeInMs = 0; } } } void CYmMusic::setAttrib(ymint _attrib) { attrib = _attrib; } ymint CYmMusic::getAttrib(void) { return attrib; } ymbool CYmMusic::isSeekable(void) { return getAttrib()&A_TIMECONTROL; } void CYmMusic::setLastError(char *pError) { pLastError = pError; } char *CYmMusic::getLastError(void) { return pLastError; } void bufferClear(ymsample *pBuffer,ymint nbSample) { memset((void*)pBuffer,0,nbSample*sizeof(ymsample)); } ymbool CYmMusic::update(ymsample *sampleBuffer,ymint nbSample) { ymint sampleToCompute; ymint vblNbSample; if ((!bMusicOk) || (bPause) || (bMusicOver)) { bufferClear(sampleBuffer,nbSample); if (bMusicOver) return YMFALSE; else return YMTRUE; } if ((songType >= YM_MIX1) && (songType < YM_MIXMAX)) { stDigitMix(sampleBuffer,nbSample); } else if ((songType >= YM_TRACKER1) && (songTypenbs) sampleToCompute = nbs; innerSamplePos += sampleToCompute; if (innerSamplePos>=vblNbSample) { player(); // Lecture de la partition (playerRate Hz) innerSamplePos -= vblNbSample; } if (sampleToCompute>0) { ymChip.update(pOut,sampleToCompute); // YM Emulation. pOut += sampleToCompute; } nbs -= sampleToCompute; } while (nbs>0); } return YMTRUE; } void CYmMusic::readYm6Effect(unsigned char *pReg,ymint code,ymint prediv,ymint count) { ymint voice; ymint ndrum; code = pReg[code]&0xf0; prediv = (pReg[prediv]>>5)&7; count = pReg[count]; if (code&0x30) { ymu32 tmpFreq; // Ici il y a un effet sur la voie: voice = ((code&0x30)>>4)-1; switch (code&0xc0) { case 0x00: // SID case 0x80: // Sinus-SID prediv = mfpPrediv[prediv]; prediv *= count; tmpFreq = 0; if (prediv) { tmpFreq = 2457600L / prediv; if ((code&0xc0)==0x00) ymChip.sidStart(voice,tmpFreq,pReg[voice+8]&15); else ymChip.sidSinStart(voice,tmpFreq,pReg[voice+8]&15); } break; case 0x40: // DigiDrum ndrum = pReg[voice+8]&31; if ((ndrum>=0) && (ndrum0) { tmpFreq = 2457600L / prediv; ymChip.drumStart(voice,pDrumTab[ndrum].pData,pDrumTab[ndrum].size,tmpFreq); } } break; case 0xc0: // Sync-Buzzer. prediv = mfpPrediv[prediv]; prediv *= count; tmpFreq = 0; if (prediv) { tmpFreq = 2457600L / prediv; ymChip.syncBuzzerStart(tmpFreq,pReg[voice+8]&15); } break; } } } void CYmMusic::setVolume(ymint volume) { // ymChip.setGlobalVolume(volume); } void CYmMusic::player(void) { ymu8 *ptr; ymu32 prediv; ymint voice; ymint ndrum; if (currentFrame<0) currentFrame = 0; if (currentFrame>=nbFrame) { if (bLoop) { currentFrame = loopFrame; } else { bMusicOver = YMTRUE; ymChip.reset(); return; } } ptr = pDataStream+currentFrame*streamInc; for (ymint i=0;i<=10;i++) ymChip.writeRegister(i,ptr[i]); ymChip.sidStop(0); ymChip.sidStop(1); ymChip.sidStop(2); ymChip.syncBuzzerStop(); //--------------------------------------------- // Check digi-drum //--------------------------------------------- if (songType == YM_V2) // MADMAX specific ! { if (ptr[13]!=0xff) { ymChip.writeRegister(11,ptr[11]); ymChip.writeRegister(12,0); ymChip.writeRegister(13,10); // MADMAX specific !! } if (ptr[10]&0x80) // bit 7 volume canal C pour annoncer une digi-drum madmax. { ymint sampleNum; ymu32 sampleFrq; ymChip.writeRegister(7,ymChip.readRegister(7)|0x24) ; // Coupe TONE + NOISE canal C. sampleNum = ptr[10]&0x7f; // Numero du sample if (ptr[12]) { sampleFrq = (MFP_CLOCK / ptr[12]); ymChip.drumStart( 2, // Voice C sampleAdress[sampleNum], sampleLen[sampleNum], sampleFrq); } } } else if (songType >= YM_V3) { ymChip.writeRegister(11,ptr[11]); ymChip.writeRegister(12,ptr[12]); if (ptr[13]!=0xff) { ymChip.writeRegister(13,ptr[13]); } if (songType >= YM_V5) { ymint code; if (songType == YM_V6) { readYm6Effect(ptr,1,6,14); readYm6Effect(ptr,3,8,15); } else { // YM5 effect decoding //------------------------------------------------------ // Sid Voice !! //------------------------------------------------------ code = (ptr[1]>>4)&3; if (code!=0) { ymu32 tmpFreq; voice = code-1; prediv = mfpPrediv[(ptr[6]>>5)&7]; prediv *= ptr[14]; tmpFreq = 0; if (prediv) { tmpFreq = 2457600L / prediv; ymChip.sidStart(voice,tmpFreq,ptr[voice+8]&15); } } //------------------------------------------------------ // YM5 Digi Drum. //------------------------------------------------------ code = (ptr[3]>>4)&3; if (code!=0) { // Ici un digidrum demarre sur la voie voice. voice = code-1; ndrum = ptr[8+voice]&31; if ((ndrum>=0) && (ndrum>5)&7]; prediv *= ptr[15]; if (prediv) { sampleFrq = MFP_CLOCK / prediv; ymChip.drumStart(voice,pDrumTab[ndrum].pData,pDrumTab[ndrum].size,sampleFrq); } } } } } } currentFrame++; } /* x x x x x x x x r0 0 0 0 0 x x x x r1 // Special FX 1a x x x x x x x x r2 0 0 0 0 x x x x r3 // Special FX 2a x x x x x x x x r4 0 0 0 0 x x x x r5 0 0 0 x x x x x r6 // Special FX 1b 0 0 x x x x x x r7 0 0 0 x x x x x r8 // Special FX 2b 0 0 0 x x x x x r9 0 0 0 x x x x x r10 x x x x x x x x r11 x x x x x x x x r12 0 0 0 0 x x x x r13 0 0 0 0 0 0 0 0 r14 // Special FX 1c 0 0 0 0 0 0 0 0 r15 // Special FX 2c Special Fx ?a 0 0 0 0 : No special FX running 0 0 0 1 : Sid Voice A 0 0 1 0 : Sid Voice B 0 0 1 1 : Sid Voice C 0 1 0 0 : Extended Fx voice A 0 1 0 1 : Digidrum voice A 0 1 1 0 : Digidrum voice B 0 1 1 1 : Digidrum voice C 1 0 0 0 : Extended Fx voice B 1 0 0 1 : Sinus SID voice A 1 0 1 0 : Sinus SID voice B 1 0 1 1 : Sinus SID voice C 1 1 0 0 : Extended Fx voice C 1 1 0 1 : Sync Buzzer voice A 1 1 1 0 : Sync Buzzer voice B 1 1 1 1 : Sync Buzzer voice C */ void CYmMusic::readNextBlockInfo(void) { nbRepeat--; if (nbRepeat<=0) { mixPos++; if (mixPos >= nbMixBlock) { mixPos = 0; if (!bLoop) bMusicOver = YMTRUE; } nbRepeat = pMixBlock[mixPos].nbRepeat; } pCurrentMixSample = pBigSampleBuffer + pMixBlock[mixPos].sampleStart; currentSampleLength = (pMixBlock[mixPos].sampleLength)<<12; currentPente = (((ymu32)pMixBlock[mixPos].replayFreq)<<12) / PC_DAC_FREQ; currentPos &= ((1<<12)-1); } void CYmMusic::stDigitMix(ymsample *pWrite16,ymint nbs) { if (bMusicOver) return; if (mixPos == -1) { nbRepeat = -1; readNextBlockInfo(); } if (nbs) do { ymint sa = (ymint)(ymsample)(pCurrentMixSample[currentPos>>12]<<8); #ifdef _LINEAR_OVRS ymint sb = sa; if ((currentPos>>12)<((currentSampleLength>>12)-1)) sb = (ymint)(ymsample)(pCurrentMixSample[(currentPos>>12)+1]<<8); ymint frac = currentPos&((1<<12)-1); sa += (((sb-sa)*frac)>>12); #endif *pWrite16++ = sa; currentPos += currentPente; if (currentPos>=currentSampleLength) { readNextBlockInfo(); if (bMusicOver) return; } } while (--nbs); } void CYmMusic::ymTrackerDesInterleave(void) { unsigned char *a0,*a1,*a2; unsigned char *pNewBuffer; ymint step; ymu32 n1,n2; if (attrib&A_STREAMINTERLEAVED) { a0 = pDataStream; ymint size = sizeof(ymTrackerLine_t)*nbVoice*nbFrame; pNewBuffer = (unsigned char*)malloc(size); step = sizeof(ymTrackerLine_t)*nbVoice; n1 = step; a2 = pNewBuffer; do { n2 = nbFrame; a1 = a2; do { *a1 = *a0++; a1 += step; } while (--n2); a2++; } while (--n1); memcpy(pDataStream,pNewBuffer,size); free(pNewBuffer); attrib &= (~A_STREAMINTERLEAVED); } } void CYmMusic::ymTrackerInit(ymint volMaxPercent) { ymint i,s; ymint vol; ymint scale; ymsample *pTab; for (i=0;ifreqHigh<<8) | pLine->freqLow; if (pVoice[i].sampleFreq) { pVoice[i].sampleVolume = pLine->volume&63; pVoice[i].bLoop = (pLine->volume&0x40); n = pLine->noteOn; if (n != 0xff) // Note ON. { pVoice[i].bRunning = 1; pVoice[i].pSample = pDrumTab[n].pData; pVoice[i].sampleSize = pDrumTab[n].size; pVoice[i].repLen = pDrumTab[n].repLen; pVoice[i].samplePos = 0; } } else { pVoice[i].bRunning = 0; } pLine++; } currentFrame++; if (currentFrame >= nbFrame) { if (!bLoop) { bMusicOver = YMTRUE; } currentFrame = 0; } } void CYmMusic::ymTrackerVoiceAdd(ymTrackerVoice_t *pVoice,ymsample *pBuffer,ymint nbs) { ymsample *pVolumeTab; ymu8 *pSample; ymu32 samplePos; ymu32 sampleEnd; ymu32 sampleInc; ymu32 repLen; double step; if (!(pVoice->bRunning)) return; pVolumeTab = &ymTrackerVolumeTable[256*(pVoice->sampleVolume&63)]; pSample = pVoice->pSample; samplePos = pVoice->samplePos; step = (double)(pVoice->sampleFreq<sampleSize<repLen<0) do { ymint va = pVolumeTab[pSample[samplePos>>YMTPREC]]; #ifdef _LINEAR_OVRS ymint vb = va; if (samplePos < (sampleEnd-(1<>YMTPREC)+1]]; ymint frac = samplePos & ((1<>YMTPREC); #endif (*pBuffer++) += va; samplePos += sampleInc; if (samplePos>=sampleEnd) { if (pVoice->bLoop) { samplePos -= repLen; } else { pVoice->bRunning = 0; return; } } } while (--nbs); pVoice->samplePos = samplePos; } void CYmMusic::ymTrackerUpdate(ymsample *pBuffer,ymint nbSample) { ymint i; ymint _nbs; // Clear les buffers. memset(pBuffer,0,sizeof(ymsample)*nbSample); if (bMusicOver) return; do { if (ymTrackerNbSampleBefore == 0) { // Lit la partition ymTracker ymTrackerPlayer(ymTrackerVoice); if (bMusicOver) return; ymTrackerNbSampleBefore = YMTNBSRATE; } _nbs = ymTrackerNbSampleBefore; // nb avant playerUpdate. if (_nbs>nbSample) _nbs = nbSample; ymTrackerNbSampleBefore -= _nbs; if (_nbs>0) { // Genere les samples. for (i=0;i0); } STYMulator-0.21a/src/stsoundlib/StSoundLibrary.h0000644000175000017500000000523410431364506021452 0ustar gandalfgandalf/*----------------------------------------------------------------------------- ST-Sound ( YM files player library ) Copyright (C) 1995-1999 Arnaud Carre ( http://leonard.oxg.free.fr ) Main header to use the StSound "C" like API in your production. -----------------------------------------------------------------------------*/ /*----------------------------------------------------------------------------- This file is part of ST-Sound ST-Sound is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. ST-Sound is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with ST-Sound; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA -----------------------------------------------------------------------------*/ #ifndef __STSOUNDLIBRARY__ #define __STSOUNDLIBRARY__ #include "YmTypes.h" typedef void YMMUSIC; typedef struct { ymchar * pSongName; ymchar * pSongAuthor; ymchar * pSongComment; ymchar * pSongType; ymchar * pSongPlayer; yms32 musicTimeInSec; // keep for compatibility yms32 musicTimeInMs; } ymMusicInfo_t; // Create object extern YMMUSIC * ymMusicCreate(); // Release object extern void ymMusicDestroy(YMMUSIC *pMusic); // Functions extern ymbool ymMusicLoad(YMMUSIC *pMusic,const char *fName); // Method 1 : Load file using stdio library (fopen/fread, etc..) extern ymbool ymMusicLoadMemory(YMMUSIC *pMusic,void *pBlock,ymu32 size); // Method 2 : Load file from a memory block extern ymbool ymMusicCompute(YMMUSIC *pMusic,ymsample *pBuffer,ymint nbSample); // Render nbSample samples of current YM tune into pBuffer PCM 16bits mono sample buffer. extern void ymMusicSetLoopMode(YMMUSIC *pMusic,ymbool bLoop); extern const char * ymMusicGetLastError(YMMUSIC *pMusic); extern int ymMusicGetRegister(YMMUSIC *pMusic,ymint reg); extern void ymMusicGetInfo(YMMUSIC *pMusic,ymMusicInfo_t *pInfo); extern void ymMusicPlay(YMMUSIC *pMusic); extern void ymMusicPause(YMMUSIC *pMusic); extern void ymMusicStop(YMMUSIC *pMusic); extern ymbool ymMusicIsSeekable(YMMUSIC *pMusic); extern ymu32 ymMusicGetPos(YMMUSIC *pMusic); extern void ymMusicSeek(YMMUSIC *pMusic,ymu32 timeInMs); #endif STYMulator-0.21a/src/stsoundlib/Ym2149Ex.cpp0000644000175000017500000003171710431443424020265 0ustar gandalfgandalf/*----------------------------------------------------------------------------- ST-Sound ( YM files player library ) Copyright (C) 1995-1999 Arnaud Carre ( http://leonard.oxg.free.fr ) Extended YM-2149 Emulator, with ATARI music demos effects. (SID-Like, Digidrum, Sync Buzzer, Sinus SID and Pattern SID) -----------------------------------------------------------------------------*/ /*----------------------------------------------------------------------------- This file is part of ST-Sound ST-Sound is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. ST-Sound is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with ST-Sound; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA -----------------------------------------------------------------------------*/ #include "YmTypes.h" #include #include #include #include #include "Ym2149Ex.h" //------------------------------------------------------------------- // env shapes. //------------------------------------------------------------------- static const ymint Env00xx[8]={ 1,0,0,0,0,0,0,0 }; static const ymint Env01xx[8]={ 0,1,0,0,0,0,0,0 }; static const ymint Env1000[8]={ 1,0,1,0,1,0,1,0 }; static const ymint Env1001[8]={ 1,0,0,0,0,0,0,0 }; static const ymint Env1010[8]={ 1,0,0,1,1,0,0,1 }; static const ymint Env1011[8]={ 1,0,1,1,1,1,1,1 }; static const ymint Env1100[8]={ 0,1,0,1,0,1,0,1 }; static const ymint Env1101[8]={ 0,1,1,1,1,1,1,1 }; static const ymint Env1110[8]={ 0,1,1,0,0,1,1,0 }; static const ymint Env1111[8]={ 0,1,0,0,0,0,0,0 }; static const ymint * EnvWave[16] = { Env00xx,Env00xx,Env00xx,Env00xx, Env01xx,Env01xx,Env01xx,Env01xx, Env1000,Env1001,Env1010,Env1011, Env1100,Env1101,Env1110,Env1111}; static ymint ymVolumeTable[16] = { 62,161,265,377,580,774,1155,1575,2260,3088,4570,6233,9330,13187,21220,32767}; //---------------------------------------------------------------------- // Very cool and fast DC Adjuster ! This is the *new* stuff of that // package coz I get that idea working on SainT in 2004 ! // ( almost everything here is from 1995 !) //---------------------------------------------------------------------- CDcAdjuster::CDcAdjuster() { Reset(); } void CDcAdjuster::Reset(void) { for (ymint i=0;i>2)&1); rndRack = (rndRack>>1) | (rBit<<16); return (rBit ? 0 : 0xffff); } ymu32 CYm2149Ex::envStepCompute(ymu8 rHigh,ymu8 rLow) { ymint per = rHigh; per = (per<<8)+rLow; if (per<3) return 0; #ifdef YM_INTEGER_ONLY yms64 step = internalClock; step <<= (16+16-9); step /= (per * replayFrequency); #else ymfloat step = internalClock; step /= ((ymfloat)per*512.0*(ymfloat)replayFrequency); step *= 65536.0*65536.0; #endif return (ymu32)step; } void CYm2149Ex::reset(void) { for (int i=0;i<14;i++) writeRegister(i,0); writeRegister(7,0xff); currentNoise = 0xffff; rndRack = 1; sidStop(0); sidStop(1); sidStop(2); envShape = 0; envPhase = 0; envPos = 0; m_dcAdjust.Reset(); memset(specialEffect,0,sizeof(specialEffect)); syncBuzzerStop(); m_lowPassFilter[0] = 0; m_lowPassFilter[1] = 0; } void CYm2149Ex::sidVolumeCompute(ymint voice,ymint *pVol) { struct YmSpecialEffect *pVoice = specialEffect+voice; if (pVoice->bSid) { if (pVoice->sidPos & (1<<31)) writeRegister(8+voice,pVoice->sidVol); else writeRegister(8+voice,0); } else if (pVoice->bDrum) { // writeRegister(8+voice,pVoice->drumData[pVoice->drumPos>>DRUM_PREC]>>4); *pVol = (pVoice->drumData[pVoice->drumPos>>DRUM_PREC] * 255) / 6; switch (voice) { case 0: pVolA = &volA; mixerTA = 0xffff; mixerNA = 0xffff; break; case 1: pVolB = &volB; mixerTB = 0xffff; mixerNB = 0xffff; break; case 2: pVolC = &volC; mixerTC = 0xffff; mixerNC = 0xffff; break; } pVoice->drumPos += pVoice->drumStep; if ((pVoice->drumPos>>DRUM_PREC) >= pVoice->drumSize) { pVoice->bDrum = YMFALSE; } } } int CYm2149Ex::LowPassFilter(int in) { const int out = (m_lowPassFilter[0]>>2) + (m_lowPassFilter[1]>>1) + (in>>2); m_lowPassFilter[0] = m_lowPassFilter[1]; m_lowPassFilter[1] = in; return out; } ymsample CYm2149Ex::nextSample(void) { ymint vol; ymint bt,bn; if (noisePos&0xffff0000) { currentNoise ^= rndCompute(); noisePos &= 0xffff; } bn = currentNoise; volE = ymVolumeTable[envData[envShape][envPhase][envPos>>(32-5)]]; sidVolumeCompute(0,&volA); sidVolumeCompute(1,&volB); sidVolumeCompute(2,&volC); //--------------------------------------------------- // Tone+noise+env+DAC for three voices ! //--------------------------------------------------- bt = ((((yms32)posA)>>31) | mixerTA) & (bn | mixerNA); vol = (*pVolA)&bt; bt = ((((yms32)posB)>>31) | mixerTB) & (bn | mixerNB); vol += (*pVolB)&bt; bt = ((((yms32)posC)>>31) | mixerTC) & (bn | mixerNC); vol += (*pVolC)&bt; //--------------------------------------------------- // Inc //--------------------------------------------------- posA += stepA; posB += stepB; posC += stepC; noisePos += noiseStep; envPos += envStep; if (0 == envPhase) { if (envPos=0) && (reg<=13)) return registers[reg]; else return -1; } void CYm2149Ex::writeRegister(ymint reg,ymint data) { switch (reg) { case 0: registers[0] = data&255; stepA = toneStepCompute(registers[1],registers[0]); if (!stepA) posA = (1<<31); // Assume output always 1 if 0 period (for Digi-sample !) break; case 2: registers[2] = data&255; stepB = toneStepCompute(registers[3],registers[2]); if (!stepB) posB = (1<<31); // Assume output always 1 if 0 period (for Digi-sample !) break; case 4: registers[4] = data&255; stepC = toneStepCompute(registers[5],registers[4]); if (!stepC) posC = (1<<31); // Assume output always 1 if 0 period (for Digi-sample !) break; case 1: registers[1] = data&15; stepA = toneStepCompute(registers[1],registers[0]); if (!stepA) posA = (1<<31); // Assume output always 1 if 0 period (for Digi-sample !) break; case 3: registers[3] = data&15; stepB = toneStepCompute(registers[3],registers[2]); if (!stepB) posB = (1<<31); // Assume output always 1 if 0 period (for Digi-sample !) break; case 5: registers[5] = data&15; stepC = toneStepCompute(registers[5],registers[4]); if (!stepC) posC = (1<<31); // Assume output always 1 if 0 period (for Digi-sample !) break; case 6: registers[6] = data&0x1f; noiseStep = noiseStepCompute(registers[6]); if (!noiseStep) { noisePos = 0; currentNoise = 0xffff; } break; case 7: registers[7] = data&255; mixerTA = (data&(1<<0)) ? 0xffff : 0; mixerTB = (data&(1<<1)) ? 0xffff : 0; mixerTC = (data&(1<<2)) ? 0xffff : 0; mixerNA = (data&(1<<3)) ? 0xffff : 0; mixerNB = (data&(1<<4)) ? 0xffff : 0; mixerNC = (data&(1<<5)) ? 0xffff : 0; break; case 8: registers[8] = data&31; volA = ymVolumeTable[data&15]; if (data&0x10) pVolA = &volE; else pVolA = &volA; break; case 9: registers[9] = data&31; volB = ymVolumeTable[data&15]; if (data&0x10) pVolB = &volE; else pVolB = &volB; break; case 10: registers[10] = data&31; volC = ymVolumeTable[data&15]; if (data&0x10) pVolC = &volE; else pVolC = &volC; break; case 11: registers[11] = data&255; envStep = envStepCompute(registers[12],registers[11]); break; case 12: registers[12] = data&255; envStep = envStepCompute(registers[12],registers[11]); break; case 13: registers[13] = data&0xf; envPos = 0; envPhase = 0; envShape = data&0xf; break; } } void CYm2149Ex::update(ymsample *pSampleBuffer,ymint nbSample) { ymsample *pBuffer = pSampleBuffer; if (nbSample>0) { do { *pBuffer++ = nextSample(); } while (--nbSample); } } void CYm2149Ex::drumStart(ymint voice,ymu8 *pDrumBuffer,ymu32 drumSize,ymint drumFreq) { specialEffect[voice].drumData = pDrumBuffer; specialEffect[voice].drumPos = 0; specialEffect[voice].drumSize = drumSize; specialEffect[voice].drumStep = (drumFreq< #include #else #include #endif #include /* My I/O functions */ int read0 (void far *p, int n) {return read (0, p, n);} int write1 (void far *p, int n) {return write (1, p, n);} /* My Memory functions */ void *mymalloc (unsigned n) {return malloc (n);} void myfree (void far *p) {free (p);} void main (void) { long n; #ifdef __TURBOC__ setmode (0, O_BINARY); setmode (1, O_BINARY); #endif /* Get the length of the input file */ n = lseek (0, 0, 2); lseek (0, 0, 0); /* Write this length to the output file */ write (1, &n, sizeof (n)); /* Now, Call the compression function */ lzh_freeze (read0, write1, mymalloc, myfree); } Sample Decompressor: #ifdef __TURBOC__ #include #include #else #include #endif #include /* My I/O functions */ int read0 (void far *p, int n) {return read (0, p, n);} int write1 (void far *p, int n) {return write (1, p, n);} /* My Memory functions */ void *mymalloc (unsigned n) {return malloc (n);} void myfree (void far *p) {free (p);} void main (void) { long n; #ifdef __TURBOC__ setmode (0, O_BINARY); setmode (1, O_BINARY); #endif /* Get the original file length */ read (0, &n, sizeof (n)); /* Now, Call the decompression function */ lzh_melt (read0, write1, malloc, free, n); } The description of the library API is given in more detail below: Prototypes: int lzh_freeze (type_fnc_read pfnc_read, type_fnc_write pfnc_write, type_fnc_malloc pfnc_malloc, type_fnc_free pfnc_free); int lzh_melt (type_fnc_read pfnc_read, type_fnc_write pfnc_write, type_fnc_malloc pfnc_malloc, type_fnc_free pfnc_free, unsigned long origsize); Remarks: "lzh_freeze" will perform an LZH compression on input data that the caller provides through the "fnc_read" callback function, and will output the compressed result through a call to "fnc_write". "lzh_melt" will perform decompression of input data that the caller provides through the "fnc_read" callback function, and will output the decompressed result through a call to "fnc_write". Argumets What it does -------- ------------ fnc_read a callback function that library will call when needing input data. "fnc_read" must return the number of input bytes or -1 if there is an error. fnc_write a callback function that library will call when needing to output data. "fnc_write" must return the number of outputed bytes (or -1 if there is an error). fnc_malloc a callback function that library will call when needing to allocate memory. "fnc_malloc" must return the address of the allocated memory or NULL if there is an error. fnc_free a callback function that library will call when needing to free a memory that was allocated using "fnc_malloc". origsize the original number of bytes of the uncompressed data. STYMulator-0.21a/src/stsoundlib/lzh/lzh.h0000644000175000017500000001041510451041610020103 0ustar gandalfgandalf/*----------------------------------------------------------------------------- ST-Sound ( YM files player library ) Copyright (C) 1995-1999 Arnaud Carre ( http://leonard.oxg.free.fr ) LZH depacking routine Original LZH code by Haruhiko Okumura (1991) and Kerwin F. Medina (1996) I changed to C++ object to remove global vars, so it should be thread safe now. -----------------------------------------------------------------------------*/ /*----------------------------------------------------------------------------- This file is part of ST-Sound ST-Sound is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. ST-Sound is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with ST-Sound; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA -----------------------------------------------------------------------------*/ #ifndef LZH_H #define LZH_H #define BUFSIZE (1024 * 4) typedef unsigned char uchar; /* 8 bits or more */ typedef unsigned int uint; /* 16 bits or more */ typedef unsigned short ushort; /* 16 bits or more */ typedef unsigned long ulong; /* 32 bits or more */ #ifndef CHAR_BIT #define CHAR_BIT 8 #endif #ifndef UCHAR_MAX #define UCHAR_MAX 255 #endif typedef ushort BITBUFTYPE; #define BITBUFSIZ (CHAR_BIT * sizeof (BITBUFTYPE)) #define DICBIT 13 /* 12(-lh4-) or 13(-lh5-) */ #define DICSIZ (1U << DICBIT) #define MAXMATCH 256 /* formerly F (not more than UCHAR_MAX + 1) */ #define THRESHOLD 3 /* choose optimal value */ #define NC (UCHAR_MAX + MAXMATCH + 2 - THRESHOLD) /* alphabet = {0, 1, 2, ..., NC - 1} */ #define CBIT 9 /* $\lfloor \log_2 NC \rfloor + 1$ */ #define CODE_BIT 16 /* codeword length */ #define MAX_HASH_VAL (3 * DICSIZ + (DICSIZ / 512 + 1) * UCHAR_MAX) #define NP (DICBIT + 1) #define NT (CODE_BIT + 3) #define PBIT 4 /* smallest integer such that (1U << PBIT) > NP */ #define TBIT 5 /* smallest integer such that (1U << TBIT) > NT */ #if NT > NP #define NPT NT #else #define NPT NP #endif class CLzhDepacker { public: bool LzUnpack(void *pSrc,int srcSize,void *pDst,int dstSize); private: //---------------------------------------------- // New stuff to handle memory IO //---------------------------------------------- uchar * m_pSrc; int m_srcSize; uchar * m_pDst; int m_dstSize; int DataIn(void *pBuffer,int nBytes); int DataOut(void *pOut,int nBytes); //---------------------------------------------- // Original Lzhxlib static func //---------------------------------------------- void fillbuf (int n); ushort getbits (int n); void init_getbits (void); int make_table (int nchar, uchar *bitlen,int tablebits, ushort *table); void read_pt_len (int nn, int nbit, int i_special); void read_c_len (void); ushort decode_c(void); ushort decode_p(void); void huf_decode_start (void); void decode_start (void); void decode (uint count, uchar buffer[]); //---------------------------------------------- // Original Lzhxlib static vars //---------------------------------------------- int fillbufsize; uchar buf[BUFSIZE]; uchar outbuf[DICSIZ]; ushort left [2 * NC - 1]; ushort right[2 * NC - 1]; BITBUFTYPE bitbuf; uint subbitbuf; int bitcount; int decode_j; /* remaining bytes to copy */ uchar c_len[NC]; uchar pt_len[NPT]; uint blocksize; ushort c_table[4096]; ushort pt_table[256]; int with_error; uint fillbuf_i; // NOTE: these ones are not initialized at constructor time but inside the fillbuf and decode func. uint decode_i; }; #endif /* ifndef LZH_H */ STYMulator-0.21a/src/stsoundlib/lzh/lzhlib.cpp0000644000175000017500000002331410454747415021152 0ustar gandalfgandalf/*----------------------------------------------------------------------------- ST-Sound ( YM files player library ) Copyright (C) 1995-1999 Arnaud Carre ( http://leonard.oxg.free.fr ) LZH depacking routine Original LZH code by Haruhiko Okumura (1991) and Kerwin F. Medina (1996) I changed to C++ object to remove global vars, so it should be thread safe now. -----------------------------------------------------------------------------*/ /*----------------------------------------------------------------------------- This file is part of ST-Sound ST-Sound is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. ST-Sound is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with ST-Sound; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA -----------------------------------------------------------------------------*/ #include #include "lzh.h" /* * Additions */ int CLzhDepacker::DataIn(void *pBuffer,int nBytes) { const int np = (nBytes <= m_srcSize) ? nBytes : m_srcSize; if (np > 0) { memcpy(pBuffer,m_pSrc,np); m_pSrc += np; m_srcSize -= np; } return np; } int CLzhDepacker::DataOut(void *pBuffer,int nBytes) { const int np = (nBytes <= m_dstSize) ? nBytes : m_dstSize; if (np > 0) { memcpy(m_pDst,pBuffer,np); m_pDst += np; m_dstSize -= np; } return np; } /* * io.c */ /** Shift bitbuf n bits left, read n bits */ void CLzhDepacker::fillbuf (int n) { bitbuf = (bitbuf << n) & 0xffff; while (n > bitcount) { bitbuf |= subbitbuf << (n -= bitcount); if (fillbufsize == 0) { fillbuf_i = 0; fillbufsize = DataIn(buf, BUFSIZE - 32); } if (fillbufsize > 0) fillbufsize--, subbitbuf = buf[fillbuf_i++]; else subbitbuf = 0; bitcount = CHAR_BIT; } bitbuf |= subbitbuf >> (bitcount -= n); } ushort CLzhDepacker::getbits (int n) { ushort x; x = bitbuf >> (BITBUFSIZ - n); fillbuf (n); return x; } void CLzhDepacker::init_getbits (void) { bitbuf = 0; subbitbuf = 0; bitcount = 0; fillbuf (BITBUFSIZ); } /* * maketbl.c */ int CLzhDepacker::make_table (int nchar, uchar *bitlen, int tablebits, ushort *table) { ushort count[17], weight[17], start[18], *p; uint jutbits, avail, mask; int i,ch,len,nextcode; for (i = 1; i <= 16; i++) count[i] = 0; for (i = 0; i < nchar; i++) count[bitlen[i]]++; start[1] = 0; for (i = 1; i <= 16; i++) start[i + 1] = start[i] + (count[i] << (16 - i)); if (start[17] != (ushort) (1U << 16)) return (1); /* error: bad table */ jutbits = 16 - tablebits; for (i = 1; i <= tablebits; i++) { start[i] >>= jutbits; weight[i] = 1U << (tablebits - i); } while (i <= 16) weight[i++] = 1U << (16 - i); i = start[tablebits + 1] >> jutbits; if (i != (ushort) (1U << 16)) { int k = 1U << tablebits; while (i != k) table[i++] = 0; } avail = nchar; mask = 1U << (15 - tablebits); for (ch = 0; ch < nchar; ch++) { if ((len = bitlen[ch]) == 0) continue; nextcode = start[len] + weight[len]; if (len <= tablebits) { for (i = start[len]; i < nextcode; i++) table[i] = ch; } else { uint k = start[len]; p = &table[k >> jutbits]; i = len - tablebits; while (i != 0) { if (*p == 0) { right[avail] = left[avail] = 0; *p = avail++; } if (k & mask) p = &right[*p]; else p = &left[*p]; k <<= 1; i--; } *p = ch; } start[len] = nextcode; } return (0); } /* * huf.c */ void CLzhDepacker::read_pt_len (int nn, int nbit, int i_special) { int i, n; short c; ushort mask; n = getbits (nbit); if (n == 0) { c = getbits (nbit); for (i = 0; i < nn; i++) pt_len[i] = 0; for (i = 0; i < 256; i++) pt_table[i] = c; } else { i = 0; while (i < n) { c = bitbuf >> (BITBUFSIZ - 3); if (c == 7) { mask = 1U << (BITBUFSIZ - 1 - 3); while (mask & bitbuf) { mask >>= 1; c++; } } fillbuf ((c < 7) ? 3 : c - 3); pt_len[i++] = uchar(c); if (i == i_special) { c = getbits (2); while (--c >= 0) pt_len[i++] = 0; } } while (i < nn) pt_len[i++] = 0; make_table (nn, pt_len, 8, pt_table); } } void CLzhDepacker::read_c_len (void) { short i, c, n; ushort mask; n = getbits (CBIT); if (n == 0) { c = getbits (CBIT); for (i = 0; i < NC; i++) c_len[i] = 0; for (i = 0; i < 4096; i++) c_table[i] = c; } else { i = 0; while (i < n) { c = pt_table[bitbuf >> (BITBUFSIZ - 8)]; if (c >= NT) { mask = 1U << (BITBUFSIZ - 1 - 8); do { if (bitbuf & mask) c = right[c]; else c = left[c]; mask >>= 1; } while (c >= NT); } fillbuf (pt_len[c]); if (c <= 2) { if (c == 0) c = 1; else if (c == 1) c = getbits (4) + 3; else c = getbits (CBIT) + 20; while (--c >= 0) c_len[i++] = 0; } else c_len[i++] = c - 2; } while (i < NC) c_len[i++] = 0; make_table (NC, c_len, 12, c_table); } } ushort CLzhDepacker::decode_c (void) { ushort j, mask; if (blocksize == 0) { blocksize = getbits (16); read_pt_len (NT, TBIT, 3); read_c_len (); read_pt_len (NP, PBIT, -1); } blocksize--; j = c_table[bitbuf >> (BITBUFSIZ - 12)]; if (j >= NC) { mask = 1U << (BITBUFSIZ - 1 - 12); do { if (bitbuf & mask) j = right[j]; else j = left[j]; mask >>= 1; } while (j >= NC); } fillbuf (c_len[j]); return j; } ushort CLzhDepacker::decode_p (void) { ushort j, mask; j = pt_table[bitbuf >> (BITBUFSIZ - 8)]; if (j >= NP) { mask = 1U << (BITBUFSIZ - 1 - 8); do { if (bitbuf & mask) j = right[j]; else j = left[j]; mask >>= 1; } while (j >= NP); } fillbuf (pt_len[j]); if (j != 0) j = (1U << (j - 1)) + getbits (j - 1); return j; } void CLzhDepacker::huf_decode_start (void) { init_getbits (); blocksize = 0; } /* * decode.c */ void CLzhDepacker::decode_start (void) { fillbufsize = 0; huf_decode_start (); decode_j = 0; } /* * The calling function must keep the number of bytes to be processed. This * function decodes either 'count' bytes or 'DICSIZ' bytes, whichever is * smaller, into the array 'buffer[]' of size 'DICSIZ' or more. Call * decode_start() once for each new file before calling this function. */ void CLzhDepacker::decode (uint count, uchar buffer[]) { uint r, c; r = 0; while (--decode_j >= 0) { buffer[r] = buffer[decode_i]; decode_i = (decode_i + 1) & (DICSIZ - 1); if (++r == count) return; } for (;;) { c = decode_c (); if (c <= UCHAR_MAX) { buffer[r] = c; if (++r == count) return; } else { decode_j = c - (UCHAR_MAX + 1 - THRESHOLD); decode_i = (r - decode_p () - 1) & (DICSIZ - 1); while (--decode_j >= 0) { buffer[r] = buffer[decode_i]; decode_i = (decode_i + 1) & (DICSIZ - 1); if (++r == count) return; } } } } bool CLzhDepacker::LzUnpack(void *pSrc,int srcSize,void *pDst,int dstSize) { with_error = 0; m_pSrc = (uchar*)pSrc; m_srcSize = srcSize; m_pDst = (uchar*)pDst; m_dstSize = dstSize; decode_start (); int origsize = dstSize; while (origsize != 0) { int n = (uint) ((origsize > DICSIZ) ? DICSIZ : origsize); decode (n, outbuf); if (with_error) break; DataOut(outbuf,n); origsize -= n; if (with_error) break; } return (0 == with_error); } STYMulator-0.21a/src/stsoundlib/lzh/Makefile0000644000175000017500000000025610454747732020624 0ustar gandalfgandalfCC = gcc AR = ar cr RM = rm -f CFLAGS = -Wall liblzh.a: lzhlib.o $(AR) liblzh.a lzhlib.o lzhlib.o: lzhlib.cpp lzh.h $(CC) -c lzhlib.cpp clean: $(RM) *~ *.o *.a dist: STYMulator-0.21a/src/stsoundlib/YmUserInterface.cpp0000644000175000017500000000641510573207673022140 0ustar gandalfgandalf/*----------------------------------------------------------------------------- ST-Sound ( YM files player library ) Copyright (C) 1995-1999 Arnaud Carre ( http://leonard.oxg.free.fr ) ST-Sound library "C-like" interface wrapper -----------------------------------------------------------------------------*/ /*----------------------------------------------------------------------------- This file is part of ST-Sound ST-Sound is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. ST-Sound is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with ST-Sound; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA -----------------------------------------------------------------------------*/ #include "YmMusic.h" #include "StSoundLibrary.h" // Static assert to check various type len YMMUSIC * ymMusicCreate() { return (YMMUSIC*)(new CYmMusic); } ymbool ymMusicLoad(YMMUSIC *pMus,const char *fName) { CYmMusic *pMusic = (CYmMusic*)pMus; return pMusic->load(fName); } ymbool ymMusicLoadMemory(YMMUSIC *pMus,void *pBlock,ymu32 size) { CYmMusic *pMusic = (CYmMusic*)pMus; return pMusic->loadMemory(pBlock,size); } void ymMusicDestroy(YMMUSIC *pMus) { CYmMusic *pMusic = (CYmMusic*)pMus; delete pMusic; } ymbool ymMusicCompute(YMMUSIC *_pMus,ymsample *pBuffer,int nbSample) { CYmMusic *pMusic = (CYmMusic*)_pMus; return pMusic->update(pBuffer,nbSample); } void ymMusicSetLoopMode(YMMUSIC *_pMus,ymbool bLoop) { CYmMusic *pMusic = (CYmMusic*)_pMus; pMusic->setLoopMode(bLoop); } const char *ymMusicGetLastError(YMMUSIC *_pMus) { CYmMusic *pMusic = (CYmMusic*)_pMus; return pMusic->getLastError(); } int ymMusicGetRegister(YMMUSIC *_pMus,ymint reg) { CYmMusic *pMusic = (CYmMusic*)_pMus; return pMusic->readYmRegister(reg); } void ymMusicGetInfo(YMMUSIC *_pMus,ymMusicInfo_t *pInfo) { CYmMusic *pMusic = (CYmMusic*)_pMus; pMusic->getMusicInfo(pInfo); } void ymMusicPlay(YMMUSIC *_pMus) { CYmMusic *pMusic = (CYmMusic*)_pMus; pMusic->play(); } void ymMusicPause(YMMUSIC *_pMus) { CYmMusic *pMusic = (CYmMusic*)_pMus; pMusic->pause(); } void ymMusicStop(YMMUSIC *_pMus) { CYmMusic *pMusic = (CYmMusic*)_pMus; pMusic->stop(); } ymbool ymMusicIsSeekable(YMMUSIC *_pMus) { CYmMusic *pMusic = (CYmMusic*)_pMus; return pMusic->isSeekable() ? YMTRUE : YMFALSE; } //changed for 64bit compatibility by Grzegorz Stanczyk (2007.03.06) //unsigned long ymMusicGetPos(YMMUSIC *_pMus) ymu32 ymMusicGetPos(YMMUSIC *_pMus) { CYmMusic *pMusic = (CYmMusic*)_pMus; if (!pMusic->isSeekable()) return 0; return pMusic->getPos(); } void ymMusicSeek(YMMUSIC *_pMus,ymu32 timeInMs) { CYmMusic *pMusic = (CYmMusic*)_pMus; if (pMusic->isSeekable()) { pMusic->setMusicTime(timeInMs); } } STYMulator-0.21a/src/stsoundlib/digidrum.h0000644000175000017500000000257210240753442020333 0ustar gandalfgandalf/*----------------------------------------------------------------------------- ST-Sound ( YM files player library ) Copyright (C) 1995-1999 Arnaud Carre ( http://leonard.oxg.free.fr ) Sample datas of some common YM music. ( YM2 format ) YM3 or greater uses sample data inside the music file. -----------------------------------------------------------------------------*/ /*----------------------------------------------------------------------------- This file is part of ST-Sound ST-Sound is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. ST-Sound is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with ST-Sound; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA -----------------------------------------------------------------------------*/ #ifndef __DIGIDRUM__ #define __DIGIDRUM__ extern ymu8 * sampleAdress[]; extern ymu32 sampleLen[]; #endif STYMulator-0.21a/src/stsoundlib/Ym2149Ex.h0000644000175000017500000000770010431726012017722 0ustar gandalfgandalf/*----------------------------------------------------------------------------- ST-Sound ( YM files player library ) Copyright (C) 1995-1999 Arnaud Carre ( http://leonard.oxg.free.fr ) Extended YM-2149 Emulator, with ATARI music demos effects. (SID-Like, Digidrum, Sync Buzzer, Sinus SID and Pattern SID) -----------------------------------------------------------------------------*/ /*----------------------------------------------------------------------------- This file is part of ST-Sound ST-Sound is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. ST-Sound is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with ST-Sound; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA -----------------------------------------------------------------------------*/ #ifndef __YM2149EX__ #define __YM2149EX__ #define AMSTRAD_CLOCK 1000000L #define ATARI_CLOCK 2000000L #define SPECTRUM_CLOCK 1773400L #define MFP_CLOCK 2457600L #define NOISESIZE 16384 #define DRUM_PREC 15 #define PI 3.1415926 #define SIDSINPOWER 0.7 enum { VOICE_A=0, VOICE_B=1, VOICE_C=2, }; struct YmSpecialEffect { ymbool bDrum; ymu32 drumSize; ymu8 * drumData; ymu32 drumPos; ymu32 drumStep; ymbool bSid; ymu32 sidPos; ymu32 sidStep; ymint sidVol; }; static const ymint DC_ADJUST_BUFFERLEN = 512; class CDcAdjuster { public: CDcAdjuster(); void AddSample(ymint sample); ymint GetDcLevel(void) { return m_sum / DC_ADJUST_BUFFERLEN; } void Reset(void); private: ymint m_buffer[DC_ADJUST_BUFFERLEN]; ymint m_pos; ymint m_sum; }; class CYm2149Ex { public: CYm2149Ex(ymu32 masterClock=ATARI_CLOCK,ymint prediv=1,ymu32 playRate=44100); ~CYm2149Ex(); void reset(void); void update(signed short *pSampleBuffer,ymint nbSample); void setClock(ymu32 _clock); void writeRegister(ymint reg,ymint value); ymint readRegister(ymint reg); void drumStart(ymint voice,ymu8 *drumBuffer,ymu32 drumSize,ymint drumFreq); void drumStop(ymint voice); void sidStart(ymint voice,ymint freq,ymint vol); void sidSinStart(ymint voice,ymint timerFreq,ymint sinPattern); void sidStop(ymint voice); void syncBuzzerStart(ymint freq,ymint envShape); void syncBuzzerStop(void); private: CDcAdjuster m_dcAdjust; ymu32 frameCycle; ymu32 cyclePerSample; inline ymsample nextSample(void); ymu32 toneStepCompute(ymu8 rHigh,ymu8 rLow); ymu32 noiseStepCompute(ymu8 rNoise); ymu32 envStepCompute(ymu8 rHigh,ymu8 rLow); void updateEnvGen(ymint nbSample); void updateNoiseGen(ymint nbSample); void updateToneGen(ymint voice,ymint nbSample); ymu32 rndCompute(void); void sidVolumeCompute(ymint voice,ymint *pVol); inline int LowPassFilter(int in); ymint replayFrequency; ymu32 internalClock; ymu8 registers[14]; ymu32 cycleSample; ymu32 stepA,stepB,stepC; ymu32 posA,posB,posC; ymint volA,volB,volC,volE; ymu32 mixerTA,mixerTB,mixerTC; ymu32 mixerNA,mixerNB,mixerNC; ymint *pVolA,*pVolB,*pVolC; ymu32 noiseStep; ymu32 noisePos; ymu32 rndRack; ymu32 currentNoise; ymu32 bWrite13; ymu32 envStep; ymu32 envPos; ymint envPhase; ymint envShape; ymu8 envData[16][2][16*2]; ymint globalVolume; struct YmSpecialEffect specialEffect[3]; ymbool bSyncBuzzer; ymu32 syncBuzzerStep; ymu32 syncBuzzerPhase; ymint syncBuzzerShape; int m_lowPassFilter[2]; }; #endif STYMulator-0.21a/src/stsoundlib/Ymload.cpp0000644000175000017500000004006610454752325020315 0ustar gandalfgandalf/*----------------------------------------------------------------------------- ST-Sound ( YM files player library ) Copyright (C) 1995-1999 Arnaud Carre ( http://leonard.oxg.free.fr ) Manage YM file depacking and parsing -----------------------------------------------------------------------------*/ /*----------------------------------------------------------------------------- This file is part of ST-Sound ST-Sound is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. ST-Sound is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with ST-Sound; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA -----------------------------------------------------------------------------*/ #include #include #include #include "YmMusic.h" #include "lzh/lzh.h" static ymu16 ymVolumeTable[16] = { 62,161,265,377,580,774,1155,1575,2260,3088,4570,6233,9330,13187,21220,32767}; static void signeSample(ymu8 *ptr,yms32 size) { if (size>0) { do { *ptr++ ^= 0x80; } while (--size); } } char *mstrdup(char *in) { char *out = (char*)malloc(strlen(in)+1); if (out) strcpy(out,in); return out; } ymu32 readMotorolaDword(ymu8 **ptr) { ymu32 n; ymu8 *p = *ptr; n = (p[0]<<24)|(p[1]<<16)|(p[2]<<8)|p[3]; p+=4; *ptr = p; return n; } ymu16 readMotorolaWord(ymu8 **ptr) { ymu16 n; ymu8 *p = *ptr; n = (p[0]<<8)|p[1]; p+=2; *ptr = p; return n; } ymchar *readNtString(ymchar **ptr) { ymchar *p; p = mstrdup(*ptr); (*ptr) += strlen(*ptr)+1; return p; } yms32 ReadLittleEndian32(ymu8 *pLittle) { yms32 v = ( (pLittle[0]<<0) | (pLittle[1]<<8) | (pLittle[2]<<16) | (pLittle[3]<<24)); return v; } yms32 ReadBigEndian32(ymu8 *pBig) { yms32 v = ( (pBig[0]<<24) | (pBig[1]<<16) | (pBig[2]<<8) | (pBig[3]<<0)); return v; } unsigned char *CYmMusic::depackFile(void) { lzhHeader_t *pHeader; ymu8 *pNew; ymu8 *pSrc; pHeader = (lzhHeader_t*)pBigMalloc; if ((pHeader->size==0) || // NOTE: Endianness works because value is 0 (strncmp(pHeader->id,"-lh5-",5))) { // Le fichier n'est pas compresse, on retourne l'original. return pBigMalloc; } fileSize = (ymu32)-1; if (pHeader->level != 0) // NOTE: Endianness works because value is 0 { // Compression LH5, header !=0 : Error. free(pBigMalloc); pBigMalloc = NULL; setLastError("LHARC Header must be 0 !"); return NULL; } fileSize = ReadLittleEndian32((ymu8*)&pHeader->original); pNew = (ymu8*)malloc(fileSize); if (!pNew) { setLastError("MALLOC Failed !"); free(pBigMalloc); pBigMalloc = NULL; return NULL; } pSrc = pBigMalloc+sizeof(lzhHeader_t)+pHeader->name_lenght; // NOTE: Endianness works because name_lenght is a byte pSrc += 2; // skip CRC16 const int packedSize = ReadLittleEndian32((ymu8*)&pHeader->packed); // alloc space for depacker and depack data CLzhDepacker *pDepacker = new CLzhDepacker; const bool bRet = pDepacker->LzUnpack(pSrc,packedSize,pNew,fileSize); delete pDepacker; // Free up source buffer, whatever depacking fail or success free(pBigMalloc); if (!bRet) { // depacking error setLastError("LH5 Depacking Error !"); free(pNew); pNew = NULL; } return pNew; } static ymint fileSizeGet(FILE *h) { ymint size; ymint old; old = ftell(h); fseek(h,0,SEEK_END); size = ftell(h); fseek(h,old,SEEK_SET); return size; } ymbool CYmMusic::deInterleave(void) { yms32 nextPlane[32]; ymu8 *pW,*tmpBuff; yms32 j,k; if (attrib&A_STREAMINTERLEAVED) { tmpBuff = (ymu8*)malloc(nbFrame*streamInc); if (!tmpBuff) { setLastError("Malloc error in deInterleave()\n"); return YMFALSE; } // Precalcul les offsets. for (j=0;j0) { pDrumTab=(digiDrum_t*)malloc(nbDrum*sizeof(digiDrum_t)); for (i=0;i>7; } } ptr += pDrumTab[i].size; } else { pDrumTab[i].pData = NULL; } } attrib &= (~A_DRUM4BITS); } pSongName = readNtString((char**)&ptr); pSongAuthor = readNtString((char**)&ptr); pSongComment = readNtString((char**)&ptr); songType = YM_V5; if (id=='YM6!') { songType = YM_V6; pSongType = mstrdup("YM 6"); } else { pSongType = mstrdup("YM 5"); } pDataStream = ptr; streamInc = 16; setAttrib(A_STREAMINTERLEAVED|A_TIMECONTROL); pSongPlayer = mstrdup("YM-Chip driver."); break; case 'MIX1': // ATARI Remix digit format. if (strncmp((const char*)(pBigMalloc+4),"LeOnArD!",8)) { setLastError("Not a valid YM format !"); return YMFALSE; } ptr = pBigMalloc+12; songType = YM_MIX1; tmp = readMotorolaDword(&ptr); setAttrib(0); if (tmp&1) setAttrib(A_DRUMSIGNED); sampleSize = readMotorolaDword(&ptr); nbMixBlock = readMotorolaDword(&ptr); pMixBlock = (mixBlock_t*)malloc(nbMixBlock*sizeof(mixBlock_t)); for (i=0;i0) { pDrumTab=(digiDrum_t*)malloc(nbDrum*sizeof(digiDrum_t)); for (i=0;i<(ymint)nbDrum;i++) { pDrumTab[i].size = readMotorolaWord(&ptr); pDrumTab[i].repLen = pDrumTab[i].size; if ('YMT2' == id) { pDrumTab[i].repLen = readMotorolaWord(&ptr); // repLen readMotorolaWord(&ptr); // flag } if (pDrumTab[i].repLen>pDrumTab[i].size) { pDrumTab[i].repLen = pDrumTab[i].size; } if (pDrumTab[i].size) { pDrumTab[i].pData = (ymu8*)malloc(pDrumTab[i].size); memcpy(pDrumTab[i].pData,ptr,pDrumTab[i].size); ptr += pDrumTab[i].size; } else { pDrumTab[i].pData = NULL; } } } ymTrackerFreqShift = 0; if ('YMT2' == id) { ymTrackerFreqShift = (attrib>>28)&15; attrib &= 0x0fffffff; pSongType = mstrdup("YM-T2"); } else { pSongType = mstrdup("YM-T1"); } pDataStream = ptr; ymChip.setClock(ATARI_CLOCK); ymTrackerInit(100); // 80% de volume maxi. streamInc = 16; setTimeControl(YMTRUE); pSongPlayer = mstrdup("Universal Tracker"); break; default: setLastError("Unknow YM format !"); return YMFALSE; break; } if (!deInterleave()) { return YMFALSE; } return YMTRUE; } ymbool CYmMusic::checkCompilerTypes() { setLastError("Basic types size are not correct (check ymTypes.h)"); if (1 != sizeof(ymu8)) return YMFALSE; if (1 != sizeof(yms8)) return YMFALSE; if (1 != sizeof(ymchar)) return YMFALSE; if (2 != sizeof(ymu16)) return YMFALSE; if (2 != sizeof(yms16)) return YMFALSE; if (4 != sizeof(ymu32)) return YMFALSE; if (4 != sizeof(yms32)) return YMFALSE; if (2 != sizeof(ymsample)) return YMFALSE; #ifdef YM_INTEGER_ONLY if (8 != sizeof(yms64)) return YMFALSE; #endif if (sizeof(ymint) < 4) return YMFALSE; // ymint should be at least 32bits setLastError(""); return YMTRUE; } ymbool CYmMusic::load(const char *fileName) { FILE *in; stop(); unLoad(); if (!checkCompilerTypes()) return YMFALSE; in = fopen(fileName,"rb"); if (!in) { setLastError("File not Found"); return YMFALSE; } //--------------------------------------------------- // Allocation d'un buffer pour lire le fichier. //--------------------------------------------------- fileSize = fileSizeGet(in); pBigMalloc = (unsigned char*)malloc(fileSize); if (!pBigMalloc) { setLastError("MALLOC Error"); fclose(in); return YMFALSE; } //--------------------------------------------------- // Chargement du fichier complet. //--------------------------------------------------- if (fread(pBigMalloc,1,fileSize,in)!=(size_t)fileSize) { free(pBigMalloc); setLastError("File is corrupted."); fclose(in); return YMFALSE; } fclose(in); //--------------------------------------------------- // Transforme les donn‚es en donn‚es valides. //--------------------------------------------------- pBigMalloc = depackFile(); if (!pBigMalloc) { return YMFALSE; } //--------------------------------------------------- // Lecture des donn‚es YM: //--------------------------------------------------- if (!ymDecode()) { free(pBigMalloc); pBigMalloc = NULL; return YMFALSE; } ymChip.reset(); bMusicOk = YMTRUE; bPause = YMFALSE; return YMTRUE; } ymbool CYmMusic::loadMemory(void *pBlock,ymu32 size) { stop(); unLoad(); if (!checkCompilerTypes()) return YMFALSE; //--------------------------------------------------- // Allocation d'un buffer pour lire le fichier. //--------------------------------------------------- fileSize = size; pBigMalloc = (unsigned char*)malloc(fileSize); if (!pBigMalloc) { setLastError("MALLOC Error"); return YMFALSE; } //--------------------------------------------------- // Chargement du fichier complet. //--------------------------------------------------- memcpy(pBigMalloc,pBlock,size); //--------------------------------------------------- // Transforme les donn‚es en donn‚es valides. //--------------------------------------------------- pBigMalloc = depackFile(); if (!pBigMalloc) { return YMFALSE; } //--------------------------------------------------- // Lecture des donn‚es YM: //--------------------------------------------------- if (!ymDecode()) { free(pBigMalloc); pBigMalloc = NULL; return YMFALSE; } ymChip.reset(); bMusicOk = YMTRUE; bPause = YMFALSE; return YMTRUE; } void myFree(void **pPtr) { if (*pPtr) free(*pPtr); *pPtr = NULL; } void CYmMusic::unLoad(void) { bMusicOk = YMFALSE; bPause = YMTRUE; bMusicOver = YMFALSE; myFree((void**)&pSongName); myFree((void**)&pSongAuthor); myFree((void**)&pSongComment); myFree((void**)&pSongType); myFree((void**)&pSongPlayer); myFree((void**)&pBigMalloc); if (nbDrum>0) { for (ymint i=0;i void draw_frame(void); int ui_init(void); void ui_end(void); void draw_info(ymMusicInfo_t &info, const char *argv); void draw_time(int sec); extern int pos_x; extern int pos_y;; #endif STYMulator-0.21a/src/sound.h0000644000175000017500000000331010351726371015464 0ustar gandalfgandalf/* file: sound.h This file is a part of STYMulator - GNU/Linux YM player Player & ST-Sound GPL library GNU/Linux port by Grzegorz Tomasz Stanczyk Project Page: http://atariarea.krap.pl/stymulator Original ST-Sound GPL library by Arnaud Carre (http://leonard.oxg.free.fr) ALSA (Advanced Linux Sound Architecture) library (http://www.alsa-project.org/) ----------------------------------------------------------------------------- * STYMulator is free software; you can redistribute it and/or modify * * it under the terms of the GNU General Public License as published by * * the Free Software Foundation; either version 2 of the License, or * * (at your option) any later version. * * * * STYMulator is distributed in the hope that it will be useful, * * but WITHOUT ANY WARRANTY; without even the implied warranty of * * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * * GNU General Public License for more details. * * * * You should have received a copy of the GNU General Public License * * along with STYMulator; if not, write to the * * Free Software Foundation, Inc., * * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * ---------------------------------------------------------------------------*/ #ifndef SOUND_H #define SOUND_H #include int alsa_init(snd_pcm_t *pcm_handle, snd_pcm_hw_params_t *hwparams); #endif STYMulator-0.21a/src/ym2wav.cpp0000644000175000017500000001265010573216507016124 0ustar gandalfgandalf/*----------------------------------------------------------------------------- ST-Sound ( YM files player library ) Copyright (C) 1995-1999 Arnaud Carre ( http://leonard.oxg.free.fr ) This is a sample program: it's an YM to WAV converter. -----------------------------------------------------------------------------*/ /*----------------------------------------------------------------------------- This file is part of ST-Sound ST-Sound is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. ST-Sound is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with ST-Sound; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA -----------------------------------------------------------------------------*/ #if defined(__x86_64__) || defined(__alpha__) || defined(__ia64__)\ || defined(__ppc64__) || defined(__s390x__) #define PLATFORM 1 #else #define PLATFORM 0 #endif #include #include #include "stsoundlib/StSoundLibrary.h" //--------------------------------------------------------------------- //--------------------------------------------------------------------- #define NBSAMPLEPERBUFFER 1024 static ymsample convertBuffer[NBSAMPLEPERBUFFER]; // Sound buffer to create WAV file. //--------------------------------------------------------------------- // To produce a WAV file. //--------------------------------------------------------------------- #define ID_RIFF 0x46464952 #define ID_WAVE 0x45564157 #define ID_FMT 0x20746D66 #define ID_DATA 0x61746164 typedef struct { ymu32 RIFFMagic; ymu32 FileLength; ymu32 FileType; ymu32 FormMagic; ymu32 FormLength; ymu16 SampleFormat; ymu16 NumChannels; ymu32 PlayRate; ymu32 BytesPerSec; ymu16 Pad; ymu16 BitsPerSample; ymu32 DataMagic; ymu32 DataLength; } WAVHeader; int main(int argc, char* argv[]) { char *platform; if (PLATFORM) platform = "64bit"; else platform = "32bit"; //-------------------------------------------------------------------------- // Checks args. //-------------------------------------------------------------------------- printf( "ym2wav (%s) - YM to WAV converter.\n" "Using ST-Sound Library, under GPL license\n" "Copyright (C) 1995-1999 Arnaud Carre ( http://leonard.oxg.free.fr )\n" "GNU/Linux (%s) port by Grzegorz Stanczyk\n", platform, platform); if (argc!=3) { printf("Usage: ym2wav \n\n"); return -1; } //-------------------------------------------------------------------------- // Load YM music and creates WAV file //-------------------------------------------------------------------------- YMMUSIC *pMusic = ymMusicCreate(); if (ymMusicLoad(pMusic,argv[1])) { // Get info about the current music. ymMusicInfo_t info; ymMusicGetInfo(pMusic,&info); printf("Generating wav file from \"%s\"\n",argv[1]); printf("%s\n%s\n(%s)\n",info.pSongName,info.pSongAuthor,info.pSongComment); printf("Total music time: %ld seconds.\n",info.musicTimeInSec); FILE *out = fopen(argv[2],"wb"); if (!out) { printf("Unable to create %s file.\n",argv[2]); return -1; } // Reserve space to write the header. WAVHeader head; fwrite(&head,1,sizeof(WAVHeader),out); // write non initialized dummy data to reserve space //-------------------------------------------------------------------------- // Main loop: render each music frame and store to the WAV file. //-------------------------------------------------------------------------- ymMusicSetLoopMode(pMusic,YMFALSE); // Be sure there is no loop (to avoid a BIG wav file :-) ) ymu32 totalNbSample = 0; ymMusicStop(pMusic); ymMusicPlay(pMusic); while (ymMusicCompute(pMusic,convertBuffer,NBSAMPLEPERBUFFER)) { fwrite((void*)convertBuffer,sizeof(ymsample),NBSAMPLEPERBUFFER,out); totalNbSample += NBSAMPLEPERBUFFER; } //-------------------------------------------------------------------------- // Write the WAV file header and close the file. //-------------------------------------------------------------------------- fseek(out,0,SEEK_SET); head.RIFFMagic = ID_RIFF; head.FileType = ID_WAVE; head.FormMagic = ID_FMT; head.DataMagic = ID_DATA; head.FormLength = 0x10; head.SampleFormat = 1; head.NumChannels = 1; head.PlayRate = 44100; head.BitsPerSample = 16; head.BytesPerSec = 44100*(16/8); head.Pad = (16/8); head.DataLength = totalNbSample*(16/8); head.FileLength = head.DataLength + sizeof(WAVHeader) - 8; fwrite(&head,1,sizeof(WAVHeader),out); fseek(out,0,SEEK_END); fclose(out); printf("%ld samples written (%.02f Mb).\n",totalNbSample,(float)(totalNbSample*sizeof(ymsample))/(1024*1024)); } else { // Error in loading music. printf("Error in loading file %s:\n%s\n",argv[1],ymMusicGetLastError(pMusic)); return -1; } ymMusicDestroy(pMusic); return 0; } STYMulator-0.21a/src/sound.cpp0000644000175000017500000001042610573222562016024 0ustar gandalfgandalf/* file: sound.cpp This file is a part of STYMulator - GNU/Linux YM player Player & ST-Sound GPL library GNU/Linux port by Grzegorz Tomasz Stanczyk Project Page: http://atariarea.krap.pl/stymulator Original ST-Sound GPL library by Arnaud Carre (http://leonard.oxg.free.fr) ALSA (Advanced Linux Sound Architecture) library (http://www.alsa-project.org/) ----------------------------------------------------------------------------- * STYMulator is free software; you can redistribute it and/or modify * * it under the terms of the GNU General Public License as published by * * the Free Software Foundation; either version 2 of the License, or * * (at your option) any later version. * * * * STYMulator is distributed in the hope that it will be useful, * * but WITHOUT ANY WARRANTY; without even the implied warranty of * * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * * GNU General Public License for more details. * * * * You should have received a copy of the GNU General Public License * * along with STYMulator; if not, write to the * * Free Software Foundation, Inc., * * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * ---------------------------------------------------------------------------*/ #include "sound.h" snd_pcm_format_t format = SND_PCM_FORMAT_S16; int err, dir; int resample = 1; unsigned int rate = 44100; unsigned int channels = 1; unsigned int buffer_time = 500000; unsigned int period_time = 100000; snd_pcm_uframes_t buffer_size; //22050 snd_pcm_uframes_t period_size; //4410 int alsa_init(snd_pcm_t *pcm_handle, snd_pcm_hw_params_t *hwparams) { if ((err = snd_pcm_hw_params_any(pcm_handle, hwparams)) < 0) { printf("Broken configuration for playback: no configurations available: %s\n", snd_strerror(err)); return err; } /* removed snd_pcm_hw_params_set_rate_resample function that has been added to alsa-lib since 1.0.9rc2 (more portability) if ((err = snd_pcm_hw_params_set_rate_resample(pcm_handle, hwparams, resample)) < 0) { printf("Resampling setup failed for playback: %s\n", snd_strerror(err)); return err; } */ if ((err = snd_pcm_hw_params_set_access(pcm_handle, hwparams, SND_PCM_ACCESS_RW_INTERLEAVED)) < 0) { printf("Access type not available for playback: %s\n", snd_strerror(err)); return err; } if ((err = snd_pcm_hw_params_set_format(pcm_handle, hwparams, format)) < 0) { printf("Sample format not available for playback: %s\n", snd_strerror(err)); return err; } if ((err = snd_pcm_hw_params_set_channels(pcm_handle, hwparams, channels)) < 0) { printf("Channels count (%i) not available for playbacks: %s\n", channels, snd_strerror(err)); return err; } unsigned int rrate = rate; if ((err = snd_pcm_hw_params_set_rate_near(pcm_handle, hwparams, &rrate, 0)) < 0) { printf("Rate %iHz not available for playback: %s\n", rate, snd_strerror(err)); return err; } if (rrate != rate) { printf("Rate doesn't match (requested %iHz, get %iHz)\n", rate, err); return -EINVAL; } if ((err = snd_pcm_hw_params_set_buffer_time_near(pcm_handle, hwparams, &buffer_time, &dir)) < 0) { printf("Unable to set buffer time %i for playback: %s\n", buffer_time, snd_strerror(err)); return err; } if ((err = snd_pcm_hw_params_get_buffer_size(hwparams, &buffer_size)) < 0) { printf("Unable to get buffer size for playback: %s\n", snd_strerror(err)); return err; } if ((err = snd_pcm_hw_params_set_period_time_near(pcm_handle, hwparams, &period_time, &dir)) < 0) { printf("Unable to set period time %i for playback: %s\n", period_time, snd_strerror(err)); return err; } if ((err = snd_pcm_hw_params_get_period_size(hwparams, &period_size, &dir)) < 0) { printf("Unable to get period size for playback: %s\n", snd_strerror(err)); return err; } if ((err = snd_pcm_hw_params(pcm_handle, hwparams)) < 0) { printf("Unable to set hw params for playback: %s\n", snd_strerror(err)); return err; } return 0; } STYMulator-0.21a/src/ui.c0000644000175000017500000001040110600204343014726 0ustar gandalfgandalf/* file: ui.c This file is a part of STYMulator - GNU/Linux YM player Player & ST-Sound GPL library GNU/Linux port by Grzegorz Tomasz Stanczyk Project Page: http://atariarea.krap.pl/stymulator Original ST-Sound GPL library by Arnaud Carre (http://leonard.oxg.free.fr) ALSA (Advanced Linux Sound Architecture) library (http://www.alsa-project.org/) ----------------------------------------------------------------------------- * STYMulator is free software; you can redistribute it and/or modify * * it under the terms of the GNU General Public License as published by * * the Free Software Foundation; either version 2 of the License, or * * (at your option) any later version. * * * * STYMulator is distributed in the hope that it will be useful, * * but WITHOUT ANY WARRANTY; without even the implied warranty of * * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * * GNU General Public License for more details. * * * * You should have received a copy of the GNU General Public License * * along with STYMulator; if not, write to the * * Free Software Foundation, Inc., * * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * ---------------------------------------------------------------------------*/ #if defined(__x86_64__) || defined(__alpha__) || defined(__ia64__)\ || defined(__ppc64__) || defined(__s390x__) #define PLATFORM 1 #else #define PLATFORM 0 #endif #include "stsoundlib/StSoundLibrary.h" #include "ui.h" #include extern bool digi; int pos_x = 0, pos_y = 0; static int height = 13; static int width = 80; void draw_frame(void) { int y = pos_y; move(pos_y, pos_x+1); if (PLATFORM) addstr("---- STYMulator v0.21a (64bit) - Atari ST (16-bit) YM music files player -----"); else addstr("---- STYMulator v0.21a (32bit) - Atari ST (16-bit) YM music files player -----"); move(pos_y+8, pos_x+1); addstr("------------------------------------------------------------------------------"); move(pos_y+12, pos_x+1); addstr("----------------------- Copyright (C) 2005-2007 by Grzegorz Tomasz Stanczyk --"); for (y = pos_y; y < pos_y + 13; y++) { mvaddch(y, pos_x, '|'); mvaddch(y, pos_x+79, '|'); } mvaddstr(pos_y+1, pos_x+5, "Filename.:"); mvaddstr(pos_y+2, pos_x+5, "Name.....:"); mvaddstr(pos_y+3, pos_x+5, "Author...:"); mvaddstr(pos_y+4, pos_x+5, "Comment..:"); mvaddstr(pos_y+5, pos_x+5, "Type.....:"); mvaddstr(pos_y+6, pos_x+5, "Player...:"); if (digi) { mvaddstr(pos_y+7, pos_x+5, "Duration.:"); mvaddstr(pos_y+5, pos_x+58, "Time...:"); } mvaddstr(pos_y+6, pos_x+58, "Status.:"); mvaddstr(pos_y+7, pos_x+58, "Repeat.:"); mvaddstr(pos_y+9, pos_x+11, "| z - play | x - pause | c - stop | r - repeat | q - quit |"); if (digi) mvaddstr(pos_y+10, pos_x+27, "| n - << | m - >> | "); move(0,0); refresh(); } static void clearscreen(void) { wclear(stdscr); move(0,0); refresh(); } int ui_init(void) { initscr(); cbreak(); noecho(); curs_set(0); keypad(stdscr, TRUE); nodelay(stdscr, 1); if (COLS < width || LINES < height) { ui_end(); printf("COLS: %d, LINES: %d\n", COLS, LINES); printf("Sorry, you need a terminal with at least 80 cols and 13 lines.\n"); exit(0); } pos_y=(LINES - height) / 2; pos_x=(COLS - width) / 2; return 0; } void ui_end(void) { clearscreen(); move(LINES - 1, 0); refresh(); nodelay(stdscr, 0); echo(); nocbreak(); endwin(); putchar('\n'); } void draw_info(ymMusicInfo_t &info, const char *filename) { mvprintw(pos_y+1, pos_x+16, filename); mvprintw(pos_y+2, pos_x+16, info.pSongName); mvprintw(pos_y+3, pos_x+16, info.pSongAuthor); mvprintw(pos_y+4, pos_x+16, info.pSongComment); mvprintw(pos_y+5, pos_x+16, info.pSongType); mvprintw(pos_y+6, pos_x+16, info.pSongPlayer); if (digi) mvprintw(pos_y+7, pos_x+16, "%2d:%02d", info.musicTimeInSec/60,info.musicTimeInSec%60); move(0,0); refresh(); } void draw_time(int sec) { mvprintw(pos_y+5, pos_x+67, "%2d:%02d ", sec / 60, sec % 60); move(0,0); refresh(); } STYMulator-0.21a/src/ymplayer.cpp0000644000175000017500000001311410577705233016540 0ustar gandalfgandalf/* file: ymplayer.cpp This file is a part of STYMulator - GNU/Linux YM player Player & ST-Sound GPL library GNU/Linux port by Grzegorz Tomasz Stanczyk Project Page: http://atariarea.krap.pl/stymulator Original ST-Sound GPL library by Arnaud Carre (http://leonard.oxg.free.fr) ALSA (Advanced Linux Sound Architecture) library (http://www.alsa-project.org/) ----------------------------------------------------------------------------- * STYMulator is free software; you can redistribute it and/or modify * * it under the terms of the GNU General Public License as published by * * the Free Software Foundation; either version 2 of the License, or * * (at your option) any later version. * * * * STYMulator is distributed in the hope that it will be useful, * * but WITHOUT ANY WARRANTY; without even the implied warranty of * * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * * GNU General Public License for more details. * * * * You should have received a copy of the GNU General Public License * * along with STYMulator; if not, write to the * * Free Software Foundation, Inc., * * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * ---------------------------------------------------------------------------*/ #if defined(__x86_64__) || defined(__alpha__) || defined(__ia64__)\ || defined(__ppc64__) || defined(__s390x__) #define PLATFORM 1 #else #define PLATFORM 0 #endif #include "stsoundlib/StSoundLibrary.h" #include "ui.h" #include "sound.h" #include #include #include #include extern snd_pcm_uframes_t period_size; bool digi; int main(int argc, char **argv) { bool quit = false; bool repeat = false; bool rmode = true; bool stop = false; bool pmode = true; bool paused = false; bool playing; bool ff = false; bool rew = false; char *platform; if (PLATFORM) platform = "64bit"; else platform = "32bit"; if (argc != 2) { printf("STYMulator v0.21a (%s) - Copyright (C) 2005-2007 by Grzegorz Tomasz Stanczyk\n", platform); printf("http://atariarea.krap.pl/stymulator\n"); printf("\nUsage: ymplayer \n\n"); return -1; } snd_pcm_t *pcm_handle; snd_pcm_hw_params_t *hwparams; snd_pcm_hw_params_alloca(&hwparams); int err; unsigned int buf; snd_output_t *output = NULL; char pcm_name[] = "default"; YMMUSIC *pMusic = ymMusicCreate(); if (ymMusicLoad(pMusic,argv[1])) { if ((err = snd_output_stdio_attach(&output, stdout, 0)) < 0) { printf("Output failed: %s\n", snd_strerror(err)); return 0; } if ((err = snd_pcm_open(&pcm_handle, pcm_name, SND_PCM_STREAM_PLAYBACK, 0)) < 0) { printf("Playback open error: %s\n", snd_strerror(err)); return 0; } if ((err = alsa_init(pcm_handle, hwparams)) < 0) { printf("Setting of hwparams failed: %s\n", snd_strerror(err)); exit(EXIT_FAILURE); } buf = period_size; ymsample *convertBuffer = new ymsample[buf]; ymMusicInfo_t info; ymMusicGetInfo(pMusic,&info); digi = strncmp(info.pSongType,"MIX1",4); ui_init(); draw_frame(); draw_info(info, argv[1]); while(!quit) { playing = ymMusicCompute(pMusic,convertBuffer, buf); if (digi) draw_time(ymMusicGetPos(pMusic) / 1000); if ((err = snd_pcm_writei(pcm_handle, convertBuffer, buf)) == -EPIPE) { err = snd_pcm_prepare(pcm_handle); } else if (err == -ESTRPIPE) { while ((err = snd_pcm_resume(pcm_handle)) == -EAGAIN) sleep(1); if (err < 0) { err = snd_pcm_prepare(pcm_handle); } } switch(getch()) { case 27: case 'q': quit = true; break; case 'z': pmode = true; break; //play case 'x': paused = true; break; //pause case 'c': pmode = false; break; //stop case 'r': rmode = true; break; case 'm': ff = true; break; case 'n': rew = true; break; } if (rmode) if (repeat) { ymMusicSetLoopMode(pMusic,YMTRUE); mvaddstr(pos_y+7,pos_x+67,"Yes"); rmode = false; repeat = false; } else { ymMusicSetLoopMode(pMusic,YMFALSE); mvaddstr(pos_y+7,pos_x+67,"No "); rmode = false; repeat = true; } if (!stop && playing) { if (pmode && !paused) mvaddstr(pos_y+6,pos_x+67,"Play"); //play else if (pmode && paused) { ymMusicPause(pMusic); //pause mvaddstr(pos_y+6,pos_x+67,"Pause"); stop = true; pmode = false; } else if (!pmode) { //stop ymMusicStop(pMusic); mvaddstr(pos_y+6,pos_x+67,"Stop "); stop = true; } } else if (pmode && playing) { ymMusicPlay(pMusic); mvaddstr(pos_y+6,pos_x+67,"Play "); stop = false; paused = false; } else if (!playing) { ymMusicLoad(pMusic,argv[1]); // hmmm :/ pmode = false; } if (ymMusicIsSeekable(pMusic) && digi) if (ff) { ymMusicSeek(pMusic, ymMusicGetPos(pMusic) + 1000); ff = false; } else if (rew) { ymMusicSeek(pMusic, ymMusicGetPos(pMusic) - 1000); rew = false; } } ymMusicStop(pMusic); snd_pcm_close(pcm_handle); delete convertBuffer; ui_end(); } else { printf("Error in loading file %s: %s\n", argv[1], ymMusicGetLastError(pMusic)); } ymMusicDestroy(pMusic); return 0; } STYMulator-0.21a/src/Makefile0000644000175000017500000000163110576240174015630 0ustar gandalfgandalfRM = rm -f CC = g++ CFLAGS = -Wall LZH = stsoundlib/lzh STLIB = stsoundlib INCLUDE = -L$(LZH) -L$(STLIB) INSTALL = /usr/bin/install -c all: libs ymplayer ym2wav libs: @for subdir in $(STLIB) $(LZH); do \ (cd $$subdir && make) || exit 1; \ done ymplayer: ymplayer.o sound.o ui.o $(CC) -o ymplayer $(INCLUDE) ymplayer.o sound.o ui.o -lasound -lym -llzh -lncurses ym2wav: ym2wav.o $(CC) -o ym2wav $(INCLUDE) ym2wav.o -lym -llzh ymplayer.o: ymplayer.cpp $(STLIB)/StSoundLibrary.h ui.h sound.h $(CC) $(INLCUDE) -c ymplayer.cpp ym2wav.o: ym2wav.cpp $(STLIB)/StSoundLibrary.h $(CC) $(INCLUDE) -c ym2wav.cpp sound.o: sound.cpp sound.h $(CC) -c sound.cpp ui.o: ui.c ui.h $(STLIB)/StSoundLibrary.h $(CC) -c ui.c install: all $(INSTALL) ymplayer /usr/bin $(INSTALL) ym2wav /usr/bin clean: @for subdir in $(LZH) $(STLIB); do \ (cd $$subdir && make $@) || exit 1; \ done $(RM) *.o ymplayer ym2wav *~