zoukankan      html  css  js  c++  java
  • C# BASS音频库 + DSP插件使用方法

    正确加载插件会显示如下图

    DSP插件需要BASS库支持,在debug目录加入bass_wadsp.dll扩展库

    完整代码如下:

    using System;
    using System.Collections.Generic;
    using System.ComponentModel;
    using System.Data;
    using System.Drawing;
    using System.Linq;
    using System.Text;
    using System.Windows.Forms;
    using Un4seen.Bass;
    using Un4seen.Bass.AddOn.WaDsp;
    
    namespace WindowsFormsApp3
    {
        public partial class Form3 : Form
        {
            public Form3()
            {
                InitializeComponent();
            }
    
            private void Form3_Load(object sender, EventArgs e)
            {
                //-1 表示 默认设备输出
                //44100 表示 输出采样率
                //BASS_DEVICE_CPSPEAKERS 表示输出模式
                if (!Bass.BASS_Init(-1, 44100, BASSInit.BASS_DEVICE_CPSPEAKERS, this.Handle))
                {
                    MessageBox.Show("出错了," + Bass.BASS_ErrorGetCode().ToString());
                }
            }
    
            string fileName;
            int stream;
            int dspHandle;
            int dspModule = 0;
            private void btn_play_Click(object sender, EventArgs e)
            {
                OpenFileDialog o = new OpenFileDialog();
                if (o.ShowDialog() == DialogResult.OK)
                {
                    fileName = o.FileName;
    
                    //第一个参数是文件名,
                    //第二个参数是文件流开始位置,
                    //第三个是文件流长度 0为使用文件整个长度,
                    //最后一个是流的创建模式
                    stream = Bass.BASS_StreamCreateFile(fileName, 0L, 0L, BASSFlag.BASS_DEFAULT);
    
                    Bass.BASS_ChannelPlay(stream, true); //开始播放
                }
            }
    
    
            private void btn_load_Click(object sender, EventArgs e)
            {
                OpenFileDialog o = new OpenFileDialog();
                if (o.ShowDialog() == DialogResult.OK)
                {
                    BassWaDsp.BASS_WADSP_Init(this.Handle);
                    dspHandle = BassWaDsp.BASS_WADSP_Load(o.FileName, 5, 5, 100, 100, null);
    
                    BassWaDsp.BASS_WADSP_Start(dspHandle, dspModule, 0);
    
                    int hDsp = BassWaDsp.BASS_WADSP_ChannelSetDSP(dspHandle, stream, 1);
                }
            }
    
            private void btn_dsp_set_Click(object sender, EventArgs e)
            {
                if (dspHandle >= 0 && dspModule >= 0)
                {
                    BassWaDsp.BASS_WADSP_Config(dspHandle);
                }
            }
    
            private void btn_dsp_stop_Click(object sender, EventArgs e)
            {
                BassWaDsp.BASS_WADSP_Stop(dspHandle);
            }
    
            private void Form3_FormClosing(object sender, FormClosingEventArgs e)
            {
                Bass.BASS_ChannelStop(stream);  //停止播放
                BassWaDsp.BASS_WADSP_Stop(dspHandle);
            }
        }
    }
    View Code

    需要注意一下的是,同EQ设置一样,每次播放完歌曲 播放新的歌曲时,都要重新设置一次。

    可以这样操作:

    最后附上demo地址:

    链接: https://pan.baidu.com/s/1ocvKixBjIvBk6tKv4uzBfQ 提取码: dvtn

    另附同款dsp音效(更多音效可以去网上找找):

    链接: https://pan.baidu.com/s/1Jy60GqbcnNduZ0kFbANA4w 提取码: udes

  • 相关阅读:
    Anaconda下载与安装
    短语,直接短语,句柄,素短语,最左素短语区分
    sublime text安装package control
    Json数据解析
    hbase shell命令
    Web三级联动,数据库到界面
    解决C#窗体项目在win10运行模糊的问题
    Java通过反射访问及修改类内的私有变量
    PyCharm更改.PyCharm配置文件夹存储位置
    MineCraft Forge开发mod踩坑记录
  • 原文地址:https://www.cnblogs.com/mumu9008/p/12930729.html
Copyright © 2011-2022 走看看