简体   繁体   English

将多个MP3曲目合并为一个曲目

[英]Merging several MP3 tracks in to one track

Well frankly, I don't know where to begin with this one. 坦率地说,我不知道从哪开始。 I have to have a program that merges a few mp3 tracks in to one track (not concatenate, but actually merge them, sorta like playing a few audiotracks all at once). 我必须有一个程序,可以将几个mp3曲目合并到一个曲目中(不是串联,而是实际上合并它们,有点像一次播放一些音轨)。 Is there a library available or another basic program that will automatically do this? 是否有可用的库或其他自动执行此操作的基本程序? I also need to change the volume of each track, and I don't know where to start with that too. 我还需要更改每个曲目的音量,我也不知道从哪里开始。

Speed and efficiency is a major factor in this, so I can't just do the lazy thing and play them and capture it. 速度和效率是其中的一个主要因素,所以我不能只是做一些懒惰的事情,然后播放并捕获它。

I will try to draw some general steps that you can follow: 我将尝试绘制一些您可以遵循的一般步骤:

  1. You will need to decompress your mp3 files into raw audio. 您将需要将mp3文件解压缩为原始音频。 Depending on what kind of application you are developing you could use madlib (GPL) or ffmpeg (LGPL) for example. 例如,根据开发的应用程序类型,可以使用madlib (GPL)或ffmpeg (LGPL)。

  2. You will need to normalize all your tracks into the same frequency (re-sampling), and decide on an output bit-depth . 您将需要将所有轨道归一化为相同的频率 (重新采样),并确定输出位深度

  3. Now you can mix all your tracks. 现在,您可以混合所有曲目。 Assuming that you have 2 channels, the basic idea is to compute an average of all samples of the right channel of your tracks, then do the same with the left channel. 假设您有2个通道,基本思想是计算轨道右通道的所有样本的平均值,然后对左通道进行相同的操作。 There are many approaches for this and here you will have to decide on a trade-off in performance/quality for your results. 有很多方法可以解决这个问题,在这里您将不得不权衡结果的性能/质量。 For example some developers will prefer to do the mix operation on float point, in order to deal with clipping (d)effects , but others may advise against it because it affects performance. 例如,一些开发人员可能更喜欢在浮点上执行混合操作,以处理裁剪(d)效果 ,但其他开发人员可能建议不要这样做,因为它会影响性能。 There is a good post about integer-based mixing here (it has been referenced several times in SO). 关于基于整数的混合, 这里有一篇很好的文章(在SO中已经多次引用)。 Also before (or during) this step you could implement some audio normalization process by using a multiplier on the samples of the channel that you want to normalize. 同样,在此步骤之前(或之中),您可以通过在要标准化的通道样本上使用乘法器来执行一些音频标准化过程。

  4. Finally you can compress your mixed audio again. 最后,您可以再次压缩混合音频。 You could use lame for example on this task, or ffmpeg one more time. 例如,您可以在此任务上使用la脚,或者再次使用ffmpeg。

There are many DSP packages for linux out there that might do several (or all) of these steps for you. 那里有许多适用于Linux的DSP软件包,它们可能为您完成了几个(或全部)这些步骤。 One GPL project that comes to my mind is VLC (VideoLan Client). 我想到的一个GPL项目是VLC (VideoLan客户端)。 You could try to call it as an external process or schedule it with VLM (VideoLan Manager). 您可以尝试将其称为外部进程,也可以使用VLM (VideoLan Manager)对其进行计划。 From the documentation : 文档中

Scheduled broadcasting: 预定广播:

new my_media broadcast enabled
setup my_media input my_video.mpeg input my_other_movie.mpeg 
setup my_media output #rtp{mux=ts,dst=239.255.1.1,sdp=sap://,name="My Media"}

Naturally, the output stream in VLC can also be a local file. 当然,VLC中的输出流也可以是本地文件。

Edit: I also found a question on SO where the accepted answer can be useful to you, it recommends using Sox . 编辑:我还在SO上发现了一个问题,在该问题上可以接受的答案对您有用,它建议使用Sox From the homepage: 从首页:

SoX is a cross-platform (Windows, Linux, MacOS X, etc.) command line utility that can convert various formats of computer audio files in to other formats. SoX是跨平台(Windows,Linux,MacOS X等)命令行实用程序,可以将各种格式的计算机音频文件转换为其他格式。 It can also apply various effects to these sound files(...) 它还可以对这些声音文件应用各种效果(...)

You could mix them as separate tracks in audacity. 您可以将它们混合成大胆的单独曲目。 Is it a requirement that you write the code yourself? 您需要自己编写代码吗?

when you have the data streams in raw form, you can treat the midpoint of possible sample values as zero.. (8bit samples.. 256 values possible.. 127 is zero.. samples at 0 or 255 are at max volume). 当您具有原始格式的数据流时,可以将可能的样本值的中点视为零。(8位样本。可能的256个值。127为零。0或255的样本为最大音量)。

to adjust volume, shift, multiply to increase volume, divide to decrease (be mindful of clipping) 调整音量,移位,乘以增加音量,除以减少音量(请注意裁剪)

to mix, just add values of each stream, one sample at a time (mindful of clipping). 进行混合,只需将每个流的值相加一次即可(注意剪辑)。

Here is a good link too: http://www.4front-tech.com/pguide/audio.html 这也是一个很好的链接: http : //www.4front-tech.com/pguide/audio.html

This can be done real-time, given enough processor performance. 只要有足够的处理器性能,就可以实时完成此操作。 You need to be able to read the mp3 files, some real-time software mp3 decoder blocks (similar to what one would use to make your own mp3 player/visualizer) that are fast enough to run N copies/threads in real-time, possibly some DSP sample rate conversion blocks, and a DSP mixer block. 您需要能够读取mp3文件,一些实时软件mp3解码器块(类似于用来制作自己的mp3播放器/可视化器的软件),其速度足以实时运行N个副本/线程,可能还有一些DSP采样率转换模块和一个DSP混频器模块。 All software. 所有软件。 Tie all the processing threads together with queues and data fifos. 将所有处理线程与队列和数据FIFO绑定在一起。

There my be library code available for some of these blocks (decoders, resamplers), but beware potential licensing restrictions. 我的库代码可用于其中一些模块(解码器,重采样器),但要注意潜在的许可限制。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM