To check out this repository please hg clone the following URL, or open the URL using EasyMercurial or your preferred Mercurial client.

The primary repository for this project is hosted at https://github.com/sonic-visualiser/sv-dependency-builds .
This repository is a read-only copy which is updated automatically every hour.

Statistics Download as Zip
| Branch: | Tag: | Revision:

root / src / portaudio_20161030_catalina_patch / src / hostapi / oss / recplay.c @ 164:9fa11135915a

History | View | Annotate | Download (2.24 KB)

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
}