コード例 #1
1
ファイル: WaveFileHelper.cs プロジェクト: JoeGilkey/RadioLog
 public static void ProcessProvider(NAudio.Wave.ISampleProvider provider, string sourceName)
 {
     if (provider == null)
         return;
     float[] buffer = new float[1024];
     bool bContinue = true;
     int sampleRate = provider.WaveFormat.SampleRate;
     Decoders.MDC1200 mdc = new Decoders.MDC1200(sampleRate, MDCDelegate, sourceName);
     //Decoders.STAR star = new Decoders.STAR(sampleRate, null, RadioLog.AudioProcessing.Decoders.STAR.star_format.star_format_1_16383);
     while (bContinue)
     {
         int iCnt = provider.Read(buffer, 0, buffer.Length);
         bContinue = iCnt > 0;
         if (bContinue)
         {
             mdc.ProcessSamples(buffer, iCnt, true);
             //star.star_decoder_process_samples(buffer, iCnt);
         }
     }
 }
コード例 #2
0
ファイル: NAudioWrapper.cs プロジェクト: YaStark/ShazamO
        private static int[][] _readMp3(NAudio.Wave.Mp3FileReader reader)
        {
            // Preparing converting
            int bytePerSample = reader.WaveFormat.BitsPerSample / 8 * reader.WaveFormat.Channels;

            int samplesCount = (int)(reader.Length / bytePerSample);

            int[][] receivedSamples = new int[reader.WaveFormat.Channels][];
            for (int i = 0; i < receivedSamples.Length; i++) receivedSamples[i] = new int[samplesCount];

            switch (reader.WaveFormat.BitsPerSample)
            {
                case 32:
                    #region 32 bitrate
                    for (int i = 0; i < samplesCount; i++)
                    {
                        byte[] read = new byte[bytePerSample];
                        int received = reader.Read(read, 0, bytePerSample);
                        if (received < bytePerSample) throw new EndOfStreamException();

                        for (int j = 0; j < receivedSamples.Length; j++)
                        {
                            receivedSamples[j][i] = BitConverter.ToInt32(read, j * 4);
                        }
                    }
                    #endregion
                    break;

                case 24:
                    #region 24 bitrate
                    for (int i = 0; i < samplesCount; i++)
                    {
                        byte[] read = new byte[bytePerSample];
                        int received = reader.Read(read, 0, bytePerSample);
                        if (received < bytePerSample) throw new EndOfStreamException();
                        int n = 0;

                        for (int j = 0; j < receivedSamples.Length; j++)
                        {
                            receivedSamples[j][i] = (read[n] << 16) + (read[n + 1] << 8) + read[n + 2];
                            n += 3;
                        }
                    }
                    #endregion
                    break;

                case 16:
                    #region 16 bitrate
                    for (int i = 0; i < samplesCount; i++)
                    {
                        byte[] read = new byte[bytePerSample];
                        int received = reader.Read(read, 0, bytePerSample);
                        if (received < bytePerSample) throw new EndOfStreamException();

                        for (int j = 0; j < receivedSamples.Length; j++)
                        {
                            receivedSamples[j][i] = BitConverter.ToInt16(read, j * 2);
                        }
                    }
                    #endregion
                    break;

                case 8:
                    #region 8 bitrate
                    for (int i = 0; i < samplesCount; i++)
                    {
                        byte[] read = new byte[bytePerSample];
                        int received = reader.Read(read, 0, bytePerSample);
                        if (received < bytePerSample) throw new EndOfStreamException();

                        for (int j = 0; j < receivedSamples.Length; j++)
                        {
                            receivedSamples[j][i] = BitConverter.ToInt32(read, j);
                        }
                    }
                    #endregion
                    break;

                default:
                    throw new NotImplementedException("This file format is not supported");
            }
            return receivedSamples;
        }