Browse Source

debut de la partie son

phyto 1 year ago
parent
commit
6bbeb33d25
4 changed files with 140 additions and 0 deletions
  1. 16
    0
      audio/Makefile
  2. 98
    0
      audio/player.c
  3. 3
    0
      audio/player.h
  4. 23
    0
      audio/t.c

+ 16
- 0
audio/Makefile View File

@@ -0,0 +1,16 @@
1
+#
2
+#	audio part of the phytotron
3
+#
4
+
5
+
6
+CC      = gcc
7
+CCOPT   = -Wall -g -DDEBUG_LEVEL=1
8
+LIBS	= -lao -lsndfile -lm 
9
+player.o:	player.c Makefile
10
+	 $(CC) ${CCOPT} -c $< 
11
+
12
+t.o:	t.c player.h Makefile
13
+	 $(CC) ${CCOPT} -c $< 
14
+
15
+t:	player.o t.o Makefile
16
+	$(CC) t.o player.o ${LIBS} -o t

+ 98
- 0
audio/player.c View File

@@ -0,0 +1,98 @@
1
+/*
2
+ *	Audio player for the phytotron
3
+ */
4
+ 
5
+#include  <stdio.h>
6
+#include  <unistd.h>
7
+#include  <string.h>
8
+#include  <fcntl.h>
9
+
10
+#include <ao/ao.h>
11
+#include <sndfile.h>
12
+
13
+/* --------------------------------------------------------------------- */
14
+
15
+#define   T_BUFF_WAVES          (8192*4)
16
+#define   T_FNAME               1000
17
+static ao_device                *device;
18
+static ao_sample_format         format;
19
+static int                      coefficient;
20
+static int16_t          	buffer[T_BUFF_WAVES];
21
+
22
+/* --------------------------------------------------------------------- */
23
+int init_waveout(int smplrate)
24
+{
25
+int                     default_driver;
26
+
27
+ao_initialize();
28
+
29
+default_driver = ao_default_driver_id();
30
+#if DEBUG_LEVEL
31
+fprintf(stderr, "%s : ao default driver #%d\n", __func__, default_driver);
32
+#endif
33
+
34
+memset(&format, 0, sizeof(format));
35
+format.bits = 16;
36
+format.channels = 2;
37
+format.rate = smplrate;
38
+format.byte_format = AO_FMT_LITTLE;
39
+
40
+device = ao_open_live(default_driver, &format, NULL);
41
+if (device == NULL) {
42
+        fprintf(stderr, "Error opening AO device.\n");
43
+        return -1;
44
+        }
45
+
46
+return 0;
47
+}
48
+
49
+/* --------------------------------------------------------------------- */
50
+int close_waveout(void)
51
+{
52
+ao_close(device);
53
+ao_shutdown();
54
+return 0;
55
+}
56
+/* --------------------------------------------------------------------- */
57
+
58
+int blast_this_file(char *fname)
59
+{
60
+SNDFILE                 *sndf;
61
+SF_INFO                 sfinfo;
62
+int			foo, lus;
63
+
64
+sndf = sf_open(fname, SFM_READ, &sfinfo);
65
+if (NULL==sndf)
66
+        {
67
+        perror("sf_open");
68
+        abort();
69
+        }
70
+
71
+#if DEBUG_LEVEL
72
+fprintf(stderr, "samplerate : %d\n", sfinfo.samplerate);
73
+fprintf(stderr, "frames     : %ld\n", sfinfo.frames);
74
+fprintf(stderr, "seekable   : %d\n", sfinfo.seekable);
75
+#endif
76
+
77
+while ((lus = sf_read_short(sndf, buffer, T_BUFF_WAVES)))
78
+        {
79
+#if DEBUG_LEVEL      
80
+	fprintf(stderr, "%s : %d bytes read\n", fname, lus);
81
+#endif
82
+
83
+
84
+	}
85
+	
86
+/* do some cleanup */
87
+sf_close(sndf);
88
+
89
+return -1;
90
+}
91
+
92
+
93
+/* --------------------------------------------------------------------- */
94
+
95
+
96
+
97
+
98
+/* --------------------------------------------------------------------- */

+ 3
- 0
audio/player.h View File

@@ -0,0 +1,3 @@
1
+
2
+
3
+int blast_this_file(char *fname);

+ 23
- 0
audio/t.c View File

@@ -0,0 +1,23 @@
1
+/*
2
+ *	Audio player for the phytotron
3
+ */
4
+ 
5
+#include  <stdio.h>
6
+
7
+
8
+#include  "player.h"
9
+
10
+/* --------------------------------------------------------------------- */
11
+
12
+int main(int argc, char *argv[])
13
+{
14
+char		*wavname = "1337.wav";
15
+int		foo;
16
+
17
+
18
+foo = blast_this_file(wavname);
19
+fprintf(stderr, "audio blaster -> %d\n", foo);
20
+
21
+return 0;
22
+}
23
+/* --------------------------------------------------------------------- */

Loading…
Cancel
Save