1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
|
/*
* lingot, a musical instrument tuner.
*
* Copyright (C) 2004-2011 Ibán Cereijo Graña, Jairo Chapela Martínez.
*
* This file is part of lingot.
*
* lingot is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* lingot is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with lingot; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
#ifndef __LINGOT_AUDIO_H__
#define __LINGOT_AUDIO_H__
#ifdef ALSA
#include <alsa/asoundlib.h>
#endif
#ifdef JACK
#include <jack/jack.h>
#endif
#ifdef PORTAUDIO
#include <portaudio.h>
#endif
#include <stdint.h>
#include <pthread.h>
#include "lingot-config.h"
typedef void (*LingotAudioProcessCallback)(FLT* read_buffer,
int read_buffer_size, void *arg);
typedef struct _LingotAudioHandler LingotAudioHandler;
struct _LingotAudioHandler {
int audio_system;
char device[100];
LingotAudioProcessCallback process_callback;
void* process_callback_arg;
#ifdef ALSA
snd_pcm_t *capture_handle;
#endif
int dsp; // file handler.
int read_buffer_size;
SAMPLE_TYPE* read_buffer;
FLT* flt_read_buffer;
# ifdef JACK
jack_port_t *jack_input_port;
jack_client_t *jack_client;
int nframes;
# endif
# ifdef PORTAUDIO
PaStream *portaudio_stream;
# endif
// char error_message[100];
unsigned int real_sample_rate;
// pthread-related member variables
pthread_t thread_input_read;
pthread_attr_t thread_input_read_attr;
// indicates whether the audio thread is running
int running;
// indicates whether the thread was interrupted (by the audio server, not
// by the user)
int interrupted;
};
typedef struct _LingotAudioSystemProperties LingotAudioSystemProperties;
struct _LingotAudioSystemProperties {
int forced_sample_rate; // tells whether the sample rate can be changed
int n_sample_rates; // number of available sample rates
int* sample_rates; // sample rates
int n_devices; // number of available devices
char** devices; // devices
};
LingotAudioSystemProperties* lingot_audio_get_audio_system_properties(
audio_system_t audio_system);
void lingot_audio_audio_system_properties_destroy(LingotAudioSystemProperties*);
// creates an audio handler
LingotAudioHandler
*
lingot_audio_new(audio_system_t audio_system, char* device,
int sample_rate, LingotAudioProcessCallback process_callback,
void *process_callback_arg);
// destroys an audio handler
void lingot_audio_destroy(LingotAudioHandler*);
int lingot_audio_start(LingotAudioHandler*);
void lingot_audio_stop(LingotAudioHandler*);
#endif
|