summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorxant <xant@dyne.org>2013-07-08 16:05:17 (GMT)
committer xant <xant@dyne.org>2013-07-08 16:05:17 (GMT)
commit56b56931c396902dd7ef3febcc28cea1b5bdc906 (patch)
tree172ea1f3db5b873ed1d98f4ecf9424b78724ecc0
parent4167aea761c5803fa742d78c8e502b6bfbed267c (diff)
audio dumper + debugging the spectrum analyzer
-rw-r--r--JMX.xcodeproj/project.pbxproj14
-rw-r--r--JMXAppDelegate.m3
-rw-r--r--core/JMXAudioDumper.h27
-rw-r--r--core/JMXAudioDumper.mm63
-rw-r--r--entities/JMXAudioOutput.mm3
-rw-r--r--entities/JMXAudioSpectrumAnalyzer.h2
-rw-r--r--entities/JMXAudioSpectrumAnalyzer.mm2
-rw-r--r--entities/audio/JMXAudioToneGenerator.mm2
8 files changed, 107 insertions, 9 deletions
diff --git a/JMX.xcodeproj/project.pbxproj b/JMX.xcodeproj/project.pbxproj
index 299e65d..531721b 100644
--- a/JMX.xcodeproj/project.pbxproj
+++ b/JMX.xcodeproj/project.pbxproj
@@ -71,6 +71,7 @@
AA0A89C01675E09C00FF784F /* JMXAudioToneGenerator.mm in Sources */ = {isa = PBXBuildFile; fileRef = AA0A89BF1675E09C00FF784F /* JMXAudioToneGenerator.mm */; };
AA0BFDFE1587E5B600D3C8E4 /* Phidget21.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = AA0BFDFD1587E5B600D3C8E4 /* Phidget21.framework */; settings = {ATTRIBUTES = (Weak, ); }; };
AA1E53AD14AE114D00F80337 /* JMXGraphFragment.mm in Sources */ = {isa = PBXBuildFile; fileRef = AA1E53AC14AE114D00F80337 /* JMXGraphFragment.mm */; };
+ AA29A2E7167E3F7D000AE0EA /* JMXAudioDumper.mm in Sources */ = {isa = PBXBuildFile; fileRef = AA29A2E6167E3F7D000AE0EA /* JMXAudioDumper.mm */; };
AA2BE3F312353BA6006087E7 /* CoreAudio.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = AA2BE3F212353BA6006087E7 /* CoreAudio.framework */; };
AA2BE40B12353D5C006087E7 /* Accelerate.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = AA2BE40A12353D5C006087E7 /* Accelerate.framework */; };
AA3557441277468800EAA2E4 /* JMXTextRenderer.m in Sources */ = {isa = PBXBuildFile; fileRef = AA3557001277347300EAA2E4 /* JMXTextRenderer.m */; };
@@ -445,6 +446,8 @@
AA1E53AB14AE114D00F80337 /* JMXGraphFragment.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = JMXGraphFragment.h; sourceTree = "<group>"; };
AA1E53AC14AE114D00F80337 /* JMXGraphFragment.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = JMXGraphFragment.mm; sourceTree = "<group>"; };
AA1E53B714AF60F200F80337 /* Global.js */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.javascript; path = Global.js; sourceTree = "<group>"; };
+ AA29A2E5167E3F7D000AE0EA /* JMXAudioDumper.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = JMXAudioDumper.h; path = core/JMXAudioDumper.h; sourceTree = SOURCE_ROOT; };
+ AA29A2E6167E3F7D000AE0EA /* JMXAudioDumper.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; name = JMXAudioDumper.mm; path = core/JMXAudioDumper.mm; sourceTree = SOURCE_ROOT; };
AA2BE3F212353BA6006087E7 /* CoreAudio.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = CoreAudio.framework; path = System/Library/Frameworks/CoreAudio.framework; sourceTree = SDKROOT; };
AA2BE40A12353D5C006087E7 /* Accelerate.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = Accelerate.framework; path = System/Library/Frameworks/Accelerate.framework; sourceTree = SDKROOT; };
AA3556F41277340200EAA2E4 /* JMXTextEntity.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = JMXTextEntity.h; sourceTree = "<group>"; };
@@ -1391,14 +1394,16 @@
AA8CC473128745B600A17115 /* Audio */ = {
isa = PBXGroup;
children = (
- 825C31001275ADB6006376B8 /* JMXAudioMixer.h */,
- 825C31011275ADB6006376B8 /* JMXAudioMixer.mm */,
+ AA29A2E5167E3F7D000AE0EA /* JMXAudioDumper.h */,
+ AA29A2E6167E3F7D000AE0EA /* JMXAudioDumper.mm */,
825C30EC1275ADB6006376B8 /* JMXAudioFileEntity.h */,
825C30ED1275ADB6006376B8 /* JMXAudioFileEntity.mm */,
- 825C30F01275ADB6006376B8 /* JMXQtAudioCaptureEntity.h */,
- 825C30F11275ADB6006376B8 /* JMXQtAudioCaptureEntity.mm */,
+ 825C31001275ADB6006376B8 /* JMXAudioMixer.h */,
+ 825C31011275ADB6006376B8 /* JMXAudioMixer.mm */,
AA0A89BE1675E09C00FF784F /* JMXAudioToneGenerator.h */,
AA0A89BF1675E09C00FF784F /* JMXAudioToneGenerator.mm */,
+ 825C30F01275ADB6006376B8 /* JMXQtAudioCaptureEntity.h */,
+ 825C30F11275ADB6006376B8 /* JMXQtAudioCaptureEntity.mm */,
);
name = Audio;
path = audio;
@@ -1999,6 +2004,7 @@
AA9B58D914FE1E4F00F63C33 /* NSNumber+V8.mm in Sources */,
AA9B58DA14FE1E4F00F63C33 /* NSString+V8.mm in Sources */,
AA0A89C01675E09C00FF784F /* JMXAudioToneGenerator.mm in Sources */,
+ AA29A2E7167E3F7D000AE0EA /* JMXAudioDumper.mm in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
diff --git a/JMXAppDelegate.m b/JMXAppDelegate.m
index d848ebe..7f99f8f 100644
--- a/JMXAppDelegate.m
+++ b/JMXAppDelegate.m
@@ -42,6 +42,7 @@
#import "JMXGlobals.h"
#import "JMXLibraryTableView.h"
#import "JMXHIDInputEntity.h"
+#import "JMXAudioDumper.h"
#import "CIAlphaBlend.h"
#import "CIAdditiveBlur.h"
#import <QTKit/QTKit.h>
@@ -68,6 +69,8 @@
[sharedContext registerClass:[JMXScriptLive class]];
[sharedContext registerClass:[JMXHIDInputEntity class]];
[sharedContext registerClass:[JMXAudioToneGenerator class]];
+ [sharedContext registerClass:[JMXAudioDumper class]];
+
//[QTMovie initialize];
[CIAlphaBlend class]; // trigger initialize to have the filter registered and available in the videomixer
[CIAdditiveBlur class];
diff --git a/core/JMXAudioDumper.h b/core/JMXAudioDumper.h
new file mode 100644
index 0000000..d8d509e
--- /dev/null
+++ b/core/JMXAudioDumper.h
@@ -0,0 +1,27 @@
+//
+// JMXAudioDumper.h
+// JMX
+//
+// Created by xant on 9/28/10.
+// Copyright 2010 Dyne.org. All rights reserved.
+//
+
+#import <Cocoa/Cocoa.h>
+#import "JMXEntity.h"
+
+#define kJMXAudioMixerSamplesBufferCount 512
+
+@class JMXPin;
+@class JMXAudioBuffer;
+@class JMXAudioDevice;
+
+@interface JMXAudioDumper : JMXEntity {
+@protected
+ NSArray *audioInputs;
+ JMXInputPin *audioInputPin;
+@private
+}
+
+@end
+
+
diff --git a/core/JMXAudioDumper.mm b/core/JMXAudioDumper.mm
new file mode 100644
index 0000000..5fe0140
--- /dev/null
+++ b/core/JMXAudioDumper.mm
@@ -0,0 +1,63 @@
+//
+// JMXAudioMixer.m
+// JMX
+//
+// Created by xant on 9/28/10.
+// Copyright 2010 Dyne.org. All rights reserved.
+//
+
+#import "JMXAudioDumper.h"
+#include <Accelerate/Accelerate.h>
+#import "JMXAudioFormat.h"
+#import "JMXAudioDevice.h"
+#import <QuartzCore/QuartzCore.h>
+#import "JMXThreadedEntity.h"
+#import <AudioToolbox/AudioConverter.h>
+
+@implementation JMXAudioDumper
+{
+ FILE *outFile;
+ int dumpCounter;
+}
+
+- (id)init
+{
+ self = [super init];
+ if (self) {
+ audioInputPin = [self registerInputPin:@"audio" withType:kJMXAudioPin andSelector:@"audio:"];
+ outFile = fopen("/tmp/jmx-audiodumper.dump", "w");
+
+ return self;
+ }
+ return nil;
+}
+
+- (void)dealloc
+{
+ if (outFile)
+ fclose(outFile);
+ [super dealloc];
+}
+
+- (void)audio:(JMXAudioBuffer *)buffer
+{
+ AudioStreamBasicDescription inputDescription = buffer.format.audioStreamBasicDescription;
+
+ if (inputDescription.mFormatID != kAudioFormatLinearPCM)
+ return;
+
+ if (inputDescription.mFramesPerPacket != 1)
+ return;
+
+ const int BufferCount = 100;
+
+ if (dumpCounter++ < BufferCount)
+ fwrite(buffer.data.bytes, 1, buffer.data.length, outFile);
+
+ if (dumpCounter++ == BufferCount) {
+ fclose(outFile);
+ outFile = nil;
+ }
+}
+
+@end
diff --git a/entities/JMXAudioOutput.mm b/entities/JMXAudioOutput.mm
index d8d9754..f66b5fe 100644
--- a/entities/JMXAudioOutput.mm
+++ b/entities/JMXAudioOutput.mm
@@ -230,8 +230,7 @@ static OSStatus _FillComplexBufferProc (
- (void)dealloc
{
- if (format)
- [format dealloc];
+ [format release];
for (int i = 0; i < kJMXAudioOutputSamplesBufferCount; i++) {
if (samples[i])
[samples[i] release];
diff --git a/entities/JMXAudioSpectrumAnalyzer.h b/entities/JMXAudioSpectrumAnalyzer.h
index 2c306a1..72201da 100644
--- a/entities/JMXAudioSpectrumAnalyzer.h
+++ b/entities/JMXAudioSpectrumAnalyzer.h
@@ -10,7 +10,7 @@
#import <AudioToolbox/AudioConverter.h>
#import "JMXEntity.h"
-#define kJMXAudioSpectrumNumFrequencies 14
+#define kJMXAudioSpectrumNumFrequencies 512
#define kJMXAudioSpectrumImageBufferCount 32
@class JMXSpectrumAnalyzer;
diff --git a/entities/JMXAudioSpectrumAnalyzer.mm b/entities/JMXAudioSpectrumAnalyzer.mm
index 3cd13a5..160a319 100644
--- a/entities/JMXAudioSpectrumAnalyzer.mm
+++ b/entities/JMXAudioSpectrumAnalyzer.mm
@@ -209,7 +209,7 @@ static int _defaultFrequencies[kJMXAudioSpectrumNumFrequencies] =
for (UInt32 i = 0; i < kJMXAudioSpectrumNumFrequencies; i++) { // for each frequency
int freq = [[frequencies objectAtIndex:i] intValue];
- int offset = freq*numBins/44100*analyzer.numChannels;
+ int offset = freq*numBins/(44100*analyzer.numChannels);
Float32 value = (((Float32 *)(spectrumBuffer->mBuffers[0].mData))[offset] +
((Float32 *)(spectrumBuffer->mBuffers[1].mData))[offset]) * 0.5;
if (value < 0.0)
diff --git a/entities/audio/JMXAudioToneGenerator.mm b/entities/audio/JMXAudioToneGenerator.mm
index 3657e3f..992a51d 100644
--- a/entities/audio/JMXAudioToneGenerator.mm
+++ b/entities/audio/JMXAudioToneGenerator.mm
@@ -83,7 +83,7 @@
copy:NO
freeOnRelease:YES];
// Fixed amplitude is good enough for our purposes
- const double amplitude = 0.25;
+ const double amplitude = 0.50;
double freq = [frequency doubleValue];
double theta1_increment = 2.0 * M_PI * freq / self->sampleRate;
double theta2_increment = 2.0 * M_PI * (freq + [channelSkew doubleValue]) / self->sampleRate;