-
Notifications
You must be signed in to change notification settings - Fork 6
/
TunerAudioInput.h
93 lines (73 loc) · 2.67 KB
/
TunerAudioInput.h
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
// Copyright (C) 2014 Jimmy Johnson
//
// This program 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.
//
// This program 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 this program; if not, write to the Free Software Foundation, Inc.,
// 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
//
// See the read me file for licensing information
/*
* This file contains the classes needed to initalize and read audio data from
* apple's Core Audio devices. See the method implementations for deatils.
*
*/
#ifndef TUNERAUDIOINPUT_H
#define TUNERAUDIOINPUT_H
#include <pthread.h>
#include <string.h>
#include <unistd.h>
#include <semaphore.h>
#include "AudioToolbox/AudioToolbox.h"
#include "FastFourier.h"
static const int kNumberBuffers = 3;
typedef struct AudioStreamData
{
AudioStreamBasicDescription dataFormat;
AudioQueueRef queue;
SInt64 currentPacket;
AudioQueueBufferRef buffers[3];
UInt32 bufferByteSize;
bool mIsRunning;
}AudioStreamData;
class CTAudioBuffer
{
private:
bool write_flag; // A read/write buffer flag
pthread_mutex_t flag_lock; // var lock for read/write
pthread_mutex_t spin_lock; // var lock for syncronization
protected:
public:
int16_t * buffer; // Shared buffer
int buf_index; // Current shared buffer write index;
AudioStreamData audioStreamData;
void ReInit();
public : CTAudioBuffer();
void SetWriteOkay();
void SetReadOkay();
void Synchronize();
inline int16_t * AudioBuffer(){ return buffer; };
inline int AudioBufferSize(){ return (buf_index*sizeof(int16_t )); };
inline int NumberofSamples(){ return (buf_index); };
inline bool WriteStatus(){ return write_flag; };
};
void DeriveBufferSize (AudioQueueRef audioQueue, // 1
AudioStreamBasicDescription * ASBDescription, // 2
Float64 seconds, // 3
UInt32 *outBufferSize); // 4
static void HandleInputBuffer (void *userData,
AudioQueueRef inAQ,
AudioQueueBufferRef inBuffer,
const AudioTimeStamp *inStartTime,
UInt32 inNumPackets,
AudioStreamPacketDescription *inPacketDesc);
CTAudioBuffer * InitAudio(void);
#endif