diff -urN sidplay-base-1.0.4/audio/oss/audiodrv.cpp sidplay-base-1.0.4-agenda.2/audio/oss/audiodrv.cpp --- sidplay-base-1.0.4/audio/oss/audiodrv.cpp Sun Apr 11 06:00:00 1999 +++ sidplay-base-1.0.4-agenda.2/audio/oss/audiodrv.cpp Sat Jun 9 19:18:42 2001 @@ -15,6 +15,7 @@ // Reset everything. errorString = "None"; frequency = 0; + volume = 255; channels = 0; encoding = 0; precision = 0; @@ -25,13 +26,21 @@ bool audioDriver::IsThere() { // Check device availability and write permissions. - return (access(AUDIODEVICE,W_OK)==0); + // return (access(AUDIODEVICE,W_OK)==0); + return(1); } bool audioDriver::Open(udword inFreq, int inPrecision, int inChannels, int inFragments, int inFragBase) { - if ((audioHd=open(AUDIODEVICE,O_WRONLY,0)) == (-1)) + uid_t ru, eu; + + ru=getuid(); + eu=geteuid(); + setreuid(0,0); + audioHd=open(AUDIODEVICE,O_WRONLY,0); + setreuid(ru,eu); + if (audioHd == (-1)) { perror(AUDIODEVICE); errorString = "ERROR: Could not open audio device."; @@ -191,9 +200,9 @@ { perror(AUDIODEVICE); errorString = "AUDIO: Could not get audio_buf_info."; - return false; - } - fragments = myAudInfo.fragstotal; +// return false; + } else + fragments = myAudInfo.fragstotal; //cout << "fragsize = " << (int)myAudInfo.fragsize << endl; //cout << "bytes = " << (int)myAudInfo.bytes << endl; @@ -213,6 +222,8 @@ void audioDriver::Play(ubyte* pBuffer, int bufferSize) { + sword *tp; + long t; if (audioHd != (-1)) { if (swapEndian) @@ -222,6 +233,14 @@ ubyte tmp = pBuffer[n+0]; pBuffer[n+0] = pBuffer[n+1]; pBuffer[n+1] = tmp; + } + } + if (volume != 255) + { + for (tp=(sword *)pBuffer; tp < (sword *)(pBuffer+bufferSize); tp++) + { + t=(long)(*tp)*(long)volume; + *tp=(sword)(t>>8); } } write(audioHd,pBuffer,bufferSize); diff -urN sidplay-base-1.0.4/audio/oss/audiodrv.h sidplay-base-1.0.4-agenda.2/audio/oss/audiodrv.h --- sidplay-base-1.0.4/audio/oss/audiodrv.h Sun Apr 11 06:00:00 1999 +++ sidplay-base-1.0.4-agenda.2/audio/oss/audiodrv.h Mon May 21 00:16:54 2001 @@ -55,6 +55,16 @@ return frequency; } + udword GetVolume() + { + return volume; + } + + udword SetVolume(udword v) + { + return volume=v; + } + int GetChannels() { return channels; @@ -102,6 +112,7 @@ int fragSizeBase; udword frequency; + udword volume; // These are constants/enums from ``libsidplay/include/emucfg.h''. int encoding; diff -urN sidplay-base-1.0.4/configure sidplay-base-1.0.4-agenda.2/configure --- sidplay-base-1.0.4/configure Wed May 31 20:52:45 2000 +++ sidplay-base-1.0.4-agenda.2/configure Fri May 11 19:43:14 2001 @@ -1010,12 +1010,13 @@ my_ldflags_save=$LDFLAGS my_libs_save=$LIBS - CXXFLAGS="$CXXFLAGS $my_sidplay_incadd" + CXXFLAGS="$CXXFLAGS -I/usr/mipsel-linux/include/g++ $my_sidplay_incadd" LDFLAGS="$LDFLAGS $my_sidplay_libadd" LIBS="-lsidplay" cat > conftest.$ac_ext < #include "confdefs.h" #include int main() { @@ -1175,7 +1176,9 @@ { echo "configure: error: SIDPLAY library and/or headers found not found. Please check your installation! -" 1>&2; exit 1; }; +" 1>&2; +#exit 1; +}; fi echo $ac_n "checking how to run the C++ preprocessor""... $ac_c" 1>&6 diff -urN sidplay-base-1.0.4/sidplay.cpp sidplay-base-1.0.4-agenda.2/sidplay.cpp --- sidplay-base-1.0.4/sidplay.cpp Thu Jun 14 01:16:01 2001 +++ sidplay-base-1.0.4-agenda.2/sidplay.cpp Thu Jun 14 01:17:42 2001 @@ -30,6 +30,9 @@ #include #include "audiodrv.h" +#include +#include + #if defined(__amigaos__) #define EXIT_ERROR_STATUS (20) #else @@ -53,6 +56,7 @@ void printSyntax(char* arg0); bool exitFlag; +bool quitFlag; void (*oldSigHupHandler)(int); void (*oldSigIntHandler)(int); @@ -75,6 +79,7 @@ case SIGQUIT: { exitFlag = true; + quitFlag = true; break; } case SIGTERM: @@ -82,15 +87,28 @@ exitFlag = true; break; } + case SIGALRM: + { + exitFlag = true; + break; + } default: break; } } static bool verboseOutput = false; +static int volume = 255; int main(int argc, char *argv[]) { + int readfromstdin=0; + int tty; + int jump; + struct termios termios,termios_old; + int songtime=0; + char *console="/dev/stdin"; + // ====================================================================== // INITIALIZE THE EMULATOR ENGINE // ====================================================================== @@ -127,6 +145,7 @@ << "Version " << myEmuEngine.getVersionString() << endl; uword selectedSong = 0; + uword lastSong = 0; // Default audio settings. myEmuConfig.frequency = 22050; @@ -136,7 +155,7 @@ uword fragSizeBase = 12; int forceBufSize = 0; // get it from argument line - int infile = 0; + int infile = 0, numfiles=0, infiles[1024]; // parse command line arguments int a = 1; @@ -146,9 +165,10 @@ { // Reading from stdin? if ( strlen(argv[a]) == 1 ) - if ( infile == 0 ) + if ( numfiles < 1024 ) { - infile = a; + infiles[numfiles++] = a; + console="/dev/tty"; break; } else @@ -196,6 +216,9 @@ case 'c': myEmuConfig.forceSongSpeed = true; break; + case 'C': + console=argv[a]+2; + break; case 'f': myEmuConfig.frequency = (udword)atol(argv[a]+2); break; @@ -228,9 +251,18 @@ } break; #endif + case 'S': + myEmuConfig.channels = SIDEMU_NONE; + break; + case 't': + songtime = atoi(argv[a]+2); + break; case 'v': verboseOutput = true; break; + case 'V': + volume = atoi(argv[a]+2); + break; default: printSyntax(argv[0]); exit(0); @@ -238,8 +270,8 @@ } else { - if ( infile == 0 ) - infile = a; // filename argument + if ( numfiles < 1024 ) + infiles[numfiles++] = a; // filename argument else { printSyntax(argv[0]); @@ -249,7 +281,7 @@ a++; // next argument }; - if (infile == 0) + if (numfiles == 0) { // Neither file nor stdin. printSyntax(argv[0]); @@ -275,46 +307,24 @@ // INSTANTIATE A SIDTUNE OBJECT // ====================================================================== - sidTune myTune( argv[infile] ); - struct sidTuneInfo mySidInfo; - myTune.getInfo( mySidInfo ); - if ( !myTune ) - { - cerr << argv[0] << ": " << mySidInfo.statusString << endl; - exit(EXIT_ERROR_STATUS); - } - else - { - if (verboseOutput) - { - cout << "File format : " << mySidInfo.formatString << endl; - cout << "Filenames : " << mySidInfo.dataFileName << ", " - << mySidInfo.infoFileName << endl; - cout << "Condition : " << mySidInfo.statusString << endl; - } - cout << "--------------------------------------------------" << endl; - if ( mySidInfo.numberOfInfoStrings == 3 ) - { - cout << "Name : " << mySidInfo.nameString << endl; - cout << "Author : " << mySidInfo.authorString << endl; - cout << "Copyright : " << mySidInfo.copyrightString << endl; - } - else - { - for ( int infoi = 0; infoi < mySidInfo.numberOfInfoStrings; infoi++ ) - cout << "Description : " << mySidInfo.infoString[infoi] << endl; - } - cout << "--------------------------------------------------" << endl; - if (verboseOutput) - { - cout << "Load address : $" << hex << setw(4) << setfill('0') - << mySidInfo.loadAddr << endl; - cout << "Init address : $" << hex << setw(4) << setfill('0') - << mySidInfo.initAddr << endl; - cout << "Play address : $" << hex << setw(4) << setfill('0') - << mySidInfo.playAddr << dec << endl; - } - } + tty=open(console,O_RDWR|O_NONBLOCK); + if (tcgetattr (tty, &termios ) == 0) { + memcpy(&termios_old,&termios,sizeof(struct termios *)); + termios.c_lflag &= ~(ECHO | ISIG | ICANON); + /* get input on each char, timeout = 0 */ + termios.c_cc[VMIN] = 1; + termios.c_cc[VTIME] = 0; + + // cfmakeraw(&termios); + if(tcsetattr ( tty, TCSANOW, &termios ) != 0) + perror("tcsetattr"); + } else + perror("tcgetattr"); + + jump=0; + while (!quitFlag) { + char *fp, filename[256]; + fp=filename; // ====================================================================== // CONFIGURE THE AUDIO DRIVER @@ -341,103 +351,293 @@ cout << "Block size : " << (udword)myAudio.GetBlockSize() << endl << "Fragments : " << myAudio.GetFragments() << endl; } + // myAudio.SetVolume(volume); - // ====================================================================== - // CONFIGURE THE EMULATOR ENGINE - // ====================================================================== + if (argv[infiles[infile]][0] == '-') + readfromstdin = 1; + if (songtime>0) { + if (signal(SIGALRM,&mysighandler) == SIG_ERR) + perror("signal SIGALRM"); + alarm(songtime); + } + /* take away '-' from sid library */ + if(jump && !(jump == 1 && selectedSong == lastSong && lastSong > 0)) { + if (jump < 0 && selectedSong == 1) { + selectedSong=0; + lastSong=0; + if (infile > 0) + infile--; + } else + selectedSong += jump; + jump=0; + } else if (readfromstdin) { + selectedSong=0; + lastSong=0; + if (!fgets(fp,255,stdin)) { + break; + } + filename[255]='\0'; + filename[strlen(filename)-1]='\0'; // gobble \n + } else { + infile++; + } - // Configure the SID emulator according to the audio driver settings. - myEmuConfig.frequency = myAudio.GetFrequency(); - myEmuConfig.bitsPerSample = myAudio.GetSamplePrecision(); - myEmuConfig.sampleFormat = myAudio.GetSampleEncoding(); - myEmuEngine.setConfig( myEmuConfig ); - // Print the relevant settings. - if (verboseOutput) - { - cout << "Frequency : " << dec << myEmuConfig.frequency << " Hz" - << " (" << ((myEmuConfig.bitsPerSample==SIDEMU_8BIT) ? "8" : "16") - << "-bit " << ((myEmuConfig.channels==SIDEMU_MONO) ? "mono" : "stereo") - << ")" << endl; - cout << "SID Filter : " << ((myEmuConfig.emulateFilter == true) ? "Yes" : "No") << endl; - if (myEmuConfig.memoryMode == MPU_PLAYSID_ENVIRONMENT) - { - cout << "Memory mode : PlaySID (this is supposed to fix PlaySID-specific rips)" << endl; + if (readfromstdin) { + fp=filename; + } else { + fp=argv[infiles[infile]]; } - else if (myEmuConfig.memoryMode == MPU_TRANSPARENT_ROM) + cout << "playing " << fp << endl; + sidTune myTune( fp ); + + struct sidTuneInfo mySidInfo; + myTune.getInfo( mySidInfo ); + if ( !myTune ) { - cout << "Memory mode : Transparent ROM (SIDPLAY default)" << endl; + cerr << argv[0] << ": " << mySidInfo.statusString << endl; + if(tcsetattr ( tty, TCSANOW, &termios_old ) != 0) + perror("tcsetattr"); + exit(EXIT_ERROR_STATUS); } - else if (myEmuConfig.memoryMode == MPU_BANK_SWITCHING) + else { - cout << "Memory mode : Bank Switching" << endl; + if (verboseOutput) + { + cout << "File format : " << mySidInfo.formatString << endl; + cout << "Filenames : " << mySidInfo.dataFileName << ", " + << mySidInfo.infoFileName << endl; + cout << "Condition : " << mySidInfo.statusString << endl; + } + cout << "--------------------------------------------------" << endl; + if ( mySidInfo.numberOfInfoStrings == 3 ) + { + cout << "Name : " << mySidInfo.nameString << endl; + cout << "Author : " << mySidInfo.authorString << endl; + cout << "Copyright : " << mySidInfo.copyrightString << endl; + } + else + { + for ( int infoi = 0; infoi < mySidInfo.numberOfInfoStrings; infoi++ ) + cout << "Description : " << mySidInfo.infoString[infoi] << endl; + } + cout << "--------------------------------------------------" << endl; + if (verboseOutput) + { + cout << "Load address : $" << hex << setw(4) << setfill('0') + << mySidInfo.loadAddr << endl; + cout << "Init address : $" << hex << setw(4) << setfill('0') + << mySidInfo.initAddr << endl; + cout << "Play address : $" << hex << setw(4) << setfill('0') + << mySidInfo.playAddr << dec << endl; + } } - } - // ====================================================================== - // INITIALIZE THE EMULATOR ENGINE TO PREPARE PLAYING A SIDTUNE - // ====================================================================== - if ( !sidEmuInitializeSong(myEmuEngine,myTune,selectedSong) ) - { - cerr << argv[0] << ": SID Emulator Engine components not ready." << endl; - exit(EXIT_ERROR_STATUS); - } - // Read out the current settings of the sidtune. - myTune.getInfo( mySidInfo ); - if ( !myTune ) - { - cerr << argv[0] << ": " << mySidInfo.statusString << endl; - exit(EXIT_ERROR_STATUS); - } - cout << "Setting song : " << mySidInfo.currentSong - << " out of " << mySidInfo.songs - << " (default = " << mySidInfo.startSong << ')' << endl; - if (verboseOutput) - { - cout << "Song speed : " << mySidInfo.speedString << endl; - } + // ====================================================================== + // CONFIGURE THE EMULATOR ENGINE + // ====================================================================== + + // Configure the SID emulator according to the audio driver settings. + myEmuConfig.frequency = myAudio.GetFrequency(); + myEmuConfig.bitsPerSample = myAudio.GetSamplePrecision(); + myEmuConfig.sampleFormat = myAudio.GetSampleEncoding(); + myEmuEngine.setConfig( myEmuConfig ); + // Print the relevant settings. + if (verboseOutput) + { + cout << "Frequency : " << dec << myEmuConfig.frequency << " Hz" + << " (" << ((myEmuConfig.bitsPerSample==SIDEMU_8BIT) ? "8" : "16") + << "-bit " << ((myEmuConfig.channels==SIDEMU_MONO) ? "mono" : "stereo") + << ")" << endl; + cout << "SID Filter : " << ((myEmuConfig.emulateFilter == true) ? "Yes" : "No") << endl; + if (myEmuConfig.memoryMode == MPU_PLAYSID_ENVIRONMENT) + { + cout << "Memory mode : PlaySID (this is supposed to fix PlaySID-specific rips)" << endl; + } + else if (myEmuConfig.memoryMode == MPU_TRANSPARENT_ROM) + { + cout << "Memory mode : Transparent ROM (SIDPLAY default)" << endl; + } + else if (myEmuConfig.memoryMode == MPU_BANK_SWITCHING) + { + cout << "Memory mode : Bank Switching" << endl; + } + } - // ====================================================================== - // KEEP UP A CONTINUOUS OUTPUT SAMPLE STREAM - // ====================================================================== + // ====================================================================== + // INITIALIZE THE EMULATOR ENGINE TO PREPARE PLAYING A SIDTUNE + // ====================================================================== - int bufSize = myAudio.GetBlockSize(); - if (forceBufSize != 0) - { - bufSize = forceBufSize; + if ( !sidEmuInitializeSong(myEmuEngine,myTune,selectedSong) ) + { + cerr << argv[0] << ": SID Emulator Engine components not ready." << endl; + if(tcsetattr ( tty, TCSANOW, &termios_old ) != 0) + perror("tcsetattr"); + exit(EXIT_ERROR_STATUS); + } + // Read out the current settings of the sidtune. + myTune.getInfo( mySidInfo ); + if ( !myTune ) + { + cerr << argv[0] << ": " << mySidInfo.statusString << endl; + if(tcsetattr ( tty, TCSANOW, &termios_old ) != 0) + perror("tcsetattr"); + exit(EXIT_ERROR_STATUS); + } + selectedSong = mySidInfo.currentSong; + lastSong = mySidInfo.songs; + cout << "Setting song : " << mySidInfo.currentSong + << " out of " << mySidInfo.songs + << " (default = " << mySidInfo.startSong << ')' << endl; if (verboseOutput) { - cout << "Buffer size : " << bufSize << endl; + cout << "Song speed : " << mySidInfo.speedString << endl; } - } - ubyte* buffer; - if ((buffer = new ubyte[bufSize]) == 0) - { - printError(argv[0],ERR_NOT_ENOUGH_MEMORY); - exit(EXIT_ERROR_STATUS); - } - exitFlag = false; - if ((signal(SIGHUP,&mysighandler) == SIG_ERR) - || (signal(SIGINT,&mysighandler) == SIG_ERR) - || (signal(SIGQUIT,&mysighandler) == SIG_ERR) - || (signal(SIGTERM,&mysighandler) == SIG_ERR)) - { - printError(argv[0],ERR_SIGHANDLER); - exit(EXIT_ERROR_STATUS); - } + // ====================================================================== + // KEEP UP A CONTINUOUS OUTPUT SAMPLE STREAM + // ====================================================================== - cout << "Playing, press ^C to stop ..." << endl; - for (;;) - { - sidEmuFillBuffer(myEmuEngine,myTune,buffer,bufSize); - myAudio.Play(buffer,bufSize); - if (exitFlag) - break; - } + int bufSize = myAudio.GetBlockSize(); + if (forceBufSize != 0) + { + bufSize = forceBufSize; + if (verboseOutput) + { + cout << "Buffer size : " << bufSize << endl; + } + } + ubyte* buffer; + if ((buffer = new ubyte[bufSize]) == 0) + { + printError(argv[0],ERR_NOT_ENOUGH_MEMORY); + if(tcsetattr ( tty, TCSANOW, &termios_old ) != 0) + perror("tcsetattr"); + exit(EXIT_ERROR_STATUS); + } + + exitFlag = false; + quitFlag = false; + if ((signal(SIGHUP,&mysighandler) == SIG_ERR) + || (signal(SIGINT,&mysighandler) == SIG_ERR) + || (signal(SIGQUIT,&mysighandler) == SIG_ERR) + || (signal(SIGTERM,&mysighandler) == SIG_ERR)) + { + printError(argv[0],ERR_SIGHANDLER); + if(tcsetattr ( tty, TCSANOW, &termios_old ) != 0) + perror("tcsetattr"); + exit(EXIT_ERROR_STATUS); + } + + if (volume != 255) { + // myEmuConfig.autoPanning = SIDEMU_NONE; + myEmuConfig.volumeControl = SIDEMU_VOLCONTROL; + myEmuEngine.setVoiceVolume(0,volume,volume,volume); + myEmuEngine.setVoiceVolume(1,volume,volume,volume); + myEmuEngine.setVoiceVolume(2,volume,volume,volume); + myEmuEngine.setVoiceVolume(3,volume,volume,volume); + myEmuEngine.setConfig( myEmuConfig ); + } else { + myEmuConfig.volumeControl = SIDEMU_NONE; + } + cout << "\033[1m\033[0m vol \033[1m^\033[0m|\033[1mv\033[0m \033[1mq\033[0muit" << endl; + + for (;;) + { + char inc[1024]; + int i; + size_t numread; + + sidEmuFillBuffer(myEmuEngine,myTune,buffer,bufSize); + myAudio.Play(buffer,bufSize); + + inc[0]=0; + numread = read(tty,inc,1024); + for(i=0;i= 255) + volume=255; + cout << "vol ^ " << volume << " \r" << endl; + if (volume != 255) { + // myEmuConfig.autoPanning = SIDEMU_NONE; + myEmuConfig.volumeControl = SIDEMU_VOLCONTROL; + myEmuEngine.setVoiceVolume(0,volume,volume,volume); + myEmuEngine.setVoiceVolume(1,volume,volume,volume); + myEmuEngine.setVoiceVolume(2,volume,volume,volume); + myEmuEngine.setVoiceVolume(3,volume,volume,volume); + myEmuEngine.setConfig( myEmuConfig ); + } else { + myEmuConfig.volumeControl = SIDEMU_NONE; + } + break; + case '6': /* voldown */ + i++; + case 'B': + volume-=1; + if (volume <= 0) + volume=0; + cout << "vol v " << volume << " \r" << endl; + myEmuConfig.volumeControl = SIDEMU_VOLCONTROL; + myEmuEngine.setVoiceVolume(0,volume,volume,volume); + myEmuEngine.setVoiceVolume(1,volume,volume,volume); + myEmuEngine.setVoiceVolume(2,volume,volume,volume); + myEmuEngine.setVoiceVolume(3,volume,volume,volume); + myEmuEngine.setConfig( myEmuConfig ); + break; + } + } + break; + default: + fprintf(stderr,"%c (%i)\n",inc[0],inc[0]&0xff); + // ungetc(inc,stdin); + break; + } + } + inc[0]=0; + if (exitFlag) + break; + } + // if (myTune) + // myTune.~sidTune(); + delete[] buffer; + myAudio.Reset(); + myAudio.Close(); + }; - myAudio.Reset(); - delete[] buffer; + if(tcsetattr ( tty, TCSANOW, &termios_old ) != 0) + perror("tcsetattr"); exit(0); } @@ -492,6 +692,8 @@ << " -bn set number of audio buffer fragments to use" << endl << " -bs set size 2^ of audio buffer fragments" << endl << " -b set sample buffer size" << endl + << " -V volume (default == 255 == max)" << endl + << " -t song timeout in seconds" << endl << endl << "Mail comments, bug reports, or contributions to ." << endl; }