AudioToolbox

RSS for tag

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

Posts under AudioToolbox tag

135 Posts

Post

Replies

Boosts

Views

Activity

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.1k
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.5k
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
769
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
946
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
2.8k
Jul ’22
Physical 16.0 iPhone XS does not show among Xcode targets
I am trying to compile on my iPhone XS device an app on Xcode Version 14.0 beta 2. First time I connected the device it correctly showed among the devices urging me to enable Developer Modality on Privacy & Security. I did it and the iPhone restarted, but once it happened the iPhone disappeared from the targets, thus not allowing me to compile on it. For some strange reason my iPad instead showed, but when I tried to compile on it, Xcode of course urged me to connect it. So it seems Xcode sees not connected device and does not see connected devices. Is anyone able to give a sense to that and possibly a solution?
0
0
926
Jul ’22
The AudioUnit user presets system has ceased to work as expected in iPadOS 14
The AUAudioUnit in my app uses the user presets system that was introduced with iPadOS/iOS 13. The user presets system worked well in iPadOS 13, and it worked in at least one of the pre-release beta versions of iPadOS 14. However, it has not worked since iPadOS 14.0 was released. The problem is (superficially, at least) that: saveUserPreset no longer writes preset files to the app's Documents folder, but the method doesn't fail either. The userPresets array, which typically contains the presets that were deserialised from the files stored in the Documents folder, is invariably empty. The presets that the array would contain prior to upgrading from iPadOS 13 are no longer accessible. In other words, prior to upgrading to iPadOS 14, my app could save user presets using the saveUserPreset method and subsequently access their contents from the userPresets array. Since upgrading to iPadOS 14, the userPresets array is invariably empty and the saveUserPreset method no longer saves presets to the Documents folder. Has anyone else experienced this problem?
1
0
1.3k
Jun ’22
AudioObjectSetPropertyData with bluetooth devices on macOS Monterey (12.0.1)
In previous versions of macOS (Catalina & Big Sur) I used the following code in my app to mute the system Input device (assuming a good inputDeviceId): let inputDeviceId = input.id var address = AudioObjectPropertyAddress( mSelector: AudioObjectPropertySelector(kAudioDevicePropertyMute), mScope: AudioObjectPropertyScope(kAudioDevicePropertyScopeInput), mElement: AudioObjectPropertyElement(kAudioObjectPropertyElementMaster)) let size = UInt32(MemoryLayout<UInt32>.size) var mute: UInt32 = muted ? 1 : 0 AudioObjectSetPropertyData(inputDeviceId, &address, 0, nil, size, &mute) This worked great in both previous operating systems across all input devices I tested. However, in macOS 12.0.1 this no longer works specifically for bluetooth devices. And, beyond that, it instead mutes the Output volume of these bluetooth devices. On the system microphone or via a line-in, this still works as expected. I'm trying to determined what changed in Monterey that caused bluetooth devices to start behaving the opposite as they were before with respect to this API? Is there a new recommended approach for muting microphone input from Bluetooth devices? Any help, guidance, or context here is appreciated.
5
2
3.2k
Jun ’22
AUParameterNode defaultValue ??
We're seeing the following when running auvaltool It seems AUParameterNode cannot be constructed with a default value and has no option to set default values via property or method so what does this mean? .... Does it mean we ALSO have to iterate all the parameters using the old fashioned long winded toolbox calls ? Or does it mean nothing at all? The "Will fail in future auval version" is worrying! Values: Minimum = 5.000000, Default = 0.000000, Maximum = 300.000000 Flags: Expert Mode, Readable,  WARNING: use -strict_DefP flag * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * Parameter's Published defaultvalue does not fall with [min, max] range  * * This will fail using -strict option. Will fail in future auval version  * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *   -parameter PASS
2
0
1.9k
May ’22
Caching the view for an out-of-process audio unit
I'm writing a macOS audio unit hosting app using the AVAudioUnit and AUAudioUnit APIs. I'm trying to use the NSView cacheDisplay(in:to:) function to capture an image of a plugin's view: func viewToImage(veiwToCapture: NSView) -> NSImage? {     var image: NSImage? = nil     if let rep = veiwToCapture.bitmapImageRepForCachingDisplay(in: veiwToCapture.bounds) {       veiwToCapture.cacheDisplay(in: veiwToCapture.bounds, to: rep)       image = NSImage(size: veiwToCapture.bounds.size)       image!.addRepresentation(rep)     }     return image   } } This works ok when a plugin is instantiated using the .loadInProcess option. If the plugin is instantiated using the .loadOutOfProcess option the resulting bitmapImageRep is blank. I'd much rather be loading plugins out-of-process for the enhanced stability. Is there any trick I'm missing to be able to capture the contents of the NSView from an out-of-process audio unit?
1
0
1.2k
Apr ’22
Developing a call recorder app for ptivate use
Hello, Is there any way to create a call recording app without distributing it to the app store? And just use it as a beta local app on my iphone only? If there is a way to do it, can you briefly explain how can i do it? Because all of the app store recording apps store my calls on their server and i dont want that, i just want to save my calls locally on my iphone. Thanks!
0
0
1.5k
Apr ’22
How to use CoreAudio
MacOS CoreAudio buffer playback produces annoying noise between correct sound. I'm interested to play valid .wav data though the buffer. Why I'm playing a .wav? It has valid data. What I'm trying to achieve is to understand how to write correctly to the sound buffer. I'm porting a music engine to MacOS .... #include <string.h> #include <math.h> #include <unistd.h> #include <stdio.h> #include <AudioToolbox/AudioToolbox.h> FILE *fp; typedef struct TwavHeader{ char RIFF[4]; uint32_t RIFFChunkSize; char WAVE[4]; char fmt[4]; uint32_t Subchunk1Size; uint16_t AudioFormat; uint16_t NumOfChan; uint32_t SamplesPerSec; uint32_t bytesPerSec; uint16_t blockAlign; uint16_t bitsPerSample; char Subchunk2ID[4]; uint32_t Subchunk2Size; }TwavHeader; typedef struct SoundState { bool done; }SoundState; void auCallback(void *inUserData, AudioQueueRef queue, AudioQueueBufferRef buffer) { buffer->mAudioDataByteSize = 1024*4; int numToRead = buffer->mAudioDataByteSize / sizeof(float) * 2; void *p = malloc(numToRead); fread(p, numToRead,1,fp); void *myBuf = buffer->mAudioData; for (int i=0; i < numToRead / 2; i++) { uint16_t w = *(uint16_t *)&(p[i*sizeof(uint16_t)]); float f = ((float)w / (float)0x8000) - 1.0; *(float *)&(myBuf[i*sizeof(float)]) = f; } free(p); AudioQueueEnqueueBuffer(queue, buffer, 0, 0); } void checkError(OSStatus error){ if (error != noErr) { printf("Error: %d", error); exit(error); } } int main(int argc, const char * argv[]) { printf("START\n"); TwavHeader theHeader; fp = fopen("/Users/kirillkranz/Documents/mytralala-code/CoreAudioTest/unreal.wav", "r"); fread(&theHeader, sizeof(TwavHeader),1,fp); printf("%i\n",theHeader.bitsPerSample); AudioStreamBasicDescription auDesc = {}; auDesc.mSampleRate = theHeader.SamplesPerSec; auDesc.mFormatID = kAudioFormatLinearPCM; auDesc.mFormatFlags = kLinearPCMFormatFlagIsFloat | kLinearPCMFormatFlagIsPacked; auDesc.mBytesPerPacket = 8; auDesc.mFramesPerPacket = 1; auDesc.mBytesPerFrame = 8; auDesc.mChannelsPerFrame = 2; auDesc.mBitsPerChannel = 32; AudioQueueRef auQueue = 0; AudioQueueBufferRef auBuffers[2] ={}; // our persistent state for sound playback SoundState soundState= {}; soundState.done=false; OSStatus err; // most of the 0 and nullptr params here are for compressed sound formats etc. err = AudioQueueNewOutput(&auDesc, &auCallback, &soundState, 0, 0, 0, &auQueue); checkError(err); // generate buffers holding at most 1/16th of a second of data uint32_t bufferSize = auDesc.mBytesPerFrame * (auDesc.mSampleRate / 16); err = AudioQueueAllocateBuffer(auQueue, bufferSize, &(auBuffers[0])); checkError(err); err = AudioQueueAllocateBuffer(auQueue, bufferSize, &(auBuffers[1])); checkError(err); // prime the buffers auCallback(&soundState, auQueue, auBuffers[0]); auCallback(&soundState, auQueue, auBuffers[1]); // enqueue for playing AudioQueueEnqueueBuffer(auQueue, auBuffers[0], 0, 0); AudioQueueEnqueueBuffer(auQueue, auBuffers[1], 0, 0); // go! AudioQueueStart(auQueue, 0); char rxChar[10]; scanf( "%s", &rxChar); printf("FINISH"); fclose(fp); // be nice even it doesn't really matter at this point if (auQueue) AudioQueueDispose(auQueue, true); } what do I do wrong?
0
0
1.7k
Apr ’22
USB Live Stream not working in osx 12
Dear Apple Expert, Our project uses libUSB library to interact with a USB based camera device. Our application is working fine in macOS Mojave (10.14.6 ). When the new MacOS 12 beta version was made available, we tested our code. But when we try to claim the interface via "CreateInterfaceIterator" API, we are getting "kIOReturnExclusiveAccess" error code and ultimately our application fails. The failure is observed in both libUSB versions 1.0.23 and 1.0.24. Could you help us by explaining if there is change in the new OS with respect to access to USB devices?
1
0
1.8k
Mar ’22
[AVAssetWriter addInput:] Format ID 'lpcm' is not compatible with file type com.apple.m4a-audio
This is the crash log from Firebase. Fatal Exception: NSInvalidArgumentException *** -[AVAssetWriter addInput:] Format ID 'lpcm' is not compatible with file type com.apple.m4a-audio But I can't reproduce the crash ... This is the demo code Does anyone know where the problem is ? let normalOutputSettings:[String:Any] = [     AVFormatIDKey : kAudioFormatLinearPCM,     AVSampleRateKey : 44100,     AVNumberOfChannelsKey : 2,     AVLinearPCMBitDepthKey : 16,     AVLinearPCMIsNonInterleaved : false,     AVLinearPCMIsFloatKey : false,     AVLinearPCMIsBigEndianKey : false   ] let writerInput = AVAssetWriterInput(mediaType: .audio, outputSettings: outputSettings) let outputURL = URL(fileURLWithPath: NSTemporaryDirectory() + UUID().uuidString + ".m4a") self.writer = try! AVAssetWriter(outputURL: outputURL, fileType: fileType) writer?.add(writerInput)
0
0
1.3k
Mar ’22
How to put the midi and recorded audio file into a single player?
The GarageBand app can import both midi and recorded audio file into a single player to play. Just like this: My App have the same feature but I don't know how to implement it. I have tried the AVAudioSequencer,but it only can load and play MIDI file. I have tried the AVPlayer and AVPlayerItem,but it seems that it can't load the MIDI file. So How to combine MIDI file and audio file into a single AVPlayerItem or anything else to play?
0
0
1.2k
Feb ’22
How to populate AudioStreamBasicDescription for AMR_WB?
Hey I am trying to decode AMR_WB audio on iOS, for this I am using the below settings var asbd = AudioStreamBasicDescription() asbd.mSampleRate = Float64(sampleRate) asbd.mFormatID = kAudioFormatAMR_WB asbd.mFormatFlags = 0 asbd.mFramesPerPacket = 320 asbd.mChannelsPerFrame = UInt32(channels) asbd.mBitsPerChannel = 16 * UInt32(MemoryLayout<UInt8>.size) asbd.mReserved = 0 asbd.mBytesPerFrame = 2 asbd.mBytesPerPacket = asbd.mBytesPerFrame * asbd.mFramesPerPacket let _audioFormat = AVAudioFormat(streamDescription: &asbd)! return _audioFormat But I encounter the error as follows: Error Domain=AVFoundationErrorDomain Code=-11800 "The operation could not be completed" UserInfo={NSLocalizedFailureReason=An unknown error occurred (1885696621), NSLocalizedDescription=The operation could not be completed, NSUnderlyingError=0x283fb1920 {Error Domain=NSOSStatusErrorDomain Code=1885696621 "(null)" UserInfo={AVErrorFourCharCode='perm'}}} Now as per the documentation found here, it looks to be supported but I am unable what permission to give to the application for this to work. Any help will be appreciated.
0
0
919
Feb ’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.1k
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.5k
Activity
Sep ’22
ios15.x AVMIDIPlayer can't play midi file which use ios16.x create
when we use AVMIDIPlayer play midi file, it throw a exception: The operation couldn’t be completed. (com.apple.coreaudio.avfaudio error -3.) and i find midi file's structure create at ios15.x is different with ios16.x
Replies
1
Boosts
0
Views
1.1k
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
769
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
946
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
2.8k
Activity
Jul ’22
iMessage and sounds
The possibility of sending predefined sounds and being able to associate them with images should be implemented in iMessage. For example, the iconic sound of netflix.
Replies
0
Boosts
0
Views
836
Activity
Jul ’22
Inserting Audio Files into Comments in MS Word for Mac
I am working on a function that inserts audio files into comments in MS Word for Mac. I can insert MS Word, MS Excel, and picture files, but not audio files. It was also a problem for MS Word in Windows 11, but Microsoft eventually fixed it.
Replies
0
Boosts
0
Views
800
Activity
Jul ’22
Physical 16.0 iPhone XS does not show among Xcode targets
I am trying to compile on my iPhone XS device an app on Xcode Version 14.0 beta 2. First time I connected the device it correctly showed among the devices urging me to enable Developer Modality on Privacy & Security. I did it and the iPhone restarted, but once it happened the iPhone disappeared from the targets, thus not allowing me to compile on it. For some strange reason my iPad instead showed, but when I tried to compile on it, Xcode of course urged me to connect it. So it seems Xcode sees not connected device and does not see connected devices. Is anyone able to give a sense to that and possibly a solution?
Replies
0
Boosts
0
Views
926
Activity
Jul ’22
The AudioUnit user presets system has ceased to work as expected in iPadOS 14
The AUAudioUnit in my app uses the user presets system that was introduced with iPadOS/iOS 13. The user presets system worked well in iPadOS 13, and it worked in at least one of the pre-release beta versions of iPadOS 14. However, it has not worked since iPadOS 14.0 was released. The problem is (superficially, at least) that: saveUserPreset no longer writes preset files to the app's Documents folder, but the method doesn't fail either. The userPresets array, which typically contains the presets that were deserialised from the files stored in the Documents folder, is invariably empty. The presets that the array would contain prior to upgrading from iPadOS 13 are no longer accessible. In other words, prior to upgrading to iPadOS 14, my app could save user presets using the saveUserPreset method and subsequently access their contents from the userPresets array. Since upgrading to iPadOS 14, the userPresets array is invariably empty and the saveUserPreset method no longer saves presets to the Documents folder. Has anyone else experienced this problem?
Replies
1
Boosts
0
Views
1.3k
Activity
Jun ’22
AudioObjectSetPropertyData with bluetooth devices on macOS Monterey (12.0.1)
In previous versions of macOS (Catalina & Big Sur) I used the following code in my app to mute the system Input device (assuming a good inputDeviceId): let inputDeviceId = input.id var address = AudioObjectPropertyAddress( mSelector: AudioObjectPropertySelector(kAudioDevicePropertyMute), mScope: AudioObjectPropertyScope(kAudioDevicePropertyScopeInput), mElement: AudioObjectPropertyElement(kAudioObjectPropertyElementMaster)) let size = UInt32(MemoryLayout<UInt32>.size) var mute: UInt32 = muted ? 1 : 0 AudioObjectSetPropertyData(inputDeviceId, &address, 0, nil, size, &mute) This worked great in both previous operating systems across all input devices I tested. However, in macOS 12.0.1 this no longer works specifically for bluetooth devices. And, beyond that, it instead mutes the Output volume of these bluetooth devices. On the system microphone or via a line-in, this still works as expected. I'm trying to determined what changed in Monterey that caused bluetooth devices to start behaving the opposite as they were before with respect to this API? Is there a new recommended approach for muting microphone input from Bluetooth devices? Any help, guidance, or context here is appreciated.
Replies
5
Boosts
2
Views
3.2k
Activity
Jun ’22
AUParameterNode defaultValue ??
We're seeing the following when running auvaltool It seems AUParameterNode cannot be constructed with a default value and has no option to set default values via property or method so what does this mean? .... Does it mean we ALSO have to iterate all the parameters using the old fashioned long winded toolbox calls ? Or does it mean nothing at all? The "Will fail in future auval version" is worrying! Values: Minimum = 5.000000, Default = 0.000000, Maximum = 300.000000 Flags: Expert Mode, Readable,  WARNING: use -strict_DefP flag * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * Parameter's Published defaultvalue does not fall with [min, max] range  * * This will fail using -strict option. Will fail in future auval version  * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *   -parameter PASS
Replies
2
Boosts
0
Views
1.9k
Activity
May ’22
Instance count for same AUv3 component in app
Curious if there is a sound way for an AUv3 component to identify how many other instances of it that are running on a device. For instance, if GarageBand has 4 tracks and all of the tracks use the same AUv3 component, is there a sound way for each one to obtain a unique index value? Thanks!
Replies
1
Boosts
0
Views
2.0k
Activity
May ’22
Caching the view for an out-of-process audio unit
I'm writing a macOS audio unit hosting app using the AVAudioUnit and AUAudioUnit APIs. I'm trying to use the NSView cacheDisplay(in:to:) function to capture an image of a plugin's view: func viewToImage(veiwToCapture: NSView) -> NSImage? {     var image: NSImage? = nil     if let rep = veiwToCapture.bitmapImageRepForCachingDisplay(in: veiwToCapture.bounds) {       veiwToCapture.cacheDisplay(in: veiwToCapture.bounds, to: rep)       image = NSImage(size: veiwToCapture.bounds.size)       image!.addRepresentation(rep)     }     return image   } } This works ok when a plugin is instantiated using the .loadInProcess option. If the plugin is instantiated using the .loadOutOfProcess option the resulting bitmapImageRep is blank. I'd much rather be loading plugins out-of-process for the enhanced stability. Is there any trick I'm missing to be able to capture the contents of the NSView from an out-of-process audio unit?
Replies
1
Boosts
0
Views
1.2k
Activity
Apr ’22
Developing a call recorder app for ptivate use
Hello, Is there any way to create a call recording app without distributing it to the app store? And just use it as a beta local app on my iphone only? If there is a way to do it, can you briefly explain how can i do it? Because all of the app store recording apps store my calls on their server and i dont want that, i just want to save my calls locally on my iphone. Thanks!
Replies
0
Boosts
0
Views
1.5k
Activity
Apr ’22
How to use CoreAudio
MacOS CoreAudio buffer playback produces annoying noise between correct sound. I'm interested to play valid .wav data though the buffer. Why I'm playing a .wav? It has valid data. What I'm trying to achieve is to understand how to write correctly to the sound buffer. I'm porting a music engine to MacOS .... #include <string.h> #include <math.h> #include <unistd.h> #include <stdio.h> #include <AudioToolbox/AudioToolbox.h> FILE *fp; typedef struct TwavHeader{ char RIFF[4]; uint32_t RIFFChunkSize; char WAVE[4]; char fmt[4]; uint32_t Subchunk1Size; uint16_t AudioFormat; uint16_t NumOfChan; uint32_t SamplesPerSec; uint32_t bytesPerSec; uint16_t blockAlign; uint16_t bitsPerSample; char Subchunk2ID[4]; uint32_t Subchunk2Size; }TwavHeader; typedef struct SoundState { bool done; }SoundState; void auCallback(void *inUserData, AudioQueueRef queue, AudioQueueBufferRef buffer) { buffer->mAudioDataByteSize = 1024*4; int numToRead = buffer->mAudioDataByteSize / sizeof(float) * 2; void *p = malloc(numToRead); fread(p, numToRead,1,fp); void *myBuf = buffer->mAudioData; for (int i=0; i < numToRead / 2; i++) { uint16_t w = *(uint16_t *)&(p[i*sizeof(uint16_t)]); float f = ((float)w / (float)0x8000) - 1.0; *(float *)&(myBuf[i*sizeof(float)]) = f; } free(p); AudioQueueEnqueueBuffer(queue, buffer, 0, 0); } void checkError(OSStatus error){ if (error != noErr) { printf("Error: %d", error); exit(error); } } int main(int argc, const char * argv[]) { printf("START\n"); TwavHeader theHeader; fp = fopen("/Users/kirillkranz/Documents/mytralala-code/CoreAudioTest/unreal.wav", "r"); fread(&theHeader, sizeof(TwavHeader),1,fp); printf("%i\n",theHeader.bitsPerSample); AudioStreamBasicDescription auDesc = {}; auDesc.mSampleRate = theHeader.SamplesPerSec; auDesc.mFormatID = kAudioFormatLinearPCM; auDesc.mFormatFlags = kLinearPCMFormatFlagIsFloat | kLinearPCMFormatFlagIsPacked; auDesc.mBytesPerPacket = 8; auDesc.mFramesPerPacket = 1; auDesc.mBytesPerFrame = 8; auDesc.mChannelsPerFrame = 2; auDesc.mBitsPerChannel = 32; AudioQueueRef auQueue = 0; AudioQueueBufferRef auBuffers[2] ={}; // our persistent state for sound playback SoundState soundState= {}; soundState.done=false; OSStatus err; // most of the 0 and nullptr params here are for compressed sound formats etc. err = AudioQueueNewOutput(&auDesc, &auCallback, &soundState, 0, 0, 0, &auQueue); checkError(err); // generate buffers holding at most 1/16th of a second of data uint32_t bufferSize = auDesc.mBytesPerFrame * (auDesc.mSampleRate / 16); err = AudioQueueAllocateBuffer(auQueue, bufferSize, &(auBuffers[0])); checkError(err); err = AudioQueueAllocateBuffer(auQueue, bufferSize, &(auBuffers[1])); checkError(err); // prime the buffers auCallback(&soundState, auQueue, auBuffers[0]); auCallback(&soundState, auQueue, auBuffers[1]); // enqueue for playing AudioQueueEnqueueBuffer(auQueue, auBuffers[0], 0, 0); AudioQueueEnqueueBuffer(auQueue, auBuffers[1], 0, 0); // go! AudioQueueStart(auQueue, 0); char rxChar[10]; scanf( "%s", &rxChar); printf("FINISH"); fclose(fp); // be nice even it doesn't really matter at this point if (auQueue) AudioQueueDispose(auQueue, true); } what do I do wrong?
Replies
0
Boosts
0
Views
1.7k
Activity
Apr ’22
USB Live Stream not working in osx 12
Dear Apple Expert, Our project uses libUSB library to interact with a USB based camera device. Our application is working fine in macOS Mojave (10.14.6 ). When the new MacOS 12 beta version was made available, we tested our code. But when we try to claim the interface via "CreateInterfaceIterator" API, we are getting "kIOReturnExclusiveAccess" error code and ultimately our application fails. The failure is observed in both libUSB versions 1.0.23 and 1.0.24. Could you help us by explaining if there is change in the new OS with respect to access to USB devices?
Replies
1
Boosts
0
Views
1.8k
Activity
Mar ’22
[AVAssetWriter addInput:] Format ID 'lpcm' is not compatible with file type com.apple.m4a-audio
This is the crash log from Firebase. Fatal Exception: NSInvalidArgumentException *** -[AVAssetWriter addInput:] Format ID 'lpcm' is not compatible with file type com.apple.m4a-audio But I can't reproduce the crash ... This is the demo code Does anyone know where the problem is ? let normalOutputSettings:[String:Any] = [     AVFormatIDKey : kAudioFormatLinearPCM,     AVSampleRateKey : 44100,     AVNumberOfChannelsKey : 2,     AVLinearPCMBitDepthKey : 16,     AVLinearPCMIsNonInterleaved : false,     AVLinearPCMIsFloatKey : false,     AVLinearPCMIsBigEndianKey : false   ] let writerInput = AVAssetWriterInput(mediaType: .audio, outputSettings: outputSettings) let outputURL = URL(fileURLWithPath: NSTemporaryDirectory() + UUID().uuidString + ".m4a") self.writer = try! AVAssetWriter(outputURL: outputURL, fileType: fileType) writer?.add(writerInput)
Replies
0
Boosts
0
Views
1.3k
Activity
Mar ’22
How to put the midi and recorded audio file into a single player?
The GarageBand app can import both midi and recorded audio file into a single player to play. Just like this: My App have the same feature but I don't know how to implement it. I have tried the AVAudioSequencer,but it only can load and play MIDI file. I have tried the AVPlayer and AVPlayerItem,but it seems that it can't load the MIDI file. So How to combine MIDI file and audio file into a single AVPlayerItem or anything else to play?
Replies
0
Boosts
0
Views
1.2k
Activity
Feb ’22
How to populate AudioStreamBasicDescription for AMR_WB?
Hey I am trying to decode AMR_WB audio on iOS, for this I am using the below settings var asbd = AudioStreamBasicDescription() asbd.mSampleRate = Float64(sampleRate) asbd.mFormatID = kAudioFormatAMR_WB asbd.mFormatFlags = 0 asbd.mFramesPerPacket = 320 asbd.mChannelsPerFrame = UInt32(channels) asbd.mBitsPerChannel = 16 * UInt32(MemoryLayout<UInt8>.size) asbd.mReserved = 0 asbd.mBytesPerFrame = 2 asbd.mBytesPerPacket = asbd.mBytesPerFrame * asbd.mFramesPerPacket let _audioFormat = AVAudioFormat(streamDescription: &asbd)! return _audioFormat But I encounter the error as follows: Error Domain=AVFoundationErrorDomain Code=-11800 "The operation could not be completed" UserInfo={NSLocalizedFailureReason=An unknown error occurred (1885696621), NSLocalizedDescription=The operation could not be completed, NSUnderlyingError=0x283fb1920 {Error Domain=NSOSStatusErrorDomain Code=1885696621 "(null)" UserInfo={AVErrorFourCharCode='perm'}}} Now as per the documentation found here, it looks to be supported but I am unable what permission to give to the application for this to work. Any help will be appreciated.
Replies
0
Boosts
0
Views
919
Activity
Feb ’22