Subversion Repositories svnkaklik

Rev

Rev 520 | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log

Rev 520 Rev 521
Line 1... Line 1...
1
	#include <stdio.h>
1
	#include <stdio.h>
2
	#include <stdlib.h>
2
	#include <stdlib.h>
3
	#include <alsa/asoundlib.h>
3
	#include <alsa/asoundlib.h>
4
 
4
 
5
	int exact_rate = 44100;
5
	int exact_rate = 44100;
-
 
6
#define BUFFER_SIZE	1024
6
	      
7
 
7
	main (int argc, char *argv[])
8
	main (int argc, char *argv[])
8
	{
9
	{
9
		int i;
10
		int i,j;
10
		int err;
11
		int err;
11
		short buf[128];
12
		short buf[BUFFER_SIZE];
12
		snd_pcm_t *capture_handle;
13
		snd_pcm_t *capture_handle;
13
		snd_pcm_hw_params_t *hw_params;
14
		snd_pcm_hw_params_t *hw_params;
14
	
15
	
15
		if ((err = snd_pcm_open (&capture_handle, argv[1], SND_PCM_STREAM_CAPTURE, 0)) < 0) {
16
		if ((err = snd_pcm_open (&capture_handle, argv[1], SND_PCM_STREAM_CAPTURE, 0)) < 0) {
16
			fprintf (stderr, "cannot open audio device %s (%s)\n", 
17
			fprintf (stderr, "cannot open audio device %s (%s)\n", 
17
				 argv[1],
18
				 argv[1],
18
				 snd_strerror (err));
19
				 snd_strerror (err));
19
			exit (1);
20
			exit (1);
20
		}
21
		}
21
		   
22
		   
22
fprintf (stdout,"nastaveni formatu");
23
fprintf (stdout,"nastaveni formatu\n");
23
 
24
 
24
		if ((err = snd_pcm_hw_params_malloc (&hw_params)) < 0) {
25
		if ((err = snd_pcm_hw_params_malloc (&hw_params)) < 0) {
25
			fprintf (stderr, "cannot allocate hardware parameter structure (%s)\n",
26
			fprintf (stderr, "cannot allocate hardware parameter structure (%s)\n",
26
				 snd_strerror (err));
27
				 snd_strerror (err));
27
			exit (1);
28
			exit (1);
Line 42... Line 43...
42
		if ((err = snd_pcm_hw_params_set_format (capture_handle, hw_params, SND_PCM_FORMAT_S16_LE)) < 0) {
43
		if ((err = snd_pcm_hw_params_set_format (capture_handle, hw_params, SND_PCM_FORMAT_S16_LE)) < 0) {
43
			fprintf (stderr, "cannot set sample format (%s)\n",
44
			fprintf (stderr, "cannot set sample format (%s)\n",
44
				 snd_strerror (err));
45
				 snd_strerror (err));
45
			exit (1);
46
			exit (1);
46
		}
47
		}
47
fprintf (stdout,"nastaveni formatu");
48
fprintf (stdout,"nastaveni formatu\n");
48
	
49
	
49
		if ((err = snd_pcm_hw_params_set_rate_near (capture_handle, hw_params, &exact_rate, 0)) < 0) {
50
		if ((err = snd_pcm_hw_params_set_rate_near (capture_handle, hw_params, &exact_rate, 0)) < 0) {
50
			fprintf (stderr, "cannot set sample rate (%s)\n",
51
			fprintf (stderr, "cannot set sample rate (%s)\n",
51
				 snd_strerror (err));
52
				 snd_strerror (err));
52
			exit (1);
53
			exit (1);
53
		}
54
		}
54
fprintf (stdout,"nastaveni vzorkovani");
55
fprintf (stdout,"nastaveni vzorkovani\n");
55
	
56
	
56
		if ((err = snd_pcm_hw_params_set_channels (capture_handle, hw_params, 2)) < 0) {
57
		if ((err = snd_pcm_hw_params_set_channels (capture_handle, hw_params, 2)) < 0) {
57
			fprintf (stderr, "cannot set channel count (%s)\n",
58
			fprintf (stderr, "cannot set channel count (%s)\n",
58
				 snd_strerror (err));
59
				 snd_strerror (err));
59
			exit (1);
60
			exit (1);
60
		}
61
		}
61
	
62
	
62
fprintf (stdout,"nastaveni poctu kanalu");
63
fprintf (stdout,"nastaveni poctu kanalu\n");
63
 
64
 
64
		if ((err = snd_pcm_hw_params (capture_handle, hw_params)) < 0) {
65
		if ((err = snd_pcm_hw_params (capture_handle, hw_params)) < 0) {
65
			fprintf (stderr, "cannot set parameters (%s)\n",
66
			fprintf (stderr, "cannot set parameters (%s)\n",
66
				 snd_strerror (err));
67
				 snd_strerror (err));
67
			exit (1);
68
			exit (1);
68
		}
69
		}
69
 
70
 
70
fprintf (stdout,"nastaveni parametru");
71
fprintf (stdout,"nastaveni parametru\n");
71
	
72
	
72
		snd_pcm_hw_params_free (hw_params);
73
		snd_pcm_hw_params_free (hw_params);
73
	
74
	
74
		if ((err = snd_pcm_prepare (capture_handle)) < 0) {
75
		if ((err = snd_pcm_prepare (capture_handle)) < 0) {
75
			fprintf (stderr, "cannot prepare audio interface for use (%s)\n",
76
			fprintf (stderr, "cannot prepare audio interface for use (%s)\n",
76
				 snd_strerror (err));
77
				 snd_strerror (err));
77
			exit (1);
78
			exit (1);
78
		}
79
		}
79
fprintf (stdout,"povoleni audia");
80
fprintf (stdout,"povoleni audia\n");
80
	
81
	
81
		for (i = 0; i < 10; ++i) {
-
 
-
 
82
 
82
			if ((err = snd_pcm_readi (capture_handle, buf, 128)) != 128) {
83
		if ((err = snd_pcm_readi (capture_handle, buf, BUFFER_SIZE)) != BUFFER_SIZE) {
83
				fprintf (stderr, "read from audio interface failed (%s)\n",
84
				fprintf (stderr, "read from audio interface failed (%s)\n",
84
					 snd_strerror (err));
85
					 snd_strerror (err));
85
				exit (1);
86
				exit (1);
86
 
87
 
87
			}
-
 
88
		}
88
		}	
-
 
89
		for (j=0; j < 500; j=j+2) fprintf (stdout,"%u:%d %d\n ",j,buf[j], buf[j+1]);	
89
	
90
 
90
		snd_pcm_close (capture_handle);
91
		snd_pcm_close (capture_handle);
91
		exit (0);
92
		exit (0);
92
	}
93
	}
-
 
94