Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>I'm a java-guy in heart, but this task (especially on a cpu constrained device, like a handheld) is crying for C. I would suggest simply using the libsamplerate. It has a simple API, and even if you're new to C you'll find plenty of examples by just googling around.</p> <p><em>of course the java based solution could and would work, it just doesn't seem polite to the users to eat up their batteries just because your new to C :)</em></p> <p>EDIT: I might contradict myself a bit, but even though performance is a serious issue, I would avoid doing <em>anything</em> in kernel-space, unless I know the kernel and the hardware <strong>really</strong> well. In light of this I would go with a user-space program linked to libsamplerate. After a bit of googling around I've found this example (<em>note that the output is the jack interface, obviously it has to be different for you</em>)</p> <pre><code>#include &lt;jack/jack.h&gt; #include &lt;samplerate.h&gt; int channels; float data_samplerate; ///////////////////////////////////////////////////// ///////////////////////////////////////////////////// void getDasData(float **dst,int num_frames){ /* Provide sound data here, and only here. */ } ///////////////////////////////////////////////////// ///////////////////////////////////////////////////// long getDasResampledData_callback(void *cb_data, float **data){ static float ret[1024]; static float ret3[1024]; static float *ret2[2]={&amp;ret[0],&amp;ret[512]}; getDasData(ret2,512); for(int i=0;i&lt;512;i++){ ret3[i*2]=ret2[0][i]; ret3[i*2+1]=ret2[1][i]; } *data=&amp;ret3[0]; return 512; } void getDasResampledData(float **dst,int num_frames){ double ratio=samplerate/getSourceRate(); float outsound[num_frames*2]; long read=src_callback_read(dassrc_state,ratio,num_frames,outsound); //fprintf(stderr,"read: %d, num_frames: %d\n",read,num_frames); for(int i=0;i&lt;read;i++){ dst[0][i]=outsound[i*2]; dst[1][i]=outsound[i*2+1]; } if(read&lt;num_frames){ float *newdst[2]={dst[0]+read,dst[1]+read}; getDasResampledData(newdst,num_frames-read); } } static int process (jack_nframes_t nframes, void *arg){ int ch; sample_t *out[channels]; for(ch=0;ch&lt;channels;ch++){ out[ch]=(sample_t*)jack_port_get_buffer(ports[ch],nframes); } if( (fabs(data_samplerate - jack_samplerate)) &gt; 0.1) getDasResampledData(out,numSamples); else getDasData(outputChannelData,numSamples); return; audioCallback(NULL,0,out,channels,nframes); } int main(){ dassrc_state=src_callback_new(getDasResampledData_callback,SRC_QUALITY,2,NULL,NULL); jack_set_process_callback(client, process,NULL); } </code></pre> <blockquote> <p>from <a href="http://old.nabble.com/Example-of-using-libresample-with-jack-td8795847.html" rel="nofollow">http://old.nabble.com/Example-of-using-libresample-with-jack-td8795847.html</a></p> </blockquote> <p>This example seems pretty straightforward, I hope you can use it.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload