2012-04-30 24 views
6

पाशन मैं OpenAL के साथ अपने खेल के लिए आवाज़ खेल रहा हूँ और मुझे लगता है कि कभी कभी एक छोटी सी गड़बड़ जबकि पाशन खेला जाता है कुछ समस्याएं हैं। लूपिंग के बिना मुझे एक छोटा पॉप मिलता है ... कभी-कभी लेकिन सभी नहीं।OpenAL बनाने गड़बड़ जब ध्वनि

मुझे लगता है कि बफर बहुत लंबा तो अंत में कुछ अनिर्धारित डेटा है वहाँ एक छोटे से किया जा रहा है के साथ कुछ नहीं है। मैं बस यह नहीं समझ सकता कि इसे कैसे बदला जाए। मैं इस समारोह के साथ एक CAF फ़ाइल लोड कर रहा हूँ:

void* MyGetOpenALAudioData(CFURLRef inFileURL, ALsizei *outDataSize, ALenum *outDataFormat, ALsizei *outSampleRate, ALdouble *duration) { 
OSStatus      err = noErr;  
SInt64       theFileLengthInFrames = 0; 
AudioStreamBasicDescription  theFileFormat; 
UInt32       thePropertySize = sizeof(theFileFormat); 
ExtAudioFileRef     extRef = NULL; 
void*       theData = NULL; 
AudioStreamBasicDescription  theOutputFormat; 

// Open a file with ExtAudioFileOpen() 
err = ExtAudioFileOpenURL(inFileURL, &extRef); 
if(err) { printf("MyGetOpenALAudioData: ExtAudioFileOpenURL FAILED, Error = %ld\n", err); goto Exit; } 

// Get the audio data format 
err = ExtAudioFileGetProperty(extRef, kExtAudioFileProperty_FileDataFormat, &thePropertySize, &theFileFormat); 
if(err) { printf("MyGetOpenALAudioData: ExtAudioFileGetProperty(kExtAudioFileProperty_FileDataFormat) FAILED, Error = %ld\n", err); goto Exit; } 
if (theFileFormat.mChannelsPerFrame > 2) { printf("MyGetOpenALAudioData - Unsupported Format, channel count is greater than stereo\n"); goto Exit;} 

// Set the client format to 16 bit signed integer (native-endian) data 
// Maintain the channel count and sample rate of the original source format 
theOutputFormat.mSampleRate = theFileFormat.mSampleRate; 
theOutputFormat.mChannelsPerFrame = theFileFormat.mChannelsPerFrame; 

theOutputFormat.mFormatID = kAudioFormatLinearPCM; 
theOutputFormat.mBytesPerPacket = 2 * theOutputFormat.mChannelsPerFrame; 
theOutputFormat.mFramesPerPacket = 1; 
theOutputFormat.mBytesPerFrame = 2 * theOutputFormat.mChannelsPerFrame; 
theOutputFormat.mBitsPerChannel = 16; 
theOutputFormat.mFormatFlags = kAudioFormatFlagsNativeEndian | kAudioFormatFlagIsPacked | kAudioFormatFlagIsSignedInteger; 

// Set the desired client (output) data format 
err = ExtAudioFileSetProperty(extRef, kExtAudioFileProperty_ClientDataFormat, sizeof(theOutputFormat), &theOutputFormat); 
if(err) { printf("MyGetOpenALAudioData: ExtAudioFileSetProperty(kExtAudioFileProperty_ClientDataFormat) FAILED, Error = %ld\n", err); goto Exit; } 

// Get the total frame count 
thePropertySize = sizeof(theFileLengthInFrames); 
err = ExtAudioFileGetProperty(extRef, kExtAudioFileProperty_FileLengthFrames, &thePropertySize, &theFileLengthInFrames); 
if(err) { printf("MyGetOpenALAudioData: ExtAudioFileGetProperty(kExtAudioFileProperty_FileLengthFrames) FAILED, Error = %ld\n", err); goto Exit; } 

// Read all the data into memory 
UInt32  dataSize = theFileLengthInFrames * theOutputFormat.mBytesPerFrame;; 
theData = malloc(dataSize); 
if (theData) 
{ 
    AudioBufferList  theDataBuffer; 
    theDataBuffer.mNumberBuffers = 1; 
    theDataBuffer.mBuffers[0].mDataByteSize = dataSize; 
    theDataBuffer.mBuffers[0].mNumberChannels = theOutputFormat.mChannelsPerFrame; 
    theDataBuffer.mBuffers[0].mData = theData; 

    // Read the data into an AudioBufferList 
    err = ExtAudioFileRead(extRef, (UInt32*)&theFileLengthInFrames, &theDataBuffer); 
    if(err == noErr) 
    { 
     // success 
     *outDataSize = (ALsizei)dataSize; 
     *outDataFormat = (theOutputFormat.mChannelsPerFrame > 1) ? AL_FORMAT_STEREO16 : AL_FORMAT_MONO16; 
     *outSampleRate = (ALsizei)theOutputFormat.mSampleRate; 
    } 
    else 
    { 
     // failure 
     free (theData); 
     theData = NULL; // make sure to return NULL 
     printf("MyGetOpenALAudioData: ExtAudioFileRead FAILED, Error = %ld\n", err); goto Exit; 
    } 
} 

// Alex(Colombiamug): get the file duration... 
// first, get the audioID for the file... 
AudioFileID audioID; 
UInt32 audioIDSize = sizeof(audioID); 
err = ExtAudioFileGetProperty(extRef, kExtAudioFileProperty_AudioFile, &audioIDSize, &audioID); 
if(err) { printf("MyGetOpenALAudioData: ExtAudioFileGetProperty(kExtAudioFileProperty_AudioFile) FAILED, Error = %ld\n", err); goto Exit; } 

//now the duration... 
double soundDuration; 
UInt32 durationSize = sizeof(soundDuration); 
err = AudioFileGetProperty(audioID, kAudioFilePropertyEstimatedDuration, &durationSize, &soundDuration); 
if(err) { printf("MyGetOpenALAudioData: AudioFileGetProperty(kAudioFilePropertyEstimatedDuration) FAILED, Error = %ld\n", err); goto Exit; } 

*duration = soundDuration; 
//printf("Audio duration:%f secs.\n", soundDuration); 

बाहर निकलें: // निपटान ExtAudioFileRef, यह अब जरूरत है अगर (extRef) ExtAudioFileDispose (extRef); डेटा वापस करें; }

यह इस soundengine का हिस्सा है: SoundEngine

मैं अपने CAF फ़ाइल नमूना कोड में सीधे डाल करने की कोशिश की है और यह एक ही छोटे गड़बड़ है। (यह CAF फ़ाइल पुराने एप्पल SoundEngine.cpp के साथ ठीक कर रहा था, लेकिन मैं उस के साथ अन्य मुद्दों पर था तो मैं बदलने का फैसला किया)

+0

पॉप पाश में एक अंतराल के परिणाम के रूप में हो सकता है। क्या आप पाश को लुप्त कर रहे हैं? – learnvst

+0

हाँ मैंने ध्वनिफाइल संपादित करते समय क्रॉसफ़ेडिंग किया था। यह मेरी soundeditor में पूरी तरह से पाशन है, इसलिए मैं जानता हूँ कि यह मेरे CAF फ़ाइल – broch

उत्तर

4

मेरे अपने प्रश्न का उत्तर देना;)

शुद्ध भाग्य से मैं स्वीकार करना होगा मैं करने की कोशिश की इस लाइन से kAudioFormatFlagIsPacked ध्वज निकालें:

theOutputFormat.mFormatFlags = kAudioFormatFlagsNativeEndian | kAudioFormatFlagIsPacked | kAudioFormatFlagIsSignedInteger; 

और है कि यह तय हो गई।

किसी को भी मुझे बता सकते हैं, तो क्यों यह अगर वहाँ मैं भी इसके बारे में सुनना पसंद करेंगे कि झंडा को दूर करने में कुछ समस्याएं भी हैं know..or के लिए अच्छा हो सकता है।

+0

एक ही मुद्दा नहीं है। इससे मेरी मदद नहीं हुई है। कोई अन्य समाधान? –

+0

मैं एक soundengine का उपयोग कर समाप्त हो गया है, अर्थात यह: https://github.com/alexrestrepo/SoundEngine यह एक बहुत बेहतर काम करने लगता है – broch

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