Ejemplo n.º 1
0
        private static int ReadWavFile(string path, out AudioData ad)
        {
            ad = new AudioData();

            using (var br = new BinaryReader(File.Open(path, FileMode.Open, FileAccess.Read, FileShare.Read))) {
                var reader = new WavRWLib2.WavReader();
                if (!reader.ReadHeaderAndSamples(br, 0, -1))
                {
                    MessageBox.Show(
                        string.Format("Error: Failed to read WAV file: {0}", path));
                    return(-1);
                }

                ad.meta              = new WWFlacRWCS.Metadata();
                ad.meta.albumStr     = reader.AlbumName;
                ad.meta.artistStr    = reader.ArtistName;
                ad.meta.titleStr     = reader.Title;
                ad.meta.pictureBytes = reader.PictureBytes;
                ad.picture           = reader.PictureData;
                ad.meta.totalSamples = reader.NumFrames;
                ad.meta.channels     = reader.NumChannels;
                ad.meta.sampleRate   = reader.SampleRate;

                var interleaved    = reader.GetSampleArray();
                int bytesPerSample = reader.BitsPerSample / 8;

                ad.pcm = new List <AudioDataPerChannel>();
                for (int ch = 0; ch < reader.NumChannels; ++ch)
                {
                    var pcmOneChannel = new byte[reader.NumFrames * bytesPerSample];
                    for (int i = 0; i < reader.NumFrames; ++i)
                    {
                        for (int b = 0; b < reader.BitsPerSample / 8; ++b)
                        {
                            pcmOneChannel[bytesPerSample * i + b] =
                                interleaved[bytesPerSample * (reader.NumChannels * i + ch) + b];
                        }
                    }

                    var pcm24 = PcmDataLib.Util.ConvertTo24bit(reader.BitsPerSample, reader.NumFrames, reader.SampleValueRepresentationType, pcmOneChannel);

                    var adp = new AudioDataPerChannel();
                    adp.data          = pcm24;
                    adp.offsBytes     = 0;
                    adp.bitsPerSample = 24;
                    adp.totalSamples  = ad.meta.totalSamples;
                    ad.pcm.Add(adp);
                }

                // converted to 24bit
                ad.meta.bitsPerSample  = 24;
                ad.preferredSaveFormat = FileFormatType.FLAC;
                return(0);
            }
        }
Ejemplo n.º 2
0
        private void buttonStartConversion_Click(object sender, RoutedEventArgs e)
        {
            if (textBoxInputFile.Text.Length == 0) {
                MessageBox.Show(Properties.Resources.ErrSpecifyInputWavFile);
                return;
            }
            if (textBoxOutputFile.Text.Length == 0) {
                MessageBox.Show(Properties.Resources.ErrSpecifyOutputWavFile);
                return;
            }

            string pathRead = textBoxInputFile.Text;
            string pathWrite = textBoxOutputFile.Text;

            WavRWLib2.WavReader r = new WavRWLib2.WavReader();
            using (var br = new BinaryReader(File.Open(pathRead, FileMode.Open, FileAccess.Read, FileShare.Read))) {
                if (!r.ReadHeaderAndSamples(br, 0, -1)) {
                    string s = string.Format("エラー: ファイル読み込み失敗 {0}", pathRead);
                    MessageBox.Show(s);
                    Log(s + "\n");
                    return;
                }
            }

            Log(string.Format("WAVファイル読み込み。{0}\n    読み込んだファイルのfmt subchunkSize = {1}\n", pathRead, r.FmtSubChunkSize));

            WavRWLib2.WavWriter w = new WavRWLib2.WavWriter();

            string directory = System.IO.Path.GetDirectoryName(pathWrite);
            if (!System.IO.Directory.Exists(directory)) {
                System.IO.Directory.CreateDirectory(directory);
            }

            using (var bw = new BinaryWriter(File.Open(pathWrite, FileMode.Create, FileAccess.Write, FileShare.Write))) {
                w.Write(bw, r.NumChannels, r.BitsPerSample, r.ValidBitsPerSample, r.SampleRate, r.SampleValueRepresentationType, r.NumFrames, r.GetSampleArray());
            }
            Log(string.Format("WAVファイル書き込み終了。{0}\n", pathWrite));
        }
Ejemplo n.º 3
0
        private static int ReadWavFile(string path, out AudioData ad)
        {
            ad = new AudioData();

            using (var br = new BinaryReader(File.Open(path, FileMode.Open, FileAccess.Read, FileShare.Read))) {
                var reader = new WavRWLib2.WavReader();
                if (!reader.ReadHeaderAndSamples(br, 0, -1)) {
                    MessageBox.Show(
                        string.Format("Error: Failed to read WAV file: {0}", path));
                    return -1;
                }

                ad.meta = new WWFlacRWCS.Metadata();
                ad.meta.albumStr = reader.AlbumName;
                ad.meta.artistStr = reader.ArtistName;
                ad.meta.titleStr = reader.Title;
                ad.meta.pictureBytes = reader.PictureBytes;
                ad.picture = reader.PictureData;
                ad.meta.totalSamples = reader.NumFrames;
                ad.meta.channels = reader.NumChannels;
                ad.meta.sampleRate = reader.SampleRate;

                var interleaved = reader.GetSampleArray();
                int bytesPerSample = reader.BitsPerSample / 8;

                ad.pcm = new List<AudioDataPerChannel>();
                for (int ch = 0; ch < reader.NumChannels; ++ch) {

                    var pcmOneChannel = new byte[reader.NumFrames * bytesPerSample];
                    for (int i = 0; i < reader.NumFrames; ++i) {
                        for (int b = 0; b < reader.BitsPerSample / 8; ++b) {
                            pcmOneChannel[bytesPerSample * i + b] =
                                interleaved[bytesPerSample * (reader.NumChannels * i + ch) + b];
                        }
                    }

                    var pcm24 = PcmDataLib.Util.ConvertTo24bit(reader.BitsPerSample, reader.NumFrames, reader.SampleValueRepresentationType, pcmOneChannel);

                    var adp = new AudioDataPerChannel();
                    adp.data = pcm24;
                    adp.offsBytes = 0;
                    adp.bitsPerSample = 24;
                    adp.totalSamples = ad.meta.totalSamples;
                    ad.pcm.Add(adp);
                }

                // converted to 24bit
                ad.meta.bitsPerSample = 24;
                ad.preferredSaveFormat = FileFormatType.FLAC;
                return 0;
            }
        }
Ejemplo n.º 4
0
        private void buttonStartConversion_Click(object sender, RoutedEventArgs e)
        {
            if (textBoxInputFile.Text.Length == 0)
            {
                MessageBox.Show(Properties.Resources.ErrSpecifyInputWavFile);
                return;
            }
            if (textBoxOutputFile.Text.Length == 0)
            {
                MessageBox.Show(Properties.Resources.ErrSpecifyOutputWavFile);
                return;
            }

            string pathRead  = textBoxInputFile.Text;
            string pathWrite = textBoxOutputFile.Text;

            WavRWLib2.WavReader r = new WavRWLib2.WavReader();
            using (var br = new BinaryReader(File.Open(pathRead, FileMode.Open, FileAccess.Read, FileShare.Read))) {
                if (!r.ReadHeaderAndSamples(br, 0, -1))
                {
                    string s = string.Format("エラー: ファイル読み込み失敗 {0}", pathRead);
                    MessageBox.Show(s);
                    Log(s + "\n");
                    return;
                }
            }

            Log(string.Format("WAVファイル読み込み。{0}\n    読み込んだファイルのfmt subchunkSize = {1}\n", pathRead, r.FmtSubChunkSize));

            WavRWLib2.WavWriter w = new WavRWLib2.WavWriter();

            string directory = System.IO.Path.GetDirectoryName(pathWrite);

            if (!System.IO.Directory.Exists(directory))
            {
                System.IO.Directory.CreateDirectory(directory);
            }

            using (var bw = new BinaryWriter(File.Open(pathWrite, FileMode.Create, FileAccess.Write, FileShare.Write))) {
                w.Write(bw, r.NumChannels, r.BitsPerSample, r.ValidBitsPerSample, r.SampleRate, r.SampleValueRepresentationType, r.NumFrames, r.GetSampleArray());
            }
            Log(string.Format("WAVファイル書き込み終了。{0}\n", pathWrite));
        }