Skip to content

Commit ede6f3f

Browse files
dsward2dsward2
authored andcommitted
In AudioMonitor, the code for producing Mac direct mode audio was substantially revised. The Novocaine code for audio output was removed. AudioMonitor now uses Apple's AudioConverter and AudioQueue services to resample audio to 48000 Hz (compared to 44100 with Novocaine). TPCircularBuffer was added and used for a couple of buffers. The first buffer stores the original LPCM audio data from the RTL-SDR USB device. That buffer is also used as the input for the AudioConverter to resample the LPCM. The second buffer stores the output after the data is resampled, which is used as input to the AudioQueue for playback on the currently selected system audio device, usually the Mac speakers. Most of the processing occurs on threads threads. The first thread gets the RTL-SDR data and stores it to the first buffer. The second thread resamples the audio and stores it to the second buffer. The third thread retrieves the resampled data and renders it to audio.
In the initial test, AudioMonitor is running with about 2% CPU utilization. A known problem is that audio resampled from a lower source rate than 48000 Hz has buffering problems when using Icecast playback, that problem will be investigated and fixed. The project version was incremented to 1.11.
1 parent dd847c0 commit ede6f3f

47 files changed

Lines changed: 1901 additions & 8314 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

AudioMonitor/AudioMonitor.xcodeproj/project.pbxproj

Lines changed: 22 additions & 198 deletions
Large diffs are not rendered by default.

AudioMonitor/AudioMonitor/AudioMonitor.h

Lines changed: 26 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -8,31 +8,45 @@
88

99
#import <Foundation/Foundation.h>
1010

11-
#import "Novocaine.h"
12-
#import "RingBuffer.h"
11+
#import <AudioToolbox/AudioToolbox.h>
12+
#import <Accelerate/Accelerate.h>
13+
//#import "TPCircularBuffer+AudioBufferList.h"
14+
#import "TPCircularBuffer.h"
1315

1416

17+
// AudioQueue values
18+
#define kAudioQueueBuffersCount 3
19+
1520
@interface AudioMonitor : NSObject
1621
{
17-
AudioConverterRef inAudioConverter;
22+
AudioConverterRef inAudioConverter; // AudioConverter for resampling PCM data to 48000 Hz
23+
24+
AudioStreamBasicDescription audioConverterInputDescription;
25+
AudioStreamBasicDescription audioConverterOutputDescription;
1826

19-
AudioStreamBasicDescription inputDescription;
20-
AudioStreamBasicDescription outputDescription;
27+
AudioBuffer audioConverterInputAudioBuffer;
28+
UInt64 audioConverterInputBufferOffset;
29+
UInt32 audioConverterInputPacketsRemain;
2130

22-
AudioBuffer inputAudioBuffer;
23-
UInt64 inputBufferOffset;
24-
UInt32 inputPacketsRemain;
31+
TPCircularBuffer inputCircularBuffer; // TPCircularBuffer for storage and retrieval of input PCM data from stdin
32+
TPCircularBuffer audioConverterCircularBuffer; // TPCircularBuffer for storage and retrieval of resampled PCM data
2533

26-
AudioBufferList outputBufferList;
27-
void * outputBufferPtr;
28-
UInt32 outputBytes;
34+
AudioBufferList audioConverterOutputBufferList;
35+
void * audioConverterOutputBufferPtr;
36+
UInt32 audioConverterOutputBytes;
37+
38+
AudioQueueRef audioQueue; // AudioQueue for playing resampled PCM data to current audio output device, usually speakers
39+
40+
AudioStreamBasicDescription audioQueueDescription;
41+
AudioQueueBufferRef buffers[kAudioQueueBuffersCount];
42+
NSUInteger audioQueueIndex;
2943
}
3044

31-
@property (nonatomic, strong) Novocaine * audioManager;
3245
@property (assign) NSInteger sampleRate;
3346
@property (assign) float volume;
3447

3548

49+
3650
- (void)runAudioMonitorWithSampleRate:(NSInteger)sampleRate volume:(float)volume;
3751
- (void)convertBuffer:(void *)inputBufferPtr length:(UInt32)dataLength;
3852

0 commit comments

Comments
 (0)