Re: Errors in application building

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Hello All:

Okay, I have progressed past the segfault issue. Definitely was the lack of
-lpthread in the compile. Now I have the code in place to do a simple
read/write operation to ensure I can make the application capture and play
audio. I copied some example code and am trying to get it to work. I can
scope my pcm interface and it appears to be working, but no audio as of yet.
I am not sure how ALSA is dealing with the audio buffer, so it may be a
fundamental problem with that. It may also be the way I am setting the
parameters. Both arecord and aplay work just fine, so I do not believe it is
a hardware or driver issue.

For clarity, I am using ALSA 1.0.14a with an ARM9 processor using the SoC
driver package and a custom machine/codec driver for an at91sam9260ek dev
board and winbond w6811 codec. It is a simple pcm, mono, 8k codec. My params
are:

Access Type: SND_PCM_ACCESS_RW_INTERLEAVED
Sample Format: SND_PCM_FORMAT_S8
Sample Rate: 8000
Channel Count: 1

My code is attached. Through gdb I get the following:

--snip--
~ $ gdb grh_audio


dlopen failed on 'libthread_db.so.1' - File not found
GDB will not be able to debug pthreads.

GNU gdb 6.4
Copyright 2005 Free Software Foundation, Inc.
GDB is free software, covered by the GNU General Public License, and you are
welcome to change it and/or distribute copies of it under certain
conditions.
Type "show copying" to see the conditions.
There is absolutely no warranty for GDB.  Type "show warranty" for details.
This GDB was configured as "arm-linux-uclibc"...
(gdb) break 131
Breakpoint 1 at 0x8f50: file grh_audio0.c, line 131.
(gdb) break 214
Breakpoint 2 at 0x9364: file grh_audio0.c, line 214.
(gdb) display buf
(gdb) start
Breakpoint 3 at 0x8a8c: file grh_audio0.c, line 33.
Starting program: /usr/sbin/grh_audio
main () at grh_audio0.c:33
33      grh_audio0.c: No such file or directory.
       in grh_audio0.c
1: buf = {0 <repeats 512 times>}
(gdb) continue
Continuing.
Press enter to begin recording


Breakpoint 1, grh_capture () at grh_audio0.c:131
131     in grh_audio0.c
1: buf = {-776, -772, -1796, -2056, -1800, -263, -1, -1, -1, -1, -1793, -4,
 -4, -772, -4, -769, -1, -1, -1, -1, -1, -769, -772, -772, -776, -770, -4,
 -770, -1, -1, -1, -1, -1, -1, -1794, -1801, -1801, -1544, -1, -1, -769,
 -257, -1, -1, -1, -4, -1800, -1800, -776, -1, -2, -4, -257, -2, -1, -1,
-1,
 -1, -769, -260, -257, -769, -4, -1, -1, -1, -1, -769, -1, -4, -769, -2,
 -1800, -2057, -1800, -4, -770, -772, -772, -2, -1, -1, -769, -775, -1799,
 -260, -2, -1, -1, -1, -1, -257, -769, -1796, -264, -1, -1, -264, -769,
 -769, -1, -1, -1, -1, -1, -772, -4, -1801, -3080, -1800, -772, -1, -258,
 -769, -4, -776, -769, -1, -1, -770, -772, -1, -1, -1, -769, -1, -1, -1,
-1,
 -1, -1, -260, -2, -1, -1, -258, -2, -260, -1537, -1800, -1544, -772, -769,

 -1, -769, -1540, -769, -2, -1, -1, -769, -260, -260, -1540, -260, -257,
-2,
 -769, -1, -1, -1, -770, -2056, -8, -257, -2, -7, -1, -1, -1, -1, -1, -2,
 -1, -1, -1793, -1796, -1801, -772, -8, -1, -1537, -1799, -775, -1, -1, -1,

 -4, -260, -769, -2, -1, -257, -769, -1, -1, -1, -769, -1793, -775...}
(gdb) continue
Continuing.
Audio Captured. Press enter to playback


Breakpoint 2, grh_playback () at grh_audio0.c:214
214     in grh_audio0.c
1: buf = {-776, -772, -1796, -2056, -1800, -263, -1, -1, -1, -1, -1793, -4,
 -4, -772, -4, -769, -1, -1, -1, -1, -1, -769, -772, -772, -776, -770, -4,
 -770, -1, -1, -1, -1, -1, -1, -1794, -1801, -1801, -1544, -1, -1, -769,
 -257, -1, -1, -1, -4, -1800, -1800, -776, -1, -2, -4, -257, -2, -1, -1,
-1,
 -1, -769, -260, -257, -769, -4, -1, -1, -1, -1, -769, -1, -4, -769, -2,
 -1800, -2057, -1800, -4, -770, -772, -772, -2, -1, -1, -769, -775, -1799,
 -260, -2, -1, -1, -1, -1, -257, -769, -1796, -264, -1, -1, -264, -769,
 -769, -1, -1, -1, -1, -1, -772, -4, -1801, -3080, -1800, -772, -1, -258,
 -769, -4, -776, -769, -1, -1, -770, -772, -1, -1, -1, -769, -1, -1, -1,
-1,
 -1, -1, -260, -2, -1, -1, -258, -2, -260, -1537, -1800, -1544, -772, -769,

 -1, -769, -1540, -769, -2, -1, -1, -769, -260, -260, -1540, -260, -257,
-2,
 -769, -1, -1, -1, -770, -2056, -8, -257, -2, -7, -1, -1, -1, -1, -1, -2,
 -1, -1, -1793, -1796, -1801, -772, -8, -1, -1537, -1799, -775, -1, -1, -1,

 -4, -260, -769, -2, -1, -257, -769, -1, -1, -1, -769, -1793, -775...}
(gdb) quit
The program is running.  Exit anyway? (y or n) y
~ $
--snip--






--
***************************************
Paul David Kavan
Project Engineer
GRH Electronics, Inc.
402-734-4900
pkavan@xxxxxxxxx
***************************************
/* GRH Audio Program
 *
 * Author: Paul Kavan, Project Engineer
 * Date: July 3, 2007
 */

#include <stdio.h>
#include <stdlib.h>
#include <alsa/asoundlib.h>

/*************************************
 * Variable and Function Declarations 
 *************************************/
int             audio_type;                     //0 = sleep; 1 = capture; 2 = playback
int             nchannels = 1;
int             buffer_size = 512;
unsigned int    sample_rate = 8000;
int             bits = 8;
char           *snd_device_in  = "hw:0,0";
char           *snd_device_out = "hw:0,0";
short           buf[512];
int grh_capture(void);
int grh_playback(void);


/*************************************
 * Main Program Section
 *************************************/
int main(void)
{
  int err;
  //Testing routine
  printf("Press enter to begin recording\n");
  getchar();
  err = grh_capture();
  printf("Audio Captured. Press enter to playback\n");
  while(1){
  getchar();
  err = grh_playback();
  printf("Audio playback complete. Again?\n");}
  return 0;
}



/*************************************************
 * Capture Function:
 * This fuction should capture audio from the PCM 
 * and store it in a buffer for transmission
 *************************************************/
int grh_capture(void)
{
  int i;
  int err;
  snd_pcm_t *capture_handle;
  snd_pcm_hw_params_t *hw_params;

  /************************************
   * Open the pcm interface
   ************************************/
  if ((err = snd_pcm_open(&capture_handle, snd_device_in, SND_PCM_STREAM_CAPTURE, 0)) < 0)
  {
    fprintf(stderr, "Failed to open input audio device %s: %s\n", snd_device_out, snd_strerror(err));
    exit(1);
  }

  /************************************
   * Configure the devices
   ************************************/
  if ((err = snd_pcm_hw_params_malloc (&hw_params)) < 0)
  {
    fprintf (stderr, "cannot allocate hardware parameter structure (%s)\n",snd_strerror (err));
    exit (1);
  }

  if ((err = snd_pcm_hw_params_any (capture_handle, hw_params)) < 0) 
  {
    fprintf (stderr, "cannot initialize hardware parameter structure (%s)\n",snd_strerror (err));
    exit (1);
  }
	
  if ((err = snd_pcm_hw_params_set_access (capture_handle, hw_params, SND_PCM_ACCESS_RW_INTERLEAVED)) < 0) 
  {
    fprintf (stderr, "cannot set access type (%s)\n",snd_strerror (err));
    exit (1);
  }

  if ((err = snd_pcm_hw_params_set_format (capture_handle, hw_params, SND_PCM_FORMAT_S8)) < 0) {
    fprintf (stderr, "cannot set sample format (%s)\n",snd_strerror (err));
    exit (1);
  }

  if ((err = snd_pcm_hw_params_set_rate_near (capture_handle, hw_params, &sample_rate, 0)) < 0) 
  {
    fprintf (stderr, "cannot set sample rate (%s)\n",snd_strerror (err));
    exit (1);
  }
	
  if ((err = snd_pcm_hw_params_set_channels (capture_handle, hw_params, nchannels)) < 0) 
  {
    fprintf (stderr, "cannot set channel count (%s)\n",snd_strerror (err));
    exit (1);
  }

  if ((err = snd_pcm_hw_params (capture_handle, hw_params)) < 0) {
    fprintf (stderr, "cannot set parameters (%s)\n",snd_strerror (err));
    exit (1);
  }

  snd_pcm_hw_params_free (hw_params);

  if ((err = snd_pcm_prepare (capture_handle)) < 0) {
    fprintf (stderr, "cannot prepare audio interface for use (%s)\n",snd_strerror (err));
    exit (1);
  }

  /******************************************
   * Perform capture and store to buffer
   ******************************************/
  for (i = 0; i < 100; ++i) {
    if ((err = snd_pcm_readi (capture_handle, buf, buffer_size)) != buffer_size) {
      fprintf (stderr, "read from audio interface failed (%s)\n",snd_strerror (err));
      exit (1);
    }
  }

  /*******************************************
   * Close PCM interface and exit
   *******************************************/
  snd_pcm_close (capture_handle);
  return 0;
}

/************************************************
 * Playback Function:
 * This function should retrieve audio from a 
 * buffer and send it to the PCM for playback
 ************************************************/
int grh_playback(void)
{
  int i;
  int err;
  snd_pcm_t *playback_handle;
  snd_pcm_hw_params_t *hw_params;

  /************************************
   * Open the pcm interface
   ************************************/
  if ((err = snd_pcm_open(&playback_handle, snd_device_out, SND_PCM_STREAM_PLAYBACK, 0)) < 0) 
  {
    fprintf(stderr, "Failed to open output audio device %s: %s\n", snd_device_in, snd_strerror(err));
    exit(1);
  }

  /************************************
   * Configure the devices
   ************************************/
  if ((err = snd_pcm_hw_params_malloc (&hw_params)) < 0) {
    fprintf (stderr, "cannot allocate hardware parameter structure (%s)\n",snd_strerror (err));
    exit (1);
  }
				 
  if ((err = snd_pcm_hw_params_any (playback_handle, hw_params)) < 0) {
    fprintf (stderr, "cannot initialize hardware parameter structure (%s)\n",snd_strerror (err));
    exit (1);
  }
	
  if ((err = snd_pcm_hw_params_set_access (playback_handle, hw_params, SND_PCM_ACCESS_RW_INTERLEAVED)) < 0) {
    fprintf (stderr, "cannot set access type (%s)\n",snd_strerror (err));
    exit (1);
  }
	
  if ((err = snd_pcm_hw_params_set_format (playback_handle, hw_params, SND_PCM_FORMAT_S8)) < 0) {
    fprintf (stderr, "cannot set sample format (%s)\n",snd_strerror (err));
    exit (1);
  }
	
  if ((err = snd_pcm_hw_params_set_rate_near (playback_handle, hw_params, &sample_rate, 0)) < 0) {
    fprintf (stderr, "cannot set sample rate (%s)\n",snd_strerror (err));
    exit (1);
  }
	
  if ((err = snd_pcm_hw_params_set_channels (playback_handle, hw_params, nchannels)) < 0) {
    fprintf (stderr, "cannot set channel count (%s)\n",snd_strerror (err));
    exit (1);
  }

  if ((err = snd_pcm_hw_params (playback_handle, hw_params)) < 0) {
    fprintf (stderr, "cannot set parameters (%s)\n",snd_strerror (err));
    exit (1);
  }
	
  snd_pcm_hw_params_free (hw_params);

  if ((err = snd_pcm_prepare (playback_handle)) < 0) {
    fprintf (stderr, "cannot prepare audio interface for use (%s)\n",snd_strerror (err));
    exit (1);
  }

  /******************************************
   * Playback from buffer
   ******************************************/
  for (i = 0; i < 100; ++i) {
    if ((err = snd_pcm_writei (playback_handle, buf, buffer_size)) != buffer_size) {
      fprintf (stderr, "write to audio interface failed (%s)\n",snd_strerror (err));
      exit (1);
    }
  }

  /*******************************************
   * Close PCM interface and exit
   *******************************************/
  snd_pcm_close (playback_handle);
  return 0;
}

_______________________________________________
Alsa-devel mailing list
Alsa-devel@xxxxxxxxxxxxxxxx
http://mailman.alsa-project.org/mailman/listinfo/alsa-devel

[Index of Archives]     [ALSA User]     [Linux Audio Users]     [Kernel Archive]     [Asterisk PBX]     [Photo Sharing]     [Linux Sound]     [Video 4 Linux]     [Gimp]     [Yosemite News]

  Powered by Linux