Tscope5
audio_internal.c
Go to the documentation of this file.
1 ////////////////////////////////////////////////////////////////////////////////
2 //
3 // __ ______
4 // / /_______________ ____ ___ / ____/
5 // / __/ ___/ ___/ __ \/ __ \/ _ \ /___ )
6 // / /_(__ ) /__/ /_/ / /_/ / __/ ____/ /
7 // \__/____/\___/\____/ .___/\___/ /_____/
8 // /_/
9 //
10 /// \file audio_internal.c
11 /// Definitions of internal audio functions
12 ////////////////////////////////////////////////////////////////////////////////
13 
14 
15 #include "../include/tscope5/audio_internal.h"
16 #include "../include/tscope5/system_internal.h"
17 
18 #include <allegro5/allegro_acodec.h>
19 
20 /// Is the audio subsystem installed?
22 
23 
24 ////////////////////////////////////////////////////////////////////////////////
25 /// Do some checks at the start of each audio function.
26 ///
27 /// \param calling_function Name the function that calls for
28 /// this check or installation.
29 ///
30 /// Checks whether the audio subsystem is installed.
31 /// If not, the audio subsystem is installed.
32 ////////////////////////////////////////////////////////////////////////////////
33 void ts5_check_audio(char *calling_function)
34 {
35  ts5_log(TS5_LOGLEVEL_6, "%s: ts5_check_audio\n", calling_function);
37  ts5_install_audio(calling_function);
38  }
39 }
40 
41 
42 ////////////////////////////////////////////////////////////////////////////////
43 /// Install the audio subsystem.
44 ///
45 /// \param calling_function Name the function that calls for
46 /// this check or installation.
47 ///
48 /// This function is called automatically if necessary.
49 ////////////////////////////////////////////////////////////////////////////////
50 void ts5_install_audio(char *calling_function)
51 {
53  ts5_install_tscope5(calling_function);
54  }
55 
57 
59  ts5_log(TS5_LOGLEVEL_1, "%s: Installing Tscope5 audio\n",
60  calling_function);
61 
62  if (!al_install_audio()) {
63  ts5_fatal("%s: could not install Tscope5 audio\n",
64  calling_function);
65  }
66 
67  if (!al_init_acodec_addon()) {
68  ts5_fatal("%s: could not install Tscope5 audio codec addon\n",
69  calling_function);
70  }
71 
72  ALLEGRO_CHANNEL_CONF channels;
73 
74  if (_ts5_status.audio.channels==TS5_MONO) {
75  channels=ALLEGRO_CHANNEL_CONF_1;
76  }
77  else if (_ts5_status.audio.channels==TS5_STEREO) {
78  channels=ALLEGRO_CHANNEL_CONF_2;
79  }
80  else {
81  ts5_fatal("%s: unknown channel configuration requested\n",
82  calling_function);
83  }
84 
85  /*
86  ALLEGRO_AUDIO_DEPTH depth;
87  if (_ts5_status.audio.depth==TS5_INTEGER) {
88  depth=ALLEGRO_AUDIO_DEPTH_INT16;
89  }
90  else if (_ts5_status.audio.depth==TS5_FLOAT) {
91  depth=ALLEGRO_AUDIO_DEPTH_FLOAT32;
92  }
93  else {
94  ts5_fatal("ts5_install_audio: unknown sample depth requested\n");
95  }
96  */
97 
98  _ts5_data.audio.voice = al_create_voice(_ts5_status.audio.frequency,
99  ALLEGRO_AUDIO_DEPTH_INT16, channels);
100 
101  if (!_ts5_data.audio.voice) {
102  ts5_fatal("%s: could not create voice\n", calling_function);
103  }
104 
105  _ts5_data.audio.mixer = al_create_mixer(_ts5_status.audio.frequency,
106  ALLEGRO_AUDIO_DEPTH_FLOAT32, channels);
107 
108  if (!_ts5_data.audio.mixer) {
109  ts5_fatal("%s: could not create mixer\n", calling_function);
110  }
111 
112  if (!al_attach_mixer_to_voice(_ts5_data.audio.mixer,
113  _ts5_data.audio.voice)) {
114  ts5_fatal("%s: could not attach mixer to voice\n",
115  calling_function);
116  }
117 
118  atexit(ts5_uninstall_audio);
119  }
120 }
121 
122 
123 ////////////////////////////////////////////////////////////////////////////////
124 /// Uninstall the audio subsystem.
125 ///
126 /// This function is called automatically at the end of the program.
127 ////////////////////////////////////////////////////////////////////////////////
129 {
131 
132  ts5_log(TS5_LOGLEVEL_1, "Uninstalling Tscope5 audio\n");
133 
134  al_detach_mixer(_ts5_data.audio.mixer);
135  al_detach_voice(_ts5_data.audio.voice);
136 
137  al_destroy_mixer(_ts5_data.audio.mixer);
138  al_destroy_voice(_ts5_data.audio.voice);
139 
140  _ts5_data.audio.mixer = NULL;
141  _ts5_data.audio.voice = NULL;
142 
143  al_uninstall_audio();
144 
146  }
147 }