/[pcsx2_0.9.7]/branch/r3113_0.9.7_beta/3rdparty/portaudio/src/hostapi/oss/recplay.c
ViewVC logotype

Contents of /branch/r3113_0.9.7_beta/3rdparty/portaudio/src/hostapi/oss/recplay.c

Parent Directory Parent Directory | Revision Log Revision Log


Revision 32 - (show annotations) (download)
Tue Sep 7 03:29:01 2010 UTC (9 years, 11 months ago) by william
File MIME type: text/plain
File size: 2292 byte(s)
branching from upstream revision (http://pcsx2.googlecode.com/svn/trunk
): r3113 to
https://svn.netsolutions.dnsalias.com/websvn/ps2/pcsx2/pcsx2_0.9.7/branch/r3113_0.9.7_beta
1 /*
2 * recplay.c
3 * Phil Burk
4 * Minimal record and playback test.
5 *
6 */
7 #include <stdio.h>
8 #include <unistd.h>
9 #include <stdlib.h>
10 #ifndef __STDC__
11 /* #include <getopt.h> */
12 #endif /* __STDC__ */
13 #include <fcntl.h>
14 #ifdef __STDC__
15 #include <string.h>
16 #else /* __STDC__ */
17 #include <strings.h>
18 #endif /* __STDC__ */
19 #include <sys/soundcard.h>
20
21 #define NUM_BYTES (64*1024)
22 #define BLOCK_SIZE (4*1024)
23
24 #define AUDIO "/dev/dsp"
25
26 char buffer[NUM_BYTES];
27
28 int audioDev = 0;
29
30 main (int argc, char *argv[])
31 {
32 int numLeft;
33 char *ptr;
34 int num;
35 int samplesize;
36
37 /********** RECORD ********************/
38 /* Open audio device. */
39 audioDev = open (AUDIO, O_RDONLY, 0);
40 if (audioDev == -1)
41 {
42 perror (AUDIO);
43 exit (-1);
44 }
45
46 /* Set to 16 bit samples. */
47 samplesize = 16;
48 ioctl(audioDev, SNDCTL_DSP_SAMPLESIZE, &samplesize);
49 if (samplesize != 16)
50 {
51 perror("Unable to set the sample size.");
52 exit(-1);
53 }
54
55 /* Record in blocks */
56 printf("Begin recording.\n");
57 numLeft = NUM_BYTES;
58 ptr = buffer;
59 while( numLeft >= BLOCK_SIZE )
60 {
61 if ( (num = read (audioDev, ptr, BLOCK_SIZE)) < 0 )
62 {
63 perror (AUDIO);
64 exit (-1);
65 }
66 else
67 {
68 printf("Read %d bytes\n", num);
69 ptr += num;
70 numLeft -= num;
71 }
72 }
73
74 close( audioDev );
75
76 /********** PLAYBACK ********************/
77 /* Open audio device for writing. */
78 audioDev = open (AUDIO, O_WRONLY, 0);
79 if (audioDev == -1)
80 {
81 perror (AUDIO);
82 exit (-1);
83 }
84
85 /* Set to 16 bit samples. */
86 samplesize = 16;
87 ioctl(audioDev, SNDCTL_DSP_SAMPLESIZE, &samplesize);
88 if (samplesize != 16)
89 {
90 perror("Unable to set the sample size.");
91 exit(-1);
92 }
93
94 /* Play in blocks */
95 printf("Begin playing.\n");
96 numLeft = NUM_BYTES;
97 ptr = buffer;
98 while( numLeft >= BLOCK_SIZE )
99 {
100 if ( (num = write (audioDev, ptr, BLOCK_SIZE)) < 0 )
101 {
102 perror (AUDIO);
103 exit (-1);
104 }
105 else
106 {
107 printf("Wrote %d bytes\n", num);
108 ptr += num;
109 numLeft -= num;
110 }
111 }
112
113 close( audioDev );
114 }

  ViewVC Help
Powered by ViewVC 1.1.22