AudioToolbox

RSS for tag

Record or play audio convert formats parse audio streams and configure your audio session using AudioToolbox.

Posts under AudioToolbox tag

141 Posts

Post

Replies

Boosts

Views

Activity

Using kAudioDevicePropertyIcon to get the icon of an audio device produces status: 2003332927
Hi, I am developing a macOS application in SwiftUI (Xcode Version 14.3 (14E222b)) which lets the users control the audio level (volume) of the running applications individually, and also enables them to change the default speaker of each running application by letting them select an audio device from a list of available audio devices connected to the Mac. Till now, I have been able to get the following: List of running applications using NSWorkspace.shared.runningApplications The default audio device using kAudioHardwarePropertyDefaultOutputDevice with id and name List of audio devices using kAudioHardwarePropertyDevices with ids and names I am trying to get the icon of the devices using kAudioDevicePropertyIcon, but it is not working. I have written the following program to achieve the same: var deviceIcon: CFTypeRef? var deviceIconSize = UInt32(MemoryLayout<CFTypeRef>.size) var deviceIconPropertyAddress = AudioObjectPropertyAddress( mSelector: kAudioDevicePropertyIcon, mScope: kAudioObjectPropertyScopeGlobal, mElement: defaultOutputDeviceID) var status = AudioObjectGetPropertyData( defaultOutputDeviceID, &deviceIconPropertyAddress, 0, nil, &deviceIconSize, &deviceIcon) guard status == noErr else { print("Error getting default output device icon: \(status)") return } When I run the above program, I get the following output: Error getting default output device icon: 2003332927 defaultOutputDeviceID is the id of the default audio device. For now, I am just trying to get the icon of the default speaker which, in my case, is MacBook Air Speakers. I have tried searching for this status code, and I found that this error is defined in AudioFile.h as kAudioFileUnspecifiedError = 'wht?', // 0x7768743F, 2003334207. Does this mean that there is no icon for the specified deviceID, or is there something wrong with my program? Could someone please let me know how to resolve this error? Thank you!
0
0
2.1k
Apr ’23
AAC decoding with Audio Toolbox is failing in Monterey RC
When I use Audio Toolbox APIs to decode AAC audio, I am getting kAudioConverterErr_FormatNotSupported(1718449215) error. This works fine in BigSur(11.5.2) and previous versions. prompt> ./ffmpeg -c:a aac_at -i audio24b_he_aac.aac -f s16le -acodec pcm_s16le output.pcm -v trace ffmpeg version N-104401-gcd38fbf4f7 Copyright (c) 2000-2021 the FFmpeg developers  built with Apple clang version 13.0.0 (clang-1300.0.29.3)  configuration: --disable-x86asm  libavutil   57. 7.100 / 57. 7.100  libavcodec   59. 12.100 / 59. 12.100  libavformat  59. 6.100 / 59. 6.100  libavdevice  59. 0.101 / 59. 0.101  libavfilter   8. 15.100 / 8. 15.100  libswscale   6. 1.100 / 6. 1.100  libswresample  4. 0.100 / 4. 0.100 Splitting the commandline. Reading option '-c:a' ... matched as option 'c' (codec name) with argument 'aac_at'. Reading option '-i' ... matched as input url with argument 'audio24b_he_aac.aac'. Reading option '-f' ... matched as option 'f' (force format) with argument 's16le'. Reading option '-acodec' ... matched as option 'acodec' (force audio codec ('copy' to copy stream)) with argument 'pcm_s16le'. Reading option 'output.pcm' ... matched as output url. Reading option '-v' ... matched as option 'v' (set logging level) with argument 'trace'. Finished splitting the commandline. Parsing a group of options: global . Applying option v (set logging level) with argument trace. Successfully parsed a group of options. Parsing a group of options: input url audio24b_he_aac.aac. Applying option c:a (codec name) with argument aac_at. Successfully parsed a group of options. Opening an input file: audio24b_he_aac.aac. [NULL @ 0x7f8cf4004d40] Opening 'audio24b_he_aac.aac' for reading [file @ 0x7f8cf4005180] Setting default whitelist 'file,crypto,data' Probing aac score:51 size:2048 [aac @ 0x7f8cf4004d40] Format aac probed with size=2048 and score=51 [aac @ 0x7f8cf4004d40] Before avformat_find_stream_info() pos: 0 bytes read:65696 seeks:4 nb_streams:1 [aac_at @ 0x7f8cf40057c0] AudioToolbox init error: 1718449215 [aac @ 0x7f8cf4004d40] All info found [aac @ 0x7f8cf4004d40] Estimating duration from bitrate, this may be inaccurate Following lines of code is failing. status = AudioConverterNew(&in_format, &out_format, &at->converter); if (status != 0) { av_log(avctx, AV_LOG_ERROR, "AudioToolbox init error: %i\n", (int)status); return AVERROR_UNKNOWN; } Is there any change with respect to these APIs in Monterey. I could not find any thing in the documentation or release notes.
1
0
2.3k
Mar ’23
Audio input bandwidth
My app samples the various inputs available on the iPhone and iPad and performs a frequency analysis. In addition to using the internal accelerometer and gyroscope I can also sample the microphone and USB input devices such as accelerometers through the audio input subsystem. The highest sample rate I use with the microphone and USB devices is the 48 KHz of the audio sampling subsystem. This provides a bandwidth of 24 kHz (Nyquist frequency) on the sampled signal. This has worked for many generations of iPhone and iPad until now. When I use my iPhone 14 Pro there is a sharp frequency cutoff at about 8 kHz. I see an artifact at the same frequency when I use the simulators. BUT when I use my 11" iPad Pro, or my current generation iPhone SE I do not see this effect and get good data out to 24 kHz. The iPad Pro does show some rolloff near 24 kHz which is noticeable but not a problem for most applications. The rolloff at 8 kHz is a serious problem for my customers who are testing equipment vibration and noise. I am wondering if this is related to the new microphone options "Standard", "Voice Isolation", and "Wide Spectrum". But if so, why only on the iPhone 14Pro and the simulators? I have searched the documentation but apparently it is not possible to programmatically change the microphone mode and the Apple documentation on how to use this new feature is lacking. I am using AVAudioSession and AVAudioRecorder methods to acquire the data through the audio capture hardware. This code has been working well for me for over 10 years so I do not think it is a code problem but it could be a configuration problem because of new hardware in the iPhone 14 although I have not found anything in the documentation. Examples from various devices and a simulator are shown below for microphone. Does anyone have an idea what may be causing this problem? iPhoneSE 3rd Gen iPad Gen 9 iPad Pro 11in iPhone 14Pro iPad 10th Generation Simulator
0
0
1.5k
Mar ’23
Starting recording from background for a VoIP application.
After searching for a few days, i have come to know that iOS doesn't allow recording in background. Through recording continues when it has started in foreground and goes to background. Came to know that, "This is a new a privacy protection restriction introduced in 12.4" When trying to start recording from background, we get “AVAudioSession.ErrorCode.cannotStartRecording” error. What do i need: our application needs to starts recording audio and transmit it while in background when user presses an external button i.e. PTT button of a BLE device. It seems there are several similar issue posted in this forum but neither could i find any plausible solution nor got any specific documentation from Apple. Requesting to help me out or at least please provide me a specific documentation stating "background recording is not possible". And if any workaround exists, please suggest. P.S. we are using **AVAudioSession.sharedInstance().setCategory(.playAndRecord, mode: .spokenAudio, options: [.mixWithOthers, .allowBluetooth, .allowBluetoothA2DP, .duckOthers]) **
0
0
1.4k
Feb ’23
core audio API library
I have a High Sierra system which I access via ssh and for which I program old-style from the command line in Objective-C and build via Makefiles. I have a very small program that employs the CoreAudio API and calls the AudioFileOpenURL and AudioFileClose functions. The program compiles ok but the linker is reporting that the symbols AudioFileOpenURL and AudioFileClose are undefined. I cannot find any dylib file among the libraries on my system that has those symbols. Can someone suggest where I might obtain the appropriate library? Here is the linker output that I am getting: gcc -o example1 example1.o -lobjc -lextension Undefined symbols for architecture x86_64: "_AudioFileClose", referenced from: _main in example1.o "_AudioFileGetProperty", referenced from: _main in example1.o "_AudioFileGetPropertyInfo", referenced from: _main in example1.o "_AudioFileOpenURL", referenced from: _main in example1.o ld: symbol(s) not found for architecture x86_64 clang: error: linker command failed with exit code 1 (use -v to see invocation) make: *** [example1] Error 1
1
0
1.5k
Feb ’23
Write AAC files in a way that they are readable even in a crash
I'm building an audio recording app. For our users it's important that recordings never get lost - even if the app crashes, users would like to have the partial recording. We encode recordings in AAC or ALAC and store them in an m4a file using AVAudioFile. However, in case the app crashes, those m4a files are invalid - the MOOV atom is missing. Are there recording settings that change the m4a file so that it is always playable, even if the recording is interrupted half-way? I'm not at all an expert in audio codecs, but from what I understand, it is possible to write the MOOV atom at the beginning of the audio file instead of the end. This could solve this. But of course, I'd prefer an actual expert to tell me what a good solution is, and how to configure this in AVAudioFile.
3
1
2.3k
Feb ’23
Writing tapped buffers to disk asynchronously
I'd like to understand the most robust way to record audio to disk using AVAudioNodes installTap(onBus:bufferSize:format:block:) method. Currently, I'm dispatching out the buffers I receive in my AVAudioNodeTapBlock to a serial dispatch queue then writing to disk using some Audio Toolbox methods, but my concern is that if I hold on to the buffer provided in the AVAudioNodeTapBlock for too long (due to disk I/O for example), I'll end up getting issues. What I'm considering is creating my own larger pool of preallocated AVAudioPCMBuffers (a few seconds worth) and copying across the data from the buffer provided by the tap into one of the buffers from this larger pool in the AVAudioNodeTapBlock directly (no dispatch queue). Is there a simpler way of handling this, or does this sound like the best route?
1
0
1.4k
Feb ’23
Low level audio recording on macOS. Please Help!
I am struggling to see why the following low-level audio recording function - which is based on tn2091 - Device input using the HAL Output Audio Unit - (a great article, btw, although a bit dated, and it would be wonderful if it was updated to use Swift and non deprecated stuff at some point!) fails to work under macOS: func createMicUnit() -> AUAudioUnit { let compDesc = AudioComponentDescription( componentType: kAudioUnitType_Output, componentSubType: kAudioUnitSubType_HALOutput, // I am on macOS, os this is good componentManufacturer: kAudioUnitManufacturer_Apple, componentFlags: 0, componentFlagsMask: 0) return try! AUAudioUnit(componentDescription: compDesc, options: []) } func startMic() { // mic permision is already granted at this point, but let's check let status = AVCaptureDevice.authorizationStatus(for: AVMediaType.audio) precondition(status == .authorized) // yes, all good let unit = createMicUnit() unit.isInputEnabled = true unit.isOutputEnabled = false precondition(!unit.canPerformInput) // can't record yet, and know why? print(deviceName(unit.deviceID)) // "MacBook Pro Speakers" - this is why let micDeviceID = defaultInputDeviceID print(deviceName(micDeviceID)) // "MacBook Pro Microphone" - this is better try! unit.setDeviceID(micDeviceID) // let's switch device to mic precondition(unit.canPerformInput) // now we can record print("\(String(describing: unit.channelMap))") // channel map is "nil" by default unit.channelMap = [0] // not sure if this helps or not let sampleRate = deviceActualFrameRate(micDeviceID) print(sampleRate) // 48000.0 let format = AVAudioFormat( commonFormat: .pcmFormatFloat32, sampleRate: sampleRate, channels: 1, interleaved: false)! try! unit.outputBusses[1].setFormat(format) unit.inputHandler = { flags, timeStamp, frameCount, bus in fatalError("never gets here") // now the weird part - this is never called! } try! unit.allocateRenderResources() try! unit.startHardware() // let's go! print("mic should be working now... why it doesn't?") // from now on the (UI) app continues its normal run loop } All sanity checks pass with flying colors but unit's inputHandler is not being called. Any idea why? Thank you!
3
0
2.5k
Jan ’23
MIDI file generated by using MusicSequenceFileCreate has Sysex MIDI message (iOS 16.0.2)
I am using the MusicSequenceFileCreate method to generate a MIDI file from a beat-based MusicSequence. In iOS 16.0.2 devices, the file that is created has a Sysex MIDI message added (not by me) to the file at time 0: f0 2a 11 67 40 40 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ff ff ff ff 00 00 00 00 00 00 00 00 00 00 f7 Sysex messages are manufacturer dependent, a file with this Sysex message can't be read into apps like Nanostudio, Ableton, Zenbeats. It can be read by GarageBand. My app's deployment target is iOS 13.0. Has anybody else ran into this issue? Thanks
1
0
1.5k
Oct ’22
Sound decibel recognition
Hi Community Members, We tried to find the particular sound through the microphone. We used PKCCheck to detect the sound decibel. we detect the sound based on the number of dB values per second we receive and add some logic over it to get the result, but when we have continuous sound like an alarm we can't detect it as the gap between the sound is very less. Any suggestion on libraries to achieve this. Also whether we can achieve this thru Frequency & Amplitude method. Please advise.
0
0
1.5k
Oct ’22
Microphone is disabled when trying to record (using getUserMedia)
I built a simple recorder on my website for users to record and playback audio. It works on ALL desktop browsers (including Safari) but when I use any browser on my iPhone, the mic is active at the opposite time. The flow is: ask permission > user allows mic access > user presses record > records audio > saves and plays back On iPhone what's happening is after the user allows permission, the mic goes active (visualized by the mic icon in safari browser) and then once the user presses record, it disables the mic. I am using getUserMedia within a React.js app Why is it doing this?
1
0
1.9k
Sep ’22
AudioUnit: AUParameterEvent vs AUParameterTree implementorValueObserver
Hello, I'm trying to write my own audio unit extension and I have a problem. I don't understand the difference between implementorValueObserver and AUParameterEvent. It looks like both of them can be used to update parameters in DSPKernel. It seems natural to use an observer, but it requires to think about thread safety in contrast to AUParameterEvent handling. Can someone comment on this or give me more context about this two entities?
0
0
1.1k
Aug ’22
How set CBR in AVAudioConverter?
I am using AVAudioConverter in Objective C. AVAudioConverter has bitRate and bitRateStrategy parameters defined. The default bitRateStrategy value is AVAudioBitRateStrategy_LongTermAverage. If I set bitRateStrategy to AVAudioBitRateStrategy_Constant there is no change. The bitRate variable works correctly. AVAudioConverter *audioConverter = [[AVAudioConverter alloc] initFromFormat:inputFormat toFormat:outputFormat]; audioConverter.bitRate = 128000; audioConverter.bitRateStrategy = AVAudioBitRateStrategy_Constant;
0
0
1.2k
Aug ’22
Why is internalRenderBlock fetched and used before allocateRenderResources() is called?
I have a working AUv3 AUAudioUnit app extension but I had to work around a strange issue: I found that the internalRenderBlock value is fetched and invoked before allocateRenderResources() is called. I have not found any documentation stating that this would be the case, and intuitively it does not make any sense. Is there something I am doing in my code that would be causing this to be the case? Should I *force* a call to allocateRenderResources() if it has not been called before internalRenderBlock is fetched? Thanks! Brad
6
1
3.3k
Jul ’22
Using kAudioDevicePropertyIcon to get the icon of an audio device produces status: 2003332927
Hi, I am developing a macOS application in SwiftUI (Xcode Version 14.3 (14E222b)) which lets the users control the audio level (volume) of the running applications individually, and also enables them to change the default speaker of each running application by letting them select an audio device from a list of available audio devices connected to the Mac. Till now, I have been able to get the following: List of running applications using NSWorkspace.shared.runningApplications The default audio device using kAudioHardwarePropertyDefaultOutputDevice with id and name List of audio devices using kAudioHardwarePropertyDevices with ids and names I am trying to get the icon of the devices using kAudioDevicePropertyIcon, but it is not working. I have written the following program to achieve the same: var deviceIcon: CFTypeRef? var deviceIconSize = UInt32(MemoryLayout<CFTypeRef>.size) var deviceIconPropertyAddress = AudioObjectPropertyAddress( mSelector: kAudioDevicePropertyIcon, mScope: kAudioObjectPropertyScopeGlobal, mElement: defaultOutputDeviceID) var status = AudioObjectGetPropertyData( defaultOutputDeviceID, &deviceIconPropertyAddress, 0, nil, &deviceIconSize, &deviceIcon) guard status == noErr else { print("Error getting default output device icon: \(status)") return } When I run the above program, I get the following output: Error getting default output device icon: 2003332927 defaultOutputDeviceID is the id of the default audio device. For now, I am just trying to get the icon of the default speaker which, in my case, is MacBook Air Speakers. I have tried searching for this status code, and I found that this error is defined in AudioFile.h as kAudioFileUnspecifiedError = 'wht?', // 0x7768743F, 2003334207. Does this mean that there is no icon for the specified deviceID, or is there something wrong with my program? Could someone please let me know how to resolve this error? Thank you!
Replies
0
Boosts
0
Views
2.1k
Activity
Apr ’23
AAC decoding with Audio Toolbox is failing in Monterey RC
When I use Audio Toolbox APIs to decode AAC audio, I am getting kAudioConverterErr_FormatNotSupported(1718449215) error. This works fine in BigSur(11.5.2) and previous versions. prompt> ./ffmpeg -c:a aac_at -i audio24b_he_aac.aac -f s16le -acodec pcm_s16le output.pcm -v trace ffmpeg version N-104401-gcd38fbf4f7 Copyright (c) 2000-2021 the FFmpeg developers  built with Apple clang version 13.0.0 (clang-1300.0.29.3)  configuration: --disable-x86asm  libavutil   57. 7.100 / 57. 7.100  libavcodec   59. 12.100 / 59. 12.100  libavformat  59. 6.100 / 59. 6.100  libavdevice  59. 0.101 / 59. 0.101  libavfilter   8. 15.100 / 8. 15.100  libswscale   6. 1.100 / 6. 1.100  libswresample  4. 0.100 / 4. 0.100 Splitting the commandline. Reading option '-c:a' ... matched as option 'c' (codec name) with argument 'aac_at'. Reading option '-i' ... matched as input url with argument 'audio24b_he_aac.aac'. Reading option '-f' ... matched as option 'f' (force format) with argument 's16le'. Reading option '-acodec' ... matched as option 'acodec' (force audio codec ('copy' to copy stream)) with argument 'pcm_s16le'. Reading option 'output.pcm' ... matched as output url. Reading option '-v' ... matched as option 'v' (set logging level) with argument 'trace'. Finished splitting the commandline. Parsing a group of options: global . Applying option v (set logging level) with argument trace. Successfully parsed a group of options. Parsing a group of options: input url audio24b_he_aac.aac. Applying option c:a (codec name) with argument aac_at. Successfully parsed a group of options. Opening an input file: audio24b_he_aac.aac. [NULL @ 0x7f8cf4004d40] Opening 'audio24b_he_aac.aac' for reading [file @ 0x7f8cf4005180] Setting default whitelist 'file,crypto,data' Probing aac score:51 size:2048 [aac @ 0x7f8cf4004d40] Format aac probed with size=2048 and score=51 [aac @ 0x7f8cf4004d40] Before avformat_find_stream_info() pos: 0 bytes read:65696 seeks:4 nb_streams:1 [aac_at @ 0x7f8cf40057c0] AudioToolbox init error: 1718449215 [aac @ 0x7f8cf4004d40] All info found [aac @ 0x7f8cf4004d40] Estimating duration from bitrate, this may be inaccurate Following lines of code is failing. status = AudioConverterNew(&in_format, &out_format, &at->converter); if (status != 0) { av_log(avctx, AV_LOG_ERROR, "AudioToolbox init error: %i\n", (int)status); return AVERROR_UNKNOWN; } Is there any change with respect to these APIs in Monterey. I could not find any thing in the documentation or release notes.
Replies
1
Boosts
0
Views
2.3k
Activity
Mar ’23
Audio input bandwidth
My app samples the various inputs available on the iPhone and iPad and performs a frequency analysis. In addition to using the internal accelerometer and gyroscope I can also sample the microphone and USB input devices such as accelerometers through the audio input subsystem. The highest sample rate I use with the microphone and USB devices is the 48 KHz of the audio sampling subsystem. This provides a bandwidth of 24 kHz (Nyquist frequency) on the sampled signal. This has worked for many generations of iPhone and iPad until now. When I use my iPhone 14 Pro there is a sharp frequency cutoff at about 8 kHz. I see an artifact at the same frequency when I use the simulators. BUT when I use my 11" iPad Pro, or my current generation iPhone SE I do not see this effect and get good data out to 24 kHz. The iPad Pro does show some rolloff near 24 kHz which is noticeable but not a problem for most applications. The rolloff at 8 kHz is a serious problem for my customers who are testing equipment vibration and noise. I am wondering if this is related to the new microphone options "Standard", "Voice Isolation", and "Wide Spectrum". But if so, why only on the iPhone 14Pro and the simulators? I have searched the documentation but apparently it is not possible to programmatically change the microphone mode and the Apple documentation on how to use this new feature is lacking. I am using AVAudioSession and AVAudioRecorder methods to acquire the data through the audio capture hardware. This code has been working well for me for over 10 years so I do not think it is a code problem but it could be a configuration problem because of new hardware in the iPhone 14 although I have not found anything in the documentation. Examples from various devices and a simulator are shown below for microphone. Does anyone have an idea what may be causing this problem? iPhoneSE 3rd Gen iPad Gen 9 iPad Pro 11in iPhone 14Pro iPad 10th Generation Simulator
Replies
0
Boosts
0
Views
1.5k
Activity
Mar ’23
Starting recording from background for a VoIP application.
After searching for a few days, i have come to know that iOS doesn't allow recording in background. Through recording continues when it has started in foreground and goes to background. Came to know that, "This is a new a privacy protection restriction introduced in 12.4" When trying to start recording from background, we get “AVAudioSession.ErrorCode.cannotStartRecording” error. What do i need: our application needs to starts recording audio and transmit it while in background when user presses an external button i.e. PTT button of a BLE device. It seems there are several similar issue posted in this forum but neither could i find any plausible solution nor got any specific documentation from Apple. Requesting to help me out or at least please provide me a specific documentation stating "background recording is not possible". And if any workaround exists, please suggest. P.S. we are using **AVAudioSession.sharedInstance().setCategory(.playAndRecord, mode: .spokenAudio, options: [.mixWithOthers, .allowBluetooth, .allowBluetoothA2DP, .duckOthers]) **
Replies
0
Boosts
0
Views
1.4k
Activity
Feb ’23
core audio API library
I have a High Sierra system which I access via ssh and for which I program old-style from the command line in Objective-C and build via Makefiles. I have a very small program that employs the CoreAudio API and calls the AudioFileOpenURL and AudioFileClose functions. The program compiles ok but the linker is reporting that the symbols AudioFileOpenURL and AudioFileClose are undefined. I cannot find any dylib file among the libraries on my system that has those symbols. Can someone suggest where I might obtain the appropriate library? Here is the linker output that I am getting: gcc -o example1 example1.o -lobjc -lextension Undefined symbols for architecture x86_64: "_AudioFileClose", referenced from: _main in example1.o "_AudioFileGetProperty", referenced from: _main in example1.o "_AudioFileGetPropertyInfo", referenced from: _main in example1.o "_AudioFileOpenURL", referenced from: _main in example1.o ld: symbol(s) not found for architecture x86_64 clang: error: linker command failed with exit code 1 (use -v to see invocation) make: *** [example1] Error 1
Replies
1
Boosts
0
Views
1.5k
Activity
Feb ’23
Write AAC files in a way that they are readable even in a crash
I'm building an audio recording app. For our users it's important that recordings never get lost - even if the app crashes, users would like to have the partial recording. We encode recordings in AAC or ALAC and store them in an m4a file using AVAudioFile. However, in case the app crashes, those m4a files are invalid - the MOOV atom is missing. Are there recording settings that change the m4a file so that it is always playable, even if the recording is interrupted half-way? I'm not at all an expert in audio codecs, but from what I understand, it is possible to write the MOOV atom at the beginning of the audio file instead of the end. This could solve this. But of course, I'd prefer an actual expert to tell me what a good solution is, and how to configure this in AVAudioFile.
Replies
3
Boosts
1
Views
2.3k
Activity
Feb ’23
Writing tapped buffers to disk asynchronously
I'd like to understand the most robust way to record audio to disk using AVAudioNodes installTap(onBus:bufferSize:format:block:) method. Currently, I'm dispatching out the buffers I receive in my AVAudioNodeTapBlock to a serial dispatch queue then writing to disk using some Audio Toolbox methods, but my concern is that if I hold on to the buffer provided in the AVAudioNodeTapBlock for too long (due to disk I/O for example), I'll end up getting issues. What I'm considering is creating my own larger pool of preallocated AVAudioPCMBuffers (a few seconds worth) and copying across the data from the buffer provided by the tap into one of the buffers from this larger pool in the AVAudioNodeTapBlock directly (no dispatch queue). Is there a simpler way of handling this, or does this sound like the best route?
Replies
1
Boosts
0
Views
1.4k
Activity
Feb ’23
Low level audio recording on macOS. Please Help!
I am struggling to see why the following low-level audio recording function - which is based on tn2091 - Device input using the HAL Output Audio Unit - (a great article, btw, although a bit dated, and it would be wonderful if it was updated to use Swift and non deprecated stuff at some point!) fails to work under macOS: func createMicUnit() -> AUAudioUnit { let compDesc = AudioComponentDescription( componentType: kAudioUnitType_Output, componentSubType: kAudioUnitSubType_HALOutput, // I am on macOS, os this is good componentManufacturer: kAudioUnitManufacturer_Apple, componentFlags: 0, componentFlagsMask: 0) return try! AUAudioUnit(componentDescription: compDesc, options: []) } func startMic() { // mic permision is already granted at this point, but let's check let status = AVCaptureDevice.authorizationStatus(for: AVMediaType.audio) precondition(status == .authorized) // yes, all good let unit = createMicUnit() unit.isInputEnabled = true unit.isOutputEnabled = false precondition(!unit.canPerformInput) // can't record yet, and know why? print(deviceName(unit.deviceID)) // "MacBook Pro Speakers" - this is why let micDeviceID = defaultInputDeviceID print(deviceName(micDeviceID)) // "MacBook Pro Microphone" - this is better try! unit.setDeviceID(micDeviceID) // let's switch device to mic precondition(unit.canPerformInput) // now we can record print("\(String(describing: unit.channelMap))") // channel map is "nil" by default unit.channelMap = [0] // not sure if this helps or not let sampleRate = deviceActualFrameRate(micDeviceID) print(sampleRate) // 48000.0 let format = AVAudioFormat( commonFormat: .pcmFormatFloat32, sampleRate: sampleRate, channels: 1, interleaved: false)! try! unit.outputBusses[1].setFormat(format) unit.inputHandler = { flags, timeStamp, frameCount, bus in fatalError("never gets here") // now the weird part - this is never called! } try! unit.allocateRenderResources() try! unit.startHardware() // let's go! print("mic should be working now... why it doesn't?") // from now on the (UI) app continues its normal run loop } All sanity checks pass with flying colors but unit's inputHandler is not being called. Any idea why? Thank you!
Replies
3
Boosts
0
Views
2.5k
Activity
Jan ’23
MIDI file generated by using MusicSequenceFileCreate has Sysex MIDI message (iOS 16.0.2)
I am using the MusicSequenceFileCreate method to generate a MIDI file from a beat-based MusicSequence. In iOS 16.0.2 devices, the file that is created has a Sysex MIDI message added (not by me) to the file at time 0: f0 2a 11 67 40 40 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ff ff ff ff 00 00 00 00 00 00 00 00 00 00 f7 Sysex messages are manufacturer dependent, a file with this Sysex message can't be read into apps like Nanostudio, Ableton, Zenbeats. It can be read by GarageBand. My app's deployment target is iOS 13.0. Has anybody else ran into this issue? Thanks
Replies
1
Boosts
0
Views
1.5k
Activity
Oct ’22
Sound decibel recognition
Hi Community Members, We tried to find the particular sound through the microphone. We used PKCCheck to detect the sound decibel. we detect the sound based on the number of dB values per second we receive and add some logic over it to get the result, but when we have continuous sound like an alarm we can't detect it as the gap between the sound is very less. Any suggestion on libraries to achieve this. Also whether we can achieve this thru Frequency & Amplitude method. Please advise.
Replies
0
Boosts
0
Views
1.5k
Activity
Oct ’22
Microphone is disabled when trying to record (using getUserMedia)
I built a simple recorder on my website for users to record and playback audio. It works on ALL desktop browsers (including Safari) but when I use any browser on my iPhone, the mic is active at the opposite time. The flow is: ask permission > user allows mic access > user presses record > records audio > saves and plays back On iPhone what's happening is after the user allows permission, the mic goes active (visualized by the mic icon in safari browser) and then once the user presses record, it disables the mic. I am using getUserMedia within a React.js app Why is it doing this?
Replies
1
Boosts
0
Views
1.9k
Activity
Sep ’22
AudioUnit: AUParameterEvent vs AUParameterTree implementorValueObserver
Hello, I'm trying to write my own audio unit extension and I have a problem. I don't understand the difference between implementorValueObserver and AUParameterEvent. It looks like both of them can be used to update parameters in DSPKernel. It seems natural to use an observer, but it requires to think about thread safety in contrast to AUParameterEvent handling. Can someone comment on this or give me more context about this two entities?
Replies
0
Boosts
0
Views
1.1k
Activity
Aug ’22
How set CBR in AVAudioConverter?
I am using AVAudioConverter in Objective C. AVAudioConverter has bitRate and bitRateStrategy parameters defined. The default bitRateStrategy value is AVAudioBitRateStrategy_LongTermAverage. If I set bitRateStrategy to AVAudioBitRateStrategy_Constant there is no change. The bitRate variable works correctly. AVAudioConverter *audioConverter = [[AVAudioConverter alloc] initFromFormat:inputFormat toFormat:outputFormat]; audioConverter.bitRate = 128000; audioConverter.bitRateStrategy = AVAudioBitRateStrategy_Constant;
Replies
0
Boosts
0
Views
1.2k
Activity
Aug ’22
Why is internalRenderBlock fetched and used before allocateRenderResources() is called?
I have a working AUv3 AUAudioUnit app extension but I had to work around a strange issue: I found that the internalRenderBlock value is fetched and invoked before allocateRenderResources() is called. I have not found any documentation stating that this would be the case, and intuitively it does not make any sense. Is there something I am doing in my code that would be causing this to be the case? Should I *force* a call to allocateRenderResources() if it has not been called before internalRenderBlock is fetched? Thanks! Brad
Replies
6
Boosts
1
Views
3.3k
Activity
Jul ’22