Web   ·   Wiki   ·   Activities   ·   Blog   ·   Lists   ·   Chat   ·   Meeting   ·   Bugs   ·   Git   ·   Translate   ·   Archive   ·   People   ·   Donate
summaryrefslogtreecommitdiffstats
path: root/Util/Clooper
diff options
context:
space:
mode:
authorJames <olpc@xo-05-28-3A.localdomain>2007-08-14 01:17:30 (GMT)
committer James <olpc@xo-05-28-3A.localdomain>2007-08-14 01:17:30 (GMT)
commitbfbc01dd88974b2cc1a143ca8269c4601a285348 (patch)
tree47da22484ca92bd64379799c3ae47a2945f9e12d /Util/Clooper
parent707f079867d46a6790a783aa85f3035b11cdf9ef (diff)
changed sample format from float to s16
Diffstat (limited to 'Util/Clooper')
-rw-r--r--Util/Clooper/aclient.cpp27
-rwxr-xr-xUtil/Clooper/aclient.sobin49464 -> 49464 bytes
-rw-r--r--Util/Clooper/audio.cpp9
3 files changed, 24 insertions, 12 deletions
diff --git a/Util/Clooper/aclient.cpp b/Util/Clooper/aclient.cpp
index baa7419..1755438 100644
--- a/Util/Clooper/aclient.cpp
+++ b/Util/Clooper/aclient.cpp
@@ -30,6 +30,7 @@ static double pytime(const struct timeval * tv)
#define ERROR_HERE if (_debug && (VERBOSE > 0)) fprintf(_debug, "ERROR: %s:%i\n", __FILE__, __LINE__)
#define IF_DEBUG(N) if (_debug && (VERBOSE > N))
+#define FLOAT_TO_SHORT(in,out) __asm__ __volatile__ ("fistps %0" : "=m" (out) : "t" (in) : "st") ;
int VERBOSE = 3;
FILE * _debug = NULL;
@@ -472,11 +473,11 @@ struct TamTamSound
return 1;
}
- assert(up_ratio = sys_stuff->rate / csound_frame_rate);
+ assert(up_ratio == (signed)(sys_stuff->rate / csound_frame_rate));
bool do_upsample = (signed)sys_stuff->period_size != csound_nframes;
- float *upbuf = do_upsample ? new float[ sys_stuff->period_size * nchannels ]: NULL; //2 channels
- int cbuf_pos = csound_nframes;
+ short *upbuf = new short[ sys_stuff->period_size * nchannels ];
+ int cbuf_pos = csound_nframes; // trigger a call to csoundPerformBuffer immediately
float *cbuf = NULL;
int up_pos = 0;
int ratio_pos = 0;
@@ -487,6 +488,7 @@ struct TamTamSound
{
up_pos = 0;
int messed = 0;
+ short cursample[2]={0,0};
while(!messed)
{
if (cbuf_pos == csound_nframes)
@@ -495,13 +497,17 @@ struct TamTamSound
if (csoundPerformBuffer(csound)) { messed = 1;break;}
cbuf = csoundGetOutputBuffer(csound);
}
- upbuf[2*up_pos+0] = cbuf[cbuf_pos*2+0];
- upbuf[2*up_pos+1] = cbuf[cbuf_pos*2+1];
+ upbuf[2*up_pos+0] = cursample[0];
+ upbuf[2*up_pos+1] = cursample[1];
if (++ratio_pos == up_ratio)
{
ratio_pos = 0;
++cbuf_pos;
+ cbuf[cbuf_pos*2+0] *= (float) ((1<<15)-100.0f);
+ cbuf[cbuf_pos*2+1] *= (float) ((1<<15)-100.0f);
+ FLOAT_TO_SHORT( cbuf[cbuf_pos*2+0], cursample[0]);
+ FLOAT_TO_SHORT( cbuf[cbuf_pos*2+1], cursample[1]);
}
if (++up_pos == (signed)sys_stuff->period_size) break;
@@ -512,9 +518,14 @@ struct TamTamSound
}
else //fill one period of audio directly from csound
{
- //if (0 > sys_stuff->readbuf((char*)csoundGetInputBuffer(csound))) break;
if (csoundPerformBuffer(csound)) break;
- if (0 > sys_stuff->writebuf(csound_nframes,csoundGetOutputBuffer(csound))) break;
+ cbuf = csoundGetOutputBuffer(csound);
+ for (int i = 0; i < csound_nframes * nchannels; ++i)
+ {
+ cbuf[i] *= (float) ((1<<15)-100.0f);
+ FLOAT_TO_SHORT( cbuf[i], upbuf[i]);
+ }
+ if (0 > sys_stuff->writebuf(csound_nframes,upbuf)) break;
}
if (thread_playloop)
@@ -533,7 +544,7 @@ struct TamTamSound
}
sys_stuff->close(1);
- if (do_upsample) delete [] upbuf;
+ delete [] upbuf;
ll->printf(2, "INFO: performance thread returning 0\n");
return 0;
}
diff --git a/Util/Clooper/aclient.so b/Util/Clooper/aclient.so
index b089412..97c9cbb 100755
--- a/Util/Clooper/aclient.so
+++ b/Util/Clooper/aclient.so
Binary files differ
diff --git a/Util/Clooper/audio.cpp b/Util/Clooper/audio.cpp
index 0d901e6..e93ea54 100644
--- a/Util/Clooper/audio.cpp
+++ b/Util/Clooper/audio.cpp
@@ -45,7 +45,8 @@ struct SystemStuff
snd_pcm_t *phandle;
snd_pcm_uframes_t period_size;
unsigned int rate;
- SystemStuff(log_t * ll) : ll(ll), phandle(NULL), period_size(0), rate(0)
+ const snd_pcm_format_t sample_format;
+ SystemStuff(log_t * ll) : ll(ll), phandle(NULL), period_size(0), rate(0), sample_format(SND_PCM_FORMAT_S16)
{
}
~SystemStuff()
@@ -95,8 +96,8 @@ struct SystemStuff
if ( 0 > snd_pcm_hw_params_set_rate_resample(phandle, hw, 0)) { ERROR_HERE; goto open_error;}
if ( 0 > snd_pcm_hw_params_test_access(phandle, hw, SND_PCM_ACCESS_RW_INTERLEAVED)){ ERROR_HERE; goto open_error;}
if ( 0 > snd_pcm_hw_params_set_access(phandle, hw, SND_PCM_ACCESS_RW_INTERLEAVED)){ ERROR_HERE; goto open_error;}
- if ( 0 > snd_pcm_hw_params_test_format(phandle, hw, SND_PCM_FORMAT_FLOAT)) { ERROR_HERE; goto open_error;}
- if ( 0 > snd_pcm_hw_params_set_format(phandle, hw, SND_PCM_FORMAT_FLOAT)) { ERROR_HERE; goto open_error;}
+ if ( 0 > snd_pcm_hw_params_test_format(phandle, hw, sample_format)) { ERROR_HERE; goto open_error;}
+ if ( 0 > snd_pcm_hw_params_set_format(phandle, hw, sample_format)) { ERROR_HERE; goto open_error;}
if ( 0 > snd_pcm_hw_params_set_channels(phandle, hw, 2)) { ERROR_HERE; goto open_error;}
if ( snd_pcm_hw_params_test_rate(phandle, hw, rate, 0))
@@ -181,7 +182,7 @@ open_error:
}
if (0 > snd_pcm_prepare(phandle)) { ERROR_HERE; }
}
- int writebuf(snd_pcm_uframes_t frame_count, float * frame_data)
+ int writebuf(snd_pcm_uframes_t frame_count, short int * frame_data)
{
if (!phandle)
{