Browse Source

[alsa_io] stop using alloca and allocate buffer on the heap.

git-svn-id: svn+ssh://jackaudio.org/trunk/jack@4133 0c269be4-1314-0410-8aa9-9f06e86f4224
tags/0.120.1
torben 15 years ago
parent
commit
e9b00c7c5a
2 changed files with 46 additions and 16 deletions
  1. +24
    -11
      tools/alsa_in.c
  2. +22
    -5
      tools/alsa_out.c

+ 24
- 11
tools/alsa_in.c View File

@@ -76,6 +76,12 @@ volatile float output_diff = 0.0;
snd_pcm_uframes_t real_buffer_size;
snd_pcm_uframes_t real_period_size;

// buffers

char *tmpbuf;
char *outbuf;
float *resampbuf;

// format selection, and corresponding functions from memops in a nice set of structs.

typedef struct alsa_format {
@@ -306,8 +312,6 @@ double hann( double x )
*/
int process (jack_nframes_t nframes, void *arg) {

char *outbuf;
float *resampbuf;
int rlen;
int err;
snd_pcm_sframes_t delay = target_delay;
@@ -321,10 +325,15 @@ int process (jack_nframes_t nframes, void *arg) {
// this is for compensating xruns etc...

if( delay > (target_delay+max_diff) ) {
char *tmp = alloca( (delay-target_delay) * formats[format].sample_size * num_channels );
snd_pcm_readi( alsa_handle, tmp, delay-target_delay );

output_new_delay = (int) delay;

while ((delay-target_delay) > 0) {
snd_pcm_uframes_t to_read = ((delay-target_delay) > 512) ? 512 : (delay-target_delay);
snd_pcm_readi( alsa_handle, tmpbuf, to_read );
delay -= to_read;
}

delay = target_delay;

// Set the resample_rate... we need to adjust the offset integral, to do this.
@@ -398,13 +407,6 @@ int process (jack_nframes_t nframes, void *arg) {

// Calculate resample_mean so we can init ourselves to saner values.
resample_mean = 0.9999 * resample_mean + 0.0001 * current_resample_factor;
/*
* now this should do it...
*/

outbuf = alloca( rlen * formats[format].sample_size * num_channels );

resampbuf = alloca( rlen * sizeof( float ) );

// get the data...
again:
@@ -743,6 +745,17 @@ int main (int argc, char *argv[]) {
// alloc input ports, which are blasted out to alsa...
alloc_ports( num_channels, 0 );

outbuf = malloc( num_periods * period_size * formats[format].sample_size * num_channels );
resampbuf = malloc( num_periods * period_size * sizeof( float ) );
tmpbuf = malloc( 512 * formats[format].sample_size * num_channels );

if ((outbuf == NULL) || (resampbuf == NULL) || (tmpbuf == NULL))
{
fprintf( stderr, "no memory for buffers.\n" );
exit(20);
}

memset( tmpbuf, 0, 512 * formats[format].sample_size * num_channels);

/* tell the JACK server that we are ready to roll */



+ 22
- 5
tools/alsa_out.c View File

@@ -76,6 +76,12 @@ volatile float output_diff = 0.0;
snd_pcm_uframes_t real_buffer_size;
snd_pcm_uframes_t real_period_size;

// buffers

char *tmpbuf;
char *outbuf;
float *resampbuf;

// format selection, and corresponding functions from memops in a nice set of structs.

typedef struct alsa_format {
@@ -310,8 +316,6 @@ double hann( double x )
*/
int process (jack_nframes_t nframes, void *arg) {

char *outbuf;
float *resampbuf;
int rlen;
int err;
snd_pcm_sframes_t delay = target_delay;
@@ -339,12 +343,15 @@ int process (jack_nframes_t nframes, void *arg) {
offset_array[i] = 0.0;
}
if( delay < (target_delay-max_diff) ) {
char *tmp = alloca( (target_delay-delay) * formats[format].sample_size * num_channels );
memset( tmp, 0, formats[format].sample_size * num_channels * (target_delay-delay) );
snd_pcm_writei( alsa_handle, tmp, target_delay-delay );

output_new_delay = (int) delay;

while ((target_delay-delay) > 0) {
snd_pcm_uframes_t to_write = ((target_delay-delay) > 512) ? 512 : (target_delay-delay);
snd_pcm_writei( alsa_handle, tmpbuf, to_write );
delay += to_write;
}

delay = target_delay;

// Set the resample_rate... we need to adjust the offset integral, to do this.
@@ -741,6 +748,16 @@ int main (int argc, char *argv[]) {
// alloc input ports, which are blasted out to alsa...
alloc_ports( 0, num_channels );

outbuf = malloc( num_periods * period_size * formats[format].sample_size * num_channels );
resampbuf = malloc( num_periods * period_size * sizeof( float ) );
tmpbuf = malloc( 512 * formats[format].sample_size * num_channels );

if ((outbuf == NULL) || (resampbuf == NULL) || (tmpbuf == NULL))
{
fprintf( stderr, "no memory for buffers.\n" );
exit(20);
}


/* tell the JACK server that we are ready to roll */



Loading…
Cancel
Save