Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

moved source buffer struct member to local var in converter callback … #2

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,7 @@
buildSettings = {
ARCHS = "$(ARCHS_STANDARD_32_64_BIT)";
PRODUCT_NAME = "$(TARGET_NAME)";
SDKROOT = macosx10.7;
SDKROOT = macosx10.11;
};
name = Debug;
};
Expand All @@ -199,7 +199,7 @@
buildSettings = {
ARCHS = "$(ARCHS_STANDARD_32_64_BIT)";
PRODUCT_NAME = "$(TARGET_NAME)";
SDKROOT = macosx10.7;
SDKROOT = macosx10.11;
};
name = Release;
};
Expand Down
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
<?xml version="1.0" encoding="UTF-8"?>
<Scheme
LastUpgradeVersion = "0710"
version = "1.3">
<BuildAction
parallelizeBuildables = "YES"
buildImplicitDependencies = "YES">
<BuildActionEntries>
<BuildActionEntry
buildForTesting = "YES"
buildForRunning = "YES"
buildForProfiling = "YES"
buildForArchiving = "YES"
buildForAnalyzing = "YES">
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "011C4AA114A505C300A35D5F"
BuildableName = "CH06_AudioConverter"
BlueprintName = "CH06_AudioConverter"
ReferencedContainer = "container:CH06_AudioConverter.xcodeproj">
</BuildableReference>
</BuildActionEntry>
</BuildActionEntries>
</BuildAction>
<TestAction
buildConfiguration = "Debug"
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
shouldUseLaunchSchemeArgsEnv = "YES">
<Testables>
</Testables>
<MacroExpansion>
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "011C4AA114A505C300A35D5F"
BuildableName = "CH06_AudioConverter"
BlueprintName = "CH06_AudioConverter"
ReferencedContainer = "container:CH06_AudioConverter.xcodeproj">
</BuildableReference>
</MacroExpansion>
<AdditionalOptions>
</AdditionalOptions>
</TestAction>
<LaunchAction
buildConfiguration = "Debug"
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
launchStyle = "0"
useCustomWorkingDirectory = "NO"
ignoresPersistentStateOnLaunch = "NO"
debugDocumentVersioning = "YES"
debugServiceExtension = "internal"
allowLocationSimulation = "YES">
<BuildableProductRunnable
runnableDebuggingMode = "0">
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "011C4AA114A505C300A35D5F"
BuildableName = "CH06_AudioConverter"
BlueprintName = "CH06_AudioConverter"
ReferencedContainer = "container:CH06_AudioConverter.xcodeproj">
</BuildableReference>
</BuildableProductRunnable>
<AdditionalOptions>
</AdditionalOptions>
</LaunchAction>
<ProfileAction
buildConfiguration = "Release"
shouldUseLaunchSchemeArgsEnv = "YES"
savedToolIdentifier = ""
useCustomWorkingDirectory = "NO"
debugDocumentVersioning = "YES">
<BuildableProductRunnable
runnableDebuggingMode = "0">
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "011C4AA114A505C300A35D5F"
BuildableName = "CH06_AudioConverter"
BlueprintName = "CH06_AudioConverter"
ReferencedContainer = "container:CH06_AudioConverter.xcodeproj">
</BuildableReference>
</BuildableProductRunnable>
</ProfileAction>
<AnalyzeAction
buildConfiguration = "Debug">
</AnalyzeAction>
<ArchiveAction
buildConfiguration = "Release"
revealArchiveInOrganizer = "YES">
</ArchiveAction>
</Scheme>
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>SchemeUserState</key>
<dict>
<key>CH06_AudioConverter.xcscheme</key>
<dict>
<key>orderHint</key>
<integer>0</integer>
</dict>
</dict>
<key>SuppressBuildableAutocreation</key>
<dict>
<key>011C4AA114A505C300A35D5F</key>
<dict>
<key>primary</key>
<true/>
</dict>
</dict>
</dict>
</plist>
20 changes: 11 additions & 9 deletions CH06_AudioConverter/CH06_AudioConverter/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
#endif


#define kInputFileLocation CFSTR("/Insert/Path/To/Audio/File.xxx")
#define kInputFileLocation CFSTR("/Users/alexanderbollbach/Desktop/qt.m4a")

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should revert this back to the generic path /Insert/Path/To/Audio/File.xxx, since other users won't have an alexanderbollbach directory, and it's better for them to blow up on a self-explanatory problem if they forget to reset the kInputFileLocation.

// #define kInputFileLocation CFSTR("/Users/kevin/Desktop/tmp_storage/audio_tests/cdsd_scratch.aiff")
// #define kInputFileLocation CFSTR("/Volumes/Sephiroth/Tunes//菅野よう子/ESCAFLOWNE - ORIGINAL MOVIE SOUNDTRACK/We're flying.m4a")

Expand All @@ -24,7 +24,7 @@ typedef struct MyAudioConverterSettings
AudioStreamPacketDescription *inputFilePacketDescriptions; // array of packet descriptions for read buffer

// KEVIN: sourceBuffer is never used outside of the callback. why couldn't it be a local there?
void *sourceBuffer;


} MyAudioConverterSettings;

Expand Down Expand Up @@ -68,7 +68,9 @@ OSStatus MyAudioConverterCallback(AudioConverterRef inAudioConverter,
AudioStreamPacketDescription **outDataPacketDescription,
void *inUserData)
{
MyAudioConverterSettings *audioConverterSettings = (MyAudioConverterSettings *)inUserData;
void *sourceBuffer = 0;

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

C convention is to use NULL for uninitialized pointers, not 0 (though i can't promise we get it right throughout the book).


MyAudioConverterSettings *audioConverterSettings = (MyAudioConverterSettings *)inUserData;

// initialize in case of failure
ioData->mBuffers[0].mData = NULL;
Expand All @@ -81,13 +83,13 @@ OSStatus MyAudioConverterCallback(AudioConverterRef inAudioConverter,
if(*ioDataPacketCount == 0)
return noErr;

if (audioConverterSettings->sourceBuffer != NULL)
if (sourceBuffer != NULL)
{
free(audioConverterSettings->sourceBuffer);
audioConverterSettings->sourceBuffer = NULL;
free(sourceBuffer);
sourceBuffer = NULL;
}

audioConverterSettings->sourceBuffer = (void *)calloc(1, *ioDataPacketCount * audioConverterSettings->inputFilePacketMaxSize);
sourceBuffer = (void *)calloc(1, *ioDataPacketCount * audioConverterSettings->inputFilePacketMaxSize);

UInt32 outByteCount = 0;
OSStatus result = AudioFileReadPackets(audioConverterSettings->inputFile,
Expand All @@ -96,7 +98,7 @@ OSStatus MyAudioConverterCallback(AudioConverterRef inAudioConverter,
audioConverterSettings->inputFilePacketDescriptions,
audioConverterSettings->inputFilePacketIndex,
ioDataPacketCount,
audioConverterSettings->sourceBuffer);
sourceBuffer);

// it's not an error if we just read the remainder of the file
#ifdef MAC_OS_X_VERSION_10_7
Expand All @@ -120,7 +122,7 @@ OSStatus MyAudioConverterCallback(AudioConverterRef inAudioConverter,
}
*/
// chris' hacky asssume-one-buffer equivalent
ioData->mBuffers[0].mData = audioConverterSettings->sourceBuffer;
ioData->mBuffers[0].mData = sourceBuffer;
ioData->mBuffers[0].mDataByteSize = outByteCount;

if (outDataPacketDescription)
Expand Down