0

I am totally new into this bluetooth side, if anyone can help me or provide over links for further information could be really helpful.

I am trying to create a seamless high quality bit rate transfer of audio from iPhone to a third party bluetooth device (i.e a headphone). Generally, from iPhone the audio will be compressed encoded and transfer for fast connectivity to a bluetooth device, but the audio quality will decrease. I am finding ways to change the codec used and to have a better bit rate so the audio listening on the bluetooth is of good quality for both listening and recording.

Senthil
  • 148
  • 1
  • 9

1 Answers1

0

You can use AudioUnit in iOS and change the sample rate using AudioStreamBasicDescription

AudioStreamBasicDescription audioDescription = {0};
audioDescription.mFormatID          = kAudioFormatLinearPCM;
audioDescription.mFormatFlags       = kAudioFormatFlagIsSignedInteger | kAudioFormatFlagIsPacked | kAudioFormatFlagsNativeEndian;
audioDescription.mChannelsPerFrame  = 1;
audioDescription.mBytesPerPacket    = sizeof(SInt16)*audioDescription.mChannelsPerFrame;
audioDescription.mFramesPerPacket   = 1;
audioDescription.mBytesPerFrame     = sizeof(SInt16)*audioDescription.mChannelsPerFrame;
audioDescription.mBitsPerChannel    = 8 * sizeof(SInt16);
audioDescription.mSampleRate        = 8000.0;

And you can change the preferred sample rate of your app:

let session = AVAudioSession.sharedInstance()
try session.setCategory(AVAudioSessionCategoryPlayAndRecord)
let bufferDuration :NSTimeInterval = 0.005
try session.setPreferredIOBufferDuration(bufferDuration)
try session.setPreferredSampleRate(8000.0)
try session.setActive(true)
Pablo Martinez
  • 1,573
  • 12
  • 31
  • Please note that the actual sample rate may be different once the AVAudioSession has been activated. – Jetdog Feb 21 '19 at 19:59