Created
October 24, 2013 10:28
-
-
Save icanswiftabit/7134786 to your computer and use it in GitHub Desktop.
iOS AudioUnit Settings and WP8 MediaStreamSource settings
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const int ChannelCount = 1; | |
const int BitsPerSample = 2; | |
const int BufferSamples = 16; // can be changed | |
const int BufferSize = 4096; //same as max buffer for iOS and Android | |
protected override void OpenMediaAsync() | |
{ | |
int byteRate = sampleRate * ChannelCount * BitsPerSample / 8; | |
Debug.WriteLine("ByteRate: "+byteRate); | |
short blockAlign = (short)(ChannelCount * (BitsPerSample / 8)); | |
//Build string-based wave-format structure | |
string waveFormat = ""; | |
waveFormat += ToLittleEndianString(string.Format("{0:X4}", 1)); // indicates PCM | |
waveFormat += ToLittleEndianString(string.Format("{0:X4}", ChannelCount)); | |
waveFormat += ToLittleEndianString(string.Format("{0:X8}", sampleRate)); | |
waveFormat += ToLittleEndianString(string.Format("{0:X8}", byteRate)); | |
waveFormat += ToLittleEndianString(string.Format("{0:X4}", blockAlign)); | |
waveFormat += ToLittleEndianString(string.Format("{0:X4}", BitsPerSample)); | |
waveFormat += ToLittleEndianString(string.Format("{0:X4}", 0)); | |
// Put wave format string in media streams dictionary | |
var mediaStreamAttributes = new Dictionary<MediaStreamAttributeKeys, string>(); | |
mediaStreamAttributes[MediaStreamAttributeKeys.CodecPrivateData] = waveFormat; | |
// Make description to add to available streams list | |
var availableMediaStreams = new List<MediaStreamDescription>(); | |
mediaStreamDescription = new MediaStreamDescription(MediaStreamType.Audio, mediaStreamAttributes); | |
availableMediaStreams.Add(mediaStreamDescription); | |
// Set some appropriate keys in the media source dictionary | |
var mediaSourceAttributes = new Dictionary<MediaSourceAttributesKeys, string>(); | |
mediaSourceAttributes[MediaSourceAttributesKeys.Duration] = "0"; | |
mediaSourceAttributes[MediaSourceAttributesKeys.CanSeek] = "false"; | |
// Signal that the open operation is completed | |
ReportOpenMediaCompleted(mediaSourceAttributes, availableMediaStreams); | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
AudioStreamBasicDescription audioFormat; | |
audioFormat.mSampleRate = 44100.00; | |
audioFormat.mFormatID = kAudioFormatLinearPCM; | |
audioFormat.mFormatFlags = kAudioFormatFlagIsPacked | kAudioFormatFlagIsSignedInteger; | |
audioFormat.mFramesPerPacket = 1; | |
audioFormat.mChannelsPerFrame = 1; | |
audioFormat.mBitsPerChannel = 16; | |
audioFormat.mBytesPerPacket = 2; | |
audioFormat.mBytesPerFrame = 2; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment