zynaddsubfx

ZynAddSubFX open source synthesizer
Log | Files | Refs | Submodules | LICENSE

commit 42a066a7d7e3c9631bde7187269acd7e9234ccf6
parent be7893b10da9814cfae9a6566eb5e1fe717f1d13
Author: fundamental <mark.d.mccurry@gmail.com>
Date:   Fri,  2 Oct 2009 17:20:23 -0400

OSS: Added failsafe based upon Jérémie Andréi patch

See Also:
https://sf.net/tracker/index.php?func=detail&aid=1781574&group_id=62934&atid=502312

Diffstat:
MAUTHORS.txt | 2+-
MChangeLog | 3++-
Msrc/Output/OSSaudiooutput.cpp | 28+++++++++++++++++++++++++++-
Msrc/Output/OSSaudiooutput.h | 2++
4 files changed, 32 insertions(+), 3 deletions(-)

diff --git a/AUTHORS.txt b/AUTHORS.txt @@ -11,7 +11,7 @@ Contributors: Daniel Clemente (with a workaround of X11 repeated key bug) Emmanuel Saracco (fix for JACK output) Achim Settelmeier (QUERTZ keyboard layout for virtual keyboard) - Jérémie Andréi (AZERTY keyboard layout, Array index fix) + Jérémie Andréi (AZERTY keyboard layout, Array index fix, OSS failsafe) Alexis Ballier (const char* <-> string mismatch, NULLMidi prototype fix) Tobias Doerffel (static vs instance variables alteration) James Morris (Memory leaks in FLTK GUI) diff --git a/ChangeLog b/ChangeLog @@ -941,5 +941,6 @@ - Corrected the ADsynth unison LFO rounding function - Made Unison based on Bandwidth (in cents) parameter - +02 Oct 2009 (Mark McCurry) + - Added OSS failsafe by Jérémie Andréi diff --git a/src/Output/OSSaudiooutput.cpp b/src/Output/OSSaudiooutput.cpp @@ -42,6 +42,8 @@ OSSaudiooutput::OSSaudiooutput() snd_stereo=1;//stereo snd_format=AFMT_S16_LE; snd_samplerate=SAMPLE_RATE; + playing_until.tv_sec=0; + playing_until.tv_usec=0; smps=new short int[SOUND_BUFFER_SIZE*2]; for (i=0;i<SOUND_BUFFER_SIZE*2;i++) smps[i]=0; @@ -71,7 +73,31 @@ void OSSaudiooutput::OSSout(REALTYPE *smp_left,REALTYPE *smp_right) { int i; REALTYPE l,r; - if (snd_handle<0) return; + if (snd_handle < 0) { //output could not be opened + struct timeval now; + int remaining; + gettimeofday(&now, NULL); + if((playing_until.tv_usec==0)&&(playing_until.tv_sec==0)) { + playing_until.tv_usec = now.tv_usec; + playing_until.tv_sec = now.tv_sec; + } + else { + remaining = (playing_until.tv_usec - now.tv_usec) + + (playing_until.tv_sec - now.tv_sec)*1000000; + if(remaining > 10000) //Don't sleep() less than 10ms. + //This will add latency... + usleep(remaining-10000); + if(remaining < 0) + cerr << "WARNING - too late" << endl; + } + playing_until.tv_usec += SOUND_BUFFER_SIZE*1000000/SAMPLE_RATE; + if(remaining < 0) + playing_until.tv_usec -= remaining; + playing_until.tv_sec += playing_until.tv_usec/1000000; + playing_until.tv_usec %= 1000000; + return; + } + for (i=0;i<SOUND_BUFFER_SIZE;i++) { l=smp_left[i]; r=smp_right[i]; diff --git a/src/Output/OSSaudiooutput.h b/src/Output/OSSaudiooutput.h @@ -23,6 +23,7 @@ #ifndef OSS_AUDIO_OUTPUT_H #define OSS_AUDIO_OUTPUT_H +#include <sys/time.h> #include "../globals.h" class OSSaudiooutput @@ -40,6 +41,7 @@ private: int snd_stereo; int snd_format; int snd_samplerate; + struct timeval playing_until; short int *smps;//Samples to be sent to soundcard };