首页 最新 热门 推荐

  • 首页
  • 最新
  • 热门
  • 推荐

C# Mel-Spectrogram 梅尔频谱

  • 25-02-19 03:01
  • 2529
  • 13142
blog.csdn.net

目录

介绍

Main features

Philosophy of NWaves

效果 

项目

代码

下载


C# Mel-Spectrogram 梅尔频谱

介绍

利用NWaves实现Mel-Spectrogram 梅尔频谱

NWaves github 地址:https://github.com/ar1st0crat/NWaves

NWaves is a .NET DSP library with a lot of audio processing functions.

Main features

  •  major DSP transforms (FFT, DCT, MDCT, STFT, FWT, Hilbert, Hartley, Mellin, cepstral, Goertzel)
  •  signal builders (sine, white/pink/red/Perlin noise, awgn, triangle, sawtooth, square, pulse, ramp, ADSR, wavetable)
  •  basic LTI digital filters (moving average, comb, Savitzky-Golay, pre/de-emphasis, DC removal, RASTA)
  •  FIR/IIR filtering (offline and online), zero-phase filtering
  •  BiQuad filters (low-pass, high-pass, band-pass, notch, all-pass, peaking, shelving)
  •  1-pole filters (low-pass, high-pass)
  •  IIR filters (Bessel, Butterworth, Chebyshev I & II, Elliptic, Thiran)
  •  basic operations (convolution, cross-correlation, rectification, amplification, fade / crossfade)
  •  block convolution (overlap-add / overlap-save offline and online)
  •  basic filter design & analysis (group delay, zeros/poles, BP, BR, HP from/to LP, SOS, combining filters)
  •  state space representation of LTI filters
  •  FIR filter design: frequency sampling, window-sinc, equiripple (Remez / Parks-McClellan)
  •  IIR filter design: IirNotch / IirPeak / IirCombNotch / IirCombPeak
  •  non-linear filters (median filter, distortion effects, bit crusher)
  •  windowing functions (Hamming, Blackman, Hann, Gaussian, Kaiser, KBD, triangular, Lanczos, flat-top, Bartlett)
  •  periodograms (Welch / Lomb-Scargle)
  •  psychoacoustic filter banks (Mel, Bark, Critical Bands, ERB, octaves) and VTLN warping
  •  customizable feature extraction (time-domain, spectral, MFCC, PNCC/SPNCC, LPC, LPCC, PLP, AMS)
  •  preconfigured MFCC extractors: HTK (MFCC-FB24), Slaney (MFCC-FB40)
  •  LPC conversions: LPC<->cepstrum, LPC<->LSF
  •  feature post-processing (mean and variance normalization, adding deltas) and CSV serialization
  •  spectral features (centroid, spread, flatness, entropy, rolloff, contrast, crest, decrease, noiseness, MPEG7)
  •  harmonic features (harmonic centroid and spread, inharmonicity, tristimulus, odd-to-even ratio)
  •  time-domain characteristics (rms, energy, zero-crossing rate, entropy)
  •  pitch tracking (autocorrelation, YIN, ZCR + Schmitt trigger, HSS/HPS, cepstrum)
  •  chromagram (chroma feature extractor)
  •  time scale modification (phase vocoder, PV with identity phase locking, WSOLA, PaulStretch)
  •  simple resampling, interpolation, decimation
  •  bandlimited resampling
  •  wavelets: haar, db, symlet, coiflet
  •  polyphase filters
  •  noise reduction (spectral subtraction, sciPy-style Wiener filtering)
  •  sound effects (echo, tremolo, wahwah, phaser, chorus, vibrato, flanger, pitch shift, morphing, robotize, whisperize)
  •  3D/Stereo audio (stereo panning, stereo and ping-pong delay, ITD-ILD, binaural panning)
  •  envelope following
  •  dynamics processing (limiter / compressor / expander / noise gate)
  •  harmonic/percussive separation
  •  Griffin-Lim algorithm
  •  Karplus-Strong synthesis
  •  PADSynth synthesis
  •  adaptive filtering (LMS, NLMS, LMF, SignLMS, RLS)
  •  simple modulation/demodulation (AM, ring, FM, PM)
  •  simple audio playback and recording

Philosophy of NWaves

NWaves was initially intended for research, visualizing and teaching basics of DSP and sound programming.

Usually, DSP code is quite complicated and difficult to read, because it's full of optimizations (which is actually a very good thing). NWaves project aims in particular at achieving a tradeoff between good understandable code/design and satisfactory performance. Yet, the main purpose of this lib is to offer the DSP codebase that would be:

  • easy to read and understand
  • easy to incorporate into existing projects
  • easy to port to other programming languages and frameworks
  • even possibly treated as the DSP/audio textbook.

效果 

项目

代码

using NWaves.Audio;
using NWaves.FeatureExtractors;
using NWaves.FeatureExtractors.Options;
using NWaves.Filters.Fda;
using NWaves.Signals;
using NWaves.Windows;
using System;
using System.IO;
using System.Text;
using System.Windows.Forms;

namespace C__Mel_Spectrogram_梅尔频谱
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        WaveFile waveContainer;
        StringBuilder sb = new StringBuilder();

        private void button1_Click(object sender, EventArgs e)
        {
            using (var stream = new FileStream("你好.wav", FileMode.Open))
            {
                waveContainer = new WaveFile(stream);
            }

            DiscreteSignal left = waveContainer[Channels.Left];
            //DiscreteSignal right = waveContainer[Channels.Right];

            //Mel-Spectrogram
            var fftSize = 1024;
            var hopSize = 512;
            var melCount = 16;
            int samplingRate = left.SamplingRate;

            var mfccExtractor = new FilterbankExtractor(
               new FilterbankOptions
               {
                   SamplingRate = samplingRate,
                   FrameSize = fftSize,
                   FftSize = fftSize,
                   HopSize = hopSize,
                   Window = WindowType.Hann,
                   FilterBank = FilterBanks.Triangular(fftSize, samplingRate, FilterBanks.MelBands(melCount, samplingRate)),
                   // if power = 1.0
                   // SpectrumType = SpectrumType.Magnitude
               });


            var mfccVectors = mfccExtractor.ParallelComputeFrom(left);

            sb.Clear();

            foreach (var item in mfccVectors)
            {
                sb.AppendLine(String.Join(",", item));
            }

            textBox1.Text = sb.ToString();
        }
    }
}

  1. using NWaves.Audio;
  2. using NWaves.FeatureExtractors;
  3. using NWaves.FeatureExtractors.Options;
  4. using NWaves.Filters.Fda;
  5. using NWaves.Signals;
  6. using NWaves.Windows;
  7. using System;
  8. using System.IO;
  9. using System.Text;
  10. using System.Windows.Forms;
  11. namespace C__Mel_Spectrogram_梅尔频谱
  12. {
  13. public partial class Form1 : Form
  14. {
  15. public Form1()
  16. {
  17. InitializeComponent();
  18. }
  19. WaveFile waveContainer;
  20. StringBuilder sb = new StringBuilder();
  21. private void button1_Click(object sender, EventArgs e)
  22. {
  23. using (var stream = new FileStream("你好.wav", FileMode.Open))
  24. {
  25. waveContainer = new WaveFile(stream);
  26. }
  27. DiscreteSignal left = waveContainer[Channels.Left];
  28. //DiscreteSignal right = waveContainer[Channels.Right];
  29. //Mel-Spectrogram
  30. var fftSize = 1024;
  31. var hopSize = 512;
  32. var melCount = 16;
  33. int samplingRate = left.SamplingRate;
  34. var mfccExtractor = new FilterbankExtractor(
  35. new FilterbankOptions
  36. {
  37. SamplingRate = samplingRate,
  38. FrameSize = fftSize,
  39. FftSize = fftSize,
  40. HopSize = hopSize,
  41. Window = WindowType.Hann,
  42. FilterBank = FilterBanks.Triangular(fftSize, samplingRate, FilterBanks.MelBands(melCount, samplingRate)),
  43. // if power = 1.0
  44. // SpectrumType = SpectrumType.Magnitude
  45. });
  46. var mfccVectors = mfccExtractor.ParallelComputeFrom(left);
  47. sb.Clear();
  48. foreach (var item in mfccVectors)
  49. {
  50. sb.AppendLine(String.Join(",", item));
  51. }
  52. textBox1.Text = sb.ToString();
  53. }
  54. }
  55. }

下载

源码下载

天天代码码天天
微信公众号
.NET 人工智能实践
注:本文转载自blog.csdn.net的天天代码码天天的文章"https://lw112190.blog.csdn.net/article/details/136482286"。版权归原作者所有,此博客不拥有其著作权,亦不承担相应法律责任。如有侵权,请联系我们删除。
复制链接
复制链接
相关推荐
发表评论
登录后才能发表评论和回复 注册

/ 登录

评论记录:

未查询到任何数据!
回复评论:

分类栏目

后端 (14832) 前端 (14280) 移动开发 (3760) 编程语言 (3851) Java (3904) Python (3298) 人工智能 (10119) AIGC (2810) 大数据 (3499) 数据库 (3945) 数据结构与算法 (3757) 音视频 (2669) 云原生 (3145) 云平台 (2965) 前沿技术 (2993) 开源 (2160) 小程序 (2860) 运维 (2533) 服务器 (2698) 操作系统 (2325) 硬件开发 (2492) 嵌入式 (2955) 微软技术 (2769) 软件工程 (2056) 测试 (2865) 网络空间安全 (2948) 网络与通信 (2797) 用户体验设计 (2592) 学习和成长 (2593) 搜索 (2744) 开发工具 (7108) 游戏 (2829) HarmonyOS (2935) 区块链 (2782) 数学 (3112) 3C硬件 (2759) 资讯 (2909) Android (4709) iOS (1850) 代码人生 (3043) 阅读 (2841)

热门文章

101
推荐
关于我们 隐私政策 免责声明 联系我们
Copyright © 2020-2025 蚁人论坛 (iYenn.com) All Rights Reserved.
Scroll to Top