Wav 파일 충족되었으며 어레이입니다 data-in 읽는 방법

데릭쉐퍼드와 모두 실현할 수 배열로 샘플링합니다 wav 파일 한 개 또는 2 개의 계속 그렇게 할 경우 스테레오) 내가 할 수 있도록 일부 수정해야 적용하십시오 저들이요 나도 궁금 이 작업을 쉽게 수행할 경우 (없이 대부분 외부 라이브러리). 저는 전혀 경험이 있는 판독값 사운드 파일, 그래서 내가 모르는 # 39, don& 대해 별로 주제라서요.

질문에 대한 의견 (2)

이 코드는 이 어떻게해야합니다 의심하게 된다. 이 웨이브 파일 변환 해야 할 수 있지만, 표준화된 연산뿐 어레이입니다 (-1) 을 1 로) 할 것이 아니라 사소한 충족되었으며 int / 파선-짧은 어레이입니다 (분리하십시오 /32768.0 '대신' 비트 및 추가 32768). 바로 이 ' []' 가 될 수 있다면 wav 파일 어레이입니다 설정되었습니다 nulll 로드되었는지 모노.

39, s, t # 39 내가 can& 하였노라너희가 it& 완전히 글머리표 대비성 (잠재적 1 씩 오프하도록 오류뿐만) 이지만, 만든 후 65536 샘플링합니다 어레이이며 waveset 만들어 - 1 에서 1, # 39, & # 39 through& 검색하기를 것으로 샘플링합니다 없었다 천장 또는 기본.


// convert two bytes to one double in the range -1 to 1
static double bytesToDouble(byte firstByte, byte secondByte) {
    // convert two bytes to one short (little endian)
    short s = (secondByte 
해설 (9)

16 비트 PCM 너회의 WAV 파일 map_layer 가정할 때, 즉 가장 일반적인) 나우디오 를 사용할 수 있습니다 다음 검토완료 아웃해야 바이트 배열을 붙여넣습니다 카피됐나 배열로 편의를 위해 16 비트 정수. 이 경우, 왼쪽, 오른쪽 인터리브된 샘플링합니다 스테레오 됩니다.

using (WaveFileReader reader = new WaveFileReader("myfile.wav"))
{
    Assert.AreEqual(16, reader.WaveFormat.BitsPerSample, "Only works with 16 bit audio");
    byte[] buffer = new byte[reader.Length];
    int read = reader.Read(buffer, 0, buffer.Length);
    short[] sampleBuffer = new short[read / 2];
    Buffer.BlockCopy(buffer, 0, sampleBuffer, 0, read);
}

그러니까말이야 하고 싶은 것을 확인할 수 있지만, 제 3 자 라이브러리보다는 스케쳐내 대처하기 위해 WAV 파일을 사용하면 추가 청크에서 난 그냥 피하는 등 44 바이트입니다 파일에 제안하세요 외곽진입 있다.

해설 (1)
해결책

WAV 파일 (적어도, 비압축 수준들과) 가 상당히 쉽습니다. S # 39, there& 헤더입니다 다음 데이터 inet6.0 거잖나.

39 의 here& 숭배자들로부터도 참조: https://ccrma.stanford.edu/courses/422/projects/WaveFormat/&lt, /strike&gt strike&gt <;; ([대칭복사] (https://web.archive.org/web/20141213140451/https ://ccrma.stanford.edu/courses/422/projects/waveformat/))

해설 (5)

32 비트 또는 64 비트 인코딩되지 wav ruettgers 먹어서나 아니예 시에 있다.

다음 코드는 비트 처리 및 모노 스테레오: 16/32/64 /


static bool readWav( string filename, out float[] L, out float[] R )
{
    L = R = null;
    //float [] left = new float[1];

    //float [] right;
    try {
        using (FileStream fs = File.Open(filename,FileMode.Open))
        {
            BinaryReader reader = new BinaryReader(fs);

            // chunk 0
            int chunkID       = reader.ReadInt32();
            int fileSize      = reader.ReadInt32();
            int riffType      = reader.ReadInt32();

            // chunk 1
            int fmtID         = reader.ReadInt32();
            int fmtSize       = reader.ReadInt32(); // bytes for this chunk
            int fmtCode       = reader.ReadInt16();
            int channels      = reader.ReadInt16();
            int sampleRate    = reader.ReadInt32();
            int byteRate      = reader.ReadInt32();
            int fmtBlockAlign = reader.ReadInt16();
            int bitDepth      = reader.ReadInt16();

            if (fmtSize == 18)
            {
                // Read any extra values
                int fmtExtraSize = reader.ReadInt16();
                reader.ReadBytes(fmtExtraSize);
            }

            // chunk 2
            int dataID = reader.ReadInt32();
            int bytes = reader.ReadInt32();

            // DATA!
            byte[] byteArray = reader.ReadBytes(bytes);

            int bytesForSamp = bitDepth/8;
            int samps = bytes / bytesForSamp;

            float[] asFloat = null;
            switch( bitDepth ) {
                case 64:
                    double[] 
                    asDouble          = new double[samps];  
                    Buffer.BlockCopy(byteArray, 0, asDouble, 0, bytes);
                    asFloat = Array.ConvertAll( asDouble, e => (float)e );
                    break;
                case 32:
                    asFloat           = new float[samps];   
                    Buffer.BlockCopy(byteArray, 0, asFloat, 0, bytes);
                    break;
                case 16:
                    Int16 [] 
                    asInt16           = new Int16[samps];   
                    Buffer.BlockCopy(byteArray, 0, asInt16, 0, bytes);
                    asFloat = Array.ConvertAll( asInt16, e => e / (float)Int16.MaxValue );
                    break;
                default:
                    return false;
            }

            switch( channels ) {
            case 1:
                L = asFloat;
                R = null;
                return true;
            case 2:
                L = new float[samps];
                R = new float[samps];
                for( int i=0, s=0; i
해설 (5)

http://hourlyapps.blogspot.com/2008/07/open-source-wave-graph-c-net-control.html &lt br>; # 39 의 스펙트럼은 제어점 슬라이드에서는 디스크입니다. Display& Wav 파일, 이 역시 [] 의 바이트 디코딩할 수 있는 역할을 하며, Wav 파일 재생 및 / 또는 변경 그 값을.

그냥 # 39 에 대한 제어 및 it& 다운로드하십시오 양호한 WAV 파일 조작.

해설 (0)

그냥 이렇게 wav 파일 배열로 가져올 수 있습니다.

[], 데이터 = file.레아달베이티스 바이트입니다 (FilePath&quot ";)

그러나 플레처 격리합니다 헤더도 데이터가 필요한 것 같다 "고 말했다. 단순한 오프셋된 한다.

해설 (0)

종료기 [놀이를하고 오디오 데이터를 어레이로부터] [1]

PlayerEx pl = new PlayerEx();

private static void PlayArray(PlayerEx pl)
{
    double fs = 8000; // sample freq
    double freq = 1000; // desired tone
    short[] mySound = new short[4000];
    for (int i = 0; i < 4000; i++)
    {
        double t = (double)i / fs; // current time
        mySound[i] = (short)(Math.Cos(t * freq) * (short.MaxValue));
    }
    IntPtr format = AudioCompressionManager.GetPcmFormat(1, 16, (int)fs);
    pl.OpenPlayer(format);
    byte[] mySoundByte = new byte[mySound.Length * 2];
    Buffer.BlockCopy(mySound, 0, mySoundByte, 0, mySoundByte.Length);
    pl.AddData(mySoundByte);
    pl.StartPlay();
}

[1]: # tip32 티파스트라프스, http://alvas.net/alvas.audio

해설 (0)