OSS: Added failsafe based upon Jrmie Andri patch

See Also:
https://sf.net/tracker/index.php?func=detail&aid=1781574&group_id=62934&atid=502312
(cherry picked from commit 42a066a7d7e3c9631bde7187269acd7e9234ccf6)
This commit is contained in:
fundamental
2009-10-02 17:20:47 -04:00
committed by Tobias Doerffel
parent c8c6ed648c
commit 2fa39bdf7a
4 changed files with 32 additions and 3 deletions

View File

@@ -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<EFBFBD>mie Andr<64>i (AZERTY keyboard layout, Array index fix)
J<>r<EFBFBD>mie Andr<64>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)

View File

@@ -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<EFBFBD>mie Andr<64>i

View File

@@ -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];

View File

@@ -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
};