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

Processing of mono AKAudioFiles causes crash #853

Closed
Audiograins opened this issue Apr 18, 2017 · 7 comments
Closed

Processing of mono AKAudioFiles causes crash #853

Audiograins opened this issue Apr 18, 2017 · 7 comments

Comments

@Audiograins
Copy link

@Audiograins Audiograins commented Apr 18, 2017

It seems that attempting to process a mono AKAudioFile will result in a crash. I tested this for both normalize() and reverse() and got the same result . I think normalized() is expecting self to be an array of floats so if the input to the function is mono it will result in a crash.

Log info below -

deleteFileWithFileName "131B033D-552D-4291-92C9-436C26C0376C.caf" deleted.
deleteFileWithFileName "3725B2AB-51C1-4E39-903F-234E9BA76679.caf" deleted.
deleteFileWithFileName "temp_recording.caf" deleted.
cleanTempDirectory() 3 files deleted
End of ViewDidLoad
This is run on the background queue
updatePCMBuffer() read 2383220 frames into buffer
-0.000132538
This is run on the main queue, after the previous code in outer block
2017-04-18 16:04:15.787097-0700 IASIAR[2021:298322] [central] 54:   ERROR:    [0x16dfdb000] >avae> AVAudioFile.mm:306: -[AVAudioFile writeFromBuffer:error:]: error -50
2017-04-18 16:04:15.787543-0700 IASIAR[2021:298322] *** Terminating app due to uncaught exception 'com.apple.coreaudio.avfaudio', reason: 'error -50'
*** First throw call stack:
(0x183b5efd8 0x1825c0538 0x183b5eeac 0x19dd131cc 0x19dd811dc 0x1003fd908 0x1003fd190 0x10035b36c 0x100078268 0x10007a830 0x1012d5a50 0x1012d5a10 0x1012e57dc 0x1012e539c 0x182c1f1d0 0x182c1ed7c)
libc++abi.dylib: terminating with uncaught exception of type NSException
(lldb) 
@aure
Copy link
Member

@aure aure commented Apr 19, 2017

Its quite possible that it expects the files to have the same number of channels as in the AudioKit settings.

@Audiograins
Copy link
Author

@Audiograins Audiograins commented Apr 19, 2017

Thanks Aure, I just updated the code with AKSettings.numberOfChannels = 1 and load only mono files but I get the same error, so that doesn't seem to be the case

@aure
Copy link
Member

@aure aure commented Apr 22, 2017

I'm thinking this might be easiest solved by converting the file to stereo, doing the processing, then creating a mono file again by dropping a channel.

@Audiograins
Copy link
Author

@Audiograins Audiograins commented Apr 25, 2017

That should be easy enough to do alright. Is there a function or approach in AudioKit to do this already?

@aure
Copy link
Member

@aure aure commented May 4, 2017

So, there are two parts of AudioKit that convert a file from stereo to mono, and it is in Swift:

https://github.com/audiokit/AudioKit/blob/master/AudioKit/Common/Nodes/Effects/Reverb/Convolution/AKConvolution.swift#L62

@aure
Copy link
Member

@aure aure commented Jun 1, 2017

AKSamplePlayer is a new player that creates a stereo file from a mono signal. I think you just need to use that code to create the file, process it and then do the conversion back to mono. Sorry that it has to be so convoluted, but we're just very stereo-centric with AudioKit.

@aure aure closed this Jun 1, 2017
@luizv
Copy link

@luizv luizv commented Dec 3, 2018

I have the same crash when trying to offlineRender.renderToUrl(_:) an AKAudioFile created with mono settings. ie.:

    settings["AVNumberOfChannelsKey"] = 1 // only one channel

Direct offlineRender.renderToURL(_:) is supported for mono files?
AKConvolution >>> AKOfflineRenderNode is still the recommended procedure?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
3 participants
You can’t perform that action at this time.