728x90
반응형
728x170
▶ Program.cs
using System;
using NAudio.Wave;
namespace TestProject
{
/// <summary>
/// 프로그램
/// </summary>
class Program
{
//////////////////////////////////////////////////////////////////////////////////////////////////// Method
////////////////////////////////////////////////////////////////////////////////////////// Static
//////////////////////////////////////////////////////////////////////////////// Private
#region 프로그램 시작하기 - Main()
/// <summary>
/// 프로그램 시작하기
/// </summary>
private static void Main()
{
using(Mp3FileReader reader = new Mp3FileReader("SOUND\\sample.mp3"))
{
Console.WriteLine($"샘플 비율 : {reader.WaveFormat.SampleRate}");
Console.WriteLine($"채널 수 : {reader.WaveFormat.Channels}");
Console.WriteLine($"샘플당 비트 수 : {reader.WaveFormat.BitsPerSample}");
Console.WriteLine($"인코딩 : {reader.WaveFormat.Encoding}");
Console.WriteLine($"블럭 정렬 : {reader.WaveFormat.BlockAlign}");
Console.WriteLine($"초당 평균 바이트 수 : {reader.WaveFormat.AverageBytesPerSecond}");
Console.WriteLine($"재생 시간 (단위 : 초) : {reader.Length / reader.WaveFormat.AverageBytesPerSecond}");
if(reader.WaveFormat.Encoding != WaveFormatEncoding.Pcm)
{
return;
}
int bufferLength = (int)reader.Length;
byte[] buffer = new byte[bufferLength];
if(reader.WaveFormat.Channels == 1) // 모노 채널인 경우
{
int readCount = reader.Read(buffer, 0, (int)bufferLength);
for(int i = 0; i < readCount; i += 2)
{
short sample = BitConverter.ToInt16(buffer, i);
Console.Write(sample);
Console.Write(" ");
if(i % 8 == 0)
{
Console.WriteLine();
}
}
}
else if(reader.WaveFormat.Channels == 2) // 스테레오 채널인 경우
{
int readCount = reader.Read(buffer, 0, (int)bufferLength);
for(int i = 0; i < readCount; i += 4)
{
short leftSample = BitConverter.ToInt16(buffer, i );
short rightSample = BitConverter.ToInt16(buffer, i + 2);
Console.Write($"{leftSample}, {rightSample}");
Console.Write(" ");
if(i % 16 == 0)
{
Console.WriteLine();
}
}
}
}
}
#endregion
}
}
728x90
반응형
그리드형(광고전용)
'C# > NAudio' 카테고리의 다른 글
[C#/NAUDIO/.NET5] MidiFile 클래스 : MIDI 파일 탐색하기 (0) | 2021.12.29 |
---|---|
[C#/NAUDIO/.NET5] MidiOut 클래스 : DeviceInfo 정적 메소드를 사용해 MIDI 출력 장치 열거하기 (0) | 2021.12.29 |
[C#/NAUDIO/.NET5] MidiIn 클래스 : DeviceInfo 정적 메소드를 사용해 MIDI 입력 장치 열거하기 (0) | 2021.12.29 |
[C#/NAUDIO/.NET5] SignalGenerator 클래스 사용하기 (0) | 2021.12.28 |
[C#/NAUDIO/.NET5] SmbPitchShiftingSampleProvider 클래스 : PitchFactor 속성을 사용해 피치 변조하기 (0) | 2021.12.28 |
[C#/NAUDIO/.NET5] WaveFormat 클래스 : CreateALawFormat 정적 메소드를 사용해 G.711 a-law 같은 포맷 사용하기 (0) | 2021.12.28 |
[C#/NAUDIO/.NET5] WaveFormat 클래스 : CreateCustomFormat 정적 메소드를 사용해 커스텀 포맷 사용하기 (0) | 2021.12.28 |
[C#/NAUDIO/.NET5] RawSourceWaveStream 클래스 사용하기 (0) | 2021.12.28 |
[C#/NAUDIO/.NET5] 건너뛰기(SkipOver) 최적화하기 (0) | 2021.12.28 |
[C#/NAUDIO/.NET5] WaveExtensionMethods 클래스 : Skip/Take 확장 메소드를 사용해 오디오 파일 잘라내기 (0) | 2021.12.28 |
댓글을 달아 주세요