2012-01-03 10 views
6

मैंने विस्तारित ऑडियो फ़ाइल सेवाओं का उपयोग करके अपने ऐप द्वारा उत्पन्न पीसीएम ऑडियो डेटा को एन्कोड करने के लिए एक लूप लिखा था। एन्कोडिंग पृष्ठभूमि थ्रेड में समकालिक रूप से होती है, न कि वास्तविक समय में।विस्तारित ऑडियो फ़ाइल सेवाओं का उपयोग करके एमएए/एएसी को एम 4 ए/एएसी में विफल करने के लिए एक्स्टऑडियो फाइलवाइट (आईपैड 2, आईफोन 4 एस)

एन्कोडिंग आईओएस 4 और 5 दोनों के लिए आईपैड 1 और आईफोन 3gs/4 पर बेकार ढंग से काम करता है। हालांकि, दोहरी कोर डिवाइस (आईफोन 4 एस, आईपैड 2) के लिए ExtAudioFileWrite को तीसरा कॉल एन्कोडिंग थ्रेड को बिना स्टैक ट्रेस के क्रैश करता है और कोई त्रुटि कोड नहीं है।

यहाँ प्रश्न में कोड है:

डेटा स्वरूप

AudioStreamBasicDescription AUCanonicalASBD(Float64 sampleRate, 
             UInt32 channel){ 
AudioStreamBasicDescription audioFormat; 
audioFormat.mSampleRate   = sampleRate; 
audioFormat.mFormatID   = kAudioFormatLinearPCM; 
audioFormat.mFormatFlags  = kAudioFormatFlagsAudioUnitCanonical; 
audioFormat.mChannelsPerFrame = channel; 
audioFormat.mBytesPerPacket  = sizeof(AudioUnitSampleType); 
audioFormat.mBytesPerFrame  = sizeof(AudioUnitSampleType); 
audioFormat.mFramesPerPacket = 1; 
audioFormat.mBitsPerChannel  = 8 * sizeof(AudioUnitSampleType); 
audioFormat.mReserved   = 0; 
return audioFormat; 
} 

AudioStreamBasicDescription MixdownAAC(void){ 
AudioStreamBasicDescription audioFormat; 
audioFormat.mSampleRate   = 44100.0; 
audioFormat.mFormatID   = kAudioFormatMPEG4AAC; 
audioFormat.mFormatFlags  = kMPEG4Object_AAC_Main; 
audioFormat.mChannelsPerFrame = 2; 
audioFormat.mBytesPerPacket  = 0; 
audioFormat.mBytesPerFrame  = 0; 
audioFormat.mFramesPerPacket = 1024; 
audioFormat.mBitsPerChannel  = 0; 
audioFormat.mReserved   = 0; 
return audioFormat; 
} 

पाश प्रस्तुत करना

OSStatus err; 
ExtAudioFileRef outFile; 
NSURL *mixdownURL = [NSURL fileURLWithPath:filePath isDirectory:NO]; 

// internal data format 
AudioStreamBasicDescription localFormat = AUCanonicalASBD(44100.0, 2); 

// output file format 
AudioStreamBasicDescription mixdownFormat = MixdownAAC(); 
err = ExtAudioFileCreateWithURL((CFURLRef)mixdownURL, 
          kAudioFileM4AType, 
          &mixdownFormat, 
          NULL, 
          kAudioFileFlags_EraseFile, 
          &outFile); 


err = ExtAudioFileSetProperty(outFile, kExtAudioFileProperty_ClientDataFormat, sizeof(AudioStreamBasicDescription), &localFormat); 

// prep 
AllRenderData *allData = &allRenderData; 
writeBuffer = malloc(sizeof(AudioBufferList) + (2*sizeof(AudioBuffer))); 
writeBuffer->mNumberBuffers = 2; 
writeBuffer->mBuffers[0].mNumberChannels = 1; 
writeBuffer->mBuffers[0].mDataByteSize = bufferBytes; 
writeBuffer->mBuffers[0].mData = malloc(bufferBytes); 
writeBuffer->mBuffers[1].mNumberChannels = 1; 
writeBuffer->mBuffers[1].mDataByteSize = bufferBytes; 
writeBuffer->mBuffers[1].mData = malloc(bufferBytes); 

memset(writeBuffer->mBuffers[0].mData, 0, bufferBytes); 
memset(writeBuffer->mBuffers[1].mData, 0, bufferBytes); 

UInt32 framesToGet; 
UInt32 frameCount = allData->gLoopStartFrame; 
UInt32 startFrame = allData->gLoopStartFrame; 
UInt32 lastFrame = allData->gLoopEndFrame; 

// write one silent buffer 
ExtAudioFileWrite(outFile, bufferFrames, writeBuffer); 

while (frameCount < lastFrame){ 

    // how many frames do we need to get 
    if (lastFrame - frameCount > bufferFrames) 
     framesToGet = bufferFrames; 
    else 
     framesToGet = lastFrame - frameCount; 

    // get dem frames 
    err = theBigOlCallback((void*)&allRenderData, 
          NULL, NULL, 1, 
          framesToGet, writeBuffer); 

    // write to output file 
    ExtAudioFileWrite(outFile, framesToGet, writeBuffer); 

    frameCount += framesToGet; 
} 

// write one trailing silent buffer 
memset(writeBuffer->mBuffers[0].mData, 0, bufferBytes); 
memset(writeBuffer->mBuffers[1].mData, 0, bufferBytes); 
processLimiterInPlace8p24(limiter, writeBuffer->mBuffers[0].mData, writeBuffer->mBuffers[1].mData, bufferFrames); 
ExtAudioFileWrite(outFile, bufferFrames, writeBuffer); 

err = ExtAudioFileDispose(outFile); 

पीसीएम फ्रेम ठीक से बनाई गई हैं, लेकिन ExtAudioFileWrite 2/3rd समय में विफल रहता है यह कहा जाता है।

कोई भी विचार? धन्यवाद!

+0

क्या आप पोस्ट कर सकते हैं बफर भरें और आप ExtAudioFileWrite को कैसे कॉल कर रहे हैं? – sbooth

+0

ऐप्पल से बहुत निराशा और कोई मदद के बाद, मेरे सहकर्मी ने समस्या का पता लगाया। स्पष्ट रूप से नए आईओएस डिवाइस (आईपैड 2 और आईफोन 4 एस) पर, 44.1 केएचजेड एएसी एन्कोडिंग के लिए वैध नमूना दर नहीं है, कम से कम बाहरी ऑडियो फाइल सेवाओं का उपयोग करना। 48 kHz बस ठीक काम करता है। मैंने ऐप्पल को एक बग के रूप में दायर किया है, उम्मीद है कि वे इसका ख्याल रखेंगे। – roperklacks

उत्तर

17

मुझे एक बहुत ही ऐसी समस्या थी जहां मैं आईपैड 2 पर एक एम 4 ए फ़ाइल में पीसीएम ध्वनि स्ट्रीम करने के लिए विस्तारित ऑडियो फ़ाइल सेवाओं का उपयोग करने का प्रयास कर रहा था। सबकुछ काम पर दिखाई देता है सिवाय इसके कि ExtAudioFileWrite को प्रत्येक कॉल त्रुटि कोड लौटा - 66567 (kExtAudioFileError_MaxPacketSize अज्ञात)। आखिर में जो फिक्स मिला वह हार्डवेयर के बजाय "कोडेक निर्माता" को सॉफ़्टवेयर में सेट करना था। तो

UInt32 codecManf = kAppleSoftwareAudioCodecManufacturer; 
ExtAudioFileSetProperty(FileToWrite, kExtAudioFileProperty_CodecManufacturer, sizeof(UInt32), &codecManf); 

क्लाइंट डेटा प्रारूप सेट करने से ठीक पहले रखें।

इससे मुझे विश्वास होगा कि ऐप्पल के हार्डवेयर कोडेक्स केवल बहुत विशिष्ट एन्कोडिंग का समर्थन कर सकते हैं, लेकिन सॉफ़्टवेयर कोडेक्स अधिक विश्वसनीय रूप से आप जो चाहते हैं वह कर सकते हैं। मेरे मामले में, एम 4 ए में सॉफ़्टवेयर कोडेक अनुवाद एलपीसीएम प्रारूप में सटीक उसी फ़ाइल को लिखने से 50% लंबा लगता है।

क्या किसी को पता है कि ऐप्पल कहीं भी निर्दिष्ट करता है कि उनके ऑडियो कोडेक हार्डवेयर क्या सक्षम हैं? ऐसा लगता है कि सॉफ़्टवेयर इंजीनियरों क्लाइंट के लिए ऑडियोस्ट्रीम बेसिक डिस्क्रिप्शन और ऑडियोChannelLayout में ~ 20 पैरामीटर सेट करने के लिए घंटों के लंबे अनुमान लगाने वाले गेम खेल रहे हैं और कुछ काम करने तक फ़ाइल को हर संभव क्रमपरिवर्तन के लिए फ़ाइल के लिए ...

+0

मैंने दो दिन डिबगिंग बिताई क्यों एएसी एन्कोडिंग ने अचानक अपने आईफोन 4 एस पर कई ऐप्स में काम करना बंद कर दिया लेकिन मेरे अन्य आईओएस डिवाइस नहीं। यह चाल है। मुझे नहीं पता कि आपने इसे कैसे समझ लिया है, लेकिन आपके लिए बहुत कुछ है और आशा है कि आप SO पर अधिक पोस्ट करें। –

+0

मैंने अभी विस्तारित ऑडियो फ़ाइल सेवा संदर्भ के माध्यम से खोला और कुछ काम किए जाने तक चर के प्रत्येक संयोजन को सेट करने का प्रयास किया: पी Glad मैं मदद करने में सक्षम था! अब अगर कोई सिर्फ यह समझा सकता है कि उपकरणों की हार्डवेयर क्षमताओं इतनी असंगत क्यों हैं ... – user1021430

+0

मैन ... आपके लिए बड़े कुडोस। मैं सोच रहा था कि ExtAudioFileWrite के लिए मेरे कोड में इतनी गड़बड़ी नहीं हो रही थी कि कोई बैकट्रैक न हो। आपकी सहायता के लिए धन्यवाद. मैंने आपको धन्यवाद दिया है, इस पर धन्यवाद। उम्मीद है कि यह roperklacks से अन्य बग रिपोर्ट के साथ विलय हो जाएगा। एक बार फिर धन्यवाद। – Dan1one

संबंधित मुद्दे