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

[MGCB] Write averageBytesPerSecond and blockAlign for SoundEffect #4254

Merged
merged 1 commit into from
Dec 14, 2015
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 19 additions & 5 deletions MonoGame.Framework.Content.Pipeline/Audio/AudioContent.cs
Original file line number Diff line number Diff line change
Expand Up @@ -260,14 +260,28 @@ public void ConvertFormat(ConversionFormat formatType, ConversionQuality quality
case "streams.stream.0.channels":
channelCount = int.Parse(kv[1].Trim('"'), numberFormat);
break;
case "streams.stream.0.bit_rate":
averageBytesPerSecond = (int.Parse(kv[1].Trim('"'), numberFormat) / 8);
break;
}
}

// This information is not available from ffprobe (and may or may not
// be relevant for non-PCM formats anyway):
//
// * averageBytesPerSecond
// * blockAlign
// Calculate blockAlign.
switch (formatType)
{
case ConversionFormat.Pcm:
// Block alignment value is the number of bytes in an atomic unit (that is, a block) of audio for a particular format. For Pulse Code Modulation (PCM) formats, the formula for calculating block alignment is as follows:
// • Block Alignment = Bytes per Sample x Number of Channels
// For example, the block alignment value for 16-bit PCM format mono audio is 2 (2 bytes per sample x 1 channel). For 16-bit PCM format stereo audio, the block alignment value is 4.
// https://msdn.microsoft.com/en-us/library/system.speech.audioformat.speechaudioformatinfo.blockalign(v=vs.110).aspx
blockAlign = (bitsPerSample / 8) * channelCount;
break;
default:
// blockAlign is not available from ffprobe (and may or may not
// be relevant for non-PCM formats anyway)
break;
}


this.duration = TimeSpan.FromSeconds(durationInSeconds);
this.format = new AudioFormat(
Expand Down