Stardew_Valley_Mods/GeneralMods/StardewSymphony/Framework/SongsProcessor/WaveFile.cs

66 lines
4.2 KiB
C#
Raw Blame History

This file contains invisible Unicode characters

This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

using System;
using System.IO;
using System.Collections.Generic;
using System.Linq;
using System.Text;
#region File Description
//-----------------------------------------------------------------------------
// WaveFile.cs
//
// Microsoft XNA Community Game Platform
// Copyright (C) Microsoft Corporation. All rights reserved.
//-----------------------------------------------------------------------------
#endregion
namespace StardewSymphony.Framework.SongsProcessor
{
public class WaveFile
{
public int SampleRate { get; private set; }
public int BitDepth { get; private set; }
public int Channels { get; private set; }
public byte[] Data { get; private set; }
private WaveFile() { }
public static WaveFile Parse(System.IO.Stream waveFileStream)
{
BinaryReader reader = new BinaryReader(waveFileStream);
int chunkID = reader.ReadInt32();
int fileSize = reader.ReadInt32();
int riffType = reader.ReadInt32();
int fmtID = reader.ReadInt32();
int fmtSize = reader.ReadInt32();
int fmtCode = reader.ReadInt16();
int fmtChannels = reader.ReadInt16();
int fmtSampleRate = reader.ReadInt32();
int fmtAvgBPS = reader.ReadInt32();
int fmtBlockAlign = reader.ReadInt16();
int fmtBitDepth = reader.ReadInt16();
if (fmtSize == 18)
{
// Read any extra values
int fmtExtraSize = reader.ReadInt16();
reader.ReadBytes(fmtExtraSize);
}
int dataID = reader.ReadInt32();
int dataSize = reader.ReadInt32();
byte[] dataBytes = reader.ReadBytes(dataSize);
WaveFile parsedFile = new WaveFile()
{
SampleRate = fmtSampleRate,
BitDepth = fmtBitDepth,
Channels = fmtChannels,
Data = dataBytes
};
return parsedFile;
}
}
}