Java SourceDataLine 播放音频 显示频谱

news2024/10/7 3:29:10

Java SourceDataLine 播放MP3音频 显示频谱

  • 1 添加依赖
  • 2 快速傅里叶变换
    • 2.1 FFT.java
    • 2.2 Complex.java
  • 3 音频播放
    • 3.1 Player.java
    • 3.1 XPlayer.java
  • 4 显示频谱
  • 5 结果

项目Value
音频格式 添加依赖
*.wav(JDK 原生支持)
*.pcm(JDK 原生支持)
*.au(JDK 原生支持)
*.aiff(JDK 原生支持)
*.mp3mp3spi.jar
*.flacjflac-codec.jar

1 添加依赖

<dependency>
	<groupId>com.googlecode.soundlibs</groupId>
	<artifactId>mp3spi</artifactId>
	<version>1.9.5.4</version>
</dependency>

<!-- 如果需要解码播放flac文件则引入这个jar包 -->
<dependency>
	<groupId>org.jflac</groupId>
	<artifactId>jflac-codec</artifactId>
	<version>1.5.2</version>
</dependency>

2 快速傅里叶变换

2.1 FFT.java

package com.xu.music.player.fft;

import java.util.stream.Stream;

public class FFT {

    /**
     * compute the FFT of x[], assuming its length is a power of 2
     *
     * @param x
     * @return
     */
    public static Complex[] fft(Complex[] x) {
        int n = x.length;

        // base case
        if (n == 1) {
            return new Complex[]{x[0]};
        }

        // radix 2 Cooley-Tukey FFT
        if (n % 2 != 0) {
            throw new RuntimeException("N is not a power of 2");
        }

        // fft of even terms
        Complex[] even = new Complex[n / 2];
        for (int k = 0; k < n / 2; k++) {
            even[k] = x[2 * k];
        }
        Complex[] q = fft(even);

        // fft of odd terms
        Complex[] odd = even; // reuse the array
        for (int k = 0; k < n / 2; k++) {
            odd[k] = x[2 * k + 1];
        }
        Complex[] r = fft(odd);

        // combine
        Complex[] y = new Complex[n];
        for (int k = 0; k < n / 2; k++) {
            double kth = -2 * k * Math.PI / n;
            Complex wk = new Complex(Math.cos(kth), Math.sin(kth));
            y[k] = q[k].plus(wk.times(r[k]));
            y[k + n / 2] = q[k].minus(wk.times(r[k]));
        }
        return y;
    }

    /**
     * compute the inverse FFT of x[], assuming its length is a power of 2
     *
     * @param x
     * @return
     */
    public static Complex[] ifft(Complex[] x) {
        int n = x.length;
        Complex[] y = new Complex[n];

        // take conjugate
        for (int i = 0; i < n; i++) {
            y[i] = x[i].conjugate();
        }

        // compute forward FFT
        y = fft(y);

        // take conjugate again
        for (int i = 0; i < n; i++) {
            y[i] = y[i].conjugate();
        }

        // divide by N
        for (int i = 0; i < n; i++) {
            y[i] = y[i].scale(1.0 / n);
        }

        return y;

    }

    /**
     * compute the circular convolution of x and y
     *
     * @param x
     * @param y
     * @return
     */
    public static Complex[] cconvolve(Complex[] x, Complex[] y) {

        // should probably pad x and y with 0s so that they have same length and are powers of 2
        if (x.length != y.length) {
            throw new RuntimeException("Dimensions don't agree");
        }

        int n = x.length;

        // compute FFT of each sequence,求值
        Complex[] a = fft(x);
        Complex[] b = fft(y);

        // point-wise multiply,点值乘法
        Complex[] c = new Complex[n];
        for (int i = 0; i < n; i++) {
            c[i] = a[i].times(b[i]);
        }

        // compute inverse FFT,插值
        return ifft(c);
    }

    /**
     * compute the linear convolution of x and y
     *
     * @param x
     * @param y
     * @return
     */
    public static Complex[] convolve(Complex[] x, Complex[] y) {
        Complex zero = new Complex(0, 0);
        // 2n次数界,高阶系数为0.
        Complex[] a = new Complex[2 * x.length];
        for (int i = 0; i < x.length; i++) {
            a[i] = x[i];
        }
        for (int i = x.length; i < 2 * x.length; i++) {
            a[i] = zero;
        }

        Complex[] b = new Complex[2 * y.length];
        for (int i = 0; i < y.length; i++) {
            b[i] = y[i];
        }
        for (int i = y.length; i < 2 * y.length; i++) {
            b[i] = zero;
        }

        return cconvolve(a, b);
    }

    /**
     * Complex[] to double array for MusicPlayer
     *
     * @param x
     * @return
     */
    public static Double[] array(Complex[] x) {//for MusicPlayer
        int len = x.length;//修正幅过小 输出幅值 * 2 / length * 50
        return Stream.of(x).map(a -> a.abs() * 2 / len * 50).toArray(Double[]::new);
    }

    /**
     * display an array of Complex numbers to standard output
     *
     * @param x
     * @param title
     */
    public static void show(Double[] x, String... title) {
        for (String s : title) {
            System.out.print(s);
        }
        System.out.println();
        System.out.println("-------------------");
        for (int i = 0, len = x.length; i < len; i++) {
            System.out.println(x[i]);
        }
        System.out.println();
    }

    /**
     * display an array of Complex numbers to standard output
     *
     * @param x
     * @param title
     */
    public static void show(Complex[] x, String title) {
        System.out.println(title);
        System.out.println("-------------------");
        for (int i = 0, len = x.length; i < len; i++) {
            // 输出幅值需要 * 2 / length
            System.out.println(x[i].abs() * 2 / len);
        }
        System.out.println();
    }

    /**
     * 将数组数据重组成2的幂次方输出
     *
     * @param data
     * @return
     */
    public static Double[] pow2DoubleArr(Double[] data) {

        // 创建新数组
        Double[] newData = null;

        int dataLength = data.length;

        int sumNum = 2;
        while (sumNum < dataLength) {
            sumNum = sumNum * 2;
        }
        int addLength = sumNum - dataLength;

        if (addLength != 0) {
            newData = new Double[sumNum];
            System.arraycopy(data, 0, newData, 0, dataLength);
            for (int i = dataLength; i < sumNum; i++) {
                newData[i] = 0d;
            }
        } else {
            newData = data;
        }

        return newData;
    }

    /**
     * 去偏移量
     *
     * @param originalArr 原数组
     * @return 目标数组
     */
    public static Double[] deskew(Double[] originalArr) {
        // 过滤不正确的参数
        if (originalArr == null || originalArr.length <= 0) {
            return null;
        }

        // 定义目标数组
        Double[] resArr = new Double[originalArr.length];

        // 求数组总和
        Double sum = 0D;
        for (int i = 0; i < originalArr.length; i++) {
            sum += originalArr[i];
        }

        // 求数组平均值
        Double aver = sum / originalArr.length;

        // 去除偏移值
        for (int i = 0; i < originalArr.length; i++) {
            resArr[i] = originalArr[i] - aver;
        }

        return resArr;
    }

}

2.2 Complex.java

package com.xu.music.player.fft;

import java.util.Objects;

public class Complex {

    private final double re; // the real part
    private final double im; // the imaginary part

    // create a new object with the given real and imaginary parts
    public Complex(double real, double imag) {
        re = real;
        im = imag;
    }

    // a static version of plus
    public static Complex plus(Complex a, Complex b) {
        double real = a.re + b.re;
        double imag = a.im + b.im;
        Complex sum = new Complex(real, imag);
        return sum;
    }

    // sample client for testing
    public static void main(String[] args) {
        Complex a = new Complex(3.0, 4.0);
        Complex b = new Complex(-3.0, 4.0);

        System.out.println("a            = " + a);
        System.out.println("b            = " + b);
        System.out.println("Re(a)        = " + a.re());
        System.out.println("Im(a)        = " + a.im());
        System.out.println("b + a        = " + b.plus(a));
        System.out.println("a - b        = " + a.minus(b));
        System.out.println("a * b        = " + a.times(b));
        System.out.println("b * a        = " + b.times(a));
        System.out.println("a / b        = " + a.divides(b));
        System.out.println("(a / b) * b  = " + a.divides(b).times(b));
        System.out.println("conj(a)      = " + a.conjugate());
        System.out.println("|a|          = " + a.abs());
        System.out.println("tan(a)       = " + a.tan());
    }

    // return a string representation of the invoking Complex object
    @Override
    public String toString() {
        if (im == 0) {
            return re + "";
        }
        if (re == 0) {
            return im + "i";
        }
        if (im < 0) {
            return re + " - " + (-im) + "i";
        }
        return re + " + " + im + "i";
    }

    // return abs/modulus/magnitude
    public double abs() {
        return Math.hypot(re, im);
    }

    // return angle/phase/argument, normalized to be between -pi and pi
    public double phase() {
        return Math.atan2(im, re);
    }

    // return a new Complex object whose value is (this + b)
    public Complex plus(Complex b) {
        Complex a = this; // invoking object
        double real = a.re + b.re;
        double imag = a.im + b.im;
        return new Complex(real, imag);
    }

    // return a new Complex object whose value is (this - b)
    public Complex minus(Complex b) {
        Complex a = this;
        double real = a.re - b.re;
        double imag = a.im - b.im;
        return new Complex(real, imag);
    }

    // return a new Complex object whose value is (this * b)
    public Complex times(Complex b) {
        Complex a = this;
        double real = a.re * b.re - a.im * b.im;
        double imag = a.re * b.im + a.im * b.re;
        return new Complex(real, imag);
    }

    // return a new object whose value is (this * alpha)
    public Complex scale(double alpha) {
        return new Complex(alpha * re, alpha * im);
    }

    // return a new Complex object whose value is the conjugate of this
    public Complex conjugate() {
        return new Complex(re, -im);
    }

    // return a new Complex object whose value is the reciprocal of this
    public Complex reciprocal() {
        double scale = re * re + im * im;
        return new Complex(re / scale, -im / scale);
    }

    // return the real or imaginary part
    public double re() {
        return re;
    }

    public double im() {
        return im;
    }

    // return a / b
    public Complex divides(Complex b) {
        Complex a = this;
        return a.times(b.reciprocal());
    }

    // return a new Complex object whose value is the complex exponential of
    // this
    public Complex exp() {
        return new Complex(Math.exp(re) * Math.cos(im), Math.exp(re) * Math.sin(im));
    }

    // return a new Complex object whose value is the complex sine of this
    public Complex sin() {
        return new Complex(Math.sin(re) * Math.cosh(im), Math.cos(re) * Math.sinh(im));
    }

    // return a new Complex object whose value is the complex cosine of this
    public Complex cos() {
        return new Complex(Math.cos(re) * Math.cosh(im), -Math.sin(re) * Math.sinh(im));
    }

    // return a new Complex object whose value is the complex tangent of this
    public Complex tan() {
        return sin().divides(cos());
    }

    // See Section 3.3.
    @Override
    public boolean equals(Object x) {
        if (x == null) {
            return false;
        }
        if (this.getClass() != x.getClass()) {
            return false;
        }
        Complex that = (Complex) x;
        return (this.re == that.re) && (this.im == that.im);
    }

    // See Section 3.3.
    @Override
    public int hashCode() {
        return Objects.hash(re, im);
    }
}

3 音频播放

3.1 Player.java

package com.xu.music.player.player;

import javax.sound.sampled.AudioFormat;
import javax.sound.sampled.AudioFormat.Encoding;
import javax.sound.sampled.AudioInputStream;

import java.io.File;
import java.net.URL;

/**
 * Java 音频播放
 *
 * @author hyacinth
 * @date 2019年10月31日19:06:39
 */
public interface Player {

    /**
     * Java Music 加载音频
     *
     * @param url 音频文件url
     * @throws Exception 异常
     * @date 2019年10月31日19:06:39
     */
    void load(URL url) throws Exception;

    /**
     * Java Music 加载音频
     *
     * @param file 音频文件
     * @throws Exception 异常
     * @date 2019年10月31日19:06:39
     */
    void load(File file) throws Exception;

    /**
     * Java Music 加载音频
     *
     * @param path 文件路径
     * @throws Exception 异常
     * @date 2019年10月31日19:06:39
     */
    void load(String path) throws Exception;

    /**
     * Java Music 加载音频
     *
     * @param stream 音频文件输入流
     * @throws Exception 异常
     * @date 2019年10月31日19:06:39
     */
    void load(AudioInputStream stream) throws Exception;

    /**
     * Java Music 加载音频
     *
     * @param encoding Encoding
     * @param stream   AudioInputStream
     * @throws Exception 异常
     * @date 2019年10月31日19:06:39
     */
    void load(Encoding encoding, AudioInputStream stream) throws Exception;

    /**
     * Java Music 加载音频
     *
     * @param format AudioFormat
     * @param stream AudioInputStream
     * @throws Exception 异常
     * @date 2019年10月31日19:06:39
     */
    void load(AudioFormat format, AudioInputStream stream) throws Exception;

    /**
     * Java Music 暂停播放
     *
     * @date 2019年10月31日19:06:39
     */
    void pause();

    /**
     * Java Music 继续播放
     *
     * @date 2019年10月31日19:06:39
     */
    void resume();

    /**
     * Java Music 开始播放
     *
     * @throws Exception 异常
     * @date 2019年10月31日19:06:39
     */
    void play() throws Exception;

    /**
     * Java Music 结束播放
     *
     * @description: Java Music 结束播放
     * @date 2019年10月31日19:06:39
     */
    void stop();

}

3.1 XPlayer.java

package com.xu.music.player.player;

import cn.hutool.core.io.IoUtil;
import cn.hutool.core.text.CharSequenceUtil;
import javazoom.spi.mpeg.sampled.file.MpegAudioFileReader;

import javax.sound.sampled.AudioFormat;
import javax.sound.sampled.AudioInputStream;
import javax.sound.sampled.AudioSystem;
import javax.sound.sampled.DataLine;
import javax.sound.sampled.SourceDataLine;

import java.io.File;
import java.io.IOException;
import java.net.URL;
import java.util.LinkedList;

/**
 * Java 音频播放
 *
 * @author hyacinth
 * @date 2019年10月31日19:06:39
 */
public class XPlayer implements Player {

    private static SourceDataLine data = null;

    private static AudioInputStream audio = null;

    public static volatile LinkedList<Double> deque = new LinkedList<>();

    public void put(Double v) {
        synchronized (deque) {
            deque.add(Math.abs(v));
            if (deque.size() > 90) {
                deque.removeFirst();
            }
        }
    }

    private XPlayer() {

    }

    public static XPlayer createPlayer() {
        return XPlayer.SingletonHolder.player;
    }

    private static class SingletonHolder {
        private static final XPlayer player = new XPlayer();
    }

    @Override
    public void load(URL url) throws Exception {
        load(AudioSystem.getAudioInputStream(url));
    }

    @Override
    public void load(File file) throws Exception {
        String name = file.getName();
        if (CharSequenceUtil.endWithIgnoreCase(name, ".mp3")) {
            AudioInputStream stream = new MpegAudioFileReader().getAudioInputStream(file);

            AudioFormat format = stream.getFormat();
            format = new AudioFormat(AudioFormat.Encoding.PCM_SIGNED, format.getSampleRate(), 16, format.getChannels(),
                    format.getChannels() * 2, format.getSampleRate(), false);

            stream = AudioSystem.getAudioInputStream(format, stream);
            load(stream);
        } else if (CharSequenceUtil.endWithIgnoreCase(name, ".flac")) {
            AudioInputStream stream = AudioSystem.getAudioInputStream(file);

            AudioFormat format = stream.getFormat();
            format = new AudioFormat(AudioFormat.Encoding.PCM_SIGNED, format.getSampleRate(), 16, format.getChannels(),
                    format.getChannels() * 2, format.getSampleRate(), false);

            stream = AudioSystem.getAudioInputStream(format, stream);

            load(stream);
        } else {
            load(AudioSystem.getAudioInputStream(file));
        }
    }

    @Override
    public void load(String path) throws Exception {
        load(new File(path));
    }

    @Override
    public void load(AudioInputStream stream) throws Exception {
        DataLine.Info info = new DataLine.Info(SourceDataLine.class, stream.getFormat(), AudioSystem.NOT_SPECIFIED);
        data = (SourceDataLine) AudioSystem.getLine(info);
        data.open(stream.getFormat());
        audio = stream;
    }

    @Override
    public void load(AudioFormat.Encoding encoding, AudioInputStream stream) throws Exception {
        load(AudioSystem.getAudioInputStream(encoding, stream));
    }

    @Override
    public void load(AudioFormat format, AudioInputStream stream) throws Exception {
        load(AudioSystem.getAudioInputStream(format, stream));
    }

    @Override
    public void pause() {

    }

    @Override
    public void resume() {

    }

    @Override
    public void play() throws IOException {
        if (null == audio || null == data) {
            return;
        }
        data.start();
        byte[] buf = new byte[4];
        int channels = audio.getFormat().getChannels();
        float rate = audio.getFormat().getSampleRate();
        while (audio.read(buf) != -1) {
            if (channels == 2) {//立体声
                if (rate == 16) {
                    put((double) ((buf[1] << 8) | buf[0]));//左声道
                    //put((double) ((buf[3] << 8) | buf[2]));//右声道
                } else {
                    put((double) buf[1]);//左声道
                    put((double) buf[3]);//左声道
                    //put((double) buf[2]);//右声道
                    //put((double) buf[4]);//右声道
                }
            } else {//单声道
                if (rate == 16) {
                    put((double) ((buf[1] << 8) | buf[0]));
                    put((double) ((buf[3] << 8) | buf[2]));
                } else {
                    put((double) buf[0]);
                    put((double) buf[1]);
                    put((double) buf[2]);
                    put((double) buf[3]);
                }
            }
            data.write(buf, 0, 4);
        }
    }

    @Override
    public void stop() {
        if (null == audio || null == data) {
            return;
        }
        IoUtil.close(audio);
        data.stop();
        IoUtil.close(data);
    }

}

4 显示频谱

package com.xu.music.player.test;

import cn.hutool.core.collection.CollUtil;
import org.eclipse.swt.SWT;
import org.eclipse.swt.graphics.Color;
import org.eclipse.swt.graphics.GC;
import org.eclipse.swt.graphics.Rectangle;
import org.eclipse.swt.layout.FillLayout;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Shell;

import java.io.File;
import java.util.LinkedList;
import java.util.List;
import java.util.Random;
import java.util.Timer;
import java.util.TimerTask;

import com.xu.music.player.fft.Complex;
import com.xu.music.player.fft.FFT;
import com.xu.music.player.player.Player;
import com.xu.music.player.player.XPlayer;

/**
 * SWT Composite 绘画
 *
 * @date 2024年2月2日19点27分
 * @since V1.0.0.0
 */
public class SwtDraw {

    private Shell shell = null;

    private Display display = null;

    private Composite composite = null;

    private final Random random = new Random();

    private final List<Integer> spectrum = new LinkedList<>();

    public static void main(String[] args) {
        SwtDraw test = new SwtDraw();
        test.open();
    }

    /**
     * 测试播放
     */
    public void play() {
        try {
            Player player = XPlayer.createPlayer();
            player.load(new File("D:\\Kugou\\梦涵 - 加减乘除.mp3"));
            new Thread(() -> {
                try {
                    player.play();
                } catch (Exception e) {
                    throw new RuntimeException(e);
                }
            }).start();
        } catch (Exception e) {

        }
    }

    /**
     * 打开 SWT 界面
     *
     * @date 2024年2月2日19点27分
     * @since V1.0.0.0
     */
    public void open() {
        display = Display.getDefault();
        createContents();
        shell.open();
        shell.layout();
        play();
        task();
        while (!shell.isDisposed()) {
            if (!display.readAndDispatch()) {
                display.sleep();
            }
        }
    }

    /**
     * 设置 SWT Shell内容
     *
     * @date 2024年2月2日19点27分
     * @since V1.0.0.0
     */
    protected void createContents() {
        shell = new Shell(display);
        shell.setSize(900, 500);
        shell.setLayout(new FillLayout(SWT.HORIZONTAL));

        // 创建一个Composite
        composite = new Composite(shell, SWT.NONE);

        // 添加绘图监听器
        composite.addPaintListener(listener -> {
            GC gc = listener.gc;

            int width = listener.width;
            int height = listener.height;
            int length = width / 25;

            if (spectrum.size() >= length) {
                for (int i = 0; i < length; i++) {
                    draw(gc, i * 25, height, 25, spectrum.get(i));
                }
            }

        });

    }

    /**
     * 模拟 需要绘画的数据 任务
     *
     * @date 2024年2月2日19点27分
     * @since V1.0.0.0
     */
    public void task() {
        Timer timer = new Timer(true);
        timer.scheduleAtFixedRate(new TimerTask() {
            @Override
            public void run() {
                display.asyncExec(() -> {
                    if (!composite.isDisposed()) {
                        // 在这里调用你更新数据的方法
                        updateData();
                        // 重绘
                        composite.redraw();
                    }
                });
            }
        }, 0, 100);
    }

    /**
     * 模拟 更新绘画的数据
     *
     * @date 2024年2月2日19点27分
     * @since V1.0.0.0
     */
    public void updateData() {
        spectrum.clear();
        if (CollUtil.isEmpty(XPlayer.deque)) {
            return;
        }

        Complex[] x = new Complex[XPlayer.deque.size()];
        for (int i = 0; i < x.length; i++) {
            try {
                x[i] = new Complex(XPlayer.deque.get(i), 0);
            } catch (Exception e) {
                x[i] = new Complex(0, 0);
            }
        }

        Double[] value = FFT.array(x);
        for (double v : value) {
            spectrum.add((int) v);
        }

    }

    /**
     * Composite 绘画
     *
     * @param gc     GC
     * @param x      x坐标
     * @param y      y坐标
     * @param width  宽度
     * @param height 高度
     * @date 2024年2月2日19点27分
     * @since V1.0.0.0
     */
    private void draw(GC gc, int x, int y, int width, int height) {
        // 设置条形的颜色
        Color color = new Color(display, random.nextInt(255), random.nextInt(255), random.nextInt(255));
        gc.setBackground(color);
        // 绘制条形
        Rectangle draw = new Rectangle(x, y, width, -height);
        gc.fillRectangle(draw);
        // 释放颜色资源
        color. Dispose();
    }

}

5 结果

请添加图片描述

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.coloradmin.cn/o/1462681.html

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈,一经查实,立即删除!

相关文章

【算法与数据结构】200、695、LeetCode岛屿数量(深搜+广搜) 岛屿的最大面积

文章目录 一、200、岛屿数量1.1 深度优先搜索DFS1.2 广度优先搜索BFS 二、695、岛屿的最大面积2.1 深度优先搜索DFS2.2 广度优先搜索BFS 三、完整代码 所有的LeetCode题解索引&#xff0c;可以看这篇文章——【算法和数据结构】LeetCode题解。 一、200、岛屿数量 1.1 深度优先搜…

C#算法(12)—对图像像素做X/Y方向的偏移

我们在上位机开发领域有时候需要对获取的图像的像素做整体的偏移,比如所有像素在X方向上偏移几个像素,或者所有像素在Y方向上偏移几个像素,本文就是开发了像素整体偏移算法来解决这个问题。 比如有一个图像大小为3*3,像素值如下图1,如果我想实现将这个幅图像的像素整体往右…

[ Python+OpenCV+Mediapipe ] 实现对象识别

一、写在前面 本文所用例子为个人学习的小结&#xff0c;如有不足之处请各位多多海涵&#xff0c;欢迎小伙伴一起学习进步&#xff0c;如果想法可在评论区指出&#xff0c;我会尽快回复您&#xff0c;不胜感激&#xff01; 所公布代码或截图均为运行成功后展示。 二、本文内容…

计网 - 域名解析的工作流程

文章目录 Pre引言1. DNS是什么2. 域名结构3. 域名解析的工作流程4. 常见的DNS记录类型5. DNS安全6. 未来的发展趋势 Pre 计网 - DNS 域名解析系统 引言 在我们日常使用互联网时&#xff0c;经常会输入各种域名来访问网站、发送电子邮件或连接其他网络服务。然而&#xff0c;我…

构建React TodoList应用:管理你的任务清单

构建React TodoList应用&#xff1a;管理你的任务清单 在日常生活和工作中&#xff0c;任务管理是一项至关重要的任务。为了更好地组织和管理我们的工作和生活&#xff0c;我们需要一个高效而简单的任务管理工具。本文将介绍如何使用React框架构建一个功能丰富的TodoList应用&…

C++动态分配内存知识点!

个人主页&#xff1a;PingdiGuo_guo 收录专栏&#xff1a;C干货专栏 大家好呀&#xff0c;又是分享干货的时间&#xff0c;今天我们来学习一下动态分配内存。 文章目录 1.动态分配内存的思想 2.动态分配内存的概念 2.1内存分配函数 2.2动态内存的申请和释放 2.3内存碎片问…

新手学习Cesium的几点建议

Cesium是当前非常火热的三维数字地球开发框架&#xff0c;很多公司基于Cesium做项目以及形成了自己的产品&#xff0c;关于Cesium的学习&#xff0c;有诸多网站、书籍、学习资料甚至培训教材&#xff0c;这里不再详细推荐&#xff0c;从学习Cesium的角度&#xff0c;资料和教程…

web开发中的长度单位详解

1、长度单位包括哪些&#xff1f; 长度单位&#xff1a;例如&#xff0c;厘米、毫米、英寸。还有像素&#xff08;px&#xff09;&#xff0c;元素的字体高度&#xff08;em&#xff09;、字母x的高度&#xff08;ex&#xff09;、百分比&#xff08;%&#xff09;等这些单位&…

[ 2024春节 Flink打卡 ] -- Paimon

2024&#xff0c;游子未归乡。工作需要&#xff0c;flink coding。觉知此事要躬行&#xff0c;未休&#xff0c;特记 Flink 社区希望能够将 Flink 的 Streaming 实时计算能力和 Lakehouse 新架构优势进一步结合&#xff0c;推出新一代的 Streaming Lakehouse 技术&#xff0c;…

MySQL加锁策略详解

我们主要从三个方面来讨论这个问题&#xff1a; 啥时候加&#xff1f;如何加&#xff1f;什么时候该加什么时候不该加&#xff1f; 1、啥时候加 1.1 显式锁 MySQL 的加锁可以分为显式加锁和隐式加锁&#xff0c;显式加锁我们比较好识别的&#xff0c;因为他往往直接体现在 S…

25-k8s集群中-RBAC用户角色资源权限

一、RBAC概述 1&#xff0c;k8s集群的交互逻辑&#xff08;简单了解&#xff09; 我们通过k8s各组件架构&#xff0c;指导各个组件之间是使用https进行数据加密及交互的&#xff0c;那么同理&#xff0c;我们作为“使用”k8s的各种资源&#xff0c;也是通过https进行数据加密的…

4 编写达梦插件包

1、初始化达梦数据库 具体脚本可以参考: https://github.com/nacos-group/nacos-plugin/blob/develop/nacos-datasource-plugin-ext/nacos-dm-datasource-plugin-ext/src/main/resources/schema/nacos-dm.sql

国际阿里云,想要使用怎么解决支付问题

在国内我们很多时候都需要用到国际阿里云&#xff0c;在国际阿里云需要使用就需要支付&#xff0c;自己办理visa卡比较麻烦&#xff0c;那么我们可以使用虚拟卡&#xff0c;虚拟卡办理快速简单 真实测评使用Fomepay的5347支持国际阿里云的支付&#xff0c;秒下卡&#xff0c;不…

Talk|北京大学杨灵:扩散模型的算法创新与领域应用

本期为TechBeat人工智能社区第572期线上Talk。 北京时间2月21日(周三)20:00&#xff0c;北京大学博士生—杨灵的Talk已准时在TechBeat人工智能社区开播&#xff01; 他与大家分享的主题是: “扩散模型的算法创新与领域应用”&#xff0c;系统地介绍了他的团队基于扩散模型的算法…

vue3在router跳转路由时,params失效问题

vue-router重要提示。 解决方案&#xff1a; 1. 使用query传参 但是变量会直接暴露在url中 2.用store或localStorage这种办法暂存一下。

书生·浦语大模型实战营第二节课作业

使用 InternLM-Chat-7B 模型生成 300 字的小故事&#xff08;基础作业1&#xff09;。 熟悉 hugging face 下载功能&#xff0c;使用 huggingface_hub python 包&#xff0c;下载 InternLM-20B 的 config.json 文件到本地&#xff08;基础作业2&#xff09;。 下载过程 进阶…

Vue+SpringBoot打造校园二手交易系统

目录 一、摘要1.1 项目介绍1.2 项目录屏 二、功能模块2.1 数据中心模块2.2 二手商品档案管理模块2.3 商品预约管理模块2.4 商品预定管理模块2.5 商品留言板管理模块2.6 商品资讯管理模块 三、实体类设计3.1 用户表3.2 二手商品表3.3 商品预约表3.4 商品预定表3.5 留言表3.6 资讯…

蓝桥杯备赛系列——倒计时50天!

蓝桥杯备赛系列 倒计时50天&#xff01; 前缀和和差分 知识点 **前缀和数组&#xff1a;**假设原数组用a[i]表示&#xff0c;前缀和数组用sum[i]表示&#xff0c;那么sum[i]表示的是原数组前i项之和&#xff0c;注意一般用前缀和数组时&#xff0c;原数组a[i]的有效下标是从…

PotPlayer+Alist挂载并播放网盘视频

文章目录 说明技术WebDAVPotPlayer 操作步骤一&#xff1a;Alist开启WebDAV代理二&#xff1a;PotPlayer连接Alist 说明 Alist网页端播放视频受限&#xff0c;主要是文件大于20MB&#xff0c;由于官方限制&#xff0c;无法播放需要使用user-agent修改插件&#xff0c;设置百度…

ES项目应用

配置: ES存储了2-3亿条&#xff0c;几百GB ES集群有5 个节点 2主2副 ES返回数据量窗口大小设置 index.max_result_window 深度翻页 1.from size 方式 2.scroll相当于维护了一份当前索引段的快照信息&#xff0c;这个快照信息是你执行这个scroll查询时的快照。在这个查询后的任…