[CM] weird problem

Tapan S. Parikh tap2k@yahoo.com
Wed, 7 Aug 2002 17:39:01 +0530


Im having a weird problem w/ using sndlib.  I am calling some
functions to record audio to a file from the mic.  But there is some
kind of weird register spill happening that is causing some local
pointer variables to be reset and screwed up.

I have a feeling this maybe thread-related?  See the following gdb
session that shows some local vars getting screwed up.
aihbox_record_audio has some code which records audio much like
sndrecord.c.  The code for that also follows.  The type of the screwed
up vars is AIHBox* for aihbox and gpointer for user_data.

Any idea what could cause this?  Im using gcc on RH Linux 7.2 on a
Pentium 3.

<gdbsession-snip>
(gdb) print aihbox
$1 = (AIHBox *) 0x81bbc80
(gdb) print filename
$2 = (gchar *) 0x81c2d18 "1028720319.wav"
(gdb) print result
$3 = {tv_sec = 1028720319, tv_usec = 83798}
(gdb) print user_data
$4 = 0x81bbc80
(gdb) next
214   aihbox_record_audio (filename, 100, 50, 4096);
(gdb) print user_data
$5 = 0x3f800000
(gdb) print result
$6 = {tv_sec = 1028720319, tv_usec = 83798}
(gdb) print aihbox
$7 = (AIHBox *) 0x3f800000
(gdb) print filename
$8 = (gchar *) 0x81c2d18 "1028720319.wav"
</gdbsession-snip>

<code-snip>
void
aihbox_record_audio(gchar* filename, int buffers, int num_reads, int
buffer_size)
{
   int fd, afd, i, err, bytes_per_sample, bytes_per_read;
  float mic_gain[1];
  short *ibuf;

  afd = -1;
  mus_sound_initialize();

  // determine num reads per sec based on sampling rate


  /* make sure the microphone is on */
  mic_gain[0] = 1.0;
  mic_gain[1] = 1.0;

  mus_audio_mixer_write(MUS_AUDIO_MICROPHONE, MUS_AUDIO_AMP, 0,
mic_gain);
  if (CHANNELS == 2) mus_audio_mixer_write(MUS_AUDIO_MICROPHONE,
MUS_AUDIO_AMP, 1, mic_gain);

  /* open the output sound file */
  bytes_per_sample = mus_data_format_to_bytes_per_sample(DATA_TYPE);
  bytes_per_read = buffer_size * bytes_per_sample;
  fd = mus_sound_open_output(filename, SAMPLING_RATE, CHANNELS,
DATA_TYPE, FILE_TYPE, "created by sndrecord");

  //fd = mus_sound_open_output(filename, 22050, 2, MUS_LSHORT,
MUS_RIFF, "created by sndlib");

  if (fd != -1)
    {
      ibuf = (short *)calloc(buffer_size, sizeof(short));
      afd = mus_audio_open_input(MUS_AUDIO_MICROPHONE, SAMPLING_RATE,
CHANNELS, DATA_TYPE, bytes_per_read);
      if (afd != -1)
 {
   for (i = 0; i < num_reads; i++)
     {
       err = mus_audio_read(afd, (char *)ibuf, bytes_per_read);
       if (err != MUS_NO_ERROR) break;
       write(fd, ibuf, bytes_per_read);
     }
   mus_audio_close(afd);
 }
      else
 {
   printf ("Error opening audio input device.\n");
 }
      mus_sound_close_output(fd, bytes_per_read * num_reads);
      free(ibuf);
    }
  else
    {
      printf ("Error opening audio input device.\n");
    }
}
</code-snip>