diff --minimal -urN sidplay-base-1.0.4/audio/oss/audiodrv.cpp sidplay-base-1.0.4-agenda.new/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.new/audio/oss/audiodrv.cpp Thu Jun 21 19:26:36 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 --minimal -urN sidplay-base-1.0.4/audio/oss/audiodrv.h sidplay-base-1.0.4-agenda.new/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.new/audio/oss/audiodrv.h Thu Jun 21 19:26:36 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 --minimal -urN sidplay-base-1.0.4/configure sidplay-base-1.0.4-agenda.new/configure --- sidplay-base-1.0.4/configure Wed May 31 20:52:45 2000 +++ sidplay-base-1.0.4-agenda.new/configure Thu Jun 21 19:26:36 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 --minimal -urN sidplay-base-1.0.4/sidplay.cpp sidplay-base-1.0.4-agenda.new/sidplay.cpp --- sidplay-base-1.0.4/sidplay.cpp Sun Apr 16 06:11:21 2000 +++ sidplay-base-1.0.4-agenda.new/sidplay.cpp Thu Jun 21 21:22:17 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; } - default: + 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,12 @@ { // Reading from stdin? if ( strlen(argv[a]) == 1 ) - if ( infile == 0 ) { - infile = a; + if ( numfiles < 1024 ) + { + infiles[numfiles++] = a; + console="/dev/tty"; + } break; } else @@ -196,6 +218,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 +253,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 +272,8 @@ } else { - if ( infile == 0 ) - infile = a; // filename argument + if ( numfiles < 1024 ) + infiles[numfiles++] = a; // filename argument else { printSyntax(argv[0]); @@ -249,7 +283,7 @@ a++; // next argument }; - if (infile == 0) + if (numfiles == 0) { // Neither file nor stdin. printSyntax(argv[0]); @@ -275,7 +309,89 @@ // INSTANTIATE A SIDTUNE OBJECT // ====================================================================== - sidTune myTune( argv[infile] ); + 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 + // ====================================================================== + + // Instantiate the audio driver. The capabilities of the audio driver + // can override the settings of the SID emulator. + audioDriver myAudio; + if ( !myAudio.IsThere() ) + { + cerr << argv[0] << ": No audio device available!" << endl; + exit(EXIT_ERROR_STATUS); + } + // Open() does not accept the "bitsize" value on all platforms, e.g. + // Sparcstations 5 and 10 tend to be 16-bit only at rates above 8000 Hz. + if ( !myAudio.Open(myEmuConfig.frequency,myEmuConfig.bitsPerSample, + myEmuConfig.channels,fragments,fragSizeBase)) + { + cerr << argv[0] << ": " << myAudio.GetErrorString() << endl; + exit(EXIT_ERROR_STATUS); + } + if (verboseOutput) + { + cout << "Block size : " << (udword)myAudio.GetBlockSize() << endl + << "Fragments : " << myAudio.GetFragments() << endl; + } + + 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++; + } + + if (readfromstdin) { + fp=filename; + } else { + fp=argv[infiles[infile]]; + } + cout << "playing " << fp << endl; + sidTune myTune( fp ); + struct sidTuneInfo mySidInfo; myTune.getInfo( mySidInfo ); if ( !myTune ) @@ -317,32 +433,6 @@ } // ====================================================================== - // CONFIGURE THE AUDIO DRIVER - // ====================================================================== - - // Instantiate the audio driver. The capabilities of the audio driver - // can override the settings of the SID emulator. - audioDriver myAudio; - if ( !myAudio.IsThere() ) - { - cerr << argv[0] << ": No audio device available!" << endl; - exit(EXIT_ERROR_STATUS); - } - // Open() does not accept the "bitsize" value on all platforms, e.g. - // Sparcstations 5 and 10 tend to be 16-bit only at rates above 8000 Hz. - if ( !myAudio.Open(myEmuConfig.frequency,myEmuConfig.bitsPerSample, - myEmuConfig.channels,fragments,fragSizeBase)) - { - cerr << argv[0] << ": " << myAudio.GetErrorString() << endl; - exit(EXIT_ERROR_STATUS); - } - if (verboseOutput) - { - cout << "Block size : " << (udword)myAudio.GetBlockSize() << endl - << "Fragments : " << myAudio.GetFragments() << endl; - } - - // ====================================================================== // CONFIGURE THE EMULATOR ENGINE // ====================================================================== @@ -384,11 +474,12 @@ } // Read out the current settings of the sidtune. myTune.getInfo( mySidInfo ); - if ( !myTune ) - { + if ( !myTune ) { cerr << argv[0] << ": " << mySidInfo.statusString << endl; exit(EXIT_ERROR_STATUS); } + selectedSong = mySidInfo.currentSong; + lastSong = mySidInfo.songs; cout << "Setting song : " << mySidInfo.currentSong << " out of " << mySidInfo.songs << " (default = " << mySidInfo.startSong << ')' << endl; @@ -418,6 +509,7 @@ } exitFlag = false; + quitFlag = false; if ((signal(SIGHUP,&mysighandler) == SIG_ERR) || (signal(SIGINT,&mysighandler) == SIG_ERR) || (signal(SIGQUIT,&mysighandler) == SIG_ERR) @@ -428,16 +520,115 @@ } cout << "Playing, press ^C to stop ..." << 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; + } + 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; } - + myAudio.Reset(); + myAudio.Close(); delete[] buffer; + } + + system("stty sane"); // should reuse the struct termios * exit(0); } @@ -492,6 +683,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; }